Move #include from h/mh.h to source files
[mmh] / sbr / context_save.c
1 /*
2 ** context_save.c -- write out the updated context file
3 **
4 ** This code is Copyright (c) 2002, by the authors of nmh.  See the
5 ** COPYRIGHT file in the root directory of the nmh distribution for
6 ** complete copyright information.
7 */
8
9 /*
10  * This function used to support setuid/setgid programs by writing
11  * the file as the user.  But that code, m_chkids(), was removed
12  * because there no longer are setuid/setgid programs in nmh.
13  */
14
15 #include <h/mh.h>
16 #include <h/signals.h>
17
18 void
19 context_save(void)
20 {
21         register struct node *np;
22         FILE *out;
23         sigset_t set, oset;
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 = lkfopen(ctxpath, "w")))
42                 adios(ctxpath, "unable to write");
43         for (np = m_defs; np; np = np->n_next)
44                 if (np->n_context)
45                         fprintf(out, "%s: %s\n", np->n_name, np->n_field);
46         lkfclose(out, ctxpath);
47
48         sigprocmask(SIG_SETMASK, &oset, &set); /* reset the signal mask */
49 }