home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / unix_c / kernel / zonk.c < prev   
Encoding:
Text File  |  1989-03-21  |  1.3 KB  |  51 lines

  1. 21-Dec-85 20:10:35-MST,1374;000000000001
  2. Return-Path: <unix-sources-request@BRL.ARPA>
  3. Received: from BRL-TGR.ARPA by SIMTEL20.ARPA with TCP; Sat 21 Dec 85 20:10:31-MST
  4. Received: from usenet by TGR.BRL.ARPA id a025820; 21 Dec 85 21:41 EST
  5. From: Ken Lalonde <kwlalonde@watmath.uucp>
  6. Newsgroups: net.sources.bugs
  7. Subject: Serious bug in "zonk"
  8. Message-ID: <588@watmath.UUCP>
  9. Date: 20 Dec 85 11:32:47 GMT
  10. To:       unix-sources-bugs@BRL-TGR.ARPA
  11.  
  12. Last September I posted the code and support programs for "zonk", a
  13. kill-by-uid system call.  There is a bug in the system call code that
  14. can cause a signal to be sent to as-yet unborn processes. 
  15. The corrected code follows.
  16.  
  17. --
  18.  
  19. /*
  20.  *  Zonk system call - apply a signal to every process owned by a user.
  21.  *  A count of the affected processes is returned.
  22.  *  If passed signal zero, no signal is sent; only the count is returned.
  23.  */
  24. zonk()
  25. {
  26.     struct a {
  27.         int    uid;
  28.         int    sig;
  29.     } *uap = (struct a *)u.u_ap;
  30.     register int sig = uap->sig;
  31.     register int count, uid;
  32.     register struct proc *p;
  33.  
  34.     if ((uid = uap->uid) != u.u_uid && !suser())
  35.         return;
  36.     if (uid == 0 && sig || (unsigned)sig >= NSIG) {
  37.         u.u_error = EINVAL;
  38.         return;
  39.     }
  40.     for (count = 0, p = proc; p < procNPROC; p++) {
  41.         if (p->p_stat == NULL)
  42.             continue;
  43.         if (p->p_uid != uid)
  44.             continue;
  45.         if (sig)
  46.             psignal(p, sig);
  47.         count++;
  48.     }
  49.     u.u_r.r_val1 = count;
  50. }
  51.