21 |
#include <hurd/ports.h> |
#include <hurd/ports.h> |
22 |
#include <idvec.h> |
#include <idvec.h> |
23 |
#include <unistd.h> |
#include <unistd.h> |
24 |
|
#include <fcntl.h> |
25 |
#include <sys/wait.h> |
#include <sys/wait.h> |
|
#include <spawn.h> |
|
26 |
#include <assert.h> |
#include <assert.h> |
27 |
#include <argp.h> |
#include <argp.h> |
28 |
#include <error.h> |
#include <error.h> |
385 |
error (2, errno, "Cannot switch to fake auth handle"); |
error (2, errno, "Cannot switch to fake auth handle"); |
386 |
mach_port_deallocate (mach_task_self (), authport); |
mach_port_deallocate (mach_task_self (), authport); |
387 |
|
|
388 |
if (posix_spawnp (&child, argv[argi], NULL, NULL, &argv[argi], environ)) |
/* We cannot use fork because it doesn't do the right thing with our send |
389 |
error (3, errno, "cannot run %s", argv[1]); |
rights that point to our own receive rights, i.e. the new auth port. |
390 |
|
Since posix_spawn might be implemented with fork (prior to glibc 2.3), |
391 |
|
we cannot use that simple interface either. We use _hurd_exec |
392 |
|
directly to effect what posix_spawn does in the simple case. */ |
393 |
|
{ |
394 |
|
task_t newtask; |
395 |
|
file_t execfile = file_name_lookup (argv[argi], O_EXEC, 0); |
396 |
|
if (execfile == MACH_PORT_NULL) |
397 |
|
error (3, errno, "%s", argv[argi]); |
398 |
|
|
399 |
|
err = task_create (mach_task_self (), |
400 |
|
#ifdef KERN_INVALID_LEDGER |
401 |
|
NULL, 0, /* OSF Mach */ |
402 |
|
#endif |
403 |
|
0, &newtask); |
404 |
|
if (err) |
405 |
|
error (3, err, "cannot create child task"); |
406 |
|
child = task2pid (newtask); |
407 |
|
if (child < 0) |
408 |
|
error (3, errno, "task2pid"); |
409 |
|
err = _hurd_exec (newtask, execfile, &argv[argi], environ); |
410 |
|
mach_port_deallocate (mach_task_self (), newtask); |
411 |
|
mach_port_deallocate (mach_task_self (), execfile); |
412 |
|
if (err) |
413 |
|
error (3, err, "cannot execute %s", argv[argi]); |
414 |
|
} |
415 |
|
|
416 |
if (waitpid (child, &status, 0) != child) |
if (waitpid (child, &status, 0) != child) |
417 |
error (4, errno, "waitpid on %d", child); |
error (4, errno, "waitpid on %d", child); |