* exec_command * Execute 'command' with 'arg' as its argument. * if !arg command is started with no arguments * Before we call execl we need to close all the file handles * that the fork inherited from the parent in order not to pass * the open handles on to the shell */
| 81 | * the open handles on to the shell |
| 82 | */ |
| 83 | static void exec_command(struct context *cnt, char *command, char *filename, int filetype) |
| 84 | { |
| 85 | char stamp[PATH_MAX]; |
| 86 | mystrftime(cnt, stamp, sizeof(stamp), command, &cnt->current_image->timestamp_tv, filename, filetype); |
| 87 | |
| 88 | if (!fork()) { |
| 89 | |
| 90 | /* Detach from parent */ |
| 91 | setsid(); |
| 92 | |
| 93 | execl("/bin/sh", "sh", "-c", stamp, " &", NULL); |
| 94 | |
| 95 | /* if above function succeeds the program never reach here */ |
| 96 | MOTION_LOG(ALR, TYPE_EVENTS, SHOW_ERRNO |
| 97 | ,_("Unable to start external command '%s'"), stamp); |
| 98 | |
| 99 | exit(1); |
| 100 | } |
| 101 | |
| 102 | MOTION_LOG(DBG, TYPE_EVENTS, NO_ERRNO |
| 103 | ,_("Executing external command '%s'"), stamp); |
| 104 | } |
| 105 | |
| 106 | /* |
| 107 | * Event handlers |
no test coverage detected