/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 1985-2010 AT&T Intellectual Property *
* and is licensed under the *
* Common Public License, Version 1.0 *
* by AT&T Intellectual Property *
* *
* A copy of the License is available at *
* (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
* *
* Information and Software Systems Research *
* AT&T Research *
* Florham Park NJ *
* *
* Glenn Fowler <gsf@research.att.com> *
* David Korn <dgk@research.att.com> *
* Phong Vo <kpv@research.att.com> *
* *
***********************************************************************/
#pragma prototyped
/*
* spawnveg -- spawnve with process group or session control
*
* pgid <0 setsid() [session group leader]
* 0 nothing [retain session and process group]
* 1 setpgid(0,0) [process group leader]
* >1 setpgid(0,pgid) [join process group]
*/
#include <ast.h>
#if _lib_spawnveg
#else
#include <spawn.h>
#include <error.h>
#include <wait.h>
{
int err;
goto nope;
if (pgid)
{
if (pgid <= 1)
pgid = 0;
goto bad;
goto bad;
}
goto bad;
#if _lib_posix_spawn < 2
{
pid = -1;
}
#endif
return pid;
bad:
nope:
return -1;
}
#else
#if _lib_spawn_mode
#include <process.h>
#ifndef P_NOWAIT
#endif
#ifndef P_DETACH
#endif
{
}
#else
#include <spawn.h>
/*
* open-edition/mvs/zos fork+exec+(setpgid)
*/
{
struct inheritance inherit;
if (pgid)
{
}
}
#else
#include <error.h>
#include <wait.h>
#include <sig.h>
#include <ast_vfork.h>
#ifndef ENOSYS
#endif
#if _lib_spawnve && _hdr_process
#include <process.h>
#endif
#endif
#if !_lib_vfork
#endif
/*
* fork+exec+(setsid|setpgid)
*/
{
#if _lib_fork || _lib_vfork
int n;
int m;
#if _real_vfork
volatile int exec_errno;
volatile int* volatile exec_errno_ptr;
#else
int err[2];
#endif
#endif
#if 0
return -1;
#endif
if (!envv)
#if _lib_spawnve
#if _lib_fork || _lib_vfork
if (!pgid)
#endif
#endif
#if _lib_fork || _lib_vfork
n = errno;
#if _real_vfork
exec_errno = 0;
#else
err[0] = -1;
else
{
}
#endif
sigcritical(1);
#if _lib_vfork
#else
#endif
sigcritical(0);
if (pid == -1)
n = errno;
else if (!pid)
{
if (pgid < 0)
setsid();
else if (pgid > 0)
{
if (pgid == 1)
pgid = 0;
setpgid(0, 0);
}
#if _real_vfork
*exec_errno_ptr = errno;
#else
if (err[0] != -1)
{
n = errno;
}
#endif
}
#if _real_vfork
{
n = m;
}
#else
if (err[0] != -1)
{
{
n = m;
}
}
#endif
{
/*
* parent and child are in a race here
*/
if (pgid == 1)
}
errno = n;
return rid;
#else
return -1;
#endif
}
#endif
#endif
#endif
#endif