- /* allocation */
- result = malloc((n+1)*sizeof(char*) + s);
- if (result == NULL) {
- errno = ENOMEM;
- return NULL;
- }
- data = (char*)(&result[n + 1]);
- }
-}
-
-static void mksecret(char buffer[9])
-{
- snprintf(buffer, 9, "%08lX", (0xffffffff & random()));
-}
-
-static int mkport()
-{
- static int port_ring = 12345;
- int port = port_ring;
- if (port < 12345 || port > 15432)
- port = 12345;
- port_ring = port + 1;
- return port;
-}
-
-static int launchexec1(struct afm_launch_desc *desc, 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);