* debug.cc (delete_handle): Report on handle value in debugging output.
* pinfo.h (_pinfo::exists): Declare "new" function. (_pinfo::kill): Ditto. * fhandler_termios.cc (tty_min::kill_pgrp): Use _pinfo::exists rather than proc_exists. * pinfo.cc (pinfo::init): Ditto. Don't do a low_priority_sleep(0) when looping to find exec'ed procinfo. (pinfo::release): Be more careful about unmapping and closing. * signal.cc (_pinfo::kill): Rename from kill_worker. Accommodate entry into _pinfo class. (kill0): Use _pinfo::kill rather than kill_worker. (kill_pgrp): Ditto. Use _pinfo::exists rather than proc_exists. * sigproc.cc (_pinfo::exists): Rename from proc_exists. (pid_exists): Use _pinfo::exists rather than proc_exists. (remove_proc): Ditto. * sigproc.h (proc_exists): Delete declaration.
This commit is contained in:
		| @@ -1,3 +1,23 @@ | |||||||
|  | 2005-02-26  Christopher Faylor  <cgf@timesys.com> | ||||||
|  |  | ||||||
|  | 	* debug.cc (delete_handle): Report on handle value in debugging output. | ||||||
|  |  | ||||||
|  | 	* pinfo.h (_pinfo::exists): Declare "new" function. | ||||||
|  | 	(_pinfo::kill): Ditto. | ||||||
|  | 	* fhandler_termios.cc (tty_min::kill_pgrp): Use _pinfo::exists rather | ||||||
|  | 	than proc_exists. | ||||||
|  | 	* pinfo.cc (pinfo::init): Ditto.  Don't do a low_priority_sleep(0) when | ||||||
|  | 	looping to find exec'ed procinfo. | ||||||
|  | 	(pinfo::release): Be more careful about unmapping and closing. | ||||||
|  | 	* signal.cc (_pinfo::kill): Rename from kill_worker.  Accommodate entry | ||||||
|  | 	into _pinfo class. | ||||||
|  | 	(kill0): Use _pinfo::kill rather than kill_worker. | ||||||
|  | 	(kill_pgrp): Ditto.  Use _pinfo::exists rather than proc_exists. | ||||||
|  | 	* sigproc.cc (_pinfo::exists): Rename from proc_exists. | ||||||
|  | 	(pid_exists): Use _pinfo::exists rather than proc_exists. | ||||||
|  | 	(remove_proc): Ditto. | ||||||
|  | 	* sigproc.h (proc_exists): Delete declaration. | ||||||
|  |  | ||||||
| 2005-02-25  Corinna Vinschen  <corinna@vinschen.de> | 2005-02-25  Corinna Vinschen  <corinna@vinschen.de> | ||||||
|  |  | ||||||
| 	* fhandler.h (class fhandler_base): Declare fixup_mmap_after_fork | 	* fhandler.h (class fhandler_base): Declare fixup_mmap_after_fork | ||||||
|   | |||||||
| @@ -162,7 +162,7 @@ static void __stdcall | |||||||
| delete_handle (handle_list *hl) | delete_handle (handle_list *hl) | ||||||
| { | { | ||||||
|   handle_list *hnuke = hl->next; |   handle_list *hnuke = hl->next; | ||||||
|   debug_printf ("nuking handle '%s'", hnuke->name); |   debug_printf ("nuking handle '%s' (%p)", hnuke->name, hnuke->h); | ||||||
|   hl->next = hl->next->next; |   hl->next = hl->next->next; | ||||||
|   memset (hnuke, 0, sizeof (*hnuke)); |   memset (hnuke, 0, sizeof (*hnuke)); | ||||||
| } | } | ||||||
|   | |||||||
| @@ -94,7 +94,7 @@ tty_min::kill_pgrp (int sig) | |||||||
|   for (unsigned i = 0; i < pids.npids; i++) |   for (unsigned i = 0; i < pids.npids; i++) | ||||||
|     { |     { | ||||||
|       _pinfo *p = pids[i]; |       _pinfo *p = pids[i]; | ||||||
|       if (!proc_exists (p) || p->ctty != ntty || p->pgid != pgid) |       if (!p->exists () || p->ctty != ntty || p->pgid != pgid) | ||||||
| 	continue; | 	continue; | ||||||
|       if (p == myself) |       if (p == myself) | ||||||
| 	killself++; | 	killself++; | ||||||
|   | |||||||
| @@ -181,7 +181,7 @@ pinfo::init (pid_t n, DWORD flag, HANDLE h0) | |||||||
|     } |     } | ||||||
|  |  | ||||||
|   void *mapaddr; |   void *mapaddr; | ||||||
|   bool createit = !!(flag & (PID_IN_USE | PID_EXECED)); |   int createit = flag & (PID_IN_USE | PID_EXECED); | ||||||
|   bool created = false; |   bool created = false; | ||||||
|   DWORD access = FILE_MAP_READ |   DWORD access = FILE_MAP_READ | ||||||
| 		 | (flag & (PID_IN_USE | PID_EXECED | PID_MAP_RW) | 		 | (flag & (PID_IN_USE | PID_EXECED | PID_MAP_RW) | ||||||
| @@ -257,7 +257,7 @@ pinfo::init (pid_t n, DWORD flag, HANDLE h0) | |||||||
|  |  | ||||||
|       if (procinfo->process_state & PID_EXECED) |       if (procinfo->process_state & PID_EXECED) | ||||||
| 	{ | 	{ | ||||||
| 	  assert (!i); | 	  assert (i == 0); | ||||||
| 	  pid_t realpid = procinfo->pid; | 	  pid_t realpid = procinfo->pid; | ||||||
| 	  debug_printf ("execed process windows pid %d, cygwin pid %d", n, realpid); | 	  debug_printf ("execed process windows pid %d, cygwin pid %d", n, realpid); | ||||||
| 	  if (realpid == n) | 	  if (realpid == n) | ||||||
| @@ -296,6 +296,7 @@ pinfo::init (pid_t n, DWORD flag, HANDLE h0) | |||||||
|  |  | ||||||
|     loop: |     loop: | ||||||
|       release (); |       release (); | ||||||
|  |       if (h0) | ||||||
| 	low_priority_sleep (0); | 	low_priority_sleep (0); | ||||||
|     } |     } | ||||||
|  |  | ||||||
| @@ -338,7 +339,7 @@ _pinfo::set_ctty (tty_min *tc, int flags, fhandler_tty_slave *arch) | |||||||
| 		      tc->ntty, sid, pid, pgid, tc->getsid ()); | 		      tc->ntty, sid, pid, pgid, tc->getsid ()); | ||||||
|  |  | ||||||
|       pinfo p (tc->getsid ()); |       pinfo p (tc->getsid ()); | ||||||
|       if (sid == pid && (!p || p->pid == pid || !proc_exists (p))) |       if (sid == pid && (!p || p->pid == pid || !p->exists ())) | ||||||
| 	{ | 	{ | ||||||
| 	  paranoid_printf ("resetting tty%d sid.  Was %d, now %d.  pgid was %d, now %d.", | 	  paranoid_printf ("resetting tty%d sid.  Was %d, now %d.  pgid was %d, now %d.", | ||||||
| 			   tc->ntty, tc->getsid (), sid, tc->getpgid (), pgid); | 			   tc->ntty, tc->getsid (), sid, tc->getpgid (), pgid); | ||||||
| @@ -1132,17 +1133,15 @@ pinfo::release () | |||||||
| { | { | ||||||
|   if (procinfo) |   if (procinfo) | ||||||
|     { |     { | ||||||
| #ifdef DEBUGGING |       void *unmap_procinfo = procinfo; | ||||||
|       if (((DWORD) procinfo & 0x77000000) == 0x61000000) |  | ||||||
| 	try_to_debug (); |  | ||||||
| #endif |  | ||||||
|       UnmapViewOfFile (procinfo); |  | ||||||
|       procinfo = NULL; |       procinfo = NULL; | ||||||
|  |       UnmapViewOfFile (unmap_procinfo); | ||||||
|     } |     } | ||||||
|   if (h) |   if (h) | ||||||
|     { |     { | ||||||
|       ForceCloseHandle1 (h, pinfo_shared_handle); |       HANDLE close_h = h; | ||||||
|       h = NULL; |       h = NULL; | ||||||
|  |       ForceCloseHandle1 (close_h, pinfo_shared_handle); | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -123,6 +123,8 @@ public: | |||||||
|   bool dup_proc_pipe (HANDLE) __attribute__ ((regparm(2))); |   bool dup_proc_pipe (HANDLE) __attribute__ ((regparm(2))); | ||||||
|   void sync_proc_pipe (); |   void sync_proc_pipe (); | ||||||
|   bool alert_parent (char); |   bool alert_parent (char); | ||||||
|  |   int __stdcall kill (siginfo_t&) __attribute__ ((regparm (2))); | ||||||
|  |   bool __stdcall exists () __attribute__ ((regparm (1))); | ||||||
|  |  | ||||||
|   friend void __stdcall set_myself (HANDLE); |   friend void __stdcall set_myself (HANDLE); | ||||||
|  |  | ||||||
|   | |||||||
| @@ -182,16 +182,15 @@ handle_sigprocmask (int sig, const sigset_t *set, sigset_t *oldset, sigset_t& op | |||||||
|   return 0; |   return 0; | ||||||
| } | } | ||||||
|  |  | ||||||
| static int | int __stdcall | ||||||
| kill_worker (pid_t pid, siginfo_t& si) | _pinfo::kill (siginfo_t& si) | ||||||
| { | { | ||||||
|   sig_dispatch_pending (); |   sig_dispatch_pending (); | ||||||
|  |  | ||||||
|   int res = 0; |   int res = 0; | ||||||
|   pinfo dest (pid); |  | ||||||
|   bool sendSIGCONT; |   bool sendSIGCONT; | ||||||
|  |  | ||||||
|   if (!dest) |   if (!exists ()) | ||||||
|     { |     { | ||||||
|       set_errno (ESRCH); |       set_errno (ESRCH); | ||||||
|       return -1; |       return -1; | ||||||
| @@ -200,14 +199,10 @@ kill_worker (pid_t pid, siginfo_t& si) | |||||||
|   if ((sendSIGCONT = (si.si_signo < 0))) |   if ((sendSIGCONT = (si.si_signo < 0))) | ||||||
|     si.si_signo = -si.si_signo; |     si.si_signo = -si.si_signo; | ||||||
|  |  | ||||||
|   DWORD process_state = dest->process_state; |   DWORD this_process_state = process_state; | ||||||
|   if (si.si_signo == 0) |   if (si.si_signo == 0) | ||||||
|     { |     /* ok */; | ||||||
|       res = proc_exists (dest) ? 0 : -1; |   else if ((res = sig_send (this, si))) | ||||||
|       if (res < 0) |  | ||||||
| 	set_errno (ESRCH); |  | ||||||
|     } |  | ||||||
|   else if ((res = sig_send (dest, si))) |  | ||||||
|     { |     { | ||||||
|       sigproc_printf ("%d = sig_send, %E ", res); |       sigproc_printf ("%d = sig_send, %E ", res); | ||||||
|       res = -1; |       res = -1; | ||||||
| @@ -218,11 +213,11 @@ kill_worker (pid_t pid, siginfo_t& si) | |||||||
|       si2.si_signo = SIGCONT; |       si2.si_signo = SIGCONT; | ||||||
|       si2.si_code = SI_KERNEL; |       si2.si_code = SI_KERNEL; | ||||||
|       si2.si_pid = si2.si_uid = si2.si_errno = 0; |       si2.si_pid = si2.si_uid = si2.si_errno = 0; | ||||||
|       (void) sig_send (dest, si2); |       (void) sig_send (this, si2); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|   syscall_printf ("%d = kill_worker (%d, %d), process_state %p", res, pid, |   syscall_printf ("%d = _pinfo::kill (%d, %d), process_state %p", res, pid, | ||||||
| 		  si.si_signo, process_state); | 		  si.si_signo, this_process_state); | ||||||
|   return res; |   return res; | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -250,7 +245,7 @@ kill0 (pid_t pid, siginfo_t& si) | |||||||
|       (si.si_signo == SIGTSTP || si.si_signo == SIGTTIN || si.si_signo == SIGTTOU)) |       (si.si_signo == SIGTSTP || si.si_signo == SIGTTIN || si.si_signo == SIGTTOU)) | ||||||
|     si.si_signo = 0; |     si.si_signo = 0; | ||||||
|  |  | ||||||
|   return (pid > 0) ? kill_worker (pid, si) : kill_pgrp (-pid, si); |   return (pid > 0) ? pinfo (pid)->kill (si) : kill_pgrp (-pid, si); | ||||||
| } | } | ||||||
|  |  | ||||||
| int | int | ||||||
| @@ -286,7 +281,7 @@ kill_pgrp (pid_t pid, siginfo_t& si) | |||||||
|     { |     { | ||||||
|       _pinfo *p = pids[i]; |       _pinfo *p = pids[i]; | ||||||
|  |  | ||||||
|       if (!proc_exists (p)) |       if (!p->exists ()) | ||||||
| 	continue; | 	continue; | ||||||
|  |  | ||||||
|       /* Is it a process we want to kill?  */ |       /* Is it a process we want to kill?  */ | ||||||
| @@ -298,12 +293,12 @@ kill_pgrp (pid_t pid, siginfo_t& si) | |||||||
| 		      p->pid, p->pgid, p->ctty, myself->ctty); | 		      p->pid, p->pgid, p->ctty, myself->ctty); | ||||||
|       if (p == myself) |       if (p == myself) | ||||||
| 	killself++; | 	killself++; | ||||||
|       else if (kill_worker (p->pid, si)) |       else if (p->kill (si)) | ||||||
| 	res = -1; | 	res = -1; | ||||||
|       found++; |       found++; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|   if (killself && !exit_state && kill_worker (myself->pid, si)) |   if (killself && !exit_state && myself->kill (si)) | ||||||
|     res = -1; |     res = -1; | ||||||
|  |  | ||||||
|   if (!found) |   if (!found) | ||||||
|   | |||||||
| @@ -192,16 +192,15 @@ proc_can_be_signalled (_pinfo *p) | |||||||
| bool __stdcall | bool __stdcall | ||||||
| pid_exists (pid_t pid) | pid_exists (pid_t pid) | ||||||
| { | { | ||||||
|   pinfo p (pid); |   return pinfo (pid)->exists (); | ||||||
|   return proc_exists (p); |  | ||||||
| } | } | ||||||
|  |  | ||||||
| /* Test to determine if a process really exists and is processing signals. | /* Test to determine if a process really exists and is processing signals. | ||||||
|  */ |  */ | ||||||
| bool __stdcall | bool __stdcall | ||||||
| proc_exists (_pinfo *p) | _pinfo::exists () | ||||||
| { | { | ||||||
|   return p && !(p->process_state & PID_EXITED); |   return this && !(process_state & PID_EXITED); | ||||||
| } | } | ||||||
|  |  | ||||||
| /* Return true if this is one of our children, false otherwise.  */ | /* Return true if this is one of our children, false otherwise.  */ | ||||||
| @@ -847,7 +846,7 @@ out: | |||||||
| static bool __stdcall | static bool __stdcall | ||||||
| remove_proc (int ci) | remove_proc (int ci) | ||||||
| { | { | ||||||
|   if (proc_exists (procs[ci])) |   if (procs[ci]->exists ()) | ||||||
|     return true; |     return true; | ||||||
|  |  | ||||||
|   sigproc_printf ("removing procs[%d], pid %d, nprocs %d", ci, procs[ci]->pid, |   sigproc_printf ("removing procs[%d], pid %d, nprocs %d", ci, procs[ci]->pid, | ||||||
|   | |||||||
| @@ -73,7 +73,6 @@ class _pinfo; | |||||||
| void __stdcall proc_terminate (); | void __stdcall proc_terminate (); | ||||||
| void __stdcall sigproc_init (); | void __stdcall sigproc_init (); | ||||||
| void __stdcall sigproc_terminate (); | void __stdcall sigproc_terminate (); | ||||||
| bool __stdcall proc_exists (_pinfo *) __attribute__ ((regparm(1))); |  | ||||||
| bool __stdcall pid_exists (pid_t) __attribute__ ((regparm(1))); | bool __stdcall pid_exists (pid_t) __attribute__ ((regparm(1))); | ||||||
| int __stdcall sig_send (_pinfo *, siginfo_t&, class _cygtls *tls = NULL) __attribute__ ((regparm (3))); | int __stdcall sig_send (_pinfo *, siginfo_t&, class _cygtls *tls = NULL) __attribute__ ((regparm (3))); | ||||||
| int __stdcall sig_send (_pinfo *, int) __attribute__ ((regparm (2))); | int __stdcall sig_send (_pinfo *, int) __attribute__ ((regparm (2))); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user