From 58d14708903b3ab4686fc9baaba849be8e6c64a4 Mon Sep 17 00:00:00 2001 From: Ivan Tham Date: Mon, 11 Jul 2016 18:47:18 +0800 Subject: [PATCH] Fix failed execvp notifycmd --- TODO | 3 --- spt.c | 29 ++++++++++++----------------- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/TODO b/TODO index 3cb9e0f..3803a28 100644 --- a/TODO +++ b/TODO @@ -1,6 +1,3 @@ -1. Add more support for non-libnotify such as echo(1) -2. Pause and continue the timer - Misc ---- $ grep -n 'TODO' spt.c diff --git a/spt.c b/spt.c index efe3cad..0fb311a 100644 --- a/spt.c +++ b/spt.c @@ -14,7 +14,15 @@ char *argv0; /* macros */ -#define LEN(a) (sizeof(a) / sizeof(a[0])) +#define LEN(a) (sizeof(a) / sizeof(a[0])) +#define SPAWN(cmd) if (fork() == 0) {\ + setsid();\ + cmd;\ + die("spt: spawn\n");\ + perror(" failed");\ + exit(0);\ + } + typedef struct { unsigned int tmr; @@ -27,7 +35,6 @@ static int i, timecount; /* function declarations */ static void die(const char *errstr, ...); -static void spawn(char *cmd, char *cmt); static void notify_send(char *cmt); static void remaining_time(int sigint); static void usage(void); @@ -44,18 +51,6 @@ die(const char *errstr, ...) exit(EXIT_FAILURE); } -void -spawn(char *cmd, char *cmt) -{ - if (fork() == 0) { - setsid(); - execvp("sh", (char *const []){"/bin/sh", "-c", cmd, cmt, NULL}); - fprintf(stderr, "spt: execvp %s", cmd); - perror(" failed"); /* 2 errors report? */ - exit(0); - } -} - void notify_send(char *cmt) { @@ -67,12 +62,12 @@ notify_send(char *cmt) g_object_unref(G_OBJECT(n)); notify_uninit(); #else - if (strcmp(notifycmd, "")) - spawn(notifycmd, cmt); + if (strcmp(notifycmd, "")) /* TODO: call function in config.h */ + SPAWN(execlp(notifycmd, notifycmd, "spt", cmt, NULL)) #endif /* NOTIFY */ if (strcmp(notifyext, "")) /* extra commands to use */ - spawn(notifyext, NULL); + SPAWN(execvp("sh", (char *const []){"/bin/sh", "-c", notifyext, NULL})) } void