]>
diplodocus.org Git - nmh/blob - sbr/context_save.c
3 * context_save.c -- write out the updated context file
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.
11 #include <h/signals.h>
16 static int m_chkids(void);
23 register struct node
*np
;
26 int failed_to_lock
= 0;
28 /* No context in use -- silently ignore any changes! */
32 if (!(ctxflags
& CTXMOD
))
36 if ((action
= m_chkids ()) > 0)
37 return; /* child did it for us */
39 /* block a few signals */
41 sigaddset (&set
, SIGHUP
);
42 sigaddset (&set
, SIGINT
);
43 sigaddset (&set
, SIGQUIT
);
44 sigaddset (&set
, SIGTERM
);
45 sigprocmask (SIG_BLOCK
, &set
, &oset
);
47 if (!(out
= lkfopendata (ctxpath
, "w", &failed_to_lock
))) {
49 adios (ctxpath
, "failed to lock");
51 adios (ctxpath
, "unable to write");
54 for (np
= m_defs
; np
; np
= np
->n_next
)
56 fprintf (out
, "%s: %s\n", np
->n_name
, np
->n_field
);
57 lkfclosedata (out
, ctxpath
);
59 sigprocmask (SIG_SETMASK
, &oset
, &set
); /* reset the signal mask */
62 /* This must be _exit(), not exit(), because the child didn't
63 call unregister_for_removal() in m_chkids(). */
64 _exit (0); /* we are child, time to die */
68 * This hack brought to you so we can handle set[ug]id MH programs.
69 * If we return -1, then no fork is made, we update .mh_profile
70 * normally, and return to the caller normally. If we return 0,
71 * then the child is executing, .mh_profile is modified after
72 * we set our [ug]ids to the norm. If we return > 0, then the
73 * parent is executed and .mh_profile has already be modified.
74 * We can just return to the caller immediately.
83 if (getuid () == geteuid ())
86 for (i
= 0; (pid
= fork ()) == -1 && i
< 5; i
++)
94 /* It's not necessary to call unregister_for_removal(0)
95 because the child calls _exit() in context_save(). */