Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions gtests/net/packetdrill/run.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <arpa/inet.h>
#include <errno.h>
#include <netinet/in.h>
#include <libgen.h>
#include <sched.h>
#include <signal.h>
#include <stdlib.h>
Expand Down Expand Up @@ -541,14 +542,22 @@ int run_cleanup_command(void)
{
if (cleanup_cmd != NULL && init_cmd_exed) {
char *error = NULL;
char cwd[300];
char *sp = NULL;

getcwd((char *)&cwd, sizeof(cwd));
sp = strdup(script_path);
chdir(dirname(sp));
free(sp);
if (safe_system(cleanup_cmd, &error)) {
fprintf(stderr,
"%s: error executing cleanup command: %s\n",
script_path, error);
free(error);
chdir(cwd);
return STATUS_ERR;
}
chdir(cwd);
}
return STATUS_OK;
}
Expand Down Expand Up @@ -594,13 +603,22 @@ void run_script(struct config *config, struct script *script)

init_cmd_exed = false;
if (script->init_command != NULL) {
char cwd[300];
char *sp = NULL;

getcwd((char *)&cwd, sizeof(cwd));
sp = strdup(state->config->script_path);
chdir(dirname(sp));
free(sp);
if (safe_system(script->init_command->command_line,
&error)) {
asprintf(&error, "%s: error executing init command: %s\n",
config->script_path, error);
free(error);
chdir(cwd);
exit(EXIT_FAILURE);
}
chdir(cwd);
init_cmd_exed = true;
}

Expand Down
10 changes: 10 additions & 0 deletions gtests/net/packetdrill/run_command.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@
void run_command_event(
struct state *state, struct event *event, struct command_spec *command)
{
char *script_path = NULL;
char cwd[300];

getcwd((char *)&cwd, sizeof(cwd));
script_path = strdup(state->config->script_path);
chdir(dirname(script_path));
free(script_path);

DEBUGP("%d: command: `%s`\n", event->line_number,
command->command_line);

Expand All @@ -45,9 +53,11 @@ void run_command_event(
char *error = NULL;
if (safe_system(command->command_line, &error))
goto error_out;
chdir(cwd);
return;

error_out:
chdir(cwd);
die("%s:%d: error executing `%s` command: %s\n",
state->config->script_path, event->line_number,
command->command_line, error);
Expand Down