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 | |
parent | 011ca7b06533ec8a0da516354e948904e136f372 (diff) |
instance is not running before starting up
Gbp-Pq: Name 09-process-running-checks.dpatch
-rw-r--r-- | src/osdctl/osdctl.c | 20 | ||||
-rw-r--r-- | src/osdctl/osdctl.h | 3 | ||||
-rw-r--r-- | src/osdsh/osdsh.c | 12 | ||||
-rw-r--r-- | src/osdsh/osdsh.h | 1 |
4 files changed, 35 insertions, 1 deletions
diff --git a/src/osdctl/osdctl.c b/src/osdctl/osdctl.c index 6367c5a..e26e2f6 100644 --- a/src/osdctl/osdctl.c +++ b/src/osdctl/osdctl.c @@ -36,11 +36,31 @@ void send_command(char command[BUFSIZ]) { FILE *fp; char fifo_file[PATH_MAX]; + char pid_file[PATH_MAX]; + pid_t osdsh_pid; if (strcmp(command, "")==0) return; sprintf(fifo_file, "%s.%d", OSD_FIFO_PATH, getuid()); + sprintf(pid_file, "%s.%d.pid", OSD_FIFO_PATH, getuid()); + + /* + * We need to check that osdSH is really running because writing + * to the socket without osdSH reading from it results in osdctl + * hang + */ + if((fp = fopen(pid_file, "r")) == NULL) { + perror("osdSH is not running (no pid file)"); + exit(1); + } + + if((!fscanf(fp, "%d", &osdsh_pid)) || kill(osdsh_pid, 0)) { + perror("osdSH is not running"); + exit(1); + } + + fclose(fp); if((fp = fopen(fifo_file, "w")) == NULL) { perror("Couldn't open fifo"); diff --git a/src/osdctl/osdctl.h b/src/osdctl/osdctl.h index 4fcdb48..665238a 100644 --- a/src/osdctl/osdctl.h +++ b/src/osdctl/osdctl.h @@ -1,3 +1,6 @@ #include <stdio.h> #include <getopt.h> #include <linux/limits.h> +#include <sys/types.h> +#include <signal.h> + 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); diff --git a/src/osdsh/osdsh.h b/src/osdsh/osdsh.h index e339791..62802be 100644 --- a/src/osdsh/osdsh.h +++ b/src/osdsh/osdsh.h @@ -10,6 +10,7 @@ #include <fcntl.h> #include <pthread.h> #include <dlfcn.h> +#include <signal.h> #include <linux/limits.h> #include <linux/stat.h> |