diff options
Diffstat (limited to 'src/notify.c')
-rw-r--r-- | src/notify.c | 38 |
1 files changed, 14 insertions, 24 deletions
diff --git a/src/notify.c b/src/notify.c index 549a2be..6eda361 100644 --- a/src/notify.c +++ b/src/notify.c @@ -1,7 +1,7 @@ /* * Calcurse - text-based organizer * - * Copyright (c) 2004-2017 calcurse Development Team <misc@calcurse.org> + * Copyright (c) 2004-2023 calcurse Development Team <misc@calcurse.org> * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -34,6 +34,7 @@ * */ +#include <sys/wait.h> #include <time.h> #include <stdlib.h> #include <string.h> @@ -136,9 +137,6 @@ void notify_init_vars(void) strncpy(nbar.cmd, cmd, BUFSIZ); nbar.cmd[BUFSIZ - 1] = '\0'; - if ((nbar.shell = getenv("SHELL")) == NULL) - nbar.shell = "/bin/sh"; - nbar.notify_all = 0; pthread_attr_init(&detached_thread_attr); @@ -215,26 +213,18 @@ void notify_reinit_bar(void) /* Launch user defined command as a notification. */ unsigned notify_launch_cmd(void) { - int pid; + char const *arg[2] = { nbar.cmd, NULL }; + int pid, pin, pout, perr; if (notify_app.state & APOINT_NOTIFIED) return 1; notify_app.state |= APOINT_NOTIFIED; - pid = fork(); - - if (pid < 0) { - ERROR_MSG(_("error while launching command: could not fork")); - return 0; - } else if (pid == 0) { - /* Child: launch user defined command */ - if (execlp(nbar.shell, nbar.shell, "-c", nbar.cmd, NULL) < - 0) { - ERROR_MSG(_("error while launching command")); - _exit(1); - } - _exit(0); + if ((pid = shell_exec(&pin, &pout, &perr, 1, *arg, arg))) { + close(pin); + close(pout); + close(perr); } return 1; @@ -358,6 +348,9 @@ static void *notify_main_thread(void *arg) pthread_mutex_unlock(¬ify.mutex); notify_update_bar(); psleep(thread_sleep); + /* Reap the user-defined notifications. */ + while (waitpid(0, NULL, WNOHANG) > 0) + ; elapse += thread_sleep; if (elapse >= check_app) { elapse = 0; @@ -505,8 +498,7 @@ void notify_check_repeated(struct recur_apoint *i) current_time = time(NULL); pthread_mutex_lock(¬ify_app.mutex); if (recur_item_find_occurrence - (i->start, i->dur, &i->exc, i->rpt->type, i->rpt->freq, - i->rpt->until, get_today(), &real_app_time)) { + (i->start, i->dur, i->rpt, &i->exc, get_today(), &real_app_time)) { if (!notify_app.got_app) { if (real_app_time - current_time <= DAYINSEC) update_notify = 1; @@ -547,12 +539,10 @@ int notify_same_recur_item(struct recur_apoint *i) time_t item_start; /* Tomorrow? */ - recur_item_find_occurrence(i->start, i->dur, &i->exc, i->rpt->type, - i->rpt->freq, i->rpt->until, + recur_item_find_occurrence(i->start, i->dur, i->rpt, &i->exc, NEXTDAY(get_today()), &item_start); /* Today? */ - recur_item_find_occurrence(i->start, i->dur, &i->exc, i->rpt->type, - i->rpt->freq, i->rpt->until, + recur_item_find_occurrence(i->start, i->dur, i->rpt, &i->exc, get_today(), &item_start); pthread_mutex_lock(¬ify_app.mutex); if (notify_app.got_app && item_start == notify_app.time) |