static void got_line(char *cmd_buffer) { char *cmd; if (!cmd_buffer) { cleanup(); exit(0); } if (cmd_buffer[0]) { cmd = cmd_expand(cmd_buffer); if (cmd) { add_history_dedup(cmd); if (!handle_internal_command(cmd)) submit_server_command(cmd); free(cmd); } else add_history_dedup(cmd_buffer); } free(cmd_buffer); }
/*ARGSUSED*/ void dowhich(Char **v, struct command *c) { int rv = TRUE; USE(c); /* * We don't want to glob dowhich args because we lose quoteing * E.g. which \ls if ls is aliased will not work correctly if * we glob here. */ while (*++v) rv &= cmd_expand(*v, NULL); if (!rv) setcopy(STRstatus, STR1, VAR_READWRITE); }
void launcher (char *commbuff, FlowSource_t *FlowSource, char *process, int expire) { FlowSource_t *fs; struct sigaction act; char *args[MAXARGS]; int pid, stat; srecord_t *InfoRecord; InfoRecord = (srecord_t *)commbuff; syslog(LOG_INFO, "Launcher: Startup. auto-expire %s", expire ? "enabled" : "off" ); done = launch = child_exit = 0; // process may be NULL, if we only expire data files if ( process ) { char *cmd = NULL; srecord_t TestRecord; // check for valid command expansion strncpy(TestRecord.fname, "test", FNAME_SIZE-1); TestRecord.fname[FNAME_SIZE-1] = 0; strncpy(TestRecord.tstring, "200407110845", 15); TestRecord.tstring[15] = 0; TestRecord.tstamp = 1; fs = FlowSource; while ( fs ) { cmd = cmd_expand(&TestRecord, fs->Ident, fs->datadir, process); if ( cmd == NULL ) { syslog(LOG_ERR, "Launcher: ident: %s, Unable to expand command: '%s'", fs->Ident, process); exit(255); } fs = fs->next; } } /* Signal handling */ memset((void *)&act,0,sizeof(struct sigaction)); act.sa_handler = SignalHandler; sigemptyset(&act.sa_mask); act.sa_flags = 0; sigaction(SIGCHLD, &act, NULL); // child process terminated sigaction(SIGTERM, &act, NULL); // we are done sigaction(SIGINT, &act, NULL); // we are done sigaction(SIGHUP, &act, NULL); // run command while ( !done ) { // sleep until we get signaled syslog(LOG_DEBUG, "Launcher: Sleeping"); select(0, NULL, NULL, NULL, NULL); syslog(LOG_DEBUG, "Launcher: Wakeup"); if ( launch ) { // SIGHUP launch = 0; if ( process ) { char *cmd = NULL; fs = FlowSource; while ( fs ) { // Expand % placeholders cmd = cmd_expand(InfoRecord, fs->Ident, fs->datadir, process); if ( cmd == NULL ) { syslog(LOG_ERR, "Launcher: ident: %s, Unable to expand command: '%s'", fs->Ident, process); continue; } // printf("Launcher: run command: '%s'\n", cmd); syslog(LOG_DEBUG, "Launcher: ident: %s run command: '%s'", fs->Ident, cmd); // prepare args array cmd_parse(cmd, args); if ( args[0] ) cmd_execute(args); // do not flood the system with new processes sleep(1); // else cmd_parse already reported the error free(cmd); fs = fs->next; } } fs = FlowSource; while ( fs ) { if ( expire ) do_expire(fs->datadir); fs = fs->next; } } if ( child_exit ) { syslog(LOG_INFO, "laucher child exit %d childs.", child_exit); while ( (pid = waitpid (-1, &stat, WNOHANG)) > 0 ) { if ( WIFEXITED(stat) ) { syslog(LOG_DEBUG, "launcher child %i exit status: %i", pid, WEXITSTATUS(stat)); } if ( WIFSIGNALED(stat) ) { syslog(LOG_WARNING, "laucher child %i died due to signal %i", pid, WTERMSIG(stat)); } child_exit--; } syslog(LOG_INFO, "laucher waiting childs done. %d childs", child_exit); child_exit = 0; } if ( done ) { syslog(LOG_INFO, "Launcher: Terminating."); } } waitpid (-1, &stat, 0); // we are done syslog(LOG_INFO, "Launcher: exit."); } // End of launcher