|
|
1.1 root 1: /*
2:
1.1.1.3 ! root 3: Copyright 1990,1991,1992 Eric R. Smith.
! 4:
! 5: All rights reserved.
1.1 root 6:
7: */
8:
9:
10:
11: /* dossig.c:: dos signal handling routines */
12:
13:
14:
15: #include "mint.h"
16:
17:
18:
19: /*
20:
21: * send a signal to another process. If pid > 0, send the signal just to
22:
23: * that process. If pid < 0, send the signal to all processes whose process
24:
25: * group is -pid. If pid == 0, send the signal to all processes with the
26:
27: * same process group id.
28:
29: *
30:
31: * note: post_sig just posts the signal to the process.
32:
33: */
34:
35:
36:
1.1.1.2 root 37: long ARGS_ON_STACK
1.1 root 38:
39: p_kill(pid, sig)
40:
41: int pid, sig;
42:
43: {
44:
45: PROC *p;
46:
47:
48:
1.1.1.2 root 49: TRACE(("Pkill(%d, %d)", pid, sig));
1.1 root 50:
51: if (sig < 0 || sig >= NSIG) {
52:
1.1.1.2 root 53: DEBUG(("Pkill: signal out of range"));
1.1 root 54:
55: return ERANGE;
56:
57: }
58:
59:
60:
61: if (pid < 0)
62:
63: return killgroup(-pid, sig);
64:
65: else if (pid == 0)
66:
67: return killgroup(curproc->pgrp, sig);
68:
69: else {
70:
71: p = pid2proc(pid);
72:
73: if (p == 0 || p->wait_q == ZOMBIE_Q || p->wait_q == TSR_Q) {
74:
1.1.1.2 root 75: DEBUG(("Pkill: pid %d not found", pid));
1.1 root 76:
77: return EFILNF;
78:
79: }
80:
81: if (curproc->euid && curproc->ruid != p->ruid) {
82:
1.1.1.2 root 83: DEBUG(("Pkill: wrong user"));
1.1 root 84:
85: return EACCDN;
86:
87: }
88:
89:
90:
91: /* if the user sends signal 0, don't deliver it -- for users, signal
92:
93: * 0 is a null signal used to test the existence of a process
94:
95: */
96:
97: if (sig != 0)
98:
99: post_sig(p, sig);
100:
101: }
102:
103:
104:
105: check_sigs();
106:
1.1.1.2 root 107: TRACE(("Pkill: returning OK"));
1.1 root 108:
109: return 0;
110:
111: }
112:
113:
114:
115: /*
116:
117: * set a user-specified signal handler, POSIX.1 style
118:
119: * "oact", if non-null, gets the old signal handling
120:
121: * behaviour; "act", if non-null, specifies new
122:
123: * behaviour
124:
125: */
126:
127:
128:
1.1.1.2 root 129: long ARGS_ON_STACK
1.1 root 130:
131: p_sigaction(sig, act, oact)
132:
133: int sig;
134:
135: const struct sigaction *act;
136:
137: struct sigaction *oact;
138:
139: {
140:
1.1.1.2 root 141: TRACE(("Psigaction(%d)", sig));
1.1 root 142:
143: if (sig < 1 || sig >= NSIG)
144:
145: return ERANGE;
146:
147: if (act && (sig == SIGKILL || sig == SIGSTOP))
148:
149: return EACCDN;
150:
151: if (oact) {
152:
153: oact->sa_handler = curproc->sighandle[sig];
154:
155: oact->sa_mask = curproc->sigextra[sig];
156:
1.1.1.2 root 157: oact->sa_flags = curproc->sigflags[sig] & SAUSER;
1.1 root 158:
159: }
160:
161: if (act) {
162:
1.1.1.2 root 163: ushort flags;
164:
165:
166:
1.1 root 167: curproc->sighandle[sig] = act->sa_handler;
168:
169: curproc->sigextra[sig] = act->sa_mask & ~UNMASKABLE;
170:
1.1.1.2 root 171:
172:
173: /* only the flags in SAUSER can be changed by the user */
174:
175: flags = curproc->sigflags[sig] & ~SAUSER;
176:
177: flags |= act->sa_flags & SAUSER;
178:
179: curproc->sigflags[sig] = flags;
1.1 root 180:
181:
182:
183: /* various special things that should happen */
184:
185: if (act->sa_handler == SIG_IGN) {
186:
187: /* discard pending signals */
188:
189: curproc->sigpending &= ~(1L<<sig);
190:
191: }
192:
193:
194:
195: /* I dunno if this is right, but bash seems to expect it */
196:
197: curproc->sigmask &= ~(1L<<sig);
198:
199: }
200:
201: return 0;
202:
203: }
204:
205:
206:
207: /*
208:
209: * set a user-specified signal handler
210:
211: */
212:
213:
214:
1.1.1.2 root 215: long ARGS_ON_STACK
1.1 root 216:
217: p_signal(sig, handler)
218:
219: int sig;
220:
221: long handler;
222:
223: {
224:
225: long oldhandle;
226:
227:
228:
1.1.1.2 root 229: TRACE(("Psignal(%d, %lx)", sig, handler));
1.1 root 230:
231: if (sig < 1 || sig >= NSIG)
232:
233: return ERANGE;
234:
235: if (sig == SIGKILL || sig == SIGSTOP)
236:
237: return EACCDN;
238:
239: oldhandle = curproc->sighandle[sig];
240:
241: curproc->sighandle[sig] = handler;
242:
243: curproc->sigextra[sig] = 0;
244:
245: curproc->sigflags[sig] = 0;
246:
247:
248:
249: /* various special things that should happen */
250:
251: if (handler == SIG_IGN) {
252:
253: /* discard pending signals */
254:
255: curproc->sigpending &= ~(1L<<sig);
256:
257: }
258:
259:
260:
261: /* I dunno if this is right, but bash seems to expect it */
262:
263: curproc->sigmask &= ~(1L<<sig);
264:
265:
266:
267: return oldhandle;
268:
269: }
270:
271:
272:
273: /*
274:
275: * block some signals. Returns the old signal mask.
276:
277: */
278:
279:
280:
1.1.1.2 root 281: long ARGS_ON_STACK
1.1 root 282:
283: p_sigblock(mask)
284:
285: ulong mask;
286:
287: {
288:
289: ulong oldmask;
290:
291:
292:
1.1.1.2 root 293: TRACE(("Psigblock(%lx)",mask));
1.1 root 294:
295: /* some signals (e.g. SIGKILL) can't be masked */
296:
297: mask &= ~(UNMASKABLE);
298:
299: oldmask = curproc->sigmask;
300:
301: curproc->sigmask |= mask;
302:
303: return oldmask;
304:
305: }
306:
307:
308:
309: /*
310:
311: * set the signals that we're blocking. Some signals (e.g. SIGKILL)
312:
313: * can't be masked.
314:
315: * Returns the old mask.
316:
317: */
318:
319:
320:
1.1.1.2 root 321: long ARGS_ON_STACK
1.1 root 322:
323: p_sigsetmask(mask)
324:
325: ulong mask;
326:
327: {
328:
329: ulong oldmask;
330:
331:
332:
1.1.1.2 root 333: TRACE(("Psigsetmask(%lx)",mask));
1.1 root 334:
335: oldmask = curproc->sigmask;
336:
337: curproc->sigmask = mask & ~(UNMASKABLE);
338:
339: check_sigs(); /* maybe we unmasked something */
340:
341: return oldmask;
342:
343: }
344:
345:
346:
347: /*
348:
349: * p_sigpending: return which signals are pending delivery
350:
351: */
352:
353:
354:
1.1.1.2 root 355: long ARGS_ON_STACK
1.1 root 356:
357: p_sigpending()
358:
359: {
360:
1.1.1.2 root 361: TRACE(("Psigpending()"));
1.1 root 362:
363: check_sigs(); /* clear out any that are going to be delivered soon */
364:
1.1.1.2 root 365:
366:
367: /* note that signal #0 is used internally, so we don't tell the process
368:
369: * about it
370:
371: */
372:
373: return curproc->sigpending & ~1L;
1.1 root 374:
375: }
376:
377:
378:
379: /*
380:
381: * p_sigpause: atomically set the signals that we're blocking, then pause.
382:
383: * Some signals (e.g. SIGKILL) can't be masked.
384:
385: */
386:
387:
388:
1.1.1.2 root 389: long ARGS_ON_STACK
1.1 root 390:
391: p_sigpause(mask)
392:
393: ulong mask;
394:
395: {
396:
397: ulong oldmask;
398:
399:
400:
1.1.1.2 root 401: TRACE(("Psigpause(%lx)", mask));
1.1 root 402:
403: oldmask = curproc->sigmask;
404:
405: curproc->sigmask = mask & ~(UNMASKABLE);
406:
407: if (curproc->sigpending & ~(curproc->sigmask))
408:
409: check_sigs(); /* a signal is immediately pending */
410:
411: else
412:
413: sleep(IO_Q, -1L);
414:
415: curproc->sigmask = oldmask;
416:
417: check_sigs(); /* maybe we unmasked something */
418:
1.1.1.2 root 419: TRACE(("Psigpause: returning OK"));
1.1 root 420:
421: return 0;
422:
423: }
424:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.