]> diplodocus.org Git - nmh/blob - sbr/context_save.c
01afbd801f6b456138ae0bec9a9890ab84154818
[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 "error.h"
16 #include "h/signals.h"
17 #include "lock_file.h"
18
19 void
20 context_save (void)
21 {
22 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 adios (ctxpath, "unable to write");
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 }