1135809Sdeischen/*
2135809Sdeischen * Copyright (C) 2004 Daniel Eischen <deischen@freebsd.org>
3135809Sdeischen * All rights reserved.
4135809Sdeischen *
5135809Sdeischen * Redistribution and use in source and binary forms, with or without
6135809Sdeischen * modification, are permitted provided that the following conditions
7135809Sdeischen * are met:
8135809Sdeischen * 1. Redistributions of source code must retain the above copyright
9135809Sdeischen *    notice(s), this list of conditions and the following disclaimer as
10135809Sdeischen *    the first lines of this file unmodified other than the possible
11135809Sdeischen *    addition of one or more copyright notices.
12135809Sdeischen * 2. Redistributions in binary form must reproduce the above copyright
13135809Sdeischen *    notice(s), this list of conditions and the following disclaimer in
14135809Sdeischen *    the documentation and/or other materials provided with the
15135809Sdeischen *    distribution.
16135809Sdeischen *
17135809Sdeischen * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY
18135809Sdeischen * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19135809Sdeischen * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20135809Sdeischen * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE
21135809Sdeischen * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22135809Sdeischen * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23135809Sdeischen * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
24135809Sdeischen * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25135809Sdeischen * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
26135809Sdeischen * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
27135809Sdeischen * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28135809Sdeischen *
29135809Sdeischen * $FreeBSD$
30135809Sdeischen */
31135809Sdeischen
32174112Sdeischen#include "namespace.h"
33135809Sdeischen#include <errno.h>
34135809Sdeischen#include <pthread.h>
35135809Sdeischen#include <unistd.h>
36174112Sdeischen#include "un-namespace.h"
37135809Sdeischen#include "thr_private.h"
38135809Sdeischen
39135809Sdeischen__weak_reference(_execve, execve);
40135809Sdeischen
41135809Sdeischenint
42135809Sdeischen_execve(const char *name, char *const *argv, char *const *envp)
43135809Sdeischen{
44136223Sdavidxu	struct kse_execve_args args;
45136227Sdavidxu	struct pthread *curthread = _get_curthread();
46135809Sdeischen	int ret;
47135809Sdeischen
48136227Sdavidxu	if (curthread->attr.flags & PTHREAD_SCOPE_SYSTEM)
49136223Sdavidxu		ret = __sys_execve(name, argv, envp);
50136223Sdavidxu	else {
51136223Sdavidxu		/*
52136223Sdavidxu		 * When exec'ing, set the kernel signal mask to the thread's
53136223Sdavidxu	 	 * signal mask to satisfy POSIX requirements.
54136223Sdavidxu		 */
55136223Sdavidxu		args.sigmask = curthread->sigmask;
56136223Sdavidxu		args.sigpend = curthread->sigpend;
57136223Sdavidxu		args.path = (char *)name;
58136223Sdavidxu		args.argv = (char **)argv;
59136223Sdavidxu		args.envp = (char **)envp;
60136223Sdavidxu		args.reserved = NULL;
61136223Sdavidxu		ret = kse_thr_interrupt(NULL, KSE_INTR_EXECVE, (long)&args);
62136223Sdavidxu	}
63135809Sdeischen
64135809Sdeischen	return (ret);
65135809Sdeischen}
66