This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
amigaos4: better kill() implementation
authorAndy Broad <andy@broad.ology.org.uk>
Tue, 15 Sep 2015 13:01:12 +0000 (09:01 -0400)
committerJarkko Hietaniemi <jhi@iki.fi>
Wed, 16 Sep 2015 11:44:30 +0000 (07:44 -0400)
(the underlying UNIX emulation has changed)

README.amiga
amigaos4/amigaio.c
amigaos4/amigaos.h

index 934b037..41345c1 100644 (file)
@@ -181,6 +181,8 @@ This will build the default setup that installs under SDK:local/newlib/lib/
 =item Add flock() emulation using IDOS->LockRecord thanks to Tony Cook
 for the suggestion.
 
+=item Fix issue where kill was using the wrong kind of process ID
+
 =back
 
 =item B<27th November 2013>
index 53f059f..400f8d0 100644 (file)
@@ -89,6 +89,7 @@ struct thread_info
         int ti_children;
         pthread_t ti_parent;
         struct MsgPort *ti_port;
+        struct Process *ti_Process;
 };
 
 static struct thread_info pseudo_children[MAX_THREADS];
@@ -154,6 +155,31 @@ struct child_arg
         PerlInterpreter *ca_interp;
 };
 
+#undef kill
+
+/* FIXME: Is here's a chance, albeit it small of a clash between our pseudo pid */
+/* derived from the pthread API  and the dos.library pid that newlib kill uses? */
+/* clib2 used the Process address so there was no issue */
+
+int amigaos_kill(Pid_t pid, int signal)
+{
+       int i;
+       Pid_t realpid = pid; // Perhaps we have a real pid from else where?
+       /* Look for our DOS pid */
+       IExec->ObtainSemaphore(&fork_array_sema);
+       for (i = 0; i < MAX_THREADS; i++)
+       {
+               if (pseudo_children[i].ti_pid == pid)
+               {
+                       realpid = (Pid_t)IDOS->GetPID(pseudo_children[i].ti_Process,GPID_PROCESS);
+                       break;
+               }
+       }
+       IExec->ReleaseSemaphore(&fork_array_sema);
+       /* Allow the C library to work out which signals are realy valid */
+       return kill(realpid,signal);
+}
+
 static THREAD_RET_TYPE amigaos4_start_child(void *arg)
 {
 
@@ -183,6 +209,7 @@ static THREAD_RET_TYPE amigaos4_start_child(void *arg)
         nextchild = getnextchild();
 
         pseudo_children[nextchild].ti_pid = pseudo_id;
+        pseudo_children[nextchild].ti_Process = (struct Process *)IExec->FindTask(NULL);
         pseudo_children[nextchild].ti_parent =
             ((struct child_arg *)arg)->ca_parent;
         pseudo_children[nextchild].ti_port =
index 2f6d4b2..82865ba 100644 (file)
@@ -41,9 +41,14 @@ char *mystrdup(const char *s);
 char *convert_path_u2a(const char *filename);
 char *convert_path_a2u(const char *filename);
 
-/* signal.h */
+/* Need Pid_t define to make amigaos.c compile without including config.h */
+#ifndef Pid_t
+#define Pid_t pid_t
+#endif
+
+int amigaos_kill(Pid_t pid, int  signal);
 
-// #define SIGQUIT SIGABRT
+#define kill(a,b) amigaos_kill((a),(b))
 
 void ___makeenviron() __attribute__((constructor));
 void ___freeenviron() __attribute__((destructor));