Skip to content
Snippets Groups Projects
Commit a008ed08 authored by Michael Tüxen's avatar Michael Tüxen
Browse files

Support a cleanup command without an init command.

Ensure that
 0.00 socket(..., SOCK_STREAM, IPPROTO_TCP) = 3
+1.00 close(3) = -1
      `echo Cleanup`
works
parent 4aee6d8d
No related branches found
No related tags found
No related merge requests found
......@@ -71,6 +71,9 @@ const int MAX_SPIN_USECS = 20;
/* Global bool init_cmd_exed */
bool init_cmd_exed = false;
/* Global bool init_cmd_exists */
bool init_cmd_exists = false;
/* Final command to always execute at end of script, in order to clean up: */
const char *cleanup_cmd;
......@@ -541,7 +544,7 @@ void signal_handler(int signal_number)
*/
int run_cleanup_command(void)
{
if (cleanup_cmd != NULL && init_cmd_exed) {
if (cleanup_cmd != NULL && (!init_cmd_exists || init_cmd_exed)) {
char *error = NULL;
if (safe_system(cleanup_cmd, &error)) {
......@@ -562,6 +565,10 @@ void run_script(struct config *config, struct script *script)
struct netdev *netdev = NULL;
struct event *event = NULL;
init_cmd_exed = false;
if (script->init_command != NULL)
init_cmd_exists = true;
if (signal(SIGINT, signal_handler) == SIG_ERR) {
die("could not set up signal handler for SIGINT!");
}
......@@ -597,7 +604,6 @@ void run_script(struct config *config, struct script *script)
wire_client_init(state->wire_client, config, script, state);
}
init_cmd_exed = false;
if (script->init_command != NULL) {
if (safe_system(script->init_command->command_line,
&error)) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment