Add an envp argument to proc_create().
This is needed to support dtrace's -x setenv option. MFC after: 2 weeks
This commit is contained in:
parent
4fbebc7472
commit
5577b8a709
@ -38,6 +38,9 @@
|
||||
# xargs -n1 | sort | uniq -d;
|
||||
# done
|
||||
|
||||
# 20171203: libproc version bump
|
||||
OLD_LIBS+=usr/lib/libproc.so.4
|
||||
OLD_LIBS+=usr/lib32/libproc.so.4
|
||||
# 20171203: new clang import which bumps version from 5.0.0 to 5.0.1.
|
||||
OLD_FILES+=usr/lib/clang/5.0.0/include/sanitizer/allocator_interface.h
|
||||
OLD_FILES+=usr/lib/clang/5.0.0/include/sanitizer/asan_interface.h
|
||||
|
@ -967,7 +967,7 @@ dt_proc_create(dtrace_hdl_t *dtp, const char *file, char *const *argv,
|
||||
#ifdef illumos
|
||||
if ((dpr->dpr_proc = Pcreate(file, argv, &err, NULL, 0)) == NULL) {
|
||||
#else
|
||||
if ((err = proc_create(file, argv, pcf, child_arg,
|
||||
if ((err = proc_create(file, argv, NULL, pcf, child_arg,
|
||||
&dpr->dpr_proc)) != 0) {
|
||||
#endif
|
||||
return (dt_proc_error(dtp, dpr,
|
||||
|
@ -37,7 +37,7 @@ CFLAGS+= -I${SRCTOP}/cddl/contrib/opensolaris/lib/libctf/common \
|
||||
CFLAGS+= -DNO_CTF
|
||||
.endif
|
||||
|
||||
SHLIB_MAJOR= 4
|
||||
SHLIB_MAJOR= 5
|
||||
|
||||
MAN=
|
||||
|
||||
|
@ -142,8 +142,8 @@ int proc_addr2sym(struct proc_handle *, uintptr_t, char *, size_t, GElf_Sym *);
|
||||
int proc_attach(pid_t pid, int flags, struct proc_handle **pphdl);
|
||||
int proc_continue(struct proc_handle *);
|
||||
int proc_clearflags(struct proc_handle *, int);
|
||||
int proc_create(const char *, char * const *, proc_child_func *, void *,
|
||||
struct proc_handle **);
|
||||
int proc_create(const char *, char * const *, char * const *,
|
||||
proc_child_func *, void *, struct proc_handle **);
|
||||
int proc_detach(struct proc_handle *, int);
|
||||
int proc_getflags(struct proc_handle *);
|
||||
int proc_name2sym(struct proc_handle *, const char *, const char *,
|
||||
|
@ -176,9 +176,10 @@ proc_attach(pid_t pid, int flags, struct proc_handle **pphdl)
|
||||
}
|
||||
|
||||
int
|
||||
proc_create(const char *file, char * const *argv, proc_child_func *pcf,
|
||||
void *child_arg, struct proc_handle **pphdl)
|
||||
proc_create(const char *file, char * const *argv, char * const *envp,
|
||||
proc_child_func *pcf, void *child_arg, struct proc_handle **pphdl)
|
||||
{
|
||||
extern char * const *environ;
|
||||
struct proc_handle *phdl;
|
||||
int error, status;
|
||||
pid_t pid;
|
||||
@ -189,8 +190,7 @@ proc_create(const char *file, char * const *argv, proc_child_func *pcf,
|
||||
error = 0;
|
||||
phdl = NULL;
|
||||
|
||||
/* Fork a new process. */
|
||||
if ((pid = vfork()) == -1)
|
||||
if ((pid = fork()) == -1)
|
||||
error = errno;
|
||||
else if (pid == 0) {
|
||||
/* The child expects to be traced. */
|
||||
@ -200,18 +200,14 @@ proc_create(const char *file, char * const *argv, proc_child_func *pcf,
|
||||
if (pcf != NULL)
|
||||
(*pcf)(child_arg);
|
||||
|
||||
/* Execute the specified file: */
|
||||
if (envp != NULL)
|
||||
environ = envp;
|
||||
|
||||
execvp(file, argv);
|
||||
|
||||
/* Couldn't execute the file. */
|
||||
_exit(2);
|
||||
/* NOTREACHED */
|
||||
} else {
|
||||
/* The parent owns the process handle. */
|
||||
error = proc_init(pid, 0, PS_IDLE, &phdl);
|
||||
if (error != 0)
|
||||
goto bad;
|
||||
|
||||
/* Wait for the child process to stop. */
|
||||
if (waitpid(pid, &status, WUNTRACED) == -1) {
|
||||
error = errno;
|
||||
@ -221,10 +217,14 @@ proc_create(const char *file, char * const *argv, proc_child_func *pcf,
|
||||
|
||||
/* Check for an unexpected status. */
|
||||
if (!WIFSTOPPED(status)) {
|
||||
error = EBUSY;
|
||||
error = ENOENT;
|
||||
DPRINTFX("ERROR: child process %d status 0x%x", pid, status);
|
||||
goto bad;
|
||||
}
|
||||
|
||||
/* The parent owns the process handle. */
|
||||
error = proc_init(pid, 0, PS_IDLE, &phdl);
|
||||
if (error == 0)
|
||||
phdl->status = PS_STOP;
|
||||
|
||||
bad:
|
||||
|
@ -65,7 +65,7 @@ start_prog(const struct atf_tc *tc, bool sig)
|
||||
argv[1] = NULL;
|
||||
}
|
||||
|
||||
error = proc_create(argv[0], argv, NULL, NULL, &phdl);
|
||||
error = proc_create(argv[0], argv, NULL, NULL, NULL, &phdl);
|
||||
ATF_REQUIRE_EQ_MSG(error, 0, "failed to run '%s'", target_prog_file);
|
||||
ATF_REQUIRE(phdl != NULL);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user