Line data Source code
1 : /* 2 : This file is part of TALER 3 : (C) 2018 Taler Systems SA 4 : 5 : TALER is free software; you can redistribute it and/or modify 6 : it under the terms of the GNU General Public License as 7 : published by the Free Software Foundation; either version 3, or 8 : (at your option) any later version. 9 : 10 : TALER is distributed in the hope that it will be useful, but 11 : WITHOUT ANY WARRANTY; without even the implied warranty of 12 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 : GNU General Public License for more details. 14 : 15 : You should have received a copy of the GNU General Public 16 : License along with TALER; see the file COPYING. If not, see 17 : <http://www.gnu.org/licenses/> 18 : */ 19 : /** 20 : * @file testing/testing_api_cmd_signal.c 21 : * @brief command(s) to send signals to processes. 22 : * @author Marcello Stanisci 23 : */ 24 : #include "platform.h" 25 : #include "taler_json_lib.h" 26 : #include <gnunet/gnunet_curl_lib.h> 27 : #include "taler_testing_lib.h" 28 : 29 : 30 : /** 31 : * State for a "signal" CMD. 32 : */ 33 : struct SignalState 34 : { 35 : /** 36 : * The process to send the signal to. 37 : */ 38 : struct GNUNET_OS_Process *process; 39 : 40 : /** 41 : * The signal to send to the process. 42 : */ 43 : int signal; 44 : }; 45 : 46 : /** 47 : * Run the command. 48 : * 49 : * @param cls closure. 50 : * @param cmd the command to execute. 51 : * @param is the interpreter state. 52 : */ 53 : static void 54 0 : signal_run (void *cls, 55 : const struct TALER_TESTING_Command *cmd, 56 : struct TALER_TESTING_Interpreter *is) 57 : { 58 0 : struct SignalState *ss = cls; 59 : 60 0 : GNUNET_break (0 == GNUNET_OS_process_kill 61 : (ss->process, ss->signal)); 62 0 : GNUNET_log (GNUNET_ERROR_TYPE_INFO, 63 : "Signaling '%d'..\n", 64 : ss->signal); 65 0 : sleep (6); 66 0 : TALER_TESTING_interpreter_next (is); 67 0 : } 68 : 69 : 70 : /** 71 : * Cleanup the state from a "signal" CMD. 72 : * 73 : * @param cls closure. 74 : * @param cmd the command which is being cleaned up. 75 : */ 76 : static void 77 0 : signal_cleanup (void *cls, 78 : const struct TALER_TESTING_Command *cmd) 79 : { 80 0 : struct SignalState *ss = cls; 81 : 82 0 : GNUNET_free (ss); 83 0 : } 84 : 85 : 86 : /** 87 : * Create a "signal" CMD. 88 : * 89 : * @param label command label. 90 : * @param process handle to the process to signal. 91 : * @param signal signal to send. 92 : * 93 : * @return the command. 94 : */ 95 : struct TALER_TESTING_Command 96 0 : TALER_TESTING_cmd_signal (const char *label, 97 : struct GNUNET_OS_Process *process, 98 : int signal) 99 : { 100 : struct SignalState *ss; 101 : 102 0 : ss = GNUNET_new (struct SignalState); 103 0 : ss->process = process; 104 0 : ss->signal = signal; 105 : 106 : 107 0 : struct TALER_TESTING_Command cmd = { 108 : .cls = ss, 109 : .label = label, 110 : .run = &signal_run, 111 : .cleanup = &signal_cleanup 112 : }; 113 : 114 0 : return cmd; 115 : }