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