From a546ac5c47c1053b3d03cc686d1c900f601ea237 Mon Sep 17 00:00:00 2001 From: markus schnalke Date: Thu, 15 Jan 2015 20:50:50 +0100 Subject: [PATCH] sbr/ext_hook.c: Use execprog(); Refactoring --- sbr/ext_hook.c | 68 ++++++++++++++++++++++---------------------------------- 1 file changed, 26 insertions(+), 42 deletions(-) diff --git a/sbr/ext_hook.c b/sbr/ext_hook.c index 771d558..0f3bd79 100644 --- a/sbr/ext_hook.c +++ b/sbr/ext_hook.c @@ -1,58 +1,42 @@ /* -** Run a program that hooks into some other system. The first argument is -** name of the hook to use, the second is the full path name of a mail message. -** The third argument is also the full path name of a mail message, or a NULL -** pointer if it isn't needed. Look in the context for an error message if -** something goes wrong; there is a built-in message in case one isn't -** specified. Only produce the error message once. +** ext_hook.c -- Run a program that hooks into some other system. */ #include +/* +** The filename arguments are given full path names. +** msg_filename2 might contain a NULL pointer if not needed. +** Look in the context for an error message if something goes wrong; +** there is a built-in message in case one isn't specified. +** Only produces the error message once. +*/ int -ext_hook(char *hook_name, char *message_file_name_1, char *message_file_name_2) +ext_hook(char *hook_name, char *msg_filename1, char *msg_filename2) { - char *hook; /* hook program from context */ - pid_t pid; /* ID of child process */ - int status; /* exit or other child process status */ - char *vec[4]; /* argument vector for child process */ + char *hook; /* hook program from context */ + int status; - static int did_message = 0; /* set if we've already output a message */ + static int did_message = 0; /* we've already output a message */ - if ((hook = context_find(hook_name)) == NULL) + if (!(hook = context_find(hook_name))) { return (OK); - - switch (pid = fork()) { - case -1: - status = NOTOK; - advise(NULL, "external database may be out-of-date."); - break; - - case 0: - vec[0] = mhbasename(hook); - vec[1] = message_file_name_1; - vec[2] = message_file_name_2; - vec[3] = NULL; - execvp(hook, vec); - _exit(-1); - /* NOTREACHED */ - - default: - status = pidwait(pid, -1); - break; } - + status = execprogl(mhbasename(hook), mhbasename(hook), + msg_filename1, msg_filename2, + (char *)NULL); if (status != OK) { - if (did_message == 0) { - if ((hook = context_find("msg-hook")) != NULL) - advise(NULL, hook); - else - advise(NULL, "external hook (%s) did not work properly.", hook); - - did_message = 1; + if (did_message) { + return (NOTOK); } - + if ((hook = context_find("msg-hook"))) { + advise(NULL, hook); + } else { + advise(NULL, "external hook (%s) failed.", hook); + } + did_message = 1; return (NOTOK); - } else + } else { return (OK); + } } -- 1.7.10.4