From: David Levine Date: Sat, 25 Jan 2014 15:15:05 +0000 (-0600) Subject: Replaced boilerplate at beginning of each nmh program with new X-Git-Url: https://diplodocus.org/git/nmh/commitdiff_plain/b56c88e2847c582f9b18ae5bbda44f033cd49c42?ds=inline;hp=-c Replaced boilerplate at beginning of each nmh program with new nmh_init() function. It sets up an atexit() function and signal handlers so that all temporary files are removed when the program terminates, however that happens. It relies on a call in m_mktemp() to register each temporary file for removal. See new "nmh temporary files" section in README.developers and comments in m_mktemp.c. --- b56c88e2847c582f9b18ae5bbda44f033cd49c42 diff --git a/docs/README.developers b/docs/README.developers index 76f650dc..1d3fd737 100644 --- a/docs/README.developers +++ b/docs/README.developers @@ -22,6 +22,15 @@ commit checklist 8. notify nmh-users? +--------------------------------- +C library/system call usage notes +--------------------------------- +* Use m_mktemp2() or m_mktemp() instead of mkstemp(3) (see section on + nmh temporary files below). +* Use m_unlink() instead of unlink(3). +* Use done() instead of _exit(3) except after a fork(3). + + ------------------------- autoconf & automake files ------------------------- @@ -162,6 +171,21 @@ OS function nmh-local version to use instead getpass() nmh_getpass() +------------------- +nmh temporary files +------------------- + +To create a temporary file, use m_mktemp2() or m_mktemp(). They use +mkstemp(3), but they also register the temporary file for removal on +program termination. So, do not use mkstemp() directly. + +To further support this, nmh_init() must be called at the beginning of +main(). And, if a child process is not going to immediately call one +of the exec(3) functions or _exit(3) after a fork(3), it should call +unregister_for_removal(0). Finally, nmh_init() sets up signal handlers +for several signals: these signal handlers should not be disabled. + + -------------- nmh test suite -------------- diff --git a/h/prototypes.h b/h/prototypes.h index 0baa026c..eefbfec5 100644 --- a/h/prototypes.h +++ b/h/prototypes.h @@ -359,3 +359,10 @@ char *construct_build_directive(char *, const char *, int); */ void init_credentials_file (); int nmh_get_credentials (char *, char *, int, nmh_creds_t); + +/* + * temporary file management + */ +int nmh_init(const char *argv0, int read_context); +int m_unlink(const char *); +void unregister_for_removal(int remove_files); diff --git a/sbr/m_mktemp.c b/sbr/m_mktemp.c index 352cb7cd..cc9c45f5 100644 --- a/sbr/m_mktemp.c +++ b/sbr/m_mktemp.c @@ -7,6 +7,11 @@ */ #include +#include +#include + +static void register_for_removal(const char *); + /* Create a temporary file. If pfx_in is null, the temporary file * will be created in the temporary directory (more on that later). @@ -56,10 +61,14 @@ m_mktemp ( } fd = mkstemp(tmpfil); + if (fd < 0) { umask(oldmode); return NULL; } + + register_for_removal(tmpfil); + if (fd_ret != NULL) { *fd_ret = fd; keep_open = 1; @@ -141,3 +150,125 @@ get_temp_dir() } return m_maildir(""); } + + +/* + * Array of files (full pathnames) to remove on process exit. + * Instead of removing slots from the array, just set to NULL + * to indicate that the file should no longer be removed. + */ +static svector_t exit_filelist = NULL; + +/* + * Register a file for removal at program termination. + */ +static void +register_for_removal(const char *pathname) { + if (exit_filelist == NULL) exit_filelist = svector_create(20); + (void) svector_push_back(exit_filelist, add(pathname, NULL)); +} + +/* + * Unregister all files that were registered to be removed at program + * termination. When called with remove_files of 0, this function is + * intended for use by one of the programs after a fork(3) without a + * subsequent call to one of the exec(3) functions or _exit(3). When + * called with non-0 remove_files argument, it is intended for use by + * an atexit() function. + * + * Right after a fork() and before calling exec() or _exit(), if the + * child catches one of the appropriate signals, it will remove + * all the registered temporary files. Some of those may be needed by + * the parent. Some nmh programs ignore or block some of the signals + * in the child right after fork(). For the other programs, rather + * than complicate things by preventing that, just take the chance + * that it might happen. It is harmless to attempt to unlink a + * temporary file twice, assuming another one wasn't created too + * quickly created with the same name. + */ +void +unregister_for_removal(int remove_files) { + if (exit_filelist) { + size_t i; + + for (i = 0; i < svector_size(exit_filelist); ++i) { + char *filename = svector_at(exit_filelist, i); + + if (filename) { + if (remove_files) (void) unlink(filename); + free(filename); + } + } + + svector_free(exit_filelist); + exit_filelist = NULL; + } +} + +/* + * If the file was registered for removal, deregister it. In + * any case, unlink it. + */ +int +m_unlink(const char *pathname) { + if (exit_filelist) { + char **slot = svector_find(exit_filelist, pathname); + + if (slot && *slot) { + free(*slot); + *slot = NULL; + } + } + + return unlink(pathname); + /* errno should be set to ENOENT if file was not found */ +} + +/* + * Remove all registered temporary files. + */ +void +remove_registered_files_atexit() { + unregister_for_removal(1); +} + +/* + * Remove all registered temporary files. Suitable for use as a + * signal handler. If the signal is one of the usual process + * termination signals, calls exit(). Otherwise, disables itself + * by restoring the default action and then re-raises the signal, + * in case the use was expecting a core dump. + */ +void +remove_registered_files(int sig) { + struct sigaction act; + + /* + * Ignore this signal for the duration. And we either exit() or + * disable this signal handler below, so don't restore this handler. + */ + act.sa_handler = SIG_IGN; + (void) sigemptyset(&act.sa_mask); + act.sa_flags = 0; + (void) sigaction(sig, &act, 0); + + if (sig == SIGHUP || sig == SIGINT || sig == SIGQUIT || sig == SIGTERM) { + /* + * We don't need to call remove_registered_files_atexit() if + * it was registered with atexit(), but let's not assume that. + * It's harmless to call it twice. + */ + remove_registered_files_atexit(); + + exit(1); + } else { + act.sa_handler = SIG_DFL; + (void) sigemptyset(&act.sa_mask); + act.sa_flags = 0; + (void) sigaction(sig, &act, 0); + + remove_registered_files_atexit(); + + (void) raise(sig); + } +} diff --git a/sbr/signals.c b/sbr/signals.c index eb26e632..7645c1cc 100644 --- a/sbr/signals.c +++ b/sbr/signals.c @@ -10,6 +10,9 @@ #include #include +/* sbr/m_mktemp.c */ +extern void remove_registered_files(int); + /* * A version of the function `signal' that uses reliable @@ -78,3 +81,30 @@ SIGNAL2 (int sig, SIGNAL_HANDLER func) return (oact.sa_handler); } + +/* + * For use by nmh_init(). + */ +int +setup_signal_handlers() { + /* + * Catch HUP, INT, QUIT, and TERM so that we can clean up tmp + * files when the user terminates the process early. And also a + * few other common signals that can be thrown due to bugs, stack + * overflow, etc. + */ + + if (SIGNAL(SIGHUP, remove_registered_files) == SIG_ERR || + SIGNAL(SIGINT, remove_registered_files) == SIG_ERR || + SIGNAL(SIGQUIT, remove_registered_files) == SIG_ERR || + SIGNAL(SIGTERM, remove_registered_files) == SIG_ERR || + SIGNAL(SIGILL, remove_registered_files) == SIG_ERR || +# ifdef SIGBUS + SIGNAL(SIGBUS, remove_registered_files) == SIG_ERR || +# endif + SIGNAL(SIGSEGV, remove_registered_files) == SIG_ERR) { + return NOTOK; + } + + return OK; +} diff --git a/sbr/utils.c b/sbr/utils.c index 7f0760a0..d17bad94 100644 --- a/sbr/utils.c +++ b/sbr/utils.c @@ -11,6 +11,13 @@ #include #include +/* sbr/signals.c */ +extern int setup_signal_handlers(); + +/* sbr/m_mktemp.c */ +extern void remove_registered_files_atexit(); + + /* * We allocate space for messages (msgs array) * this number of elements at a time. @@ -317,3 +324,33 @@ nmh_strcasestr (const char *s1, const char *s2) { return NULL; } + + +int +nmh_init(const char *argv0, int read_context) { +#ifdef LOCALE + setlocale(LC_ALL, ""); +#endif + + invo_name = r1bindex ((char *) argv0, '/'); + + if (setup_signal_handlers()) { + admonish("sigaction", "unable to set up signal handlers"); + } + + /* POSIX atexit() does not define any error conditions. */ + if (atexit(remove_registered_files_atexit)) { + admonish("atexit", "unable to register atexit function"); + } + + if (read_context) { + context_read(); + return OK; + } else { + int status = context_foil(NULL); + if (status != OK) { + advise("", "failed to create minimal profile/conext"); + } + return status; + } +} diff --git a/uip/ali.c b/uip/ali.c index dda0a2c1..e7c865be 100644 --- a/uip/ali.c +++ b/uip/ali.c @@ -53,13 +53,7 @@ main (int argc, char **argv) char **vec = mh_xmalloc (argc * sizeof (char *)), **arguments; struct aka *ak; -#ifdef LOCALE - setlocale(LC_ALL, ""); -#endif - invo_name = r1bindex (argv[0], '/'); - - /* read user profile/context */ - context_read(); + if (nmh_init(argv[0], 1)) { return 1; } mts_init (invo_name); arguments = getarguments (invo_name, argc, argv, 1); diff --git a/uip/anno.c b/uip/anno.c index d18713ae..26706eda 100644 --- a/uip/anno.c +++ b/uip/anno.c @@ -94,13 +94,7 @@ main (int argc, char **argv) int list = 0; /* list header elements if set */ int number = 0; /* delete specific number of like elements if set */ -#ifdef LOCALE - setlocale(LC_ALL, ""); -#endif - invo_name = r1bindex (argv[0], '/'); - - /* read user profile/context */ - context_read(); + if (nmh_init(argv[0], 1)) { return 1; } arguments = getarguments (invo_name, argc, argv, 1); argp = arguments; diff --git a/uip/ap.c b/uip/ap.c index f0b0baa9..c8cf4b25 100644 --- a/uip/ap.c +++ b/uip/ap.c @@ -53,13 +53,7 @@ main (int argc, char **argv) char buf[BUFSIZ], **argp; char **arguments, *addrs[NADDRS]; -#ifdef LOCALE - setlocale(LC_ALL, ""); -#endif - invo_name = r1bindex (argv[0], '/'); - - /* read user profile/context */ - context_read(); + if (nmh_init(argv[0], 1)) { return 1; } mts_init (invo_name); arguments = getarguments (invo_name, argc, argv, 1); diff --git a/uip/burst.c b/uip/burst.c index c3f21710..ff5af237 100644 --- a/uip/burst.c +++ b/uip/burst.c @@ -75,13 +75,7 @@ main (int argc, char **argv) struct smsg *smsgs; struct msgs *mp; -#ifdef LOCALE - setlocale(LC_ALL, ""); -#endif - invo_name = r1bindex (argv[0], '/'); - - /* read user profile/context */ - context_read(); + if (nmh_init(argv[0], 1)) { return 1; } arguments = getarguments (invo_name, argc, argv, 1); argp = arguments; diff --git a/uip/comp.c b/uip/comp.c index 08507299..02feefaa 100644 --- a/uip/comp.c +++ b/uip/comp.c @@ -83,13 +83,7 @@ main (int argc, char **argv) struct format *fmt; struct stat st; -#ifdef LOCALE - setlocale(LC_ALL, ""); -#endif - invo_name = r1bindex (argv[0], '/'); - - /* read user profile/context */ - context_read(); + if (nmh_init(argv[0], 1)) { return 1; } arguments = getarguments (invo_name, argc, argv, 1); argp = arguments; diff --git a/uip/conflict.c b/uip/conflict.c index a43c70ee..4c140022 100644 --- a/uip/conflict.c +++ b/uip/conflict.c @@ -68,14 +68,7 @@ main (int argc, char **argv) char *cp, **argp, **arguments; char buf[BUFSIZ], *akv[50]; -#ifdef LOCALE - setlocale(LC_ALL, ""); -#endif - invo_name = r1bindex (argv[0], '/'); - - /* foil search of user profile/context */ - if (context_foil (NULL) == -1) - done (1); + if (nmh_init(argv[0], 0 /* use context_foil() */)) { return 1; } mts_init (invo_name); arguments = getarguments (invo_name, argc, argv, 0); diff --git a/uip/dist.c b/uip/dist.c index d3ceaec2..5a35e59a 100644 --- a/uip/dist.c +++ b/uip/dist.c @@ -83,13 +83,7 @@ main (int argc, char **argv) struct msgs *mp = NULL; struct stat st; -#ifdef LOCALE - setlocale(LC_ALL, ""); -#endif - invo_name = r1bindex (argv[0], '/'); - - /* read user profile/context */ - context_read(); + if (nmh_init(argv[0], 1)) { return 1; } arguments = getarguments (invo_name, argc, argv, 1); argp = arguments; diff --git a/uip/dp.c b/uip/dp.c index 67eef061..dabdd74c 100644 --- a/uip/dp.c +++ b/uip/dp.c @@ -51,13 +51,7 @@ main (int argc, char **argv) char buf[BUFSIZ], **argp, **arguments; char *dates[NDATES]; -#ifdef LOCALE - setlocale(LC_ALL, ""); -#endif - invo_name = r1bindex (argv[0], '/'); - - /* read user profile/context */ - context_read(); + if (nmh_init(argv[0], 1)) { return 1; } arguments = getarguments (invo_name, argc, argv, 1); argp = arguments; diff --git a/uip/flist.c b/uip/flist.c index fe3dcebd..829500d6 100644 --- a/uip/flist.c +++ b/uip/flist.c @@ -115,13 +115,7 @@ main(int argc, char **argv) char **arguments; char buf[BUFSIZ]; -#ifdef LOCALE - setlocale(LC_ALL, ""); -#endif - invo_name = r1bindex(argv[0], '/'); - - /* read user profile/context */ - context_read(); + if (nmh_init(argv[0], 1)) { return 1; } /* * If program was invoked with name ending diff --git a/uip/fmtdump.c b/uip/fmtdump.c index 65358168..f1df6f35 100644 --- a/uip/fmtdump.c +++ b/uip/fmtdump.c @@ -51,13 +51,7 @@ main (int argc, char **argv) char buf[BUFSIZ], *nfs, **argp, **arguments; struct format *fmt; -#ifdef LOCALE - setlocale(LC_ALL, ""); -#endif - invo_name = r1bindex (argv[0], '/'); - - /* read user profile/context */ - context_read(); + if (nmh_init(argv[0], 1)) { return 1; } arguments = getarguments (invo_name, argc, argv, 1); argp = arguments; diff --git a/uip/fmttest.c b/uip/fmttest.c index b39d0d52..2f45e7b5 100644 --- a/uip/fmttest.c +++ b/uip/fmttest.c @@ -121,13 +121,7 @@ main (int argc, char **argv) int dat[5]; struct fmt_callbacks cb, *cbp = NULL; -#ifdef LOCALE - setlocale(LC_ALL, ""); -#endif - invo_name = r1bindex (argv[0], '/'); - - /* read user profile/context */ - context_read(); + if (nmh_init(argv[0], 1)) { return 1; } arguments = getarguments (invo_name, argc, argv, 1); argp = arguments; diff --git a/uip/folder.c b/uip/folder.c index 9fa29840..98ecde68 100644 --- a/uip/folder.c +++ b/uip/folder.c @@ -101,13 +101,7 @@ main (int argc, char **argv) char *cp, *dp, *msg = NULL, *argfolder = NULL; char **ap, **argp, buf[BUFSIZ], **arguments; -#ifdef LOCALE - setlocale(LC_ALL, ""); -#endif - invo_name = r1bindex (argv[0], '/'); - - /* read user profile/context */ - context_read(); + if (nmh_init(argv[0], 1)) { return 1; } /* * If program was invoked with name ending diff --git a/uip/forw.c b/uip/forw.c index 45fb740f..2139d35c 100644 --- a/uip/forw.c +++ b/uip/forw.c @@ -116,16 +116,9 @@ main (int argc, char **argv) char **argp, **arguments; struct stat st; struct msgs_array msgs = { 0, 0, NULL }; - int buildsw = 0; -#ifdef LOCALE - setlocale(LC_ALL, ""); -#endif - invo_name = r1bindex (argv[0], '/'); - - /* read user profile/context */ - context_read(); + if (nmh_init(argv[0], 1)) { return 1; } arguments = getarguments (invo_name, argc, argv, 1); argp = arguments; diff --git a/uip/inc.c b/uip/inc.c index 0e527442..bf8216f4 100644 --- a/uip/inc.c +++ b/uip/inc.c @@ -197,13 +197,7 @@ main (int argc, char **argv) SAVEGROUPPRIVS(); TRYDROPGROUPPRIVS(); -#ifdef LOCALE - setlocale(LC_ALL, ""); -#endif - invo_name = r1bindex (argv[0], '/'); - - /* read user profile/context */ - context_read(); + if (nmh_init(argv[0], 1)) { return 1; } mts_init (invo_name); arguments = getarguments (invo_name, argc, argv, 1); diff --git a/uip/install-mh.c b/uip/install-mh.c index 2921d261..12377352 100644 --- a/uip/install-mh.c +++ b/uip/install-mh.c @@ -42,10 +42,8 @@ main (int argc, char **argv) FILE *in, *out; int check; -#ifdef LOCALE - setlocale(LC_ALL, ""); -#endif - invo_name = r1bindex (argv[0], '/'); + if (nmh_init(argv[0], 0 /* use context_foil() */ )) { return 1; } + arguments = getarguments (invo_name, argc, argv, 0); argp = arguments; diff --git a/uip/mark.c b/uip/mark.c index f0f3d7a6..da25f0b3 100644 --- a/uip/mark.c +++ b/uip/mark.c @@ -52,13 +52,7 @@ main (int argc, char **argv) struct msgs_array msgs = { 0, 0, NULL }; struct msgs *mp; -#ifdef LOCALE - setlocale(LC_ALL, ""); -#endif - invo_name = r1bindex (argv[0], '/'); - - /* read user profile/context */ - context_read(); + if (nmh_init(argv[0], 1)) { return 1; } arguments = getarguments (invo_name, argc, argv, 1); argp = arguments; diff --git a/uip/mhbuild.c b/uip/mhbuild.c index f3dc91c7..b0ef72ae 100644 --- a/uip/mhbuild.c +++ b/uip/mhbuild.c @@ -110,15 +110,9 @@ main (int argc, char **argv) FILE *fp_out = NULL; int header_encoding = CE_UNKNOWN; - done=unlink_done; - -#ifdef LOCALE - setlocale(LC_ALL, ""); -#endif - invo_name = r1bindex (argv[0], '/'); + if (nmh_init(argv[0], 1)) { return 1; } - /* read user profile/context */ - context_read(); + done=unlink_done; arguments = getarguments (invo_name, argc, argv, 1); argp = arguments; diff --git a/uip/mhfixmsg.c b/uip/mhfixmsg.c index d81337d6..a59ca509 100644 --- a/uip/mhfixmsg.c +++ b/uip/mhfixmsg.c @@ -134,15 +134,9 @@ main (int argc, char **argv) { fx.decodetext = CE_8BIT; fx.textcodeset = NULL; - done = freects_done; - -#ifdef LOCALE - setlocale(LC_ALL, ""); -#endif - invo_name = r1bindex (argv[0], '/'); + if (nmh_init(argv[0], 1)) { return 1; } - /* read user profile/context */ - context_read(); + done = freects_done; arguments = getarguments (invo_name, argc, argv, 1); argp = arguments; diff --git a/uip/mhl.c b/uip/mhl.c index af4cdfa8..652fb11b 100644 --- a/uip/mhl.c +++ b/uip/mhl.c @@ -13,9 +13,8 @@ int main (int argc, char **argv) { -#ifdef LOCALE - setlocale(LC_ALL, ""); -#endif + if (nmh_init(argv[0], 1)) { return 1; } + done (mhl (argc, argv)); return 1; } diff --git a/uip/mhlist.c b/uip/mhlist.c index 9cdcdf6b..f37041c3 100644 --- a/uip/mhlist.c +++ b/uip/mhlist.c @@ -104,15 +104,9 @@ main (int argc, char **argv) struct msgs *mp = NULL; CT ct, *ctp; - done=freects_done; - -#ifdef LOCALE - setlocale(LC_ALL, ""); -#endif - invo_name = r1bindex (argv[0], '/'); + if (nmh_init(argv[0], 1)) { return 1; } - /* read user profile/context */ - context_read(); + done=freects_done; arguments = getarguments (invo_name, argc, argv, 1); argp = arguments; diff --git a/uip/mhlsbr.c b/uip/mhlsbr.c index 6a1c3db7..f4df180a 100644 --- a/uip/mhlsbr.c +++ b/uip/mhlsbr.c @@ -349,11 +349,6 @@ mhl (int argc, char **argv) char buf[BUFSIZ], *files[MAXARGS]; char **argp, **arguments; - invo_name = r1bindex (argv[0], '/'); - - /* read user profile/context */ - context_read(); - arguments = getarguments (invo_name, argc, argv, 1); argp = arguments; diff --git a/uip/mhn.c b/uip/mhn.c index 49c784b9..08405d4d 100644 --- a/uip/mhn.c +++ b/uip/mhn.c @@ -164,15 +164,9 @@ main (int argc, char **argv) CT ct, *ctp; FILE *fp; - done=freects_done; - -#ifdef LOCALE - setlocale(LC_ALL, ""); -#endif - invo_name = r1bindex (argv[0], '/'); + if (nmh_init(argv[0], 1)) { return 1; } - /* read user profile/context */ - context_read(); + done=freects_done; arguments = getarguments (invo_name, argc, argv, 1); argp = arguments; diff --git a/uip/mhparam.c b/uip/mhparam.c index b0c119cf..8a276f72 100644 --- a/uip/mhparam.c +++ b/uip/mhparam.c @@ -131,10 +131,7 @@ main(int argc, char **argv) char *cp, buf[BUFSIZ], **argp; char **arguments, *comps[MAXARGS]; - invo_name = r1bindex (argv[0], '/'); - - /* read user profile/context */ - context_read(); + if (nmh_init(argv[0], 1)) { return 1; } arguments = getarguments (invo_name, argc, argv, 1); argp = arguments; diff --git a/uip/mhpath.c b/uip/mhpath.c index 3a0a628b..b9506d73 100644 --- a/uip/mhpath.c +++ b/uip/mhpath.c @@ -32,13 +32,7 @@ main(int argc, char **argv) struct msgs_array msgs = { 0, 0, NULL }; struct msgs *mp; -#ifdef LOCALE - setlocale(LC_ALL, ""); -#endif - invo_name = r1bindex (argv[0], '/'); - - /* read user profile/context */ - context_read(); + if (nmh_init(argv[0], 1)) { return 1; } arguments = getarguments (invo_name, argc, argv, 1); argp = arguments; diff --git a/uip/mhshow.c b/uip/mhshow.c index 3d1f3e6b..f83236b7 100644 --- a/uip/mhshow.c +++ b/uip/mhshow.c @@ -114,15 +114,9 @@ main (int argc, char **argv) CT ct, *ctp; FILE *fp; - done=freects_done; - -#ifdef LOCALE - setlocale(LC_ALL, ""); -#endif - invo_name = r1bindex (argv[0], '/'); + if (nmh_init(argv[0], 1)) { return 1; } - /* read user profile/context */ - context_read(); + done=freects_done; arguments = getarguments (invo_name, argc, argv, 1); argp = arguments; diff --git a/uip/mhstore.c b/uip/mhstore.c index 050310cf..fb5349fa 100644 --- a/uip/mhstore.c +++ b/uip/mhstore.c @@ -103,15 +103,9 @@ main (int argc, char **argv) CT ct, *ctp; FILE *fp; - done=freects_done; - -#ifdef LOCALE - setlocale(LC_ALL, ""); -#endif - invo_name = r1bindex (argv[0], '/'); + if (nmh_init(argv[0], 1)) { return 1; } - /* read user profile/context */ - context_read(); + done=freects_done; arguments = getarguments (invo_name, argc, argv, 1); argp = arguments; diff --git a/uip/mhtest.c b/uip/mhtest.c index abdfdadf..30459136 100644 --- a/uip/mhtest.c +++ b/uip/mhtest.c @@ -99,15 +99,9 @@ main (int argc, char **argv) struct msgs *mp = NULL; CT ct, *ctp; - done=freects_done; - -#ifdef LOCALE - setlocale(LC_ALL, ""); -#endif - invo_name = r1bindex (argv[0], '/'); + if (nmh_init(argv[0], 1)) { return 1; } - /* read user profile/context */ - context_read(); + done=freects_done; arguments = getarguments (invo_name, argc, argv, 1); argp = arguments; diff --git a/uip/msgchk.c b/uip/msgchk.c index 76bb37d8..49e758f0 100644 --- a/uip/msgchk.c +++ b/uip/msgchk.c @@ -85,13 +85,7 @@ main (int argc, char **argv) char **argp, **arguments, *vec[MAXVEC]; struct passwd *pw; -#ifdef LOCALE - setlocale(LC_ALL, ""); -#endif - invo_name = r1bindex (argv[0], '/'); - - /* read user profile/context */ - context_read(); + if (nmh_init(argv[0], 1)) { return 1; } mts_init (invo_name); diff --git a/uip/msh.c b/uip/msh.c index 2fb2b230..fbfb408e 100644 --- a/uip/msh.c +++ b/uip/msh.c @@ -203,13 +203,7 @@ main (int argc, char **argv) char *cp, *file = NULL, *folder = NULL; char **argp, **arguments, buf[BUFSIZ]; -#ifdef LOCALE - setlocale(LC_ALL, ""); -#endif - invo_name = r1bindex (argv[0], '/'); - - /* read user profile/context */ - context_read(); + if (nmh_init(argv[0], 1)) { return 1; } mts_init (invo_name); arguments = getarguments (invo_name, argc,argv, 1); diff --git a/uip/new.c b/uip/new.c index 74d4d512..6f998252 100644 --- a/uip/new.c +++ b/uip/new.c @@ -422,13 +422,7 @@ main(int argc, char **argv) char *unseen; struct node *folder; -#ifdef LOCALE - setlocale(LC_ALL, ""); -#endif - invo_name = r1bindex(argv[0], '/'); - - /* read user profile/context */ - context_read(); + if (nmh_init(argv[0], 1)) { return 1; } arguments = getarguments (invo_name, argc, argv, 1); argp = arguments; diff --git a/uip/packf.c b/uip/packf.c index f070f48d..30f0f484 100644 --- a/uip/packf.c +++ b/uip/packf.c @@ -46,15 +46,9 @@ main (int argc, char **argv) struct msgs *mp; struct stat st; - done=mbxclose_done; - -#ifdef LOCALE - setlocale(LC_ALL, ""); -#endif - invo_name = r1bindex (argv[0], '/'); + if (nmh_init(argv[0], 1)) { return 1; } - /* read user profile/context */ - context_read(); + done=mbxclose_done; arguments = getarguments (invo_name, argc, argv, 1); argp = arguments; diff --git a/uip/pick.c b/uip/pick.c index 5f280243..740f6f0a 100644 --- a/uip/pick.c +++ b/uip/pick.c @@ -66,15 +66,9 @@ main (int argc, char **argv) struct msgs *mp, *mp2; register FILE *fp; - done=putzero_done; - -#ifdef LOCALE - setlocale(LC_ALL, ""); -#endif - invo_name = r1bindex (argv[0], '/'); + if (nmh_init(argv[0], 1)) { return 1; } - /* read user profile/context */ - context_read(); + done=putzero_done; arguments = getarguments (invo_name, argc, argv, 1); argp = arguments; diff --git a/uip/post.c b/uip/post.c index 2683622e..5d227c40 100644 --- a/uip/post.c +++ b/uip/post.c @@ -283,14 +283,7 @@ main (int argc, char **argv) FILE *in, *out; m_getfld_state_t gstate = 0; -#ifdef LOCALE - setlocale(LC_ALL, ""); -#endif - invo_name = r1bindex (argv[0], '/'); - - /* foil search of user profile/context */ - if (context_foil (NULL) == -1) - done (1); + if (nmh_init(argv[0], 0 /* use context_foil() */)) { return 1; } mts_init (invo_name); arguments = getarguments (invo_name, argc, argv, 0); diff --git a/uip/prompter.c b/uip/prompter.c index 0aedc8c1..35052e62 100644 --- a/uip/prompter.c +++ b/uip/prompter.c @@ -78,13 +78,7 @@ main (int argc, char **argv) char *tmpfil; m_getfld_state_t gstate = 0; -#ifdef LOCALE - setlocale(LC_ALL, ""); -#endif - invo_name = r1bindex (argv[0], '/'); - - /* read user profile/context */ - context_read(); + if (nmh_init(argv[0], 1)) { return 1; } arguments = getarguments (invo_name, argc, argv, 1); argp = arguments; diff --git a/uip/rcvdist.c b/uip/rcvdist.c index 4f7a83f7..a87a5e84 100644 --- a/uip/rcvdist.c +++ b/uip/rcvdist.c @@ -48,15 +48,9 @@ main (int argc, char **argv) FILE *fp; char *tfile = NULL; - done=unlink_done; - -#ifdef LOCALE - setlocale(LC_ALL, ""); -#endif - invo_name = r1bindex (argv[0], '/'); + if (nmh_init(argv[0], 1)) { return 1; } - /* read user profile/context */ - context_read(); + done=unlink_done; /* * Configure this now, since any unknown switches to rcvdist get diff --git a/uip/rcvpack.c b/uip/rcvpack.c index 4725f26c..bbd0e08e 100644 --- a/uip/rcvpack.c +++ b/uip/rcvpack.c @@ -40,13 +40,7 @@ main (int argc, char **argv) char *cp, *file = NULL, buf[BUFSIZ]; char **argp, **arguments; -#ifdef LOCALE - setlocale(LC_ALL, ""); -#endif - invo_name = r1bindex (argv[0], '/'); - - /* read user profile/context */ - context_read(); + if (nmh_init(argv[0], 1)) { return 1; } mts_init (invo_name); arguments = getarguments (invo_name, argc, argv, 1); diff --git a/uip/rcvstore.c b/uip/rcvstore.c index e6de62b0..64b4a007 100644 --- a/uip/rcvstore.c +++ b/uip/rcvstore.c @@ -54,15 +54,9 @@ main (int argc, char **argv) struct msgs *mp; struct stat st; - done=unlink_done; - -#ifdef LOCALE - setlocale(LC_ALL, ""); -#endif - invo_name = r1bindex (argv[0], '/'); + if (nmh_init(argv[0], 1)) { return 1; } - /* read user profile/context */ - context_read(); + done=unlink_done; mts_init (invo_name); arguments = getarguments (invo_name, argc, argv, 1); diff --git a/uip/rcvtty.c b/uip/rcvtty.c index 9dd862c7..bf140ddd 100644 --- a/uip/rcvtty.c +++ b/uip/rcvtty.c @@ -81,13 +81,8 @@ main (int argc, char **argv) char *cp, *user, buf[BUFSIZ], tty[BUFSIZ]; char **argp, **arguments, *vec[MAXARGS]; struct utmpx *utp; -#ifdef LOCALE - setlocale(LC_ALL, ""); -#endif - invo_name = r1bindex (argv[0], '/'); - /* read user profile/context */ - context_read(); + if (nmh_init(argv[0], 1)) { return 1; } mts_init (invo_name); arguments = getarguments (invo_name, argc, argv, 1); diff --git a/uip/refile.c b/uip/refile.c index 19e12661..1dc2dff4 100644 --- a/uip/refile.c +++ b/uip/refile.c @@ -68,13 +68,7 @@ main (int argc, char **argv) struct msgs_array msgs = { 0, 0, NULL }; struct msgs *mp; -#ifdef LOCALE - setlocale(LC_ALL, ""); -#endif - invo_name = r1bindex (argv[0], '/'); - - /* read user profile/context */ - context_read(); + if (nmh_init(argv[0], 1)) { return 1; } arguments = getarguments (invo_name, argc, argv, 1); argp = arguments; diff --git a/uip/repl.c b/uip/repl.c index 84374569..7b0ab4a0 100644 --- a/uip/repl.c +++ b/uip/repl.c @@ -129,13 +129,7 @@ main (int argc, char **argv) int buildsw = 0; -#ifdef LOCALE - setlocale(LC_ALL, ""); -#endif - invo_name = r1bindex (argv[0], '/'); - - /* read user profile/context */ - context_read(); + if (nmh_init(argv[0], 1)) { return 1; } arguments = getarguments (invo_name, argc, argv, 1); argp = arguments; diff --git a/uip/rmf.c b/uip/rmf.c index 9e922475..765ec9e1 100644 --- a/uip/rmf.c +++ b/uip/rmf.c @@ -37,13 +37,7 @@ main (int argc, char **argv) char *cp, *folder = NULL, newfolder[BUFSIZ]; char buf[BUFSIZ], **argp, **arguments; -#ifdef LOCALE - setlocale(LC_ALL, ""); -#endif - invo_name = r1bindex (argv[0], '/'); - - /* read user profile/context */ - context_read(); + if (nmh_init(argv[0], 1)) { return 1; } arguments = getarguments (invo_name, argc, argv, 1); argp = arguments; diff --git a/uip/rmm.c b/uip/rmm.c index ee602b45..8644a02f 100644 --- a/uip/rmm.c +++ b/uip/rmm.c @@ -37,13 +37,7 @@ main (int argc, char **argv) struct msgs_array msgs = { 0, 0, NULL }; struct msgs *mp; -#ifdef LOCALE - setlocale(LC_ALL, ""); -#endif - invo_name = r1bindex (argv[0], '/'); - - /* read user profile/context */ - context_read(); + if (nmh_init(argv[0], 1)) { return 1; } arguments = getarguments (invo_name, argc, argv, 1); argp = arguments; diff --git a/uip/scan.c b/uip/scan.c index 1f487cdd..20668691 100644 --- a/uip/scan.c +++ b/uip/scan.c @@ -52,13 +52,7 @@ main (int argc, char **argv) struct msgs *mp; FILE *in; -#ifdef LOCALE - setlocale(LC_ALL, ""); -#endif - invo_name = r1bindex (argv[0], '/'); - - /* read user profile/context */ - context_read(); + if (nmh_init(argv[0], 1)) { return 1; } mts_init (invo_name); arguments = getarguments (invo_name, argc, argv, 1); diff --git a/uip/send.c b/uip/send.c index 2fabe1c3..c8ad788b 100644 --- a/uip/send.c +++ b/uip/send.c @@ -120,13 +120,7 @@ main (int argc, char **argv) char *attach = NMH_ATTACH_HEADER; /* header field name for attachments */ int attachformat = 1; /* mhbuild format specifier for attachments */ -#ifdef LOCALE - setlocale(LC_ALL, ""); -#endif - invo_name = r1bindex (argv[0], '/'); - - /* read user profile/context */ - context_read(); + if (nmh_init(argv[0], 1)) { return 1; } arguments = getarguments (invo_name, argc, argv, 1); argp = arguments; diff --git a/uip/show.c b/uip/show.c index 5a912f6b..acd08afb 100644 --- a/uip/show.c +++ b/uip/show.c @@ -61,13 +61,7 @@ main (int argc, char **argv) struct msgs_array msgs = { 0, 0, NULL }; struct msgs_array vec = { 0, 0, NULL }; -#ifdef LOCALE - setlocale(LC_ALL, ""); -#endif - invo_name = r1bindex (argv[0], '/'); - - /* read user profile/context */ - context_read(); + if (nmh_init(argv[0], 1)) { return 1; } if (!strcasecmp (invo_name, "next")) { mode = NEXT; diff --git a/uip/slocal.c b/uip/slocal.c index 7ffbe57d..6e22076a 100644 --- a/uip/slocal.c +++ b/uip/slocal.c @@ -188,14 +188,7 @@ main (int argc, char **argv) char mailbox[BUFSIZ], tmpfil[BUFSIZ]; char **argp, **arguments; -#ifdef LOCALE - setlocale(LC_ALL, ""); -#endif - invo_name = r1bindex (*argv, '/'); - - /* foil search of user profile/context */ - if (context_foil (NULL) == -1) - done (1); + if (nmh_init(argv[0], 0 /* use context_foil() */)) { return 1; } mts_init (invo_name); arguments = getarguments (invo_name, argc, argv, 0); diff --git a/uip/sortm.c b/uip/sortm.c index 72fe0659..3df18859 100644 --- a/uip/sortm.c +++ b/uip/sortm.c @@ -78,13 +78,7 @@ main (int argc, char **argv) struct smsg **dlist; int checksw = 0; -#ifdef LOCALE - setlocale(LC_ALL, ""); -#endif - invo_name = r1bindex (argv[0], '/'); - - /* read user profile/context */ - context_read(); + if (nmh_init(argv[0], 1)) { return 1; } arguments = getarguments (invo_name, argc, argv, 1); argp = arguments; diff --git a/uip/viamail.c b/uip/viamail.c index 198413f2..10adf537 100644 --- a/uip/viamail.c +++ b/uip/viamail.c @@ -58,14 +58,7 @@ main (int argc, char **argv) char *cp, buf[BUFSIZ]; char **argp, **arguments; -#ifdef LOCALE - setlocale(LC_ALL, ""); -#endif - invo_name = r1bindex (argv[0], '/'); - - /* foil search of user profile/context */ - if (context_foil (NULL) == -1) - done (1); + if (nmh_init(argv[0], 0 /* use context_foil() */)) { return 1; } arguments = getarguments (invo_name, argc, argv, 0); argp = arguments; diff --git a/uip/whatnow.c b/uip/whatnow.c index be50bc92..031ff3c8 100644 --- a/uip/whatnow.c +++ b/uip/whatnow.c @@ -13,8 +13,7 @@ int main (int argc, char **argv) { -#ifdef LOCALE - setlocale(LC_ALL, ""); -#endif + if (nmh_init(argv[0], 1)) { return 1; } + return WhatNow (argc, argv); } diff --git a/uip/whatnowsbr.c b/uip/whatnowsbr.c index d4141389..3663f478 100644 --- a/uip/whatnowsbr.c +++ b/uip/whatnowsbr.c @@ -130,11 +130,6 @@ WhatNow (int argc, char **argv) char *l; /* set on -l to alist command */ int n; /* set on -n to alist command */ - invo_name = r1bindex (argv[0], '/'); - - /* read user profile/context */ - context_read(); - arguments = getarguments (invo_name, argc, argv, 1); argp = arguments; diff --git a/uip/whom.c b/uip/whom.c index eca3946d..980cdda5 100644 --- a/uip/whom.c +++ b/uip/whom.c @@ -63,13 +63,7 @@ main (int argc, char **argv) char *msg = NULL, **ap, **argp, backup[BUFSIZ]; char buf[BUFSIZ], **arguments, *vec[MAXARGS]; -#ifdef LOCALE - setlocale(LC_ALL, ""); -#endif - invo_name = r1bindex (argv[0], '/'); - - /* read user profile/context */ - context_read(); + if (nmh_init(argv[0], 1)) { return 1; } arguments = getarguments (invo_name, argc, argv, 1); argp = arguments;