[Pkg-wmaker-commits] [wmix] 16/44: wmix: create the PID file only after successful initialisation

Doug Torrance dtorrance-guest at moszumanska.debian.org
Fri Sep 29 10:40:13 UTC 2017


This is an automated email from the git hooks/post-receive script.

dtorrance-guest pushed a commit to branch upstream
in repository wmix.

commit f219319e1536b886451daf9c9af7108bc9e23d1a
Author: Christophe CURIS <christophe.curis at free.fr>
Date:   Sat Jun 7 21:21:44 2014 +0200

    wmix: create the PID file only after successful initialisation
    
    The PID file was created at the early beginning, but wmix can abort later
    if something is not ok. It is better to create it at the end, so it will
    be created only if wmix will actually be running.
    
    Took the opportunity to move the code to a dedicated function to keep main
    simple, and added a check to fix possible crash on startup if environment
    variable $HOME does not exist.
    
    Signed-off-by: Christophe CURIS <christophe.curis at free.fr>
---
 include/misc.h |  1 +
 misc.c         | 23 +++++++++++++++++++++++
 wmix.c         | 13 +------------
 3 files changed, 25 insertions(+), 12 deletions(-)

diff --git a/include/misc.h b/include/misc.h
index 5a70664..7794111 100644
--- a/include/misc.h
+++ b/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/misc.c b/misc.c
index 3c7e854..544a6e9 100644
--- a/misc.c
+++ b/misc.c
@@ -22,10 +22,12 @@
 #include "config.h"
 #endif
 
+#include <sys/types.h>
 #include <stdio.h>
 #include <assert.h>
 #include <stdlib.h>
 #include <string.h>
+#include <unistd.h>
 #include <sys/time.h>
 
 #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.c b/wmix.c
index eed28b6..84b1e42 100644
--- a/wmix.c
+++ b/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);
 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-wmaker/wmix.git



More information about the Pkg-wmaker-commits mailing list