2 #include <servers/bootstrap.h>
14 #include <launch_priv.h>
17 main(int argc
, const char *const *argv
)
19 struct timeval tvs
, tve
, tvd
;
20 mach_port_t mpo
= MACH_PORT_NULL
;
24 struct spawn_via_launchd_attr attrs
;
25 memset(&attrs
, 0, sizeof(attrs
));
26 attrs
.spawn_flags
= SPAWN_VIA_LAUNCHD_STOPPED
; // | SPAWN_VIA_LAUNCHD_FORCE_PPC;
27 attrs
.spawn_observer_port
= &mpo
;
29 const char *const env
[] = { "FOO=bar", "ROCK=roll", NULL
};
30 attrs
.spawn_path
= "/bin/booger";
31 attrs
.spawn_chdir
= "/Users/me";
32 attrs
.spawn_env
= env
;
35 gettimeofday(&tvs
, NULL
);
36 p
= spawn_via_launchd("com.example.booger", argv
+ 1, &attrs
);
39 fprintf(stderr
, "spawn_via_launchd(): %s\n", strerror(errno
));
44 gettimeofday(&tve
, NULL
);
45 timersub(&tve
, &tvs
, &tvd
);
46 fprintf(stdout
, "p == %d mpo = 0x%x in %ld usec\n", p
, mpo
, tvd
.tv_sec
* 1000000 + tvd
.tv_usec
);
48 assert(mpm_wait(mpo
, &wstatus
) == 0);
50 fprintf(stdout
, "wstatus == %d\n", wstatus
);