#include "db_config.h"
#include "db_int.h"
#include <sys/wait.h>
#ifdef DB_WIN32
#define MUTEX_THREAD_TEST 1
extern int getopt(int, char * const *, const char *);
typedef HANDLE os_pid_t;
typedef HANDLE os_thread_t;
#define os_thread_create(thrp, attr, func, arg) \
(((*(thrp) = CreateThread(NULL, 0, \
(LPTHREAD_START_ROUTINE)(func), (arg), 0, NULL)) == NULL) ? -1 : 0)
#define os_thread_join(thr, statusp) \
((WaitForSingleObject((thr), INFINITE) == WAIT_OBJECT_0) && \
GetExitCodeThread((thr), (LPDWORD)(statusp)) ? 0 : -1)
#define os_thread_self() GetCurrentThreadId()
#else
typedef pid_t os_pid_t;
#if !defined(HAVE_MUTEX_FCNTL) && defined(HAVE_PTHREAD_YIELD)
#define MUTEX_THREAD_TEST 1
#include <pthread.h>
typedef pthread_t os_thread_t;
#define os_thread_create(thrp, attr, func, arg) \
pthread_create((thrp), (attr), (func), (arg))
#define os_thread_join(thr, statusp) pthread_join((thr), (statusp))
#define os_thread_self() pthread_self()
#endif
#endif
#define OS_BAD_PID ((os_pid_t)-1)
#define TESTDIR "TESTDIR"
#define MT_FILE "TESTDIR/mutex.file"
#define MT_FILE_QUIT "TESTDIR/mutex.file.quit"
typedef struct {
db_mutex_t mutex;
u_long id;
u_int wakeme;
} TM;
DB_ENV *dbenv;
size_t len;
u_int8_t *gm_addr;
u_int8_t *lm_addr;
u_int8_t *tm_addr;
#ifdef MUTEX_THREAD_TEST
os_thread_t *kidsp;
os_thread_t wakep;
#endif
#ifndef HAVE_MMAP
u_int nprocs = 1;
u_int nthreads = 20;
#elif MUTEX_THREAD_TEST
u_int nprocs = 5;
u_int nthreads = 4;
#else
u_int nprocs = 20;
u_int nthreads = 1;
#endif
u_int maxlocks = 20;
u_int nlocks = 10000;
int verbose;
const char *progname;
void data_off(u_int8_t *, DB_FH *);
void data_on(u_int8_t **, u_int8_t **, u_int8_t **, DB_FH **, int);
int locker_start(u_long);
int locker_wait(void);
os_pid_t os_spawn(const char *, char *const[]);
int os_wait(os_pid_t *, u_int);
void *run_lthread(void *);
void *run_wthread(void *);
os_pid_t spawn_proc(u_long, char *, char *);
void tm_env_close(void);
int tm_env_init(void);
void tm_mutex_destroy(void);
void tm_mutex_init(void);
void tm_mutex_stats(void);
int usage(void);
int wakeup_start(u_long);
int wakeup_wait(void);
int
main(argc, argv)
int argc;
char *argv[];
{
enum {LOCKER, WAKEUP, PARENT} rtype;
extern int optind;
extern char *optarg;
os_pid_t wakeup_pid, *pids;
u_long id;
u_int i;
DB_FH *fhp, *map_fhp;
int ch, err;
char *p, *tmpath, cmd[1024];
if ((progname = __db_rpath(argv[0])) == NULL)
progname = argv[0];
else
++progname;
rtype = PARENT;
id = 0;
tmpath = argv[0];
while ((ch = getopt(argc, argv, "l:n:p:T:t:v")) != EOF)
switch (ch) {
case 'l':
maxlocks = (u_int)atoi(optarg);
break;
case 'n':
nlocks = (u_int)atoi(optarg);
break;
case 'p':
nprocs = (u_int)atoi(optarg);
break;
case 't':
if ((nthreads = (u_int)atoi(optarg)) == 0)
nthreads = 1;
#if !defined(MUTEX_THREAD_TEST)
if (nthreads != 1) {
fprintf(stderr,
"%s: thread support not available or not compiled for this platform.\n",
progname);
return (EXIT_FAILURE);
}
#endif
break;
case 'T':
if (!memcmp(optarg, "locker", sizeof("locker") - 1))
rtype = LOCKER;
else if (
!memcmp(optarg, "wakeup", sizeof("wakeup") - 1))
rtype = WAKEUP;
else
return (usage());
if ((p = strchr(optarg, '=')) == NULL)
return (usage());
id = (u_long)atoi(p + 1);
break;
case 'v':
verbose = 1;
break;
case '?':
default:
return (usage());
}
argc -= optind;
argv += optind;
if (nprocs == 1 && nthreads == 1) {
fprintf(stderr,
"%s: running in a single process requires multiple threads\n",
progname);
return (EXIT_FAILURE);
}
len = sizeof(TM) * (1 + nthreads * nprocs + maxlocks);
if (rtype == LOCKER || rtype == WAKEUP) {
__os_sleep(dbenv, 3, 0);
srand((u_int)time(NULL) % (u_int)getpid());
if (tm_env_init() != 0)
exit(EXIT_FAILURE);
data_on(&gm_addr, &tm_addr, &lm_addr, &map_fhp, 0);
if (verbose)
printf(
"Backing file: global (%#lx), threads (%#lx), locks (%#lx)\n",
(u_long)gm_addr, (u_long)tm_addr, (u_long)lm_addr);
if ((rtype == LOCKER ?
locker_start(id) : wakeup_start(id)) != 0)
exit(EXIT_FAILURE);
if ((rtype == LOCKER ? locker_wait() : wakeup_wait()) != 0)
exit(EXIT_FAILURE);
data_off(gm_addr, map_fhp);
tm_env_close();
exit(EXIT_SUCCESS);
}
snprintf(cmd, sizeof(cmd), "rm -rf %s", TESTDIR);
(void)system(cmd);
snprintf(cmd, sizeof(cmd), "mkdir %s", TESTDIR);
(void)system(cmd);
printf(
"%s: %u processes, %u threads/process, %u lock requests from %u locks\n",
progname, nprocs, nthreads, nlocks, maxlocks);
printf("%s: backing data %lu bytes\n", progname, (u_long)len);
if (tm_env_init() != 0)
exit(EXIT_FAILURE);
data_on(&gm_addr, &tm_addr, &lm_addr, &map_fhp, 1);
if (verbose)
printf(
"backing data: global (%#lx), threads (%#lx), locks (%#lx)\n",
(u_long)gm_addr, (u_long)tm_addr, (u_long)lm_addr);
tm_mutex_init();
if (nprocs > 1) {
if ((pids = calloc(nprocs, sizeof(os_pid_t))) == NULL) {
fprintf(stderr, "%s: %s\n", progname, strerror(errno));
goto fail;
}
for (i = 0; i < nprocs; ++i) {
if ((pids[i] =
spawn_proc(id, tmpath, "locker")) == OS_BAD_PID) {
fprintf(stderr,
"%s: failed to spawn a locker\n", progname);
goto fail;
}
id += nthreads;
}
if ((wakeup_pid =
spawn_proc(id, tmpath, "wakeup")) == OS_BAD_PID) {
fprintf(stderr,
"%s: failed to spawn waker\n", progname);
goto fail;
}
++id;
if ((err = os_wait(pids, nprocs)) != 0) {
fprintf(stderr, "%s: locker wait failed with %d\n",
progname, err);
goto fail;
}
if ((err = __os_open(
dbenv, MT_FILE_QUIT, 0, DB_OSO_CREATE, 0664, &fhp)) != 0) {
fprintf(stderr,
"%s: open %s\n", progname, db_strerror(err));
goto fail;
}
(void)__os_closehandle(dbenv, fhp);
if ((err = os_wait(&wakeup_pid, 1)) != 0) {
fprintf(stderr, "%s: %lu: exited %d\n",
progname, (u_long)wakeup_pid, err);
goto fail;
}
} else {
if (locker_start(0) != 0)
goto fail;
if (wakeup_start(nthreads) != 0)
goto fail;
if (locker_wait() != 0)
goto fail;
if ((err = __os_open(
dbenv, MT_FILE_QUIT, 0, DB_OSO_CREATE, 0664, &fhp)) != 0) {
fprintf(stderr,
"%s: open %s\n", progname, db_strerror(err));
goto fail;
}
(void)__os_closehandle(dbenv, fhp);
if (wakeup_wait() != 0)
goto fail;
}
tm_mutex_stats();
tm_mutex_destroy();
data_off(gm_addr, map_fhp);
tm_env_close();
printf("%s: test succeeded\n", progname);
return (EXIT_SUCCESS);
fail: printf("%s: FAILED!\n", progname);
return (EXIT_FAILURE);
}
int
locker_start(id)
u_long id;
{
#if defined(MUTEX_THREAD_TEST)
u_int i;
int err;
if ((kidsp =
(os_thread_t *)calloc(sizeof(os_thread_t), nthreads)) == NULL) {
fprintf(stderr, "%s: %s\n", progname, strerror(errno));
return (1);
}
for (i = 0; i < nthreads; i++)
if ((err = os_thread_create(
&kidsp[i], NULL, run_lthread, (void *)(id + i))) != 0) {
fprintf(stderr, "%s: failed spawning thread: %s\n",
progname, db_strerror(err));
return (1);
}
return (0);
#else
return (run_lthread((void *)id) == NULL ? 0 : 1);
#endif
}
int
locker_wait()
{
#if defined(MUTEX_THREAD_TEST)
u_int i;
void *retp;
for (i = 0; i < nthreads; i++) {
(void)os_thread_join(kidsp[i], &retp);
if (retp != NULL) {
fprintf(stderr,
"%s: thread exited with error\n", progname);
return (1);
}
}
free(kidsp);
#endif
return (0);
}
void *
run_lthread(arg)
void *arg;
{
TM *gp, *mp, *tp;
u_long id, tid;
u_int lock, nl;
int err, i;
id = (uintptr_t)arg;
#if defined(MUTEX_THREAD_TEST)
tid = (u_long)os_thread_self();
#else
tid = 0;
#endif
printf("Locker: ID %03lu (PID: %lu; TID: %lx)\n",
id, (u_long)getpid(), tid);
gp = (TM *)gm_addr;
tp = (TM *)(tm_addr + id * sizeof(TM));
for (nl = nlocks; nl > 0;) {
lock = (u_int)rand() % maxlocks;
mp = (TM *)(lm_addr + lock * sizeof(TM));
if (verbose)
printf("%03lu: lock %d (mtx: %lu)\n",
id, lock, (u_long)mp->mutex);
if ((err = dbenv->mutex_lock(dbenv, mp->mutex)) != 0) {
fprintf(stderr, "%s: %03lu: never got lock %d: %s\n",
progname, id, lock, db_strerror(err));
return ((void *)1);
}
if (mp->id != 0) {
fprintf(stderr,
"%s: RACE! (%03lu granted lock %d held by %03lu)\n",
progname, id, lock, mp->id);
return ((void *)1);
}
mp->id = id;
for (i = 0; i < 3; ++i) {
__os_sleep(dbenv, 0, (u_long)rand() % 3);
if (mp->id != id) {
fprintf(stderr,
"%s: RACE! (%03lu stole lock %d from %03lu)\n",
progname, mp->id, lock, id);
return ((void *)1);
}
}
if ((err = dbenv->mutex_lock(dbenv, gp->mutex)) != 0) {
fprintf(stderr, "%s: %03lu: global lock: %s\n",
progname, id, db_strerror(err));
return ((void *)1);
}
if (tp->id != 0 && tp->id != id) {
fprintf(stderr,
"%s: %03lu: per-thread mutex isn't mine, owned by %03lu\n",
progname, id, tp->id);
return ((void *)1);
}
tp->id = id;
if (verbose)
printf("%03lu: self-blocking (mtx: %lu)\n",
id, (u_long)tp->mutex);
if (tp->wakeme) {
fprintf(stderr,
"%s: %03lu: wakeup flag incorrectly set\n",
progname, id);
return ((void *)1);
}
tp->wakeme = 1;
if ((err = dbenv->mutex_unlock(dbenv, gp->mutex)) != 0) {
fprintf(stderr,
"%s: %03lu: global unlock: %s\n",
progname, id, db_strerror(err));
return ((void *)1);
}
if ((err = dbenv->mutex_lock(dbenv, tp->mutex)) != 0) {
fprintf(stderr, "%s: %03lu: per-thread lock: %s\n",
progname, id, db_strerror(err));
return ((void *)1);
}
if (tp->wakeme) {
fprintf(stderr, "%s: %03lu: wakeup flag not cleared\n",
progname, id);
return ((void *)1);
}
if (verbose)
printf("%03lu: release %d (mtx: %lu)\n",
id, lock, (u_long)mp->mutex);
mp->id = 0;
if ((err = dbenv->mutex_unlock(dbenv, mp->mutex)) != 0) {
fprintf(stderr,
"%s: %03lu: lock release: %s\n",
progname, id, db_strerror(err));
return ((void *)1);
}
if (--nl % 100 == 0)
printf("%03lu: %d\n", id, nl);
}
return (NULL);
}
int
wakeup_start(id)
u_long id;
{
#if defined(MUTEX_THREAD_TEST)
int err;
if ((err = os_thread_create(
&wakep, NULL, run_wthread, (void *)id)) != 0) {
fprintf(stderr, "%s: failed spawning wakeup thread: %s\n",
progname, db_strerror(err));
return (1);
}
return (0);
#else
return (run_wthread((void *)id) == NULL ? 0 : 1);
#endif
}
int
wakeup_wait()
{
#if defined(MUTEX_THREAD_TEST)
void *retp;
(void)os_thread_join(wakep, &retp);
if (retp != NULL) {
fprintf(stderr,
"%s: wakeup thread exited with error\n", progname);
return (1);
}
#endif
return (0);
}
void *
run_wthread(arg)
void *arg;
{
TM *gp, *tp;
u_long id, tid;
u_int check_id;
int err;
id = (uintptr_t)arg;
#if defined(MUTEX_THREAD_TEST)
tid = (u_long)os_thread_self();
#else
tid = 0;
#endif
printf("Wakeup: ID %03lu (PID: %lu; TID: %lx)\n",
id, (u_long)getpid(), tid);
gp = (TM *)gm_addr;
for (check_id = 0;; ++check_id) {
if (__os_exists(dbenv, MT_FILE_QUIT, NULL) == 0)
break;
if (check_id == nthreads * nprocs)
check_id = 0;
tp = (TM *)(tm_addr + check_id * sizeof(TM));
if (!tp->wakeme)
continue;
if (verbose) {
printf("%03lu: wakeup thread %03lu (mtx: %lu)\n",
id, tp->id, (u_long)tp->mutex);
(void)fflush(stdout);
}
if ((err = dbenv->mutex_lock(dbenv, gp->mutex)) != 0) {
fprintf(stderr, "%s: wakeup: global lock: %s\n",
progname, db_strerror(err));
return ((void *)1);
}
tp->wakeme = 0;
if ((err = dbenv->mutex_unlock(dbenv, tp->mutex)) != 0) {
fprintf(stderr, "%s: wakeup: unlock: %s\n",
progname, db_strerror(err));
return ((void *)1);
}
if ((err = dbenv->mutex_unlock(dbenv, gp->mutex)) != 0) {
fprintf(stderr, "%s: wakeup: global unlock: %s\n",
progname, db_strerror(err));
return ((void *)1);
}
__os_sleep(dbenv, 0, (u_long)rand() % 3);
}
return (NULL);
}
int
tm_env_init()
{
u_int32_t flags;
int ret;
char *home;
if ((ret = db_env_create(&dbenv, 0)) != 0) {
fprintf(stderr, "%s: %s\n", progname, db_strerror(ret));
return (1);
}
dbenv->set_errfile(dbenv, stderr);
dbenv->set_errpfx(dbenv, progname);
if ((ret = dbenv->mutex_set_increment(dbenv,
1 + nthreads * nprocs + maxlocks)) != 0) {
dbenv->err(dbenv, ret, "dbenv->mutex_set_increment");
return (1);
}
flags = DB_CREATE;
if (nprocs == 1) {
home = NULL;
flags |= DB_PRIVATE;
} else
home = TESTDIR;
if (nthreads != 1)
flags |= DB_THREAD;
if ((ret = dbenv->open(dbenv, home, flags, 0)) != 0) {
dbenv->err(dbenv, ret, "environment open: %s", home);
return (1);
}
return (0);
}
void
tm_env_close()
{
(void)dbenv->close(dbenv, 0);
}
void
tm_mutex_init()
{
TM *mp;
u_int i;
int err;
if (verbose)
printf("Allocate the global mutex: ");
mp = (TM *)gm_addr;
if ((err = dbenv->mutex_alloc(dbenv, 0, &mp->mutex)) != 0) {
fprintf(stderr, "%s: DB_ENV->mutex_alloc (global): %s\n",
progname, db_strerror(err));
exit(EXIT_FAILURE);
}
if (verbose)
printf("%lu\n", (u_long)mp->mutex);
if (verbose)
printf(
"Allocate %d per-thread, self-blocking mutexes: ",
nthreads * nprocs);
for (i = 0; i < nthreads * nprocs; ++i) {
mp = (TM *)(tm_addr + i * sizeof(TM));
if ((err = dbenv->mutex_alloc(
dbenv, DB_MUTEX_SELF_BLOCK, &mp->mutex)) != 0) {
fprintf(stderr,
"%s: DB_ENV->mutex_alloc (per-thread %d): %s\n",
progname, i, db_strerror(err));
exit(EXIT_FAILURE);
}
if ((err = dbenv->mutex_lock(dbenv, mp->mutex)) != 0) {
fprintf(stderr,
"%s: DB_ENV->mutex_lock (per-thread %d): %s\n",
progname, i, db_strerror(err));
exit(EXIT_FAILURE);
}
if (verbose)
printf("%lu ", (u_long)mp->mutex);
}
if (verbose)
printf("\n");
if (verbose)
printf("Allocate %d per-lock mutexes: ", maxlocks);
for (i = 0; i < maxlocks; ++i) {
mp = (TM *)(lm_addr + i * sizeof(TM));
if ((err = dbenv->mutex_alloc(dbenv, 0, &mp->mutex)) != 0) {
fprintf(stderr,
"%s: DB_ENV->mutex_alloc (per-lock: %d): %s\n",
progname, i, db_strerror(err));
exit(EXIT_FAILURE);
}
if (verbose)
printf("%lu ", (u_long)mp->mutex);
}
if (verbose)
printf("\n");
}
void
tm_mutex_destroy()
{
TM *gp, *mp;
u_int i;
int err;
if (verbose)
printf("Destroy the global mutex.\n");
gp = (TM *)gm_addr;
if ((err = dbenv->mutex_free(dbenv, gp->mutex)) != 0) {
fprintf(stderr, "%s: DB_ENV->mutex_free (global): %s\n",
progname, db_strerror(err));
exit(EXIT_FAILURE);
}
if (verbose)
printf("Destroy the per-thread mutexes.\n");
for (i = 0; i < nthreads * nprocs; ++i) {
mp = (TM *)(tm_addr + i * sizeof(TM));
if ((err = dbenv->mutex_free(dbenv, mp->mutex)) != 0) {
fprintf(stderr,
"%s: DB_ENV->mutex_free (per-thread %d): %s\n",
progname, i, db_strerror(err));
exit(EXIT_FAILURE);
}
}
if (verbose)
printf("Destroy the per-lock mutexes.\n");
for (i = 0; i < maxlocks; ++i) {
mp = (TM *)(lm_addr + i * sizeof(TM));
if ((err = dbenv->mutex_free(dbenv, mp->mutex)) != 0) {
fprintf(stderr,
"%s: DB_ENV->mutex_free (per-lock: %d): %s\n",
progname, i, db_strerror(err));
exit(EXIT_FAILURE);
}
}
}
void
tm_mutex_stats()
{
#ifdef HAVE_STATISTICS
TM *mp;
u_int32_t set_wait, set_nowait;
u_int i;
printf("Per-lock mutex statistics.\n");
for (i = 0; i < maxlocks; ++i) {
mp = (TM *)(lm_addr + i * sizeof(TM));
__mutex_set_wait_info(dbenv, mp->mutex, &set_wait, &set_nowait);
printf("mutex %2d: wait: %lu; no wait %lu\n", i,
(u_long)set_wait, (u_long)set_nowait);
}
#endif
}
void
data_on(gm_addrp, tm_addrp, lm_addrp, fhpp, init)
u_int8_t **gm_addrp, **tm_addrp, **lm_addrp;
DB_FH **fhpp;
int init;
{
DB_FH *fhp;
size_t nwrite;
int err;
void *addr;
fhp = NULL;
if (nprocs == 1) {
if (init) {
if ((err =
__os_calloc(dbenv, (size_t)len, 1, &addr)) != 0)
exit(EXIT_FAILURE);
} else {
fprintf(stderr,
"%s: init should be set for single process call\n",
progname);
exit(EXIT_FAILURE);
}
} else {
if (init) {
if (verbose)
printf("Create the backing file.\n");
if ((err = __os_open(dbenv, MT_FILE, 0,
DB_OSO_CREATE | DB_OSO_TRUNC, 0666, &fhp)) == -1) {
fprintf(stderr, "%s: %s: open: %s\n",
progname, MT_FILE, db_strerror(err));
exit(EXIT_FAILURE);
}
if ((err = __os_seek(dbenv, fhp, 0, 0, len)) != 0 ||
(err =
__os_write(dbenv, fhp, &err, 1, &nwrite)) != 0 ||
nwrite != 1) {
fprintf(stderr, "%s: %s: seek/write: %s\n",
progname, MT_FILE, db_strerror(err));
exit(EXIT_FAILURE);
}
} else
if ((err =
__os_open(dbenv, MT_FILE, 0, 0, 0, &fhp)) != 0)
exit(EXIT_FAILURE);
if ((err =
__os_mapfile(dbenv, MT_FILE, fhp, len, 0, &addr)) != 0)
exit(EXIT_FAILURE);
}
*gm_addrp = (u_int8_t *)addr;
addr = (u_int8_t *)addr + sizeof(TM);
*tm_addrp = (u_int8_t *)addr;
addr = (u_int8_t *)addr + sizeof(TM) * (nthreads * nprocs);
*lm_addrp = (u_int8_t *)addr;
if (fhpp != NULL)
*fhpp = fhp;
}
void
data_off(addr, fhp)
u_int8_t *addr;
DB_FH *fhp;
{
if (nprocs == 1)
__os_free(dbenv, addr);
else {
if (__os_unmapfile(dbenv, addr, len) != 0)
exit(EXIT_FAILURE);
if (__os_closehandle(dbenv, fhp) != 0)
exit(EXIT_FAILURE);
}
}
int
usage()
{
fprintf(stderr, "usage: %s %s\n\t%s\n", progname,
"[-v] [-l maxlocks]",
"[-n locks] [-p procs] [-T locker=ID|wakeup=ID] [-t threads]");
return (EXIT_FAILURE);
}
int
os_wait(procs, n)
os_pid_t *procs;
u_int n;
{
u_int i;
int status;
#if defined(DB_WIN32)
DWORD ret;
#endif
status = 0;
#if defined(DB_WIN32)
do {
ret = WaitForMultipleObjects(n, procs, FALSE, INFINITE);
i = ret - WAIT_OBJECT_0;
if (i < 0 || i >= n)
return (__os_posix_err(__os_get_syserr()));
if ((GetExitCodeProcess(procs[i], &ret) == 0) || (ret != 0))
return (ret);
while (++i < n)
procs[i - 1] = procs[i];
} while (--n);
#elif !defined(HAVE_VXWORKS)
do {
if (wait(&status) == -1)
return (__os_posix_err(__os_get_syserr()));
if (WIFEXITED(status) == 0 || WEXITSTATUS(status) != 0) {
for (i = 0; i < n; i++)
(void)kill(procs[i], SIGKILL);
return (WEXITSTATUS(status));
}
} while (--n);
#endif
return (0);
}
os_pid_t
spawn_proc(id, tmpath, typearg)
u_long id;
char *tmpath, *typearg;
{
char lbuf[16], nbuf[16], pbuf[16], tbuf[16], Tbuf[256];
char *const vbuf = verbose ? "-v" : NULL;
char *args[] = { NULL ,
"-l", NULL , "-n", NULL ,
"-p", NULL , "-t", NULL ,
"-T", NULL , NULL ,
NULL
};
args[0] = tmpath;
snprintf(lbuf, sizeof(lbuf), "%d", maxlocks);
args[2] = lbuf;
snprintf(nbuf, sizeof(nbuf), "%d", nlocks);
args[4] = nbuf;
snprintf(pbuf, sizeof(pbuf), "%d", nprocs);
args[6] = pbuf;
snprintf(tbuf, sizeof(tbuf), "%d", nthreads);
args[8] = tbuf;
snprintf(Tbuf, sizeof(Tbuf), "%s=%lu", typearg, id);
args[10] = Tbuf;
args[11] = vbuf;
return (os_spawn(tmpath, args));
}
os_pid_t
os_spawn(path, argv)
const char *path;
char *const argv[];
{
os_pid_t pid;
int status;
COMPQUIET(pid, 0);
COMPQUIET(status, 0);
#ifdef HAVE_VXWORKS
fprintf(stderr, "%s: os_spawn not supported for VxWorks.\n", progname);
return (OS_BAD_PID);
#elif defined(HAVE_QNX)
return (spawnv(P_NOWAIT, path, argv));
#elif defined(DB_WIN32)
return (os_pid_t)(_spawnv(P_NOWAIT, path, argv));
#else
if ((pid = fork()) != 0) {
if (pid == -1)
return (OS_BAD_PID);
return (pid);
} else {
(void)execv(path, argv);
exit(EXIT_FAILURE);
}
#endif
}