From a008ed08374a3aa00a1fac82f484349770035af0 Mon Sep 17 00:00:00 2001 From: Michael Tuexen <tuexen@fh-muenster.de> Date: Thu, 2 Aug 2018 16:47:15 +0200 Subject: [PATCH] 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 --- gtests/net/packetdrill/run.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/gtests/net/packetdrill/run.c b/gtests/net/packetdrill/run.c index 151301ed..b2a4db22 100644 --- a/gtests/net/packetdrill/run.c +++ b/gtests/net/packetdrill/run.c @@ -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)) { -- GitLab