diff options
author | Roman Yepishev <roman.yepishev@gmail.com> | 2019-01-07 13:12:45 +0100 |
---|---|---|
committer | Andrej Shadura <andrewsh@debian.org> | 2019-01-07 13:12:45 +0100 |
commit | ee99c38adbf2d7e851b7ca14bfa1ba0c5654db5b (patch) | |
tree | 0a1efc9858613be9c55572cb701710231f714038 /src/osdsh/osdsh.c | |
parent | 011ca7b06533ec8a0da516354e948904e136f372 (diff) |
instance is not running before starting up
Gbp-Pq: Name 09-process-running-checks.dpatch
Diffstat (limited to 'src/osdsh/osdsh.c')
-rw-r--r-- | src/osdsh/osdsh.c | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/src/osdsh/osdsh.c b/src/osdsh/osdsh.c index ea6873b..e6e00b7 100644 --- a/src/osdsh/osdsh.c +++ b/src/osdsh/osdsh.c @@ -149,6 +149,7 @@ void load_basic_plugins(void) { int main(int argc, char *argv[], char *env[]) { pid_t childpid; + pid_t osdsh_pid; char pid_file[PATH_MAX+1]; FILE *fp; @@ -169,6 +170,16 @@ int main(int argc, char *argv[], char *env[]) pppset = mixerset = settings; */ + sprintf(pid_file, "%s.%d.pid", OSD_FIFO_PATH, getuid()) ; + + if(fp = fopen(pid_file, "r")) { + if((fscanf(fp, "%d", &osdsh_pid)) && !kill(osdsh_pid, 0)) { + fprintf(stderr, "osdSH is already running (pid %d)\n", osdsh_pid); + exit(1); + } + fclose(fp); + } + if((childpid=fork())<0) { perror("fork"); exit(1); @@ -177,7 +188,6 @@ int main(int argc, char *argv[], char *env[]) control_sh(NULL); } else { - sprintf(pid_file, "%s.%d.pid", OSD_FIFO_PATH, getuid()) ; fp=fopen(pid_file, "w"); fprintf(fp, "%d", childpid); fclose(fp); |