52 size_t len = snprintf(val,
sizeof(val),
"%"PRIuMAX
"\n", (uintmax_t)getpid());
58 pidfd = open(pidfile, O_CREAT | O_TRUNC |
O_NOFOLLOW | O_WRONLY, 0644);
60 SCLogError(
"unable to set pidfile '%s': %s", pidfile, strerror(errno));
64 ssize_t r = write(pidfd, val, (
unsigned int)
len);
66 SCLogError(
"unable to write pidfile: %s", strerror(errno));
69 }
else if ((
size_t)r !=
len) {
71 " %" PRIdMAX
" of %" PRIuMAX
" bytes.",
72 (intmax_t)r, (uintmax_t)
len);
88 if (pid_filename != NULL) {
90 (void)unlink(pid_filename);
113 pf = fopen(pid_filename,
"r");
115 if (access(pid_filename, F_OK) == 0) {
116 SCLogError(
"pid file '%s' exists and can not be read. Aborting!", pid_filename);
125 if (fscanf(pf,
"%d", &pidv) == 1 && kill(pidv, 0) == 0) {
126 SCLogError(
"pid file '%s' exists and Suricata appears to be running. "
132 SCLogError(
"pid file '%s' exists but appears stale. "
133 "Make sure Suricata is not running and then remove %s. "
135 pid_filename, pid_filename);