home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / gnu / glibc-1.06 / sysdeps / mach / hurd / __kill.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-04-04  |  2.4 KB  |  85 lines

  1. /* Copyright (C) 1991, 1992 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3.  
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Library General Public License as
  6. published by the Free Software Foundation; either version 2 of the
  7. License, or (at your option) any later version.
  8.  
  9. The GNU C Library is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  12. Library General Public License for more details.
  13.  
  14. You should have received a copy of the GNU Library General Public
  15. License along with the GNU C Library; see the file COPYING.LIB.  If
  16. not, write to the Free Software Foundation, Inc., 675 Mass Ave,
  17. Cambridge, MA 02139, USA.  */
  18.  
  19. #include <ansidecl.h>
  20. #include <errno.h>
  21. #include <signal.h>
  22. #include <hurd.h>
  23.  
  24. /* Send signal SIG to process number PID.  If PID is zero,
  25.    send SIG to all processes in the current process's process group.
  26.    If PID is < -1, send SIG to all processes in process group - PID.  */
  27. int
  28. DEFUN(__kill, (pid, sig), int pid AND int sig)
  29. {
  30.   error_t err;
  31.   mach_port_t portbuf[10];
  32.   mach_port_t *ports = portbuf;
  33.   mach_port_t refport;        /* XXX */
  34.   size_t nports = 10, i;
  35.   mach_port_t proc;
  36.   int dealloc_proc;
  37.  
  38.   proc = _hurd_port_get (&_hurd_proc, &dealloc_proc);
  39.  
  40.   if (pid <= 0)
  41.     {
  42.       /* Send SIG to each process in pgrp (- PID).  */
  43.       proccoll_t pcoll;
  44.       err = __proc_pgrp_pcoll (proc, - pid, &pcoll);
  45.       if (!err)
  46.     {
  47.       err = __proc_get_collports (proc, pcoll, &ports, &nports);
  48.       __mach_port_deallocate (__mach_task_self (), pcoll);
  49.     }
  50.     }
  51.   else
  52.     {
  53.       err = __proc_getmsgport (proc, pid, &ports[0]);
  54.       nports = 1;
  55.     }
  56.  
  57.   if (!err)
  58.     {
  59.       err = __proc_pid2task (proc, pid, &refport);
  60.       if (err)
  61.     err = __proc_getsidport (proc, &refport);
  62.     }
  63.  
  64.   _hurd_port_free (&_hurd_proc, proc, &dealloc_proc);
  65.  
  66.   for (i = 0; i < nports; ++i)
  67.     {
  68.       if (!err && signo == SIGKILL)
  69.     err = __task_terminate (refport); /* XXX */
  70.       if (!err)
  71.     err = __sig_post (ports[i], sig, refport); /* XXX */
  72.       __mach_port_deallocate (__mach_task_self (), ports[i]);
  73.     }
  74.  
  75.   if (refport != MACH_PORT_NULL)
  76.     __mach_port_deallocate (__mach_task_self (), refport); /* XXX */
  77.  
  78.   if (ports != portbuf)
  79.     __vm_deallocate (__mach_task_self (), ports, nports * sizeof (ports[0]));
  80.  
  81.   if (err)
  82.     return __hurd_fail (err);
  83.   return 0;
  84. }
  85.