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
----
$ grep -n 'TODO' spt.c

27
spt.c
View File

@ -15,6 +15,14 @@ char *argv0;
/* macros */
#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