- pid_t children[2],
- struct launchparam *params
-)
-{
- int rc;
- char **args;
-
- /* fork the master child */
- children[0] = fork();
- if (children[0] < 0) {
- ERROR("master fork failed: %m");
- return -1;
- }
- if (children[0]) {
- /********* in the parent process ************/
- return 0;
- }
-
- /********* in the master child ************/
-
- /* avoid set-gid effect */
- setresgid(groupid, groupid, groupid);
-
- /* enter the process group */
- rc = setpgid(0, 0);
- if (rc) {
- ERROR("setpgid failed");
- _exit(1);
- }
-
- /* enter security mode */
- rc = secmgr_prepare_exec(desc->tag);
- if (rc < 0) {
- ERROR("call to secmgr_prepare_exec failed: %m");
- _exit(1);
- }
-
- /* enter the datadirectory */
- rc = mkdir(params->datadir, 0755);
- if (rc && errno != EEXIST) {
- ERROR("creation of datadir %s failed: %m", params->datadir);
- _exit(1);
- }
- rc = chdir(params->datadir);
- if (rc) {
- ERROR("can't enter the datadir %s: %m", params->datadir);
- _exit(1);
- }
-
- args = instantiate_arguments(params->master->args, desc, params, 1).vector;
- if (args == NULL) {
- ERROR("out of memory in master");
- }
- else {
- rc = execve(args[0], args, environ);
- ERROR("failed to exec master %s: %m", args[0]);
- }
- _exit(1);
-}
-
-static int launch_local_2(
- struct afm_launch_desc *desc,
- pid_t children[2],
- struct launchparam *params