7 /* run mail component program
9 /* #include <mail_run.h>
11 /* int mail_run_foreground(dir, argv)
15 /* int mail_run_background(dir, argv)
19 /* NORETURN mail_run_replace(dir, argv)
23 /* This module runs programs that live in the mail program directory.
24 /* Each routine takes a directory and a command-line array. The program
25 /* pathname is built by prepending the directory and a slash to the
28 /* mail_run_foreground() runs the named command in the foreground and
29 /* waits until the command terminates.
31 /* mail_run_background() runs the named command in the background.
33 /* mail_run_replace() attempts to replace the current process by
34 /* an instance of the named command. This function never returns.
38 /* A null-terminated command-line vector. The first array element
39 /* is the base name of the program to be executed.
41 /* The result is (-1) if the command could not be run. Otherwise,
42 /* mail_run_foreground() returns the termination status of the
43 /* command. mail_run_background() returns the process id in case
45 /* CONFIGURATION PARAMETERS
46 /* fork_attempts: number of attempts to fork() a process;
47 /* fork_delay: delay in seconds between fork() attempts.
51 /* The Secure Mailer license must be distributed with this software.
54 /* IBM T.J. Watson Research
56 /* Yorktown Heights, NY 10598, USA
66 /* Utility library. */
69 #include <stringops.h>
74 #include "mail_params.h"
77 /* mail_run_foreground - run command in foreground */
79 int mail_run_foreground(const char *dir
, char **argv
)
87 #define RETURN(x) { myfree(path); return(x); }
89 path
= concatenate(dir
, "/", argv
[0], (char *) 0);
91 for (count
= 0; count
< var_fork_tries
; count
++) {
92 switch (pid
= fork()) {
94 msg_warn("fork %s: %m", path
);
97 /* Reset the msg_cleanup() handlers in the child process. */
98 (void) msg_cleanup((MSG_CLEANUP_FN
) 0);
100 msg_fatal("execv %s: %m", path
);
103 wpid
= waitpid(pid
, &status
, 0);
104 } while (wpid
== -1 && errno
== EINTR
);
105 RETURN(wpid
== -1 ? -1 :
106 WIFEXITED(status
) ? WEXITSTATUS(status
) : 1)
108 sleep(var_fork_delay
);
113 /* mail_run_background - run command in background */
115 int mail_run_background(const char *dir
, char **argv
)
121 #define RETURN(x) { myfree(path); return(x); }
123 path
= concatenate(dir
, "/", argv
[0], (char *) 0);
125 for (count
= 0; count
< var_fork_tries
; count
++) {
126 switch (pid
= fork()) {
128 msg_warn("fork %s: %m", path
);
131 /* Reset the msg_cleanup() handlers in the child process. */
132 (void) msg_cleanup((MSG_CLEANUP_FN
) 0);
134 msg_fatal("execv %s: %m", path
);
138 sleep(var_fork_delay
);
143 /* mail_run_replace - run command, replacing current process */
145 NORETURN
mail_run_replace(const char *dir
, char **argv
)
149 path
= concatenate(dir
, "/", argv
[0], (char *) 0);
151 msg_fatal("execv %s: %m", path
);