49 size_t len = snprintf(val,
sizeof(val),
"%"PRIuMAX
"\n", (uintmax_t)getpid());
55 pidfd = open(pidfile, O_CREAT | O_TRUNC |
O_NOFOLLOW | O_WRONLY, 0644);
57 SCLogError(
"unable to set pidfile '%s': %s", pidfile, strerror(errno));
61 ssize_t r = write(pidfd, val, (
unsigned int)
len);
63 SCLogError(
"unable to write pidfile: %s", strerror(errno));
66 }
else if ((
size_t)r !=
len) {
68 " %" PRIdMAX
" of %" PRIuMAX
" bytes.",
69 (intmax_t)r, (uintmax_t)
len);
85 if (pid_filename != NULL) {
87 (void)unlink(pid_filename);
110 pf = fopen(pid_filename,
"r");
112 if (access(pid_filename, F_OK) == 0) {
113 SCLogError(
"pid file '%s' exists and can not be read. Aborting!", pid_filename);
122 if (fscanf(pf,
"%d", &pidv) == 1 && kill(pidv, 0) == 0) {
123 SCLogError(
"pid file '%s' exists and Suricata appears to be running. "
129 SCLogError(
"pid file '%s' exists but appears stale. "
130 "Make sure Suricata is not running and then remove %s. "
132 pid_filename, pid_filename);