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
-------------------------
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
--------------
void svector_free (svector_t);
char *svector_push_back (svector_t, char *);
char *svector_at (svector_t, size_t);
+char **svector_find(svector_t, const char *);
char **svector_strs (svector_t);
size_t svector_size (svector_t);
int m_rand (unsigned char *, size_t);
char *m_mktemp(const char *, int *, FILE **);
char *m_mktemp2(const char *, const char *, int *, FILE **);
+char *get_temp_dir();
void m_unknown(m_getfld_state_t *, FILE *);
int makedir (char *);
char *message_id (time_t, 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);
sigprocmask (SIG_SETMASK, &oset, &set); /* reset the signal mask */
if (action == 0)
+ /* This must be _exit(), not exit(), because the child didn't
+ call unregister_for_removal() in m_chkids(). */
_exit (0); /* we are child, time to die */
}
break;
case 0:
+ /* It's not necessary to call unregister_for_removal(0)
+ because the child calls _exit() in context_save(). */
setgid (getgid ());
setuid (getuid ());
break;
if (unlink_msgs) {
/* just unlink the messages */
- if (unlink (dp) == -1) {
+ if (m_unlink (dp) == -1) {
admonish (dp, "unable to unlink");
retval = -1;
continue;
lockname (file, &lkinfo, 0); /* get name of lock file */
#if !defined(HAVE_LIBLOCKFILE)
- unlink (lkinfo.curlock); /* remove lock file */
+ (void) m_unlink (lkinfo.curlock); /* remove lock file */
#else
lockfile_remove(lkinfo.curlock);
#endif /* HAVE_LIBLOCKFILE */
/* check for stale lockfile, else sleep */
if (curtime > st.st_ctime + RSECS)
- unlink (lkinfo.curlock);
+ (void) m_unlink (lkinfo.curlock);
else
sleep (5);
}
lockit (struct lockinfo *li)
{
int fd;
- char *curlock, *tmplock;
+ char *curlock, *tmpfile;
#if 0
char buffer[128];
#endif
curlock = li->curlock;
- tmplock = li->tmplock;
- if ((fd = mkstemp(tmplock)) == -1)
+ if ((tmpfile = m_mktemp(li->tmplock, &fd, NULL)) == NULL) {
+ advise(NULL, "unable to create temporary file in %s", get_temp_dir());
return -1;
+ }
#if 0
/* write our process id into lock file */
* Now try to create the real lock file
* by linking to the temporary file.
*/
- fd = link(tmplock, curlock);
- unlink(tmplock);
+ fd = link(tmpfile, curlock);
+ (void) m_unlink(tmpfile);
return (fd == -1 ? -1 : 0);
}
snprintf(buffer, sizeof(buffer), "%.*s%s%s", (int)(cp - file), file,
BACKUP_PREFIX, cp);
- unlink(buffer);
+ (void) m_unlink(buffer);
return buffer;
}
*/
#include <h/mh.h>
+#include <h/utils.h>
+#include <h/signals.h>
+
+static void register_for_removal(const char *);
-static char *get_temp_dir();
/* Create a temporary file. If pfx_in is null, the temporary file
* will be created in the temporary directory (more on that later).
*
* When pfx_in is null, the temporary directory is determined as
* follows, in order:
- *
+ *
* MHTMPDIR envvar
* TMPDIR envvar
* TMP envvar
}
fd = mkstemp(tmpfil);
+
if (fd < 0) {
umask(oldmode);
return NULL;
}
+
+ register_for_removal(tmpfil);
+
if (fd_ret != NULL) {
*fd_ret = fd;
keep_open = 1;
FILE *fp = fdopen(fd, "w+");
if (fp == NULL) {
int olderr = errno;
- unlink(tmpfil);
+ (void) m_unlink(tmpfil);
close(fd);
errno = olderr;
umask(oldmode);
* by created based on a given pathname. Although m_mktemp() technically
* supports this, this version is when the directory is defined by
* a separate variable from the prefix, eliminating the caller from having
- * to do string manipulation to generate the desired. pathname prefix.
+ * to do string manipulation to generate the desired pathname prefix.
*
* The pfx_in parameter specifies a basename prefix for the file. If dir_in
* is NULL, then the defined temporary directory (see comments to m_mktemp()
}
-static char *
+char *
get_temp_dir()
{
/* Ignore envvars if we are setuid */
}
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);
+ }
+}
SIGNAL (SIGTTIN, SIG_IGN);
SIGNAL (SIGTTOU, SIG_IGN);
#endif
+
+ unregister_for_removal(0);
+
freopen ("/dev/null", "r", stdin);
freopen ("/dev/null", "w", stdout);
break;
rewind(fp);
ftruncate(fileno(fp), 0);
} else if ((fp = lkfopendata (seqfile, "w")) == NULL
- && (unlink (seqfile) == -1 ||
+ && (m_unlink (seqfile) == -1 ||
(fp = lkfopendata (seqfile, "w")) == NULL)) {
admonish (attr, "unable to write");
goto priv;
* public sequences, then remove that file.
*/
if (!is_readonly(mp))
- unlink (seqfile);
+ (void) m_unlink (seqfile);
}
/*
#include <h/mh.h>
#include <h/signals.h>
+/* sbr/m_mktemp.c */
+extern void remove_registered_files(int);
+
/*
* A version of the function `signal' that uses reliable
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;
+}
#include <h/utils.h>
#include <fcntl.h>
+/* 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.
return NULL;
}
+
+
+int
+nmh_init(const char *argv0, int read_context) {
+ setlocale(LC_ALL, "");
+
+ 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;
+ }
+}
return vec->strs[i];
}
+/*
+ * Return address of first element that stringwise matches s.
+ * The caller can replace the contents of the return address.
+ */
+char **
+svector_find (svector_t vec, const char *s) {
+ size_t i;
+ char **str = vec->strs;
+
+ for (i = 0; i < vec->size; ++i, ++str) {
+ if (*str && ! strcmp(*str, s)) {
+ return str;
+ }
+ }
+
+ return NULL;
+}
+
char **
svector_strs (svector_t vec) {
return vec->strs;
char **vec = mh_xmalloc (argc * sizeof (char *)), **arguments;
struct aka *ak;
- setlocale(LC_ALL, "");
- 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);
int list = 0; /* list header elements if set */
int number = 0; /* delete specific number of like elements if set */
- setlocale(LC_ALL, "");
- 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;
mode = fstat (fd, &st) != NOTOK ? (int) (st.st_mode & 0777) : m_gmprot ();
- strncpy (tmpfil, m_mktemp2(file, "annotate", NULL, &tmp), sizeof(tmpfil));
+ if ((cp = m_mktemp2(file, "annotate", NULL, &tmp)) == NULL) {
+ adios(NULL, "unable to create temporary file in %s", get_temp_dir());
+ }
+ strncpy (tmpfil, cp, sizeof(tmpfil));
chmod (tmpfil, mode);
/*
cpydata (tmpfd, fd, tmpfil, file);
close (tmpfd);
- unlink (tmpfil);
+ (void) m_unlink (tmpfil);
} else {
strncpy (buffer, m_backup (file), sizeof(buffer));
if (rename (file, buffer) == NOTOK) {
switch (errno) {
case ENOENT: /* unlinked early - no annotations */
- unlink (tmpfil);
+ (void) m_unlink (tmpfil);
break;
default:
char buf[BUFSIZ], **argp;
char **arguments, *addrs[NADDRS];
- setlocale(LC_ALL, "");
- 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);
struct smsg *smsgs;
struct msgs *mp;
- setlocale(LC_ALL, "");
- 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;
i = inplace ? msgnum + numburst : mp->hghmsg;
for (j = numburst; j >= (inplace ? 0 : 1); i--, j--) {
+ char *tempfile;
+
+ if ((tempfile = m_mktemp2(NULL, invo_name, NULL, &out)) == NULL) {
+ adios(NULL, "unable to create temporary file in %s",
+ get_temp_dir());
+ }
+ strncpy (f2, tempfile, sizeof(f2));
strncpy (f1, m_name (i), sizeof(f1));
- strncpy (f2, m_mktemp(invo_name, NULL, &out), sizeof(f2));
if (verbosw && i != msgnum)
printf ("message %d of digest %d becomes message %d\n", j, msgnum, i);
struct format *fmt;
struct stat st;
- setlocale(LC_ALL, "");
- 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;
char *cp, **argp, **arguments;
char buf[BUFSIZ], *akv[50];
- setlocale(LC_ALL, "");
- 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);
struct msgs *mp = NULL;
struct stat st;
- setlocale(LC_ALL, "");
- 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;
leave_bad: ;
fclose (ifp);
fclose (ofp);
- unlink (drft);
+ (void) m_unlink (drft);
if (rename (backup, drft) == NOTOK)
adios (drft, "unable to rename %s to", backup);
return NOTOK;
if (!resent) {
advise (NULL, BADMSG, "draft");
fclose (ofp);
- unlink (drft);
+ (void) m_unlink (drft);
if (rename (backup, drft) == NOTOK)
adios (drft, "unable to rename %s to", backup);
return NOTOK;
cp = m_mktemp2(NULL, "dist", &hdrfd, NULL);
if (cp == NULL) {
- adios("distsbr", "unable to create temporary file");
+ adios(NULL, "unable to create temporary file in %s", get_temp_dir());
}
- fchmod(hdrfd, 0600);
strncpy(tmpfil, cp, sizeof(tmpfil));
if ((out = dup (hdrfd)) == NOTOK
|| (ofp = fdopen (out, "w")) == NULL)
adios (NULL, "no file descriptors -- you lose big");
- unlink (tmpfil);
+ (void) m_unlink (tmpfil);
for (;;) {
int buffersz = sizeof buffer;
cp = m_mktemp2(NULL, "dist", &txtfd, NULL);
if (cp == NULL) {
- adios("distsbr", "unable to create temporary file");
+ adios(NULL, "unable to create temporary file in %s",
+ get_temp_dir());
}
fchmod(txtfd, 0600);
strncpy (tmpfil, cp, sizeof(tmpfil));
if ((out = dup (txtfd)) == NOTOK
|| (ofp = fdopen (out, "w")) == NULL)
adios (NULL, "no file descriptors -- you lose big");
- unlink (tmpfil);
+ (void) m_unlink (tmpfil);
fprintf (ofp, "\n%s", buffer);
while (state == BODY) {
buffersz = sizeof buffer;
char buf[BUFSIZ], **argp, **arguments;
char *dates[NDATES];
- setlocale(LC_ALL, "");
- 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;
clear = 1;
if (!clear && map_chk (file, fd, &d1, pos, noisy)) {
- unlink (file);
+ (void) m_unlink (file);
mbx_close (file, fd);
if ((fd = map_open (file, md)) == NOTOK)
return NOTOK;
char **arguments;
char buf[BUFSIZ];
- setlocale(LC_ALL, "");
- 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
char buf[BUFSIZ], *nfs, **argp, **arguments;
struct format *fmt;
- setlocale(LC_ALL, "");
- 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;
int dat[5];
struct fmt_callbacks cb, *cbp = NULL;
- setlocale(LC_ALL, "");
- 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;
char *cp, *dp, *msg = NULL, *argfolder = NULL;
char **ap, **argp, buf[BUFSIZ], **arguments;
- setlocale(LC_ALL, "");
- 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
char **argp, **arguments;
struct stat st;
struct msgs_array msgs = { 0, 0, NULL };
-
int buildsw = 0;
- setlocale(LC_ALL, "");
- 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;
}
cp = m_mktemp2(NULL, invo_name, NULL, &tmp);
- if (cp == NULL) adios("forw", "unable to create temporary file");
+ if (cp == NULL) {
+ adios(NULL, "unable to create temporary file in %s", get_temp_dir());
+ }
strncpy (tmpfil, cp, sizeof(tmpfil));
- unlink (tmpfil);
+ (void) m_unlink (tmpfil);
if ((in = dup (fileno (tmp))) == NOTOK)
adios ("dup", "unable to");
SAVEGROUPPRIVS();
TRYDROPGROUPPRIVS();
- setlocale(LC_ALL, "");
- 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);
} else {
if (ferror(pf) || fclose (pf)) {
int e = errno;
- unlink (cp);
+ (void) m_unlink (cp);
pop_quit ();
errno = e;
adios (cp, "write error on");
break;
if (ferror(sf) || fflush(pf) || ferror(pf)) {
int e = errno;
- fclose(pf); fclose(sf); unlink(cp);
+ fclose(pf); fclose(sf); (void) m_unlink(cp);
errno = e;
adios(cp, "copy error %s -> %s", sp, cp);
}
}
if (ferror(pf) || fclose (pf)) {
int e = errno;
- unlink (cp);
+ (void) m_unlink (cp);
errno = e;
adios (cp, "write error on");
}
pf = NULL;
free (cp);
- if (trnflag && unlink (sp) == NOTOK)
+ if (trnflag && m_unlink (sp) == NOTOK)
adios (sp, "couldn't unlink");
free (sp); /* Free Maildir[i]->filename */
}
close (newfd);
else
admonish (newmail, "error zero'ing");
- unlink(map_name(newmail));
+ (void) m_unlink(map_name(newmail));
}
} else {
if (noisy)
FILE *in, *out;
int check;
- setlocale(LC_ALL, "");
- 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;
struct msgs_array msgs = { 0, 0, NULL };
struct msgs *mp;
- setlocale(LC_ALL, "");
- 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;
DEFINE_SWITCH_ARRAY(MIMEENCODING, encodingswitches);
#undef X
-/* mhbuildsbr.c */
-extern char *tmp; /* directory to place temp files */
-
/* mhcachesbr.c */
extern int rcachesw;
extern int wcachesw;
FILE *fp_out = NULL;
int header_encoding = CE_UNKNOWN;
- done=unlink_done;
-
- setlocale(LC_ALL, "");
- 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;
cache_private = ".cache";
cache_private = getcpy (m_maildir (cache_private));
- /*
- * Check for storage directory. If defined, we
- * will store temporary files there. Else we
- * store them in standard nmh directory.
- */
- if ((cp = context_find (nmhstorage)) && *cp)
- tmp = concat (cp, "/", invo_name, NULL);
- else
- tmp = add (m_maildir (invo_name), NULL);
-
if (!context_find ("path"))
free (path ("./", TFOLDER));
* Process the composition file from standard input.
*/
if (compfile[0] == '-' && compfile[1] == '\0') {
+ if ((cp = m_mktemp2(NULL, invo_name, NULL, &fp)) == NULL) {
+ adios(NULL, "unable to create temporary file in %s",
+ get_temp_dir());
+ }
+
/* copy standard input to temporary file */
- strncpy (infile, m_mktemp(invo_name, NULL, &fp), sizeof(infile));
+ strncpy (infile, cp, sizeof(infile));
while (fgets (buffer, BUFSIZ, stdin))
fputs (buffer, fp);
fclose (fp);
free_content (ct);
}
- unlink (infile);
+ (void) m_unlink (infile);
unlink_infile = 0;
done (0);
cts[1] = NULL;
/* output MIME message to this temporary file */
- strncpy(outfile, m_mktemp2(compfile, invo_name, NULL, &fp_out),
- sizeof(outfile));
+ if ((cp = m_mktemp2(compfile, invo_name, NULL, &fp_out)) == NULL) {
+ adios(NULL, "unable to create temporary file in %s", get_temp_dir());
+ }
+ strncpy(outfile, cp, sizeof(outfile));
unlink_outfile = 1;
/* output the message */
* temporary files.
*/
if (unlink_infile)
- unlink (infile);
+ (void) m_unlink (infile);
if (unlink_outfile)
- unlink (outfile);
+ (void) m_unlink (outfile);
exit (status);
}
extern int rcachesw; /* mhcachesbr.c */
extern int wcachesw; /* mhcachesbr.c */
-/*
- * Directory to place tmp files. This must
- * be set before these routines are called.
- */
-char *tmp;
-
pid_t xpid = 0;
static char prefix[] = "----- =_aaaaaaaaaa";
FILE *out;
char *cp;
- cp = m_mktemp2(NULL, invo_name, NULL, &out);
- if (cp == NULL) adios("mhbuildsbr", "unable to create temporary file");
+ if ((cp = m_mktemp2(NULL, invo_name, NULL, &out)) == NULL) {
+ adios("mhbuildsbr", "unable to create temporary file in %s",
+ get_temp_dir());
+ }
/* use a temp file to collect the plain text lines */
ce->ce_file = add (cp, NULL);
if (!(cp = ci->ci_magic))
adios (NULL, "internal error(5)");
- tfile = m_mktemp2(NULL, invo_name, NULL, NULL);
- if (tfile == NULL) {
- adios("mhbuildsbr", "unable to create temporary file");
- }
+ if ((tfile = m_mktemp2(NULL, invo_name, NULL, NULL)) == NULL) {
+ adios("mhbuildsbr", "unable to create temporary file in %s",
+ get_temp_dir());
+ }
ce->ce_file = add (tfile, NULL);
ce->ce_unlink = 1;
if (ferror (gp)) {
admonish (ce->ce_file, "error reading");
- unlink (cachefile);
+ (void) m_unlink (cachefile);
} else {
if (ferror (fp)) {
admonish (cachefile, "error writing");
- unlink (cachefile);
+ (void) m_unlink (cachefile);
}
}
fclose (fp);
if (status == OK && writing) {
if (*writing && strchr(buffer, '/'))
make_intermediates (buffer);
- unlink (buffer);
+ (void) m_unlink (buffer);
}
free (id);
#define quitser pipeser
/* mhparse.c */
-extern char *tmp; /* directory to place tmp files */
extern int skip_mp_cte_check; /* flag to InitMultiPart */
extern int suppress_bogus_mp_content_warning; /* flag to InitMultiPart */
extern int bogus_mp_content; /* flag from InitMultiPart */
fx.decodetext = CE_8BIT;
fx.textcodeset = NULL;
- done = freects_done;
-
- setlocale(LC_ALL, "");
- 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;
fclose (fp);
}
- /*
- * Check for storage directory. If specified,
- * then store temporary files there. Else we
- * store them in standard nmh directory.
- */
- if ((cp = context_find (nmhstorage)) && *cp)
- tmp = concat (cp, "/", invo_name, NULL);
- else
- tmp = add (m_maildir (invo_name), NULL);
-
suppress_bogus_mp_content_warning = skip_mp_cte_check = 1;
if (! context_find ("path"))
using_stdin = 1;
- if ((cp = m_mktemp2 (tmp, invo_name, &fd, NULL)) == NULL) {
- adios (NULL, "unable to create temporary file");
+ if ((cp = m_mktemp2 (NULL, invo_name, &fd, NULL)) == NULL) {
+ adios (NULL, "unable to create temporary file in %s",
+ get_temp_dir());
} else {
free (file);
file = add (cp, NULL);
- chmod (file, 0600);
cpydata (STDIN_FILENO, fd, "-", file);
}
if (close (fd)) {
- unlink (file);
+ (void) m_unlink (file);
adios (NULL, "failed to write temporary file");
}
}
status += mhfixmsgsbr (ctp, &fx, outfile);
if (using_stdin) {
- unlink (file);
+ (void) m_unlink (file);
if (! outfile) {
/* Just calling m_backup() unlinks the backup file. */
}
free (outfile);
- free (tmp);
free (file);
/* done is freects_done, which will clean up all of cts. */
modify_inplace = 1;
if ((*ctp)->c_file) {
- outfile = add (m_mktemp2 (tmp, invo_name, NULL, NULL), NULL);
+ char *tempfile;
+ if ((tempfile = m_mktemp2 (NULL, invo_name, NULL, NULL)) == NULL) {
+ adios (NULL, "unable to create temporary file in %s",
+ get_temp_dir());
+ }
+ outfile = add (tempfile, NULL);
} else {
adios (NULL, "missing both input and output filenames\n");
}
}
if (modify_inplace) {
- if (status != OK) unlink (outfile);
+ if (status != OK) (void) m_unlink (outfile);
free (outfile);
outfile = NULL;
}
if (get_multipart_boundary (*ct, &part_boundary) == OK) {
char *fixed;
- if ((fixed = m_mktemp2 (tmp, invo_name, NULL, &(*ct)->c_fp))) {
+ if ((fixed = m_mktemp2 (NULL, invo_name, NULL, &(*ct)->c_fp))) {
if (replace_boundary (*ct, fixed, part_boundary) == OK) {
char *filename = add ((*ct)->c_file, NULL);
status = NOTOK;
}
} else {
- advise (NULL, "unable to create temporary file");
+ advise (NULL, "unable to create temporary file in %s",
+ get_temp_dir());
status = NOTOK;
}
contains the decoded contents. And the decoding function, such
as openQuoted, will have set ...->ce_unlink to 1 so that it will
be unlinked by free_content (). */
- tmp_plain_file = add (m_mktemp2 (tmp, invo_name, NULL, NULL), NULL);
+ char *tempfile;
+
+ if ((tempfile = m_mktemp2 (NULL, invo_name, NULL, NULL)) == NULL) {
+ advise (NULL, "unable to create temporary file in %s",
+ get_temp_dir());
+ }
+ tmp_plain_file = add (tempfile, NULL);
if (reformat_part (tp_part, tmp_plain_file,
tp_part->c_ctinfo.ci_type,
tp_part->c_ctinfo.ci_subtype,
}
free_content (tp_part);
- unlink (tmp_plain_file);
+ (void) m_unlink (tmp_plain_file);
free (tmp_plain_file);
return NULL;
decode_part (CT ct) {
char *tmp_decoded;
int status;
+ char *tempfile;
- tmp_decoded = add (m_mktemp2 (tmp, invo_name, NULL, NULL), NULL);
+ if ((tempfile = m_mktemp2 (NULL, invo_name, NULL, NULL)) == NULL) {
+ adios (NULL, "unable to create temporary file in %s", get_temp_dir());
+ }
+ tmp_decoded = add (tempfile, NULL);
/* The following call will load ct->c_cefile.ce_file with the tmp
filename of the decoded content. tmp_decoded will contain the
encoded output, get rid of that. */
status = output_message (ct, tmp_decoded);
- unlink (tmp_decoded);
+ (void) m_unlink (tmp_decoded);
free (tmp_decoded);
return status;
/* Unlink decoded content tmp file and free its filename to avoid
leaks. The file stream should already have been closed. */
if (ct->c_cefile.ce_unlink) {
- unlink (ct->c_cefile.ce_file);
+ (void) m_unlink (ct->c_cefile.ce_file);
free (ct->c_cefile.ce_file);
ct->c_cefile.ce_file = NULL;
ct->c_cefile.ce_unlink = 0;
: ct->c_ctline ? ct->c_ctline
: "");
}
- unlink (ct->c_cefile.ce_file);
+ (void) m_unlink (ct->c_cefile.ce_file);
free (ct->c_cefile.ce_file);
ct->c_cefile.ce_file = NULL;
} else if (ct->c_encoding == CE_QUOTED &&
: ct->c_ctline ? ct->c_ctline
: "");
}
- unlink (ct->c_cefile.ce_file);
+ (void) m_unlink (ct->c_cefile.ce_file);
free (ct->c_cefile.ce_file);
ct->c_cefile.ce_file = NULL;
} else {
if (has_crs) {
int fd;
- char *stripped_content_file =
- add (m_mktemp2 (tmp, invo_name, &fd, NULL), NULL);
+ char *stripped_content_file;
+ char *tempfile = m_mktemp2 (NULL, invo_name, &fd, NULL);
+
+ if (tempfile == NULL) {
+ adios (NULL, "unable to create temporary file in %s",
+ get_temp_dir());
+ }
+ stripped_content_file = add (tempfile, NULL);
/* Strip each CR before a LF from the content. */
fseeko (*fp, begin, SEEK_SET);
if (close (fd)) {
admonish (NULL, "unable to write temporary file %s",
stripped_content_file);
- unlink (stripped_content_file);
+ (void) m_unlink (stripped_content_file);
status = NOTOK;
} else {
/* Replace the decoded file with the converted one. */
if (ct->c_cefile.ce_file) {
if (ct->c_cefile.ce_unlink) {
- unlink (ct->c_cefile.ce_file);
+ (void) m_unlink (ct->c_cefile.ce_file);
}
free (ct->c_cefile.ce_file);
}
int opened_input_file = 0;
char src_buffer[BUFSIZ];
HF hf;
+ char *tempfile;
if ((conv_desc = iconv_open (dest_codeset, src_codeset)) ==
(iconv_t) -1) {
return -1;
}
- dest = add (m_mktemp2 (tmp, invo_name, &fd, NULL), NULL);
+ if ((tempfile = m_mktemp2 (NULL, invo_name, &fd, NULL)) == NULL) {
+ adios (NULL, "unable to create temporary file in %s",
+ get_temp_dir());
+ }
+ dest = add (tempfile, NULL);
if (ct->c_cefile.ce_file) {
file = &ct->c_cefile.ce_file;
/* Replace the decoded file with the converted one. */
if (ct->c_cefile.ce_file) {
if (ct->c_cefile.ce_unlink) {
- unlink (ct->c_cefile.ce_file);
+ (void) m_unlink (ct->c_cefile.ce_file);
}
free (ct->c_cefile.ce_file);
}
}
}
} else {
- unlink (dest);
+ (void) m_unlink (dest);
}
#else /* ! HAVE_ICONV */
NMH_UNUSED (message_mods);
}
if (new != -1) close (new);
if (old != -1) close (old);
- unlink (outfile);
+ (void) m_unlink (outfile);
if (i < 0) {
/* The -file argument processing used path() to
} else {
admonish (NULL, "unable to remove input file %s, "
"not modifying it", infile);
- unlink (outfile);
+ (void) m_unlink (outfile);
status = NOTOK;
}
}
} else {
/* No modifications and didn't need the tmp outfile. */
- unlink (outfile);
+ (void) m_unlink (outfile);
}
} else {
/* Output is going to some file. Produce it whether or not
if (ct->c_file) {
if (ct->c_unlink)
- unlink (ct->c_file);
+ (void) m_unlink (ct->c_file);
free (ct->c_file);
}
if (ct->c_fp)
if (ce->ce_file) {
if (ce->ce_unlink)
- unlink (ce->ce_file);
+ (void) m_unlink (ce->ce_file);
free (ce->ce_file);
ce->ce_file = NULL;
}
int
main (int argc, char **argv)
{
- setlocale(LC_ALL, "");
+ if (nmh_init(argv[0], 1)) { return 1; }
+
done (mhl (argc, argv));
return 1;
}
#undef X
-/* mhparse.c */
-extern char *tmp; /* directory to place temp files */
-
/* mhcachesbr.c */
extern int rcachesw;
extern int wcachesw;
struct msgs *mp = NULL;
CT ct, *ctp;
- done=freects_done;
-
- setlocale(LC_ALL, "");
- 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;
cache_private = ".cache";
cache_private = getcpy (m_maildir (cache_private));
- /*
- * Check for storage directory. If specified,
- * then store temporary files there. Else we
- * store them in standard nmh directory.
- */
- if ((cp = context_find (nmhstorage)) && *cp)
- tmp = concat (cp, "/", invo_name, NULL);
- else
- tmp = add (m_maildir (invo_name), NULL);
-
if (!context_find ("path"))
free (path ("./", TFOLDER));
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;
#undef X
-/* mhparse.c */
-extern char *tmp; /* directory to place temp files */
-
/* mhcachesbr.c */
extern int rcachesw;
extern int wcachesw;
CT ct, *ctp;
FILE *fp;
- done=freects_done;
-
- setlocale(LC_ALL, "");
- 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;
*/
cwd = getcpy (pwd());
- /*
- * Check for storage directory. If specified,
- * then store temporary files there. Else we
- * store them in standard nmh directory.
- */
- if ((cp = context_find (nmhstorage)) && *cp)
- tmp = concat (cp, "/", invo_name, NULL);
- else
- tmp = add (m_maildir (invo_name), NULL);
-
if (!context_find ("path"))
free (path ("./", TFOLDER));
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;
int checksw = 0; /* check Content-MD5 field */
-/*
- * Directory to place temp files. This must
- * be set before these routines are called.
- */
-char *tmp;
-
/*
* These are for mhfixmsg to:
* 1) Instruct parser not to detect invalid Content-Transfer-Encoding
if ((is_stdin = !(strcmp (file, "-")))) {
char *tfile = m_mktemp2(NULL, invo_name, NULL, &fp);
if (tfile == NULL) {
- advise("mhparse", "unable to create temporary file");
+ advise("mhparse", "unable to create temporary file in %s",
+ get_temp_dir());
return NULL;
}
file = add (tfile, NULL);
- chmod (file, 0600);
while (fgets (buffer, sizeof(buffer), stdin))
fputs (buffer, fp);
fflush (fp);
if (ferror (stdin)) {
- unlink (file);
+ (void) m_unlink (file);
advise ("stdin", "error reading");
return NULL;
}
if (ferror (fp)) {
- unlink (file);
+ (void) m_unlink (file);
advise (file, "error writing");
return NULL;
}
if (!(ct = get_content (fp, file, 1))) {
if (is_stdin)
- unlink (file);
+ (void) m_unlink (file);
advise (NULL, "unable to decode %s", file);
return NULL;
}
}
if (*file == NULL) {
- ce->ce_file = add (m_mktemp(tmp, NULL, NULL), NULL);
+ char *tempfile;
+ if ((tempfile = m_mktemp2(NULL, invo_name, NULL, NULL)) == NULL) {
+ adios(NULL, "unable to create temporary file in %s",
+ get_temp_dir());
+ }
+ ce->ce_file = add (tempfile, NULL);
ce->ce_unlink = 1;
} else {
ce->ce_file = add (*file, NULL);
cp = context_find (buffer);
}
if (cp != NULL && *cp != '\0') {
- if (ce->ce_unlink) {
- /* Temporary file already exists, so we rename to
- version with extension. */
- char *file_org = strdup(ce->ce_file);
- ce->ce_file = add (cp, ce->ce_file);
- if (rename(file_org, ce->ce_file)) {
- adios (ce->ce_file, "unable to rename %s to ", file_org);
- }
- free(file_org);
-
- } else {
+ if (! ce->ce_unlink) {
ce->ce_file = add (cp, ce->ce_file);
}
}
}
if (*file == NULL) {
- ce->ce_file = add (m_mktemp(tmp, NULL, NULL), NULL);
+ char *tempfile;
+ if ((tempfile = m_mktemp2(NULL, invo_name, NULL, NULL)) == NULL) {
+ adios(NULL, "unable to create temporary file in %s",
+ get_temp_dir());
+ }
+ ce->ce_file = add (tempfile, NULL);
ce->ce_unlink = 1;
} else {
ce->ce_file = add (*file, NULL);
cp = context_find (buffer);
}
if (cp != NULL && *cp != '\0') {
- if (ce->ce_unlink) {
- /* Temporary file already exists, so we rename to
- version with extension. */
- char *file_org = strdup(ce->ce_file);
- ce->ce_file = add (cp, ce->ce_file);
- if (rename(file_org, ce->ce_file)) {
- adios (ce->ce_file, "unable to rename %s to ", file_org);
- }
- free(file_org);
-
- } else {
+ if (! ce->ce_unlink) {
ce->ce_file = add (cp, ce->ce_file);
}
}
}
if (*file == NULL) {
- ce->ce_file = add (m_mktemp(tmp, NULL, NULL), NULL);
+ char *tempfile;
+ if ((tempfile = m_mktemp2(NULL, invo_name, NULL, NULL)) == NULL) {
+ adios(NULL, "unable to create temporary file in %s",
+ get_temp_dir());
+ }
+ ce->ce_file = add (tempfile, NULL);
ce->ce_unlink = 1;
} else {
ce->ce_file = add (*file, NULL);
cp = context_find (buffer);
}
if (cp != NULL && *cp != '\0') {
- if (ce->ce_unlink) {
- /* Temporary file already exists, so we rename to
- version with extension. */
- char *file_org = strdup(ce->ce_file);
- ce->ce_file = add (cp, ce->ce_file);
- if (rename(file_org, ce->ce_file)) {
- adios (ce->ce_file, "unable to rename %s to ", file_org);
- }
- free(file_org);
-
- } else {
+ if (! ce->ce_unlink) {
ce->ce_file = add (cp, ce->ce_file);
}
}
if (ferror (gp)) {
admonish (ce->ce_file, "error reading");
- unlink (cachefile);
+ (void) m_unlink (cachefile);
}
else
if (ferror (fp)) {
admonish (cachefile, "error writing");
- unlink (cachefile);
+ (void) m_unlink (cachefile);
}
fclose (fp);
}
ce->ce_file = add (*file, NULL);
else if (caching)
ce->ce_file = add (cachefile, NULL);
- else
- ce->ce_file = add (m_mktemp(tmp, NULL, NULL), NULL);
+ else {
+ char *tempfile;
+ if ((tempfile = m_mktemp2(NULL, invo_name, NULL, NULL)) == NULL) {
+ adios(NULL, "unable to create temporary file in %s",
+ get_temp_dir());
+ }
+ ce->ce_file = add (tempfile, NULL);
+ }
if ((ce->ce_fp = fopen (ce->ce_file, "w+")) == NULL) {
content_error (ce->ce_file, ct, "unable to fopen for reading/writing");
if (ferror (gp)) {
admonish (ce->ce_file, "error reading");
- unlink (cachefile);
+ (void) m_unlink (cachefile);
}
else
if (ferror (fp)) {
admonish (cachefile, "error writing");
- unlink (cachefile);
+ (void) m_unlink (cachefile);
}
fclose (fp);
}
}
if (*file == NULL) {
- ce->ce_file = add (m_mktemp(tmp, NULL, NULL), NULL);
+ char *tempfile;
+ if ((tempfile = m_mktemp2(NULL, invo_name, NULL, NULL)) == NULL) {
+ adios(NULL, "unable to create temporary file in %s",
+ get_temp_dir());
+ }
+ ce->ce_file = add (tempfile, NULL);
ce->ce_unlink = 1;
} else {
ce->ce_file = add (*file, NULL);
ce->ce_file = add(*file, NULL);
else if (caching)
ce->ce_file = add(cachefile, NULL);
- else
- ce->ce_file = add(m_mktemp(tmp, NULL, NULL), NULL);
+ else {
+ char *tempfile;
+ if ((tempfile = m_mktemp2(NULL, invo_name, NULL, NULL)) == NULL) {
+ adios(NULL, "unable to create temporary file in %s",
+ get_temp_dir());
+ }
+ ce->ce_file = add (tempfile, NULL);
+ }
if ((ce->ce_fp = fopen(ce->ce_file, "w+")) == NULL) {
content_error(ce->ce_file, ct, "unable to fopen for read/writing");
if (ferror(gp)) {
admonish(ce->ce_file, "error reading");
- unlink(cachefile);
+ (void) m_unlink (cachefile);
}
}
umask(mask);
struct msgs_array msgs = { 0, 0, NULL };
struct msgs *mp;
- setlocale(LC_ALL, "");
- 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;
#undef X
-/* mhparse.c */
-extern char *tmp; /* directory to place temp files */
-
/* mhcachesbr.c */
extern int rcachesw;
extern int wcachesw;
CT ct, *ctp;
FILE *fp;
- done=freects_done;
-
- setlocale(LC_ALL, "");
- 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;
cache_private = ".cache";
cache_private = getcpy (m_maildir (cache_private));
- /*
- * Check for storage directory. If specified,
- * then store temporary files there. Else we
- * store them in standard nmh directory.
- */
- if ((cp = context_find (nmhstorage)) && *cp)
- tmp = concat (cp, "/", invo_name, NULL);
- else
- tmp = add (m_maildir (invo_name), NULL);
-
if (!context_find ("path"))
free (path ("./", TFOLDER));
int save_clobber_policy (const char *);
extern int files_not_clobbered;
-/* mhparse.c */
-extern char *tmp; /* directory to place temp files */
-
/* mhcachesbr.c */
extern int rcachesw;
extern int wcachesw;
CT ct, *ctp;
FILE *fp;
- done=freects_done;
-
- setlocale(LC_ALL, "");
- 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;
*/
cwd = getcpy (pwd());
- /*
- * Check for storage directory. If specified,
- * then store temporary files there. Else we
- * store them in standard nmh directory.
- */
- if ((cp = context_find (nmhstorage)) && *cp)
- tmp = concat (cp, "/", invo_name, NULL);
- else
- tmp = add (m_maildir (invo_name), NULL);
-
if (!context_find ("path"))
free (path ("./", TFOLDER));
char *tmpfilenam, *folder;
/* Store content in temporary file for now */
- tmpfilenam = m_mktemp(invo_name, NULL, NULL);
+ if ((tmpfilenam = m_mktemp(invo_name, NULL, NULL)) == NULL) {
+ adios(NULL, "unable to create temporary file in %s",
+ get_temp_dir());
+ }
ct->c_storage = add (tmpfilenam, NULL);
/* Get the folder name */
*/
if (ct->c_folder && (!is_partial || last_partial)) {
msgnum = output_content_folder (ct->c_folder, ct->c_storage);
- unlink (ct->c_storage);
+ (void) m_unlink (ct->c_storage);
if (msgnum == NOTOK)
return NOTOK;
}
#undef X
-/* mhparse.c */
-extern char *tmp; /* directory to place temp files */
-
/* mhcachesbr.c */
extern int rcachesw;
extern int wcachesw;
struct msgs *mp = NULL;
CT ct, *ctp;
- done=freects_done;
-
- setlocale(LC_ALL, "");
- 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;
cache_private = ".cache";
cache_private = getcpy (m_maildir (cache_private));
- /*
- * Check for storage directory. If specified,
- * then store temporary files there. Else we
- * store them in standard nmh directory.
- */
- if ((cp = context_find (nmhstorage)) && *cp)
- tmp = concat (cp, "/", invo_name, NULL);
- else
- tmp = add (m_maildir (invo_name), NULL);
-
if (!context_find ("path"))
free (path ("./", TFOLDER));
pipeser (int i)
{
if (i == SIGQUIT) {
- unlink ("core");
fflush (stdout);
fprintf (stderr, "\n");
fflush (stderr);
char **argp, **arguments, *vec[MAXVEC];
struct passwd *pw;
- setlocale(LC_ALL, "");
- invo_name = r1bindex (argv[0], '/');
-
- /* read user profile/context */
- context_read();
+ if (nmh_init(argv[0], 1)) { return 1; }
mts_init (invo_name);
char *cp, *file = NULL, *folder = NULL;
char **argp, **arguments, buf[BUFSIZ];
- setlocale(LC_ALL, "");
- 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);
close (i);
else
advise (mp->foldpath, "error zero'ing");
- unlink (map_name (mp->foldpath));/* XXX */
+ (void) m_unlink (map_name (mp->foldpath));/* XXX */
}
goto release;
}
for (msgnum = mp->lowmsg; msgnum <= mp->hghmsg; msgnum++)
if (does_exist(mp, msgnum) && pack (tmpfil, md, msgnum) == NOTOK) {
mbx_close (tmpfil, md);
- unlink (tmpfil);
- unlink (map_name (tmpfil));
+ (void) m_unlink (tmpfil);
+ (void) m_unlink (map_name (tmpfil));
goto release;
}
mbx_close (tmpfil, md);
if (rename (map1, map2) == NOTOK) {
admonish (map2, "unable to rename %s to", map1);
- unlink (map1);
- unlink (map2);
+ (void) m_unlink (map1);
+ (void) m_unlink (map2);
}
}
break;
}
- unlink (tmpfil);
+ (void) m_unlink (tmpfil);
}
}
if (!fmsh)
- unlink (tmpfil);
+ (void) m_unlink (tmpfil);
return status;
}
char *unseen;
struct node *folder;
- setlocale(LC_ALL, "");
- 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;
struct msgs *mp;
struct stat st;
- done=mbxclose_done;
-
- setlocale(LC_ALL, "");
- 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;
struct msgs *mp, *mp2;
register FILE *fp;
- done=putzero_done;
-
- setlocale(LC_ALL, "");
- 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;
FILE *in, *out;
m_getfld_state_t gstate = 0;
- setlocale(LC_ALL, "");
- 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);
if ((out = fopen ("/dev/null", "w")) == NULL)
adios ("/dev/null", "unable to open");
} else {
- char *cp = m_mktemp(m_maildir(invo_name), NULL, &out);
- if (cp == NULL) {
- cp = m_mktemp2(NULL, invo_name, NULL, &out);
- if (cp == NULL) {
- adios ("post", "unable to create temporary file");
- }
- }
+ char *cp = m_mktemp2(NULL, invo_name, NULL, &out);
+ if (cp == NULL) {
+ adios(NULL, "unable to create temporary file in %s",
+ get_temp_dir());
+ }
strncpy(tmpfil, cp, sizeof(tmpfil));
- chmod (tmpfil, 0600);
}
}
post (tmpfil, 0, verbose, envelope);
}
post (bccfil, 1, verbose, envelope);
- unlink (bccfil);
+ (void) m_unlink (bccfil);
} else {
post (tmpfil, 0, isatty (1), envelope);
}
p_refile (tmpfil);
- unlink (tmpfil);
+ (void) m_unlink (tmpfil);
if (verbose) {
if (partno)
FILE *out;
char *tfile = NULL, *program;
- tfile = m_mktemp2(NULL, "bccs", NULL, &out);
- if (tfile == NULL) adios("bcc", "unable to create temporary file");
+ if ((tfile = m_mktemp2(NULL, "bccs", NULL, &out)) == NULL) {
+ adios(NULL, "unable to create temporary file in %s", get_temp_dir());
+ }
strncpy (bccfil, tfile, sizeof(bccfil));
fprintf (out, "From: %s\n", fullfrom);
{
NMH_UNUSED (i);
- unlink (tmpfil);
+ (void) m_unlink (tmpfil);
if (msgflags & MINV)
- unlink (bccfil);
+ (void) m_unlink (bccfil);
if (!whomsw || checksw)
sm_end (NOTOK);
{
va_list ap;
- unlink (tmpfil);
+ (void) m_unlink (tmpfil);
if (msgflags & MINV)
- unlink (bccfil);
+ (void) m_unlink (bccfil);
if (!whomsw || checksw)
sm_end (NOTOK);
char *tmpfil;
m_getfld_state_t gstate = 0;
- setlocale(LC_ALL, "");
- 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;
if ((in = fopen (drft, "r")) == NULL)
adios (drft, "unable to open");
- tmpfil = m_mktemp2(NULL, invo_name, NULL, &out);
- if (tmpfil == NULL) adios("prompter", "unable to create temporary file");
- chmod (tmpfil, 0600);
+ if ((tmpfil = m_mktemp2(NULL, invo_name, NULL, &out)) == NULL) {
+ adios(NULL, "unable to create temporary file in %s", get_temp_dir());
+ }
/*
* Are we changing the kill or erase character?
if (killp || erasep) {
tcsetattr(0, TCSADRAIN, &tio);
}
- unlink (tmpfil);
+ (void) m_unlink (tmpfil);
done (1);
}
if (i != 0 || (field[0] != '\n' && field[0] != 0)) {
cpydata (fdi, fdo, tmpfil, drft);
close (fdi);
close (fdo);
- unlink (tmpfil);
+ (void) m_unlink (tmpfil);
context_save (); /* save the context file */
done (0);
FILE *fp;
char *tfile = NULL;
- done=unlink_done;
-
- setlocale(LC_ALL, "");
- 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
umask (~m_gmprot ());
- tfile = m_mktemp2(NULL, invo_name, NULL, &fp);
- if (tfile == NULL) adios("rcvdist", "unable to create temporary file");
+ if ((tfile = m_mktemp2(NULL, invo_name, NULL, &fp)) == NULL) {
+ adios(NULL, "unable to create temporary file in %s", get_temp_dir());
+ }
strncpy (tmpfil, tfile, sizeof(tmpfil));
cpydata (fileno (stdin), fileno (fp), "message", tmpfil);
fseek (fp, 0L, SEEK_SET);
- tfile = m_mktemp2(NULL, invo_name, NULL, NULL);
- if (tfile == NULL) adios("forw", "unable to create temporary file");
+ if ((tfile = m_mktemp2(NULL, invo_name, NULL, NULL)) == NULL) {
+ adios(NULL, "unable to create temporary file in %s", get_temp_dir());
+ }
strncpy (drft, tfile, sizeof(tmpfil));
rcvdistout (fp, form, addrs);
unlink_done (int status)
{
if (backup[0])
- unlink (backup);
+ (void) m_unlink (backup);
if (drft[0])
- unlink (drft);
+ (void) m_unlink (drft);
if (tmpfil[0])
- unlink (tmpfil);
+ (void) m_unlink (tmpfil);
exit (status ? RCV_MBX : RCV_MOK);
}
char *cp, *file = NULL, buf[BUFSIZ];
char **argp, **arguments;
- setlocale(LC_ALL, "");
- 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);
struct msgs *mp;
struct stat st;
- done=unlink_done;
-
- setlocale(LC_ALL, "");
- 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);
/* create a temporary file */
tmpfilenam = m_mktemp (invo_name, &fd, NULL);
if (tmpfilenam == NULL) {
- adios ("rcvstore", "unable to create temporary file");
+ adios(NULL, "unable to create temporary file in %s", get_temp_dir());
}
chmod (tmpfilenam, m_gmprot());
cpydata (fileno (stdin), fd, "standard input", tmpfilenam);
if (fstat (fd, &st) == NOTOK) {
- unlink (tmpfilenam);
+ (void) m_unlink (tmpfilenam);
adios (tmpfilenam, "unable to fstat");
}
if (close (fd) == NOTOK)
/* don't add file if it is empty */
if (st.st_size == 0) {
- unlink (tmpfilenam);
+ (void) m_unlink (tmpfilenam);
advise (NULL, "empty file");
done (0);
}
folder_free (mp); /* free folder/message structure */
context_save (); /* save the global context file */
- unlink (tmpfilenam); /* remove temporary file */
+ (void) m_unlink (tmpfilenam); /* remove temporary file */
tmpfilenam = NULL;
done (0);
unlink_done(int status)
{
if (tmpfilenam && *tmpfilenam)
- unlink (tmpfilenam);
+ (void) m_unlink (tmpfilenam);
exit (status);
}
char **argp, **arguments, *vec[MAXARGS];
struct utmpx *utp;
- setlocale(LC_ALL, "");
- 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);
{
pid_t child_id;
int bytes, seconds;
- /* volatile to prevent "might be clobbered" warning from gcc: */
- volatile int fd;
- char tmpfil[BUFSIZ];
+ int fd;
+ char *tfile;
struct stat st;
- fd = mkstemp (strncpy (tmpfil, "/tmp/rcvttyXXXXX", sizeof(tmpfil)));
- unlink (tmpfil);
+ if ((tfile = m_mktemp2(NULL, invo_name, &fd, NULL)) == NULL) {
+ advise(NULL, "unable to create temporary file in %s", get_temp_dir());
+ return NOTOK;
+ }
+ (void) m_unlink(tfile); /* Use fd, no longer need the file name. */
if ((child_id = fork()) == NOTOK) {
/* fork error */
char *nfs;
char *tfile = NULL;
- tfile = m_mktemp2(NULL, invo_name, &fd, NULL);
- if (tfile == NULL) return NOTOK;
- unlink (tfile);
+ if ((tfile = m_mktemp2(NULL, invo_name, &fd, NULL)) == NULL) {
+ advise(NULL, "unable to create temporary file in %s", get_temp_dir());
+ return NOTOK;
+ }
+ (void) m_unlink(tfile); /* Use fd, no longer need the file name. */
rewind (stdin);
struct msgs_array msgs = { 0, 0, NULL };
struct msgs *mp;
- setlocale(LC_ALL, "");
- 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;
/* Else just unlink the files */
files++; /* advance past filevec[0] */
for (i = 0; i < filep; i++) {
- if (unlink (files[i]) == NOTOK)
+ if (m_unlink (files[i]) == NOTOK)
admonish (files[i], "unable to unlink");
}
}
int buildsw = 0;
- setlocale(LC_ALL, "");
- 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;
char *cp, *folder = NULL, newfolder[BUFSIZ];
char buf[BUFSIZ], **argp, **arguments;
- setlocale(LC_ALL, "");
- 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;
others++;
continue;
}
- if (unlink (dp->d_name) == NOTOK) {
+ if (m_unlink (dp->d_name) == NOTOK) {
admonish (dp->d_name, "unable to unlink %s:", folder);
others++;
}
struct msgs_array msgs = { 0, 0, NULL };
struct msgs *mp;
- setlocale(LC_ALL, "");
- 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;
struct msgs *mp;
FILE *in;
- setlocale(LC_ALL, "");
- 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);
struct msgs *mp;
struct stat st;
- setlocale(LC_ALL, "");
- 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;
&& (distsw = atoi (cp))
&& altmsg) {
vec[vecp++] = "-dist";
- distfile = getcpy (m_mktemp2 (altmsg, invo_name, NULL, NULL));
- unlink(distfile);
+ if ((cp = m_mktemp2(altmsg, invo_name, NULL, NULL)) == NULL) {
+ adios(NULL, "unable to create temporary file in %s",
+ get_temp_dir());
+ }
+ distfile = getcpy (cp);
+ (void) m_unlink(distfile);
if (link (altmsg, distfile) == NOTOK) {
/* Cygwin with FAT32 filesystem produces EPERM. */
if (errno != EXDEV && errno != EPERM
)
adios (distfile, "unable to link %s to", altmsg);
free (distfile);
- distfile = getcpy (m_mktemp2(NULL, invo_name, NULL, NULL));
+ if ((cp = m_mktemp2(NULL, invo_name, NULL, NULL)) == NULL) {
+ adios(NULL, "unable to create temporary file in %s",
+ get_temp_dir());
+ }
+ distfile = getcpy (cp);
{
int in, out;
struct stat st;
* rename the draft file. I'm not quite sure why.
*/
if (pushsw && unique) {
- char *cp = m_mktemp2(drft, invo_name, NULL, NULL);
- if (cp == NULL) {
- adios ("sendsbr", "unable to create temporary file");
- }
+ char *cp = m_mktemp2(drft, invo_name, NULL, NULL);
+ if (cp == NULL) {
+ adios(NULL, "unable to create temporary file in %s",
+ get_temp_dir());
+ }
if (rename (drft, strncpy(file, cp, sizeof(file))) == NOTOK)
adios (file, "unable to rename %s to", drft);
drft = file;
done=exit;
if (distfile)
- unlink (distfile);
+ (void) m_unlink (distfile);
return status;
}
char *cp = m_mktemp2(drft, invo_name, NULL, &out);
if (cp == NULL) {
- adios (drft, "unable to create temporary file for");
+ adios(NULL, "unable to create temporary file in %s",
+ get_temp_dir());
}
strncpy(tmpdrf, cp, sizeof(tmpdrf));
- chmod (tmpdrf, 0600);
/*
* Output the header fields
snprintf (partnum, sizeof(partnum), "%d", partno);
status = sendaux (vec, vecp, program, tmpdrf, st);
- unlink (tmpdrf);
+ (void) m_unlink (tmpdrf);
if (status != OK)
break;
snprintf (buf, sizeof(buf), "%d", fd2);
vec[vecp++] = buf;
} else {
- admonish (NULL, "unable to create file for annotation list");
+ admonish (NULL, "unable to create temporary file in %s "
+ "for annotation list", get_temp_dir());
}
}
if (distfile && distout (drft, distfile, backup) == NOTOK)
if (annotext && fd2 != NOTOK)
close (fd2);
if (distfile) {
- unlink (drft);
+ (void) m_unlink (drft);
if (rename (backup, drft) == NOTOK)
advise (drft, "unable to rename %s to", backup);
}
tmp_fd (void)
{
int fd;
- char *tfile = NULL;
+ char *tfile;
- tfile = m_mktemp2(NULL, invo_name, &fd, NULL);
- if (tfile == NULL) return NOTOK;
- fchmod(fd, 0600);
+ if ((tfile = m_mktemp2(NULL, invo_name, &fd, NULL)) == NULL) return NOTOK;
if (debugsw)
advise (NULL, "temporary file %s selected", tfile);
else
- if (unlink (tfile) == NOTOK)
+ if (m_unlink (tfile) == NOTOK)
advise (tfile, "unable to remove");
return fd;
sigaddset (&set, SIGTERM);
sigprocmask (SIG_BLOCK, &set, &oset);
+ unregister_for_removal(0);
+
annoaux (fd);
if (child_id == OK)
_exit (0);
struct msgs_array msgs = { 0, 0, NULL };
struct msgs_array vec = { 0, 0, NULL };
- setlocale(LC_ALL, "");
- 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;
char mailbox[BUFSIZ], tmpfil[BUFSIZ];
char **argp, **arguments;
- setlocale(LC_ALL, "");
- 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);
if (debug)
debug_printf ("retrieving message from file \"%s\"\n", file);
if ((fd = copy_message (tempfd, tmpfil, 1)) == -1)
- adios (NULL, "unable to create temporary file");
+ adios(NULL, "unable to create temporary file in %s",
+ get_temp_dir());
close (tempfd);
} else {
/* getting message from stdin */
if (debug)
debug_printf ("retrieving message from stdin\n");
if ((fd = copy_message (fileno (stdin), tmpfil, 1)) == -1)
- adios (NULL, "unable to create temporary file");
+ adios(NULL, "unable to create temporary file in %s",
+ get_temp_dir());
}
if (debug)
thing would be to delay this unlink() until later if debug == 1, but I'll
leave that for someone who cares about the temp-file-accessing
functionality (they'll have to watch out for cases where we adios()). */
- unlink (tmpfil);
+ (void) m_unlink (tmpfil);
if (!(fp = fdopen (fd, "r+")))
adios (NULL, "unable to access temporary file");
tfile = m_mktemp2(NULL, invo_name, &fd1, NULL);
if (tfile == NULL) return -1;
- fchmod(fd1, 0600);
strncpy (tmpfil, tfile, BUFSIZ);
if (!fold) {
if (write (fd1, buffer, i) != i) {
you_lose:
close (fd1);
- unlink (tmpfil);
+ (void) m_unlink (tmpfil);
return -1;
}
if (i == -1)
struct smsg **dlist;
int checksw = 0;
- setlocale(LC_ALL, "");
- 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;
char *cp, buf[BUFSIZ];
char **argp, **arguments;
- setlocale(LC_ALL, "");
- invo_name = r1bindex (argv[0], '/');
-
- context_read();
+ if (nmh_init(argv[0], 1)) { return 1; }
arguments = getarguments (invo_name, argc, argv, 0);
argp = arguments;
umask (~m_gmprot ());
- tfile = m_mktemp2(NULL, invo_name, NULL, &fp);
- if (tfile == NULL) adios("viamail", "unable to create temporary file");
- chmod(tfile, 0600);
+ if ((tfile = m_mktemp2(NULL, invo_name, NULL, &fp)) == NULL) {
+ adios(NULL, "unable to create temporary file in %s", get_temp_dir());
+ }
strncpy (tmpfil, tfile, sizeof(tmpfil));
if (!strchr(mailsw, '@'))
}
fclose (fp);
- if (unlink (tmpfil) == -1)
- advise (NULL, "unable to remove temp file %s", tmpfil);
+ if (m_unlink (tmpfil) == -1)
+ advise (tmpfil, "unable to remove temp file %s", tmpfil);
done (status);
return 1;
}
int
main (int argc, char **argv)
{
- setlocale(LC_ALL, "");
+ if (nmh_init(argv[0], 1)) { return 1; }
+
return WhatNow (argc, 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;
#else /* ! READLINE_SUPPORT */
if (!(argp = getans (prompt, aleqs))) {
#endif /* READLINE_SUPPORT */
- unlink (LINK);
+ (void) m_unlink (LINK);
done (1);
}
switch (smatch (*argp, aleqs)) {
snprintf (linkpath, sizeof(linkpath), "%s/%s", cwd, LINK);
if (atfile) {
- unlink (linkpath);
+ (void) m_unlink (linkpath);
if (link (altpath, linkpath) == NOTOK) {
symlink (altpath, linkpath);
slinked = 1;
&& copyf (linkpath, altpath) == NOTOK
: stat (linkpath, &st) != NOTOK
&& st.st_nlink == 1
- && (unlink (altpath) == NOTOK
+ && (m_unlink (altpath) == NOTOK
|| link (linkpath, altpath) == NOTOK)))
advise (linkpath, "unable to update %s from", altmsg);
}
*ed = NULL;
if (altmsg && atfile)
- unlink (linkpath);
+ (void) m_unlink (linkpath);
return status;
}
#endif /* not lint */
&& altmsg) {
vec[vecp++] = "-dist";
- distfile = getcpy (m_mktemp2(altmsg, invo_name, NULL, NULL));
- unlink(distfile);
+ if ((cp = m_mktemp2(altmsg, invo_name, NULL, NULL)) == NULL) {
+ adios(NULL, "unable to create temporary file in %s",
+ get_temp_dir());
+ }
+ distfile = getcpy (cp);
+ (void) m_unlink(distfile);
if (link (altmsg, distfile) == NOTOK)
adios (distfile, "unable to link %s to", altmsg);
} else {
static int
removefile (char *drft)
{
- if (unlink (drft) == NOTOK)
+ if (m_unlink (drft) == NOTOK)
adios (drft, "unable to unlink");
return OK;
char *msg = NULL, **ap, **argp, backup[BUFSIZ];
char buf[BUFSIZ], **arguments, *vec[MAXARGS];
- setlocale(LC_ALL, "");
- 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;
status = pidwait(child_id, OK);
- unlink (msg);
+ (void) m_unlink (msg);
if (rename (backup, msg) == NOTOK)
adios (msg, "unable to rename %s to", backup);
done (status);