char *pid_check_and_create() { struct stat st; char* pidfile = pid_filename(); pid_t pid = pid_read(pidfile); /* Check PID for existence and liveness. */ if (pid > 0 && pid_running(pid)) { log_server_error("Server PID found, already running.\n"); free(pidfile); return NULL; } else if (stat(pidfile, &st) == 0) { log_server_warning("Removing stale PID file '%s'.\n", pidfile); pid_remove(pidfile); } /* Create a PID file. */ int ret = pid_write(pidfile); if (ret != KNOT_EOK) { log_server_error("Couldn't create a PID file '%s'.\n", pidfile); free(pidfile); return NULL; } return pidfile; }
void quit_program(int rc) { set_process_permissions(0, 0, xstrtoo(VBOX_ROOT_UMASK, 0)); modem_hangup(&vboxmodem); log_line(LOG_D, "Closing modem device (%d)...\n", vboxmodem.fd); if (vboxmodem_close(&vboxmodem) != 0) { log_line(LOG_E, "%s (%s)\n", vboxmodem_error(), strerror(errno)); } if (isdnttyname) { printstring(temppathname, "%s/LCK..%s", LOCKDIR, isdnttyname); lock_remove(temppathname); printstring(temppathname, "%s/vboxgetty-%s.pid", PIDDIR, isdnttyname); pid_remove(temppathname); } scr_remove_interpreter(); rc_free(rc_getty_c); breaklist_clear(); log_close(); exit(rc); }
/*! \brief PID file cleanup handler. */ static void pid_cleanup(char *pidfile) { if (pidfile && pid_remove(pidfile) < 0) { log_warning("failed to remove PID file"); } }