Annotation of 43BSDReno/contrib/mh/sbr/m_update.c, revision 1.1.1.1

1.1       root        1: /* m_update.c - update the profile */
                      2: 
                      3: #include "../h/mh.h"
                      4: #include <stdio.h>
                      5: #include <signal.h>
                      6: #ifndef        sigmask
                      7: #define        sigmask(s)      (1 << ((s) - 1))
                      8: #endif not sigmask
                      9: 
                     10: static int m_chkids();
                     11: 
                     12: void
                     13: m_update()
                     14: {
                     15:     int     action;
                     16: #ifndef        BSD42
                     17:     SIGDECL (*hstat)(), (*istat)(), (*qstat)(), (*tstat)();
                     18: #else  BSD42
                     19:     int            smask;
                     20: #endif BSD42
                     21:     register struct node   *np;
                     22:     FILE * out;
                     23: 
                     24:     if (!(ctxflags & CTXMOD))
                     25:        return;
                     26:     ctxflags &= ~CTXMOD;
                     27: 
                     28:     if ((action = m_chkids ()) > OK)
                     29:        return;                 /* child did it for us */
                     30: 
                     31: #ifndef        BSD42
                     32:     hstat = signal (SIGHUP, SIG_IGN);
                     33:     istat = signal (SIGINT, SIG_IGN);
                     34:     qstat = signal (SIGQUIT, SIG_IGN);
                     35:     tstat = signal (SIGTERM, SIG_IGN);
                     36: #else  BSD42
                     37:     smask = sigblock (sigmask (SIGHUP) | sigmask (SIGINT)
                     38:                        | sigmask (SIGQUIT) | sigmask (SIGTERM));
                     39: #endif BSD42
                     40: 
                     41:     if ((out = fopen (ctxpath, "w")) == NULL)
                     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:     (void) fclose (out);
                     47: 
                     48: #ifndef        BSD42
                     49:     (void) signal (SIGHUP, hstat);
                     50:     (void) signal (SIGINT, istat);
                     51:     (void) signal (SIGQUIT, qstat);
                     52:     (void) signal (SIGTERM, tstat);
                     53: #else  BSD42
                     54:     (void) sigsetmask (smask);
                     55: #endif BSD42
                     56:     if (action == OK)
                     57:        _exit (0);              /* we are child, time to die */
                     58: }
                     59: 
                     60: /*  */
                     61: 
                     62: /* This hack brought to you so we can handle set[ug]id MH programs.  If we
                     63:    return NOTOK, then no fork is made, we update .mh_profile normally, and
                     64:    return to the caller normally.  If we return 0, then the child is
                     65:    executing, .mh_profile is modified after we set our [ug]ids to the norm.
                     66:    If we return > 0, then the parent is executed and .mh_profile has
                     67:    already be modified.  We can just return to the caller immediately. */
                     68: 
                     69: 
                     70: static int
                     71: m_chkids()
                     72: {
                     73:     int     i,
                     74:             child_id;
                     75: 
                     76:     if (getuid () == geteuid ())
                     77:        return (NOTOK);
                     78: 
                     79:     for (i = 0; (child_id = fork ()) == -1 && i < 5; i++)
                     80:        sleep (5);
                     81:     switch (child_id) {
                     82:        case NOTOK:
                     83:            break;
                     84: 
                     85:        case OK:
                     86:            (void) setgid (getgid ());
                     87:            (void) setuid (getuid ());
                     88:            break;
                     89: 
                     90:        default:
                     91:            (void) pidwait (child_id, NOTOK);
                     92:            break;
                     93:     }
                     94: 
                     95:     return child_id;
                     96: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.