diff --git a/wmix/include/misc.h b/wmix/include/misc.h index 5a70664..7794111 100644 --- a/wmix/include/misc.h +++ b/wmix/include/misc.h @@ -24,3 +24,4 @@ double get_current_time(void); void add_region (int index, int x, int y, int width, int height); int check_region (int x, int y); void config_read (void); +void create_pid_file (void); diff --git a/wmix/misc.c b/wmix/misc.c index 3c7e854..544a6e9 100644 --- a/wmix/misc.c +++ b/wmix/misc.c @@ -22,10 +22,12 @@ #include "config.h" #endif +#include #include #include #include #include +#include #include #include "include/common.h" @@ -161,3 +163,24 @@ void config_read(void) } fclose(fp); } + +/* handle writing PID file, silently ignore if we can't do it */ +void create_pid_file(void) +{ + char *home; + char *pid; + FILE *fp; + + home = getenv("HOME"); + if (home == NULL) + return; + + pid = calloc(1, strlen(home) + 10); + sprintf(pid, "%s/.wmix.pid", home); + fp = fopen(pid, "w"); + if (fp) { + fprintf(fp, "%d\n", getpid()); + fclose(fp); + } + free(pid); +} diff --git a/wmix/wmix.c b/wmix/wmix.c index eed28b6..84b1e42 100644 --- a/wmix/wmix.c +++ b/wmix/wmix.c @@ -121,8 +121,6 @@ int main(int argc, char **argv) { XEvent event; char *home; - char *pid; - FILE *fp; memset(&config, 0, sizeof(config)); @@ -133,16 +131,6 @@ int main(int argc, char **argv) sprintf(config.file, "%s/.wmixrc", home); } - /* handle writing PID file, silently ignore if we can't do it */ - pid = calloc(1, strlen(home) + 10); - sprintf(pid, "%s/.wmix.pid", home); - fp = fopen(pid, "w"); - if (fp) { - fprintf(fp, "%d\n", getpid()); - fclose(fp); - } - free(pid); - /* default values */ config.mousewheel = 1; config.scrolltext = 1; @@ -197,6 +185,7 @@ int main(int argc, char **argv) add_region(10, 3, 4, 56, 7); /* re-scroll current channel name */ /* setup up/down signal handler */ + create_pid_file(); signal(SIGUSR1, (void *) signal_catch); signal(SIGUSR2, (void *) signal_catch);