X-Git-Url: http://git.dolda2000.com/gitweb/?a=blobdiff_plain;f=clients%2Fgui-shell%2Flaunch.c;h=22a82a2b0ba21c979093cee9fcdce738643e6324;hb=f2e278c9547044173473938b4291a88a1a32aa26;hp=f31fcc2bda6914517755e122af6c71c7556d6375;hpb=f7a57385f5749e0bc0eb27028f609ca72e2b2dbd;p=doldaconnect.git diff --git a/clients/gui-shell/launch.c b/clients/gui-shell/launch.c index f31fcc2..22a82a2 100644 --- a/clients/gui-shell/launch.c +++ b/clients/gui-shell/launch.c @@ -23,14 +23,102 @@ #include #include #include +#include #ifdef HAVE_CONFIG_H #include #endif -#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) +int haveprogram(char *name) { + char buf[1024]; + char *p, *p2; + + p = getenv("PATH"); + while(p != NULL) { + if((p2 = strchr(p, ':')) != NULL) { + memcpy(buf, p, p2 - p); + buf[p2 - p] = 0; + p = p2 + 1; + } else { + strcpy(buf, p); + p = NULL; + } + strcat(buf, "/"); + strcat(buf, name); + if(!access(buf, X_OK)) + return(1); + } return(0); } + +int main(int argc, char **argv) +{ + int c; + char cf[1024], pf[1024]; + + while((c = getopt(argc, argv, "hV")) != -1) { + switch(c) { + case 'h': + printf("usage: dolcon-launch [-hV]\n"); + printf("\t-h\tDisplay this help message\n"); + printf("\t-V\tDisplay version info and exit\n"); + printf("\n"); + printf("\tIf $HOME/.doldacond.conf does not exist, dolcon-launch will run\n"); + printf("\tdolconf. Otherwise, if $HOME/.doldacond.pid does not exist,\n"); + printf("\tor does not contain a valid PID, dolcon-launch will run\n"); + printf("\tdoldacond-shell. Otherwise, dolcon-launch will run dolcon. All\n"); + printf("\tthese programs must be somewhere in $PATH for dolcon-launch to work.\n"); + printf("\n"); + printf("\tIf doldacond is not in $PATH, only running dolcon is attempted.\n"); + exit(0); + case 'V': + printf("%s", RELEASEINFO); + exit(0); + default: + fprintf(stderr, "usage: dolcon-launch [-h]\n"); + exit(1); + } + } + if(haveprogram("doldacond")) { + 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", "-l", NULL); + perror("dolcon"); + } + } else { + execlp("dolcon", "dolcon", NULL); + perror("dolcon"); + } + return(127); +}