Skip to content

Commit

Permalink
#164 add environment variable WD_MESSAGE to success cmd
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-courtis committed Nov 10, 2024
1 parent 9cdc06b commit bd5de3e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion inc/process.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pid_t pid_active_server(void);

void pid_file_create(void);

void spawn_sh_cmd(const char * const command);
void spawn_sh_cmd(const char * const command, char * const message);

// exit; caller should return afterwards
void wd_exit(int __status);
Expand Down
2 changes: 1 addition & 1 deletion src/layout.c
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ void handle_success(void) {
log_info("\nExecuting CHANGE_SUCCESS_CMD:");
log_info(" %s", cfg->change_success_cmd);

spawn_sh_cmd(cfg->change_success_cmd);
spawn_sh_cmd(cfg->change_success_cmd, "handle_success");
}

log_info("\nChanges successful");
Expand Down
8 changes: 7 additions & 1 deletion src/process.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,11 @@ void pid_file_create(void) {
free(path);
}

void spawn_sh_cmd(const char * const command) {
void spawn_sh_cmd(const char * const command, char * const message) {

// experiments show that environment variable length tops out at 128k: variable itself plus contents
message[1024 * 120] = '\0';

pid_t pid = fork();
if (pid < 0) {
log_error_errno("\nfailed to fork");
Expand All @@ -121,6 +125,8 @@ void spawn_sh_cmd(const char * const command) {
sa.sa_handler = SIG_DFL;
sigaction(SIGCHLD, &sa, NULL);

setenv("WD_MESSAGE", message, 1);

// execute command in the child process
execl("/bin/sh", "/bin/sh", "-c", command, (char *)NULL);
log_error_errno("\nfailed to execute /bin/sh");
Expand Down

0 comments on commit bd5de3e

Please sign in to comment.