summaryrefslogtreecommitdiff
path: root/regress/lib
diff options
context:
space:
mode:
authorPhilip Guenthe <guenther@cvs.openbsd.org>2011-11-25 00:31:44 +0000
committerPhilip Guenthe <guenther@cvs.openbsd.org>2011-11-25 00:31:44 +0000
commitc8f9a198a86cd1b622504d6ad93cd1bcd92374c2 (patch)
tree80b3014785de068931eeb3d9829fec96477c733f /regress/lib
parentb4a1a65ab5f84a8906895659d77a143bdbb26f3b (diff)
The execve()-vs-threads test should test not just that the thread library
doesn't blow up but also that (1) a failed execve doesn't kill other threads, and (2) a successful execve does make other threads vanish
Diffstat (limited to 'regress/lib')
-rw-r--r--regress/lib/libpthread/execve/execve.c28
1 files changed, 25 insertions, 3 deletions
diff --git a/regress/lib/libpthread/execve/execve.c b/regress/lib/libpthread/execve/execve.c
index 7e6905c5628..dcdce78b515 100644
--- a/regress/lib/libpthread/execve/execve.c
+++ b/regress/lib/libpthread/execve/execve.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: execve.c,v 1.4 2003/09/18 01:59:58 henning Exp $ */
+/* $OpenBSD: execve.c,v 1.5 2011/11/25 00:31:43 guenther Exp $ */
/*
* Copyright (c) 1993, 1994, 1995, 1996 by Chris Provenzano and contributors,
* proven@mit.edu All rights reserved.
@@ -46,18 +46,32 @@
#include "test.h"
extern char **environ;
+char *bad_argv[] = {
+ "/NO SUCH FILE",
+ NULL
+};
char *new_argv[] = {
- "/bin/echo",
- "This line should appear after the execve",
+ "/bin/sh",
+ "-c",
+ "sleep 3; echo 'This line should appear after the execve'",
NULL
};
char * should_succeed = "This line should be displayed\n";
+void *
+other(void *arg)
+{
+ sleep(2);
+ printf("%s\n", (char *)arg);
+ return NULL;
+}
+
int
main(int argc, char *argv[])
{
int fd;
+ pthread_t t1;
printf("This is the first message\n");
if (isatty(STDOUT_FILENO)) {
@@ -73,10 +87,18 @@ main(int argc, char *argv[])
CHECKn(printf("This output is necessary to set the stdout fd to NONBLOCKING\n"));
+ /* create another thread to make things interesting */
+ CHECKr(pthread_create(&t1, NULL, other, "Should see this too"));
+
/* do a dup2 */
CHECKe(dup2(fd, STDOUT_FILENO));
CHECKe(write(STDOUT_FILENO, should_succeed,
(size_t)strlen(should_succeed)));
+ CHECKn(execve(bad_argv[0], bad_argv, environ));
+ pthread_join(t1, NULL);
+ CHECKr(pthread_create(&t1, NULL, other, "failed!"));
+ sleep(1);
CHECKe(execve(new_argv[0], new_argv, environ));
DIE(errno, "execve %s", new_argv[0]);
}
+