Fix failed execvp notifycmd

This commit is contained in:
Ivan Tham 2016-07-11 18:47:18 +08:00
parent f1fe73aff8
commit 58d1470890
2 changed files with 12 additions and 20 deletions

3
TODO
View File

@ -1,6 +1,3 @@
1. Add more support for non-libnotify such as echo(1)
2. Pause and continue the timer
Misc Misc
---- ----
$ grep -n 'TODO' spt.c $ grep -n 'TODO' spt.c

27
spt.c
View File

@ -15,6 +15,14 @@ char *argv0;
/* macros */ /* 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 { typedef struct {
unsigned int tmr; unsigned int tmr;
@ -27,7 +35,6 @@ static int i, timecount;
/* function declarations */ /* function declarations */
static void die(const char *errstr, ...); static void die(const char *errstr, ...);
static void spawn(char *cmd, char *cmt);
static void notify_send(char *cmt); static void notify_send(char *cmt);
static void remaining_time(int sigint); static void remaining_time(int sigint);
static void usage(void); static void usage(void);
@ -44,18 +51,6 @@ die(const char *errstr, ...)
exit(EXIT_FAILURE); 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 void
notify_send(char *cmt) notify_send(char *cmt)
{ {
@ -67,12 +62,12 @@ notify_send(char *cmt)
g_object_unref(G_OBJECT(n)); g_object_unref(G_OBJECT(n));
notify_uninit(); notify_uninit();
#else #else
if (strcmp(notifycmd, "")) if (strcmp(notifycmd, "")) /* TODO: call function in config.h */
spawn(notifycmd, cmt); SPAWN(execlp(notifycmd, notifycmd, "spt", cmt, NULL))
#endif /* NOTIFY */ #endif /* NOTIFY */
if (strcmp(notifyext, "")) /* extra commands to use */ if (strcmp(notifyext, "")) /* extra commands to use */
spawn(notifyext, NULL); SPAWN(execvp("sh", (char *const []){"/bin/sh", "-c", notifyext, NULL}))
} }
void void