]> diplodocus.org Git - nmh/blob - sbr/context_save.c
mhlsbr.c: Don't strchr(3) non-string NUL-less buffer.
[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 #include "lock_file.h"
17
18 void
19 context_save (void)
20 {
21 struct node *np;
22 FILE *out;
23 sigset_t set, oset;
24 int failed_to_lock = 0;
25
26 /* No context in use -- silently ignore any changes! */
27 if (!ctxpath)
28 return;
29
30 if (!(ctxflags & CTXMOD))
31 return;
32 ctxflags &= ~CTXMOD;
33
34 /* block a few signals */
35 sigemptyset (&set);
36 sigaddset (&set, SIGHUP);
37 sigaddset (&set, SIGINT);
38 sigaddset (&set, SIGQUIT);
39 sigaddset (&set, SIGTERM);
40 sigprocmask (SIG_BLOCK, &set, &oset);
41
42 if (!(out = lkfopendata (ctxpath, "w", &failed_to_lock))) {
43 if (failed_to_lock)
44 adios (ctxpath, "failed to lock");
45 adios (ctxpath, "unable to write");
46 }
47 for (np = m_defs; np; np = np->n_next)
48 if (np->n_context)
49 fprintf (out, "%s: %s\n", np->n_name, np->n_field);
50 lkfclosedata (out, ctxpath);
51
52 sigprocmask (SIG_SETMASK, &oset, &set); /* reset the signal mask */
53 }