testing_api_cmd_signal.c (2630B)
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 "taler/platform.h" 25 #include "taler/taler_json_lib.h" 26 #include <gnunet/gnunet_curl_lib.h> 27 #include "taler/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 signal_run (void *cls, 55 const struct TALER_TESTING_Command *cmd, 56 struct TALER_TESTING_Interpreter *is) 57 { 58 struct SignalState *ss = cls; 59 60 GNUNET_break (0 == GNUNET_OS_process_kill 61 (ss->process, ss->signal)); 62 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 63 "Signaling '%d'..\n", 64 ss->signal); 65 TALER_TESTING_interpreter_next (is); 66 } 67 68 69 /** 70 * Cleanup the state from a "signal" CMD. 71 * 72 * @param cls closure. 73 * @param cmd the command which is being cleaned up. 74 */ 75 static void 76 signal_cleanup (void *cls, 77 const struct TALER_TESTING_Command *cmd) 78 { 79 struct SignalState *ss = cls; 80 81 GNUNET_free (ss); 82 } 83 84 85 /** 86 * Create a "signal" CMD. 87 * 88 * @param label command label. 89 * @param process handle to the process to signal. 90 * @param signal signal to send. 91 * 92 * @return the command. 93 */ 94 struct TALER_TESTING_Command 95 TALER_TESTING_cmd_signal (const char *label, 96 struct GNUNET_OS_Process *process, 97 int signal) 98 { 99 struct SignalState *ss; 100 101 ss = GNUNET_new (struct SignalState); 102 ss->process = process; 103 ss->signal = signal; 104 105 { 106 struct TALER_TESTING_Command cmd = { 107 .cls = ss, 108 .label = label, 109 .run = &signal_run, 110 .cleanup = &signal_cleanup 111 }; 112 113 return cmd; 114 } 115 }