]>
diplodocus.org Git - nmh/blob - docs/historical/mh-6.8.5/sbr/m_update.c
1 /* m_update.c - update the profile */
3 static char ident
[] = "@(#)$Id: m_update.c,v 1.7 1992/12/15 00:20:22 jromine Exp $";
10 #define sigmask(s) (1 << ((s) - 1))
11 #endif /* not sigmask */
13 static int m_chkids();
18 TYPESIG (*hstat
) (), (*istat
) (), (*qstat
) (), (*tstat
) ();
22 register struct node
*np
;
25 if (!(ctxflags
& CTXMOD
))
29 if ((action
= m_chkids ()) > OK
)
30 return; /* child did it for us */
33 hstat
= signal (SIGHUP
, SIG_IGN
);
34 istat
= signal (SIGINT
, SIG_IGN
);
35 qstat
= signal (SIGQUIT
, SIG_IGN
);
36 tstat
= signal (SIGTERM
, SIG_IGN
);
38 smask
= sigblock (sigmask (SIGHUP
) | sigmask (SIGINT
)
39 | sigmask (SIGQUIT
) | sigmask (SIGTERM
));
42 if ((out
= fopen (ctxpath
, "w")) == NULL
)
43 adios (ctxpath
, "unable to write");
44 for (np
= m_defs
; np
; np
= np
-> n_next
)
46 fprintf (out
, "%s: %s\n", np
-> n_name
, np
-> n_field
);
50 (void) signal (SIGHUP
, hstat
);
51 (void) signal (SIGINT
, istat
);
52 (void) signal (SIGQUIT
, qstat
);
53 (void) signal (SIGTERM
, tstat
);
55 (void) sigsetmask (smask
);
58 _exit (0); /* we are child, time to die */
63 /* This hack brought to you so we can handle set[ug]id MH programs. If we
64 return NOTOK, then no fork is made, we update .mh_profile normally, and
65 return to the caller normally. If we return 0, then the child is
66 executing, .mh_profile is modified after we set our [ug]ids to the norm.
67 If we return > 0, then the parent is executed and .mh_profile has
68 already be modified. We can just return to the caller immediately. */
71 static int m_chkids () {
75 if (getuid () == geteuid ())
78 for (i
= 0; (child_id
= fork ()) == -1 && i
< 5; i
++)
85 (void) setgid (getgid ());
86 (void) setuid (getuid ());
90 (void) pidwait (child_id
, NOTOK
);