3 * context_save.c -- write out the updated context file
5 * This code is Copyright (c) 2002, by the authors of nmh. See the
6 * COPYRIGHT file in the root directory of the nmh distribution for
7 * complete copyright information.
11 #include <h/signals.h>
16 static int m_chkids(void);
23 register struct node *np;
27 /* No context in use -- silently ignore any changes! */
31 if (!(ctxflags & CTXMOD))
35 if ((action = m_chkids ()) > 0)
36 return; /* child did it for us */
38 /* block a few signals */
40 sigaddset (&set, SIGHUP);
41 sigaddset (&set, SIGINT);
42 sigaddset (&set, SIGQUIT);
43 sigaddset (&set, SIGTERM);
44 sigprocmask (SIG_BLOCK, &set, &oset);
46 if (!(out = lkfopen (ctxpath, "w")))
47 adios (ctxpath, "unable to write");
48 for (np = m_defs; np; np = np->n_next)
50 fprintf (out, "%s: %s\n", np->n_name, np->n_field);
51 lkfclose (out, ctxpath);
53 sigprocmask (SIG_SETMASK, &oset, &set); /* reset the signal mask */
56 _exit (0); /* we are child, time to die */
60 * This hack brought to you so we can handle set[ug]id MH programs.
61 * If we return -1, then no fork is made, we update .mh_profile
62 * normally, and return to the caller normally. If we return 0,
63 * then the child is executing, .mh_profile is modified after
64 * we set our [ug]ids to the norm. If we return > 0, then the
65 * parent is executed and .mh_profile has already be modified.
66 * We can just return to the caller immediately.
75 if (getuid () == geteuid ())
78 for (i = 0; (pid = fork ()) == -1 && i < 5; i++)