~ubuntu-branches/ubuntu/saucy/nspr/saucy-updates

« back to all changes in this revision

Viewing changes to mozilla/nsprpub/pr/src/md/unix/uxproces.c

  • Committer: Bazaar Package Importer
  • Author(s): Alexander Sack
  • Date: 2009-08-10 11:34:26 UTC
  • mfrom: (1.1.10 upstream)
  • Revision ID: james.westby@ubuntu.com-20090810113426-3uv4diflrkcbdimm
Tags: 4.8-0ubuntu1
* New upstream release: 4.8 (LP: #387812)
* adjust patches to changed upstreanm codebase
  - update debian/patches/99_configure.patch
* update shlibs symbols to include new API elements
  - update debian/libnspr4-0d.symbols

Show diffs side-by-side

added added

removed removed

Lines of Context:
60
60
#define SA_RESTART 0
61
61
#endif
62
62
 
63
 
#if defined(VMS)
64
 
static PRLock *_pr_vms_fork_lock = NULL;
65
 
#endif
66
 
 
67
63
/*
68
64
 **********************************************************************
69
65
 *
176
172
    char *const *childEnvp;
177
173
    char **newEnvp = NULL;
178
174
    int flags;
179
 
#ifdef VMS
180
 
    char VMScurdir[FILENAME_MAX+1] = { '\0' } ;
181
 
#endif  
182
175
 
183
176
    process = PR_NEW(PRProcess);
184
177
    if (!process) {
219
212
        childEnvp = newEnvp;
220
213
    }
221
214
 
222
 
#ifdef VMS
223
 
/*
224
 
** Since vfork/exec is implemented VERY differently on OpenVMS, we have to
225
 
** handle the setting up of the standard streams very differently. And since
226
 
** none of this code can ever execute in the context of the child, we have
227
 
** to perform the chdir in the parent so the child is born into the correct
228
 
** directory (and then switch the parent back again).
229
 
*/
230
 
{
231
 
    int decc$set_child_standard_streams(int,int,int);
232
 
    int n, fd_stdin=0, fd_stdout=1, fd_stderr=2;
233
 
 
234
 
    /* Set up any standard streams we are given, assuming defaults */
235
 
    if (attr) {
236
 
       if (attr->stdinFd)
237
 
           fd_stdin = attr->stdinFd->secret->md.osfd;
238
 
       if (attr->stdoutFd)
239
 
           fd_stdout = attr->stdoutFd->secret->md.osfd;
240
 
       if (attr->stderrFd)
241
 
           fd_stderr = attr->stderrFd->secret->md.osfd;
242
 
    }
243
 
 
244
 
    /*
245
 
    ** Put a lock around anything that isn't going to be thread-safe.
246
 
    */
247
 
    PR_Lock(_pr_vms_fork_lock);
248
 
 
249
 
    /*
250
 
    ** Prepare the child's streams. We always do this in case a previous fork
251
 
    ** has left the stream assignments in some non-standard way.
252
 
    */
253
 
    n = decc$set_child_standard_streams(fd_stdin,fd_stdout,fd_stderr);
254
 
    if (n == -1) {
255
 
       PR_SetError(PR_BAD_DESCRIPTOR_ERROR, errno);
256
 
       PR_DELETE(process);
257
 
       if (newEnvp) {
258
 
           PR_DELETE(newEnvp);
259
 
       }
260
 
       PR_Unlock(_pr_vms_fork_lock);
261
 
       return NULL;
262
 
    }
263
 
 
264
 
    /* Switch directory if we have to */
265
 
    if (attr) {
266
 
       if (attr->currentDirectory) {
267
 
           if ( (getcwd(VMScurdir,sizeof(VMScurdir)) == NULL) ||
268
 
                (chdir(attr->currentDirectory) < 0) ) {
269
 
               PR_SetError(PR_DIRECTORY_OPEN_ERROR, errno);
270
 
               PR_DELETE(process);
271
 
               if (newEnvp) {
272
 
                   PR_DELETE(newEnvp);
273
 
               }
274
 
               PR_Unlock(_pr_vms_fork_lock);
275
 
               return NULL;
276
 
           }
277
 
       }
278
 
    }
279
 
}
280
 
#endif /* VMS */
281
 
 
282
215
#ifdef AIX
283
216
    process->md.pid = (*pr_wp.forkptr)();
284
 
#elif defined(NTO)
 
217
#elif defined(NTO) || defined(SYMBIAN)
285
218
    /*
286
219
     * fork() & exec() does not work in a multithreaded process.
287
220
     * Use spawn() instead.
312
245
            PR_ASSERT(attr->currentDirectory == NULL);  /* not implemented */
313
246
        }
314
247
 
 
248
#ifdef SYMBIAN
 
249
        /* In Symbian OS, we use posix_spawn instead of fork() and exec() */
 
250
        posix_spawn(&(process->md.pid), path, NULL, NULL, argv, childEnvp);
 
251
#else
315
252
        process->md.pid = spawn(path, 3, fd_map, NULL, argv, childEnvp);
 
253
#endif
316
254
 
317
255
        if (fd_map[0] != 0)
318
256
            close(fd_map[0]);
339
277
         * the parent process's standard I/O data structures.
340
278
         */
341
279
 
342
 
#if !defined(NTO)
343
 
#ifdef VMS
344
 
       /* OpenVMS has already handled all this above */
345
 
#else
 
280
#if !defined(NTO) && !defined(SYMBIAN)
346
281
        if (attr) {
347
282
            /* the osfd's to redirect stdin, stdout, and stderr to */
348
283
            int in_osfd = -1, out_osfd = -1, err_osfd = -1;
396
331
                }
397
332
            }
398
333
        }
399
 
#endif /* !VMS */
400
334
 
401
335
        if (childEnvp) {
402
336
            (void)execve(path, argv, childEnvp);
405
339
            (void)execv(path, argv);
406
340
        }
407
341
        /* Whoops! It returned. That's a bad sign. */
408
 
#ifdef VMS
409
 
       /*
410
 
       ** On OpenVMS we are still in the context of the parent, and so we
411
 
       ** can (and should!) perform normal error handling.
412
 
       */
413
 
       PR_SetError(PR_UNKNOWN_ERROR, errno);
414
 
       PR_DELETE(process);
415
 
       if (newEnvp) {
416
 
           PR_DELETE(newEnvp);
417
 
       }
418
 
       if (VMScurdir[0] != '\0')
419
 
           chdir(VMScurdir);
420
 
       PR_Unlock(_pr_vms_fork_lock);
421
 
       return NULL;
422
 
#else
423
342
        _exit(1);
424
 
#endif /* VMS */
425
343
#endif /* !NTO */
426
344
    }
427
345
 
428
346
    if (newEnvp) {
429
347
        PR_DELETE(newEnvp);
430
348
    }
431
 
#ifdef VMS
432
 
    /* If we switched directories, then remember to switch back */
433
 
    if (VMScurdir[0] != '\0') {
434
 
       chdir(VMScurdir); /* can't do much if it fails */
435
 
    }
436
 
    PR_Unlock(_pr_vms_fork_lock);
437
 
#endif /* VMS */
438
349
 
439
350
#if defined(_PR_NATIVE_THREADS)
440
351
    PR_Lock(pr_wp.ml);
842
753
    pr_wp.ml = PR_NewLock();
843
754
    PR_ASSERT(NULL != pr_wp.ml);
844
755
 
845
 
#if defined(VMS)
846
 
    _pr_vms_fork_lock = PR_NewLock();
847
 
    PR_ASSERT(NULL != _pr_vms_fork_lock);
848
 
#endif
849
 
 
850
756
#if defined(_PR_NATIVE_THREADS)
851
757
    pr_wp.numProcs = 0;
852
758
    pr_wp.cv = PR_NewCondVar(pr_wp.ml);
980
886
    PRErrorCode prerror;
981
887
    PRInt32 oserror;
982
888
 
 
889
#ifdef SYMBIAN
 
890
    /* In Symbian OS, we can not kill other process with Open C */
 
891
    PR_SetError(PR_OPERATION_NOT_SUPPORTED_ERROR, oserror);
 
892
    return PR_FAILURE;
 
893
#else
983
894
    if (kill(process->md.pid, SIGKILL) == 0) {
984
895
        return PR_SUCCESS;
985
896
    }
997
908
    }
998
909
    PR_SetError(prerror, oserror);
999
910
    return PR_FAILURE;
 
911
#endif
1000
912
}  /* _MD_KillUnixProcess */