@@ -117,12 +117,35 @@ get_arg_string_length(char *const argv[]) {
117117
118118    return  (result );
119119}
120+ /* * * * * 
121+     Apparently this doesn't work. You cannot delay a child by using signals in the EntryCode, 
122+     because - as it seems - SystemTags only returns AFTER executing EntryCode. Which, of course, 
123+     means, that the parent is never allowed to send the signal.  
124+  * * * * */ 
125+ // struct EntryData { 
126+ //     uint8 childSignal; 
127+ //     uint8 parentSignal; 
128+ //     struct Task *parent, *child; 
129+ // }; 
130+ // void amiga_entryCode(int32 entry_data); 
131+ // void 
132+ // amiga_entryCode(int32 entry_data) { 
133+ //     struct EntryData *ed = (struct EntryData *)entry_data; 
134+ //     ed->childSignal = AllocSignal(-1); 
135+ //     ed->child = FindTask(0); 
136+ //     DebugPrintF("[child :] Signalling parent...\n"); 
137+ //     Signal(ed->parent, 1 << ed->parentSignal); 
138+ //     DebugPrintF("[child :] Waiting for signal from parent...\n"); 
139+ //     Wait(1 << ed->childSignal); 
140+ //     DebugPrintF("[child :] Done."); 
141+ //     FreeSignal(ed->childSignal); 
142+ // } 
120143int 
121144spawnvpe (
122145    const  char  * file ,
123146    const  char  * * argv ,
124147    char  * * deltaenv ,
125-     const  char  * cwd ,
148+     const  char  * _cwd ,
126149    int  fhin ,
127150    int  fhout ,
128151    int  fherr 
@@ -131,6 +154,7 @@ spawnvpe(
131154    struct  name_translation_info  nti_name ;
132155    const  char  * name  =  file ;
133156    struct  name_translation_info  nti_cwd ;
157+     const  char  * cwd  =  _cwd ;
134158    BPTR  iofh [3 ] =  {BZERO , BZERO , BZERO };
135159    int  closefh [3 ] =  {FALSE, FALSE, FALSE};
136160    BPTR  fh ;
@@ -156,6 +180,7 @@ spawnvpe(
156180    }
157181
158182    D (("name after conversion: [%s]\n" , name ));
183+     // printf("[spawnvpe :] name after conversion [%s]\n", name); 
159184
160185#if  0 
161186    seglist  =  LoadSeg (name );
@@ -169,6 +194,20 @@ spawnvpe(
169194        UnLock (fileLock );
170195    }
171196
197+     // printf("[spawnvpe :] cwd before conversion: [%s]\n", cwd); 
198+ 
199+     if (cwd ) {
200+         error  =  __translate_unix_to_amiga_path_name (& cwd , & nti_cwd );
201+         if  (error ) {
202+             __set_errno (EINVAL );
203+             D (("__translate_unix_to_amiga_path_name failed: %s\n" , strerror (error )));
204+             return  ret ;
205+         }
206+     }
207+ 
208+     D (("cwd after conversion: [%s]\n" , cwd ));
209+     // printf("[spawnvpe :] cwd after conversion [%s]\n", cwd); 
210+ 
172211    BPTR  cwdLock  =  cwd  ? Lock (cwd , SHARED_LOCK ) : 0 ;
173212
174213    parameter_string_len  =  get_arg_string_length ((char  * const  * ) argv );
@@ -178,6 +217,7 @@ spawnvpe(
178217    }
179218
180219    D (("parameter_string_len: [%ld]\n" , parameter_string_len ));
220+     // printf("[spawnvpe :] parameter_string_len: [%ld]\n", parameter_string_len); 
181221
182222    arg_string  =  malloc (parameter_string_len  +  1 );
183223    if  (arg_string  ==  NULL ) {
@@ -206,6 +246,7 @@ spawnvpe(
206246    D (("File to execute: [%s]\n" , finalpath ));
207247
208248    // printf("[spawnvpe :] full command == <%s>\n", finalpath); 
249+     // printf("[spawnvpe :] processName == <%s>\n", processName); 
209250
210251    if  (fhin  >= 0 ) {
211252        err  =  __get_default_file (fhin , & fh );
@@ -252,6 +293,8 @@ spawnvpe(
252293    D (("(*)Calling SystemTags.\n" ));
253294
254295    // struct EntryData ed; 
296+     // ed.parent = FindTask(0); 
297+     // ed.parentSignal = AllocSignal(-1); 
255298
256299    struct  Task  * _me  =  FindTask (0 );
257300#if  0 
@@ -296,6 +339,8 @@ spawnvpe(
296339  );
297340  if  (p ) ret  =  0 ;
298341#else 
342+     // printf("(*)Calling SystemTags.\n"); 
343+ 
299344    ret  =  SystemTags (finalpath ,
300345                     NP_NotifyOnDeathSigTask , _me ,
301346                     SYS_Input , iofh [0 ],
@@ -309,12 +354,14 @@ spawnvpe(
309354                     NP_Name , strdup (processName ),
310355
311356                     NP_EntryCode ,  spawnedProcessEnter ,
357+                      NP_EntryData , getgid (),
358+                     //  NP_EntryCode,  amiga_entryCode, 
359+                     //  NP_EntryData,  &ed, 
312360                     NP_ExitCode ,   spawnedProcessExit ,
313361
314362                     TAG_DONE );
315- #endif 
316363
317-      D (( "SystemTags completed. return value: [%ld]\n" ,  ret )); 
364+ #endif 
318365
319366    if  (ret  !=  0 ) {
320367        __set_errno (__translate_io_error_to_errno (IoErr ()));
@@ -329,8 +376,34 @@ spawnvpe(
329376        /* 
330377         * If mode is set as P_NOWAIT we can retrieve process id calling IoErr() 
331378         * just after SystemTags. In this case spawnv will return pid 
379+          * IoErr() must be called IMMEDIATELY after SystemTags() == no other DOS calls inbetween 
332380         */ 
333-         ret  =  IoErr ();
381+ 
382+         // DebugPrintF("[main :] Child created with success.\n"); 
383+ 
384+         pid_t  pid  =  IoErr ();
385+         // gid_t groupId = getgid(); 
386+         // uint32 ppid = ((struct Process *) FindTask(NULL))->pr_ProcessID; 
387+ 
388+         // if (insertSpawnedChildren(pid, ppid, groupId)) { 
389+         //     __CLIB4->__children++; 
390+         //     D(("Children with pid %ld and gid %ld inserted into list\n", pid, groupId)); 
391+         // } 
392+         // else { 
393+         //     D(("Cannot insert children with pid %ld and gid %ld into list\n", pid, groupId)); 
394+         // } 
395+ 
396+         // DebugPrintF("[parent :] Waiting for signal from child...\n"); 
397+         // Wait(1 << ed.parentSignal); 
398+         // DebugPrintF("[parent :] Signalling child...\n"); 
399+         // Signal(ed.child, 1 << ed.childSignal); 
400+         // DebugPrintF("[parent :] Done.\n"); 
401+         // FreeSignal(ed.parentSignal); 
402+ 
403+         ret  =  pid ;
334404    }
405+     // D(("SystemTags completed. return value: [%ld]\n", ret)); 
406+     // printf("SystemTags completed. return value: [%ld]\n", ret); 
407+ 
335408    return  ret ;
336409}
0 commit comments