]> diplodocus.org Git - nmh/blob - sbr/context_save.c
Another pass at cleaning up (some of) the manpages.
[nmh] / sbr / context_save.c
1
2 /*
3 * context_save.c -- write out the updated context file
4 *
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.
8 */
9
10 /*
11 * This function used to support setuid/setgid programs by writing
12 * the file as the user. But that code, m_chkids(), was removed
13 * because there no longer are setuid/setgid programs in nmh.
14 */
15
16 #include <h/mh.h>
17 #include <h/signals.h>
18
19 void
20 context_save (void)
21 {
22 register struct node *np;
23 FILE *out;
24 sigset_t set, oset;
25 int failed_to_lock = 0;
26
27 /* No context in use -- silently ignore any changes! */
28 if (!ctxpath)
29 return;
30
31 if (!(ctxflags & CTXMOD))
32 return;
33 ctxflags &= ~CTXMOD;
34
35 /* block a few signals */
36 sigemptyset (&set);
37 sigaddset (&set, SIGHUP);
38 sigaddset (&set, SIGINT);
39 sigaddset (&set, SIGQUIT);
40 sigaddset (&set, SIGTERM);
41 sigprocmask (SIG_BLOCK, &set, &oset);
42
43 if (!(out = lkfopendata (ctxpath, "w", &failed_to_lock))) {
44 if (failed_to_lock) {
45 adios (ctxpath, "failed to lock");
46 } else {
47 adios (ctxpath, "unable to write");
48 }
49 }
50 for (np = m_defs; np; np = np->n_next)
51 if (np->n_context)
52 fprintf (out, "%s: %s\n", np->n_name, np->n_field);
53 lkfclosedata (out, ctxpath);
54
55 sigprocmask (SIG_SETMASK, &oset, &set); /* reset the signal mask */
56 }