int LshttpdMain::testRunningServer() { int count = 0; int ret; do { ret = m_pidFile.lockPidFile(PID_FILE); if (ret) { if ((ret == -2) && (errno == EACCES || errno == EAGAIN)) { ++count; if (count >= 10) { perr("LiteSpeed Web Server is running!"); return 2; } ls_sleep(100); } else { fprintf(stderr, "[ERROR] Failed to write to pid file:%s!\n", PID_FILE); return ret; } } else break; } while (true); return ret; }
int ServerInfo::cleanPidList(int toStopOnly) { PidInfo *pInfo; pid_t pids[4096]; pid_t *p = pids; pid_t *pEnd = p + 4096; for (pInfo = m_pidList.m_pBegin; (pInfo < m_pidList.m_pCur) && (p < pEnd); ++pInfo) { if ((!toStopOnly) || (pInfo->m_parent == KILL_TYPE_TERM)) if (pInfo->m_pid > 0) *p++ = pInfo->m_pid; } pid_t *p1 = pids; for (; p1 != p; p1++) { kill(*p1, SIGTERM); kill(*p1, SIGUSR1); LS_DBG_L("[AutoRestater] Clean up child process with pid: %d", *p1); } ls_sleep(100); p1 = pids; for (; p1 != p; p1++) kill(*p1, SIGKILL); if (!toStopOnly) m_pidList.m_pCur = m_pidList.m_pBegin; return 0; }