Probably working launcher.
authorFredrik Tolf <fredrik@dolda2000.com>
Mon, 13 Aug 2007 04:28:01 +0000 (06:28 +0200)
committerFredrik Tolf <fredrik@dolda2000.com>
Mon, 13 Aug 2007 04:28:01 +0000 (06:28 +0200)
clients/gui-shell/.gitignore [new file with mode: 0644]
clients/gui-shell/Makefile.am
clients/gui-shell/launch.c

diff --git a/clients/gui-shell/.gitignore b/clients/gui-shell/.gitignore
new file mode 100644 (file)
index 0000000..2a36245
--- /dev/null
@@ -0,0 +1 @@
+/dolcon-launch
index a6aa0e4..c826a0a 100644 (file)
@@ -1,3 +1,5 @@
 bin_PROGRAMS=dolcon-launch
 
 dolcon_launch_SOURCES=launch.c
+
+AM_CPPFLAGS=-I$(top_srcdir)/include
index f31fcc2..620e280 100644 (file)
@@ -23,6 +23,7 @@
 #include <string.h>
 #include <pwd.h>
 #include <libintl.h>
+#include <signal.h>
 
 #ifdef HAVE_CONFIG_H
 #include <config.h>
 
 #define _(text) gettext(text)
 
+int running(char *pf)
+{
+    FILE *pfs;
+    char buf[1024];
+    int pid;
+    
+    if((pfs = fopen(pf, "r")) == NULL) {
+       perror(pf);
+       return(0);
+    }
+    fgets(buf, sizeof(buf), pfs);
+    fclose(pfs);
+    if((pid = atoi(buf)) == 0)
+       return(0);
+    return(!kill(pid, 0));
+}
+
 int main(int argc, char **argv)
 {
-    return(0);
+    char cf[1024], pf[1024];
+    
+    if(getenv("HOME") != NULL)
+       snprintf(cf, sizeof(cf), "%s/.doldacond.conf", getenv("HOME"));
+    else
+       snprintf(cf, sizeof(cf), "%s/.doldacond.conf", getpwuid(getuid())->pw_dir);
+    if(getenv("HOME") != NULL)
+       snprintf(pf, sizeof(pf), "%s/.doldacond.pid", getenv("HOME"));
+    else
+       snprintf(pf, sizeof(pf), "%s/.doldacond.pid", getpwuid(getuid())->pw_dir);
+    if(access(cf, F_OK)) {
+       execlp("dolconf", "dolconf", "-a", NULL);
+       perror("dolconf");
+    } else if(access(pf, F_OK) || !running(pf)) {
+       execlp("doldacond-shell", "doldacond-shell", NULL);
+       perror("doldacond-shell");
+    } else {
+       execlp("dolcon", "dolcon", NULL);
+       perror("dolcon");
+    }
+    return(127);
 }