static void test_msm_removePid(void) { pid_t pid; CU_ASSERT_EQUAL(msm_removePid(5), LDM7_NOENT); log_clear(); CU_ASSERT_EQUAL(msm_removePid(1), 0); CU_ASSERT_EQUAL(msm_getPid(IDS, &pid), LDM7_NOENT); log_clear(); }
/** * Indicates if a particular multicast LDM sender is running. * * @pre {Multicast LDM sender PID map is locked for writing}. * @param[in] feedtype Feed-type of multicast group. * @retval 0 The multicast LDM sender associated with the given * multicast group is running. * @retval LDM7_NOENT No such process. * @retval LDM7_SYSTEM System error. `log_start()` called. */ static Ldm7Status mlsm_isRunning( const feedtypet feedtype) { pid_t pid; int status = msm_getPid(feedtype, &pid); if (status == 0) { if (kill(pid, 0) == 0) { /* Can signal the process */ status = 0; } else { /* Can't signal the process */ uwarn("According to my information, the PID of the multicast LDM " "sender associated with feed-type %s is %d -- but that " "process can't be signaled by this process. I'll assume " "the relevant multicast LDM sender is not running.", s_feedtypet(feedtype), pid); (void)msm_removePid(pid); // don't care if it exists or not status = LDM7_NOENT; } } return status; }
static pid_t reap( pid_t pid, int options) { pid_t wpid = 0; int status = 0; #ifdef HAVE_WAITPID wpid = waitpid(pid, &status, options); #else if(options == 0) { wpid = wait(&status); } /* customize here for older systems, use wait3 or whatever */ #endif if (wpid == -1) { if (!(errno == ECHILD && pid == -1)) /* Only complain when relevant */ serror("waitpid"); return -1; } /* else */ if (wpid != 0) { char command[512]; #if !defined(WIFSIGNALED) && !defined(WIFEXITED) #error "Can't decode wait status" #endif #if defined(WIFSTOPPED) if (WIFSTOPPED(status)) { int n = lcf_getCommandLine(wpid, command, sizeof(command)); if (n == -1) { log_add("Couldn't get command-line of EXEC process " "%ld", wpid); log_log(LOG_ERR); } unotice( n <= 0 ? "child %d stopped by signal %d" : "child %d stopped by signal %d: %*s", wpid, WSTOPSIG(status), n, command); } else #endif /*WIFSTOPPED*/ #if defined(WIFSIGNALED) if (WIFSIGNALED(status)) { int n = lcf_getCommandLine(wpid, command, sizeof(command)); if (n == -1) { log_add("Couldn't get command-line of EXEC process " "%ld", wpid); log_log(LOG_ERR); } cps_remove(wpid); /* upstream LDM processes */ lcf_freeExec(wpid); /* EXEC processes */ #if WANT_MULTICAST (void)msm_removePid(wpid); // multicast LDM senders #endif unotice( n <= 0 ? "child %d terminated by signal %d" : "child %d terminated by signal %d: %*s", wpid, WTERMSIG(status), n, command); /* DEBUG */ switch (WTERMSIG(status)) { /* * If a child dumped core, * shut everything down. */ case SIGQUIT: case SIGILL: case SIGTRAP: /* ??? */ case SIGABRT: #if defined(SIGEMT) case SIGEMT: /* ??? */ #endif case SIGFPE: /* ??? */ case SIGBUS: case SIGSEGV: #if defined(SIGSYS) case SIGSYS: /* ??? */ #endif #ifdef SIGXCPU case SIGXCPU: #endif #ifdef SIGXFSZ case SIGXFSZ: #endif unotice("Killing (SIGTERM) process group"); (void) kill(0, SIGTERM); break; } } else #endif /*WIFSIGNALED*/ #if defined(WIFEXITED) if (WIFEXITED(status)) { int exitStatus = WEXITSTATUS(status); int n = lcf_getCommandLine(wpid, command, sizeof(command)); cps_remove(wpid); /* upstream LDM processes */ lcf_freeExec(wpid); /* EXEC processes */ if (n == -1) { log_add("Couldn't get command-line of EXEC process " "%ld", wpid); log_log(LOG_ERR); } log_start( n <= 0 ? "child %d exited with status %d" : "child %d exited with status %d: %*s", wpid, exitStatus, n, command); log_log(exitStatus ? LOG_NOTICE : LOG_INFO); } #endif /*WIFEXITED*/ } return wpid; }