diff --git a/src/monitor/monitor.c b/src/monitor/monitor.c index a08087038..02a3055f3 100644 --- a/src/monitor/monitor.c +++ b/src/monitor/monitor.c @@ -2440,6 +2440,8 @@ int main(int argc, const char *argv[]) struct mt_ctx *monitor; int ret; uid_t uid; + int fd; + char pid_buf[100]; struct poptOption long_options[] = { POPT_AUTOHELP @@ -2620,8 +2622,21 @@ int main(int argc, const char *argv[]) } /* Check if the SSSD is already running */ - ret = check_file(SSSD_PIDFILE, 0, 0, S_IFREG|0600, 0, NULL, false); + ret = check_and_open_readonly(SSSD_PIDFILE, &fd, 0, 0, S_IFREG|0600, 0) if (ret == EOK) { + /* Looked for but couldn't easily find any existing code that reads + * data - would be safer potentially */ + strcpy(pid_buf, "/proc/"); + ret = read(fd, pid_buf + 6, sizeof(pid_buf)); + if (ret > 0) { + /* Multiple issues with this, like contents of file f.ex. */ + ret = access(pid_buf, X_OK); + if (ret == 0) + ret = ENOENT; + } + } + /* Could be done nicer, fall back to original code */ + if (ret == EOK) DEBUG(SSSDBG_FATAL_FAILURE, "pidfile exists at %s\n", SSSD_PIDFILE); ERROR("SSSD is already running\n");