Updated docs/README-ATTACHMENTS, mainly to reflect that no setup is
[mmh] / docs / historical / mh-6.8.5 / sbr / RCS / m_update.c,v
1 head    1.7;
2 access;
3 symbols;
4 locks; strict;
5 comment @ * @;
6
7
8 1.7
9 date    92.12.15.00.20.22;      author jromine; state Exp;
10 branches;
11 next    1.6;
12
13 1.6
14 date    92.12.14.17.54.23;      author jromine; state Exp;
15 branches;
16 next    1.5;
17
18 1.5
19 date    90.04.05.15.31.24;      author sources; state Exp;
20 branches;
21 next    1.4;
22
23 1.4
24 date    90.04.05.14.45.40;      author sources; state Exp;
25 branches;
26 next    1.3;
27
28 1.3
29 date    90.02.06.13.09.01;      author sources; state Exp;
30 branches;
31 next    1.2;
32
33 1.2
34 date    90.02.05.14.23.05;      author sources; state Exp;
35 branches;
36 next    1.1;
37
38 1.1
39 date    90.02.05.14.22.58;      author sources; state Exp;
40 branches;
41 next    ;
42
43
44 desc
45 @@
46
47
48 1.7
49 log
50 @endif sugar
51 @
52 text
53 @/* m_update.c - update the profile */
54 #ifndef lint
55 static char ident[] = "@@(#)$Id: m_update.c,v 1.6 1992/12/14 17:54:23 jromine Exp jromine $";
56 #endif  lint
57
58 #include "../h/mh.h"
59 #include <stdio.h>
60 #include <signal.h>
61 #ifndef sigmask
62 #define sigmask(s)      (1 << ((s) - 1))
63 #endif  /* not sigmask */
64
65 static int      m_chkids();
66
67 void m_update () {
68     int     action;
69 #ifndef BSD42
70     TYPESIG (*hstat) (), (*istat) (), (*qstat) (), (*tstat) ();
71 #else   /* BSD42 */
72     int     smask;
73 #endif  /* BSD42 */
74     register struct node   *np;
75     FILE * out;
76
77     if (!(ctxflags & CTXMOD))
78         return;
79     ctxflags &= ~CTXMOD;
80
81     if ((action = m_chkids ()) > OK)
82         return;                 /* child did it for us */
83
84 #ifndef BSD42
85     hstat = signal (SIGHUP, SIG_IGN);
86     istat = signal (SIGINT, SIG_IGN);
87     qstat = signal (SIGQUIT, SIG_IGN);
88     tstat = signal (SIGTERM, SIG_IGN);
89 #else   /* BSD42 */
90     smask = sigblock (sigmask (SIGHUP) | sigmask (SIGINT)
91                         | sigmask (SIGQUIT) | sigmask (SIGTERM));
92 #endif  /* BSD42 */
93
94     if ((out = fopen (ctxpath, "w")) == NULL)
95         adios (ctxpath, "unable to write");
96     for (np = m_defs; np; np = np -> n_next)
97         if (np -> n_context)
98             fprintf (out, "%s: %s\n", np -> n_name, np -> n_field);
99     (void) fclose (out);
100
101 #ifndef BSD42
102     (void) signal (SIGHUP, hstat);
103     (void) signal (SIGINT, istat);
104     (void) signal (SIGQUIT, qstat);
105     (void) signal (SIGTERM, tstat);
106 #else   /* BSD42 */
107     (void) sigsetmask (smask);
108 #endif  /* BSD42 */
109     if (action == OK)
110         _exit (0);              /* we are child, time to die */
111 }
112
113 /* \f */
114
115 /* This hack brought to you so we can handle set[ug]id MH programs.  If we
116    return NOTOK, then no fork is made, we update .mh_profile normally, and
117    return to the caller normally.  If we return 0, then the child is
118    executing, .mh_profile is modified after we set our [ug]ids to the norm.
119    If we return > 0, then the parent is executed and .mh_profile has
120    already be modified.  We can just return to the caller immediately. */
121
122
123 static int  m_chkids () {
124     int     i,
125             child_id;
126
127     if (getuid () == geteuid ())
128         return (NOTOK);
129
130     for (i = 0; (child_id = fork ()) == -1 && i < 5; i++)
131         sleep (5);
132     switch (child_id) {
133         case NOTOK:
134             break;
135
136         case OK:
137             (void) setgid (getgid ());
138             (void) setuid (getuid ());
139             break;
140
141         default:
142             (void) pidwait (child_id, NOTOK);
143             break;
144     }
145
146     return child_id;
147 }
148 @
149
150
151 1.6
152 log
153 @*** empty log message ***
154 @
155 text
156 @d3 1
157 a3 1
158 static char ident[] = "@@(#)$Id: m_update.c,v 1.5 1990/04/05 15:31:24 sources Exp jromine $";
159 d11 1
160 a11 1
161 #endif  not sigmask
162 d19 1
163 a19 1
164 #else   BSD42
165 d21 1
166 a21 1
167 #endif  BSD42
168 d37 1
169 a37 1
170 #else   BSD42
171 d40 1
172 a40 1
173 #endif  BSD42
174 d54 1
175 a54 1
176 #else   BSD42
177 d56 1
178 a56 1
179 #endif  BSD42
180 @
181
182
183 1.5
184 log
185 @add ID
186 @
187 text
188 @d3 1
189 a3 1
190 static char ident[] = "@@(#)$Id:$";
191 @
192
193
194 1.4
195 log
196 @add ID
197 @
198 text
199 @d3 1
200 a3 1
201 static char ident[] = "$Id:";
202 @
203
204
205 1.3
206 log
207 @ANSI Compilance
208 @
209 text
210 @d2 3
211 @
212
213
214 1.2
215 log
216 @TYPESIG
217 @
218 text
219 @d10 1
220 @
221
222
223 1.1
224 log
225 @Initial revision
226 @
227 text
228 @d14 1
229 a14 1
230     int     (*hstat) (), (*istat) (), (*qstat) (), (*tstat) ();
231 @