From f7a99e90470526bb28cc0c225f96490110094aed Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 10 Jan 2006 17:51:06 +0000 Subject: Merge Pierre's changes git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@445 fefdeb5f-60dc-0310-8127-8f9354f1896f --- polyp/pid.c | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) (limited to 'polyp/pid.c') diff --git a/polyp/pid.c b/polyp/pid.c index 2fac687e..ae3dc7f5 100644 --- a/polyp/pid.c +++ b/polyp/pid.c @@ -35,6 +35,10 @@ #include #include +#ifdef HAVE_WINDOWS_H +#include +#endif + #include "pid.h" #include "util.h" #include "log.h" @@ -130,6 +134,10 @@ int pa_pid_file_create(void) { pid_t pid; size_t l; +#ifdef OS_IS_WIN32 + HANDLE process; +#endif + pa_runtime_path("pid", fn, sizeof(fn)); if ((fd = open_pid_file(fn, O_CREAT|O_RDWR)) < 0) @@ -138,7 +146,12 @@ int pa_pid_file_create(void) { if ((pid = read_pid(fn, fd)) == (pid_t) -1) pa_log(__FILE__": corrupt PID file, overwriting.\n"); else if (pid > 0) { +#ifdef OS_IS_WIN32 + if ((process = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, pid)) != NULL) { + CloseHandle(process); +#else if (kill(pid, 0) >= 0 || errno != ESRCH) { +#endif pa_log(__FILE__": daemon already running.\n"); goto fail; } @@ -198,6 +211,12 @@ int pa_pid_file_remove(void) { goto fail; } +#ifdef OS_IS_WIN32 + pa_lock_fd(fd, 0); + close(fd); + fd = -1; +#endif + if (unlink(fn) < 0) { pa_log(__FILE__": failed to remove PID file '%s': %s\n", fn, strerror(errno)); goto fail; @@ -223,6 +242,8 @@ int pa_pid_file_check_running(pid_t *pid) { return pa_pid_file_kill(0, pid); } +#ifndef OS_IS_WIN32 + /* Kill a current running daemon. Return non-zero on success, -1 * otherwise. If successful *pid contains the PID of the daemon * process. */ @@ -242,7 +263,7 @@ int pa_pid_file_kill(int sig, pid_t *pid) { if ((*pid = read_pid(fn, fd)) == (pid_t) -1) goto fail; - + ret = kill(*pid, sig); fail: @@ -255,3 +276,11 @@ fail: return ret; } + +#else /* OS_IS_WIN32 */ + +int pa_pid_file_kill(int sig, pid_t *pid) { + return -1; +} + +#endif -- cgit