Skip to content

Commit ef2467a

Browse files
Andy Broadjhi
Andy Broad
authored andcommitted
amigaos4: better kill() implementation
(the underlying UNIX emulation has changed)
1 parent 1cd70ad commit ef2467a

File tree

3 files changed

+36
-2
lines changed

3 files changed

+36
-2
lines changed

README.amiga

+2
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,8 @@ This will build the default setup that installs under SDK:local/newlib/lib/
181181
=item Add flock() emulation using IDOS->LockRecord thanks to Tony Cook
182182
for the suggestion.
183183

184+
=item Fix issue where kill was using the wrong kind of process ID
185+
184186
=back
185187

186188
=item B<27th November 2013>

amigaos4/amigaio.c

+27
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ struct thread_info
8989
int ti_children;
9090
pthread_t ti_parent;
9191
struct MsgPort *ti_port;
92+
struct Process *ti_Process;
9293
};
9394

9495
static struct thread_info pseudo_children[MAX_THREADS];
@@ -154,6 +155,31 @@ struct child_arg
154155
PerlInterpreter *ca_interp;
155156
};
156157

158+
#undef kill
159+
160+
/* FIXME: Is here's a chance, albeit it small of a clash between our pseudo pid */
161+
/* derived from the pthread API and the dos.library pid that newlib kill uses? */
162+
/* clib2 used the Process address so there was no issue */
163+
164+
int amigaos_kill(Pid_t pid, int signal)
165+
{
166+
int i;
167+
Pid_t realpid = pid; // Perhaps we have a real pid from else where?
168+
/* Look for our DOS pid */
169+
IExec->ObtainSemaphore(&fork_array_sema);
170+
for (i = 0; i < MAX_THREADS; i++)
171+
{
172+
if (pseudo_children[i].ti_pid == pid)
173+
{
174+
realpid = (Pid_t)IDOS->GetPID(pseudo_children[i].ti_Process,GPID_PROCESS);
175+
break;
176+
}
177+
}
178+
IExec->ReleaseSemaphore(&fork_array_sema);
179+
/* Allow the C library to work out which signals are realy valid */
180+
return kill(realpid,signal);
181+
}
182+
157183
static THREAD_RET_TYPE amigaos4_start_child(void *arg)
158184
{
159185

@@ -183,6 +209,7 @@ static THREAD_RET_TYPE amigaos4_start_child(void *arg)
183209
nextchild = getnextchild();
184210

185211
pseudo_children[nextchild].ti_pid = pseudo_id;
212+
pseudo_children[nextchild].ti_Process = (struct Process *)IExec->FindTask(NULL);
186213
pseudo_children[nextchild].ti_parent =
187214
((struct child_arg *)arg)->ca_parent;
188215
pseudo_children[nextchild].ti_port =

amigaos4/amigaos.h

+7-2
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,14 @@ char *mystrdup(const char *s);
4141
char *convert_path_u2a(const char *filename);
4242
char *convert_path_a2u(const char *filename);
4343

44-
/* signal.h */
44+
/* Need Pid_t define to make amigaos.c compile without including config.h */
45+
#ifndef Pid_t
46+
#define Pid_t pid_t
47+
#endif
48+
49+
int amigaos_kill(Pid_t pid, int signal);
4550

46-
// #define SIGQUIT SIGABRT
51+
#define kill(a,b) amigaos_kill((a),(b))
4752

4853
void ___makeenviron() __attribute__((constructor));
4954
void ___freeenviron() __attribute__((destructor));

0 commit comments

Comments
 (0)