summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <dvlasenk@redhat.com>2009-02-25 14:24:02 +0000
committerDenys Vlasenko <dvlasenk@redhat.com>2009-02-25 14:24:02 +0000
commit8ed57276426392f961d557ea0bf54d9ba6ac4a5f (patch)
treec1acf8718735dbc42a420f5fb41eca364f86eff1
parent4dedd561d61562fe66f1a0b673ad33ac6a1e3c71 (diff)
downloadstrace-8ed57276426392f961d557ea0bf54d9ba6ac4a5f.tar.gz
strace-8ed57276426392f961d557ea0bf54d9ba6ac4a5f.tar.bz2
strace-8ed57276426392f961d557ea0bf54d9ba6ac4a5f.tar.xz
By Hans-Christian Egtvedt (hans-christian.egtvedt AT atmel.com):
strace.c: suppress "warning: unused static" message by adding #ifdef's around a variable .gitignore: trivial test/*.c: cleanup (suppress warnings, much better style).
-rw-r--r--.gitignore2
-rw-r--r--strace.c3
-rw-r--r--test/childthread.c77
-rw-r--r--test/clone.c13
-rw-r--r--test/fork.c10
-rw-r--r--test/leaderkill.c76
-rw-r--r--test/many_looping_threads.c4
-rw-r--r--test/procpollable.c11
-rw-r--r--test/sfd.c11
-rw-r--r--test/sig.c16
-rw-r--r--test/sigkill_rain.c30
-rw-r--r--test/skodic.c39
-rw-r--r--test/vfork.c10
13 files changed, 178 insertions, 124 deletions
diff --git a/.gitignore b/.gitignore
index 7977f44..9616077 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,6 +1,8 @@
+*~
*.o
.deps
.libs
+.*.swp
Makefile
Makefile.in
diff --git a/strace.c b/strace.c
index cded401..1acecf2 100644
--- a/strace.c
+++ b/strace.c
@@ -108,8 +108,9 @@ int not_failing_only = 0;
static int exit_code = 0;
static int strace_child = 0;
static int ptrace_stop_sig = SIGTRAP;
+#if defined LINUX && (defined PTRACE_SETOPTIONS || defined PT_SETOPTIONS)
static bool ptrace_opts_set;
-
+#endif
static char *username = NULL;
uid_t run_uid;
gid_t run_gid;
diff --git a/test/childthread.c b/test/childthread.c
index bd0174b..e89fb14 100644
--- a/test/childthread.c
+++ b/test/childthread.c
@@ -13,47 +13,48 @@
#include <stdio.h>
#include <sys/wait.h>
-static void *start0 (void *arg)
+static void *start0(void *arg)
{
- pause ();
- /* NOTREACHED */
- assert (0);
+ pause();
+ /* NOTREACHED */
+ assert(0);
}
-int main (void)
+int main(int argc, char *argv[])
{
- pthread_t thread0;
- int i;
- pid_t child, got_pid;
- int status;
+ pthread_t thread0;
+ pid_t child, got_pid;
+ int status;
+ int i;
- child = fork ();
- switch (child)
- {
- case -1:
- assert (0);
- case 0:
- i = pthread_create (&thread0, NULL, start0, NULL);
- assert (i == 0);
- /* The thread must be initialized, it becomes thread-child of this
- process-child (child of a child of the toplevel process). */
- sleep (1);
- /* Here the child TCB cannot be deallocated as there still exist
- * children (the thread child in START0). */
- exit (42);
- /* NOTREACHED */
- assert (0);
- default:
- /* We must not be waiting in WAITPID when the child double-exits. */
- sleep (2);
- /* PID must be -1. */
- got_pid = waitpid (-1, &status, 0);
- assert (got_pid == child);
- assert (WIFEXITED (status));
- assert (WEXITSTATUS (status) == 42);
- puts ("OK");
- exit (0);
- }
- /* NOTREACHED */
- assert (0);
+ child = fork();
+
+ switch(child) {
+ case -1:
+ assert(0);
+ case 0:
+ i = pthread_create(&thread0, NULL, start0, NULL);
+ assert(i == 0);
+ /* The thread must be initialized, it becomes thread-child of this
+ process-child (child of a child of the toplevel process). */
+ sleep(1);
+ /* Here the child TCB cannot be deallocated as there still exist
+ * children (the thread child in START0). */
+ exit(42);
+ /* NOTREACHED */
+ assert(0);
+ default:
+ /* We must not be waiting in WAITPID when the child double-exits. */
+ sleep(2);
+ /* PID must be -1. */
+ got_pid = waitpid(-1, &status, 0);
+ assert(got_pid == child);
+ assert(WIFEXITED(status));
+ assert(WEXITSTATUS(status) == 42);
+ puts("OK");
+ exit(0);
+ }
+
+ /* NOTREACHED */
+ assert(0);
}
diff --git a/test/clone.c b/test/clone.c
index 75bc545..335086f 100644
--- a/test/clone.c
+++ b/test/clone.c
@@ -1,15 +1,16 @@
#include <stdio.h>
+#include <stdlib.h>
#include <sched.h>
-int child(void* arg) {
- write(1, "clone\n", 6);
- return 0;
+int child(void* arg)
+{
+ write(1, "clone\n", 6);
+ return 0;
}
-int
-main()
+int main(int argc, char *argv[])
{
- char stack[4096];
+ char stack[4096];
clone(child, stack+4000, CLONE_VM|CLONE_FS|CLONE_FILES, NULL);
write(1, "original\n", 9);
exit(0);
diff --git a/test/fork.c b/test/fork.c
index 3f68f67..9bed1fe 100644
--- a/test/fork.c
+++ b/test/fork.c
@@ -1,10 +1,14 @@
-main()
+#include <stdlib.h>
+#include <unistd.h>
+
+int main(int argc, char *argv[])
{
- if (fork() == 0)
+ if (fork() == 0) {
write(1, "child\n", 6);
- else {
+ } else {
wait(0);
write(1, "parent\n", 7);
}
+
exit(0);
}
diff --git a/test/leaderkill.c b/test/leaderkill.c
index 18d6e12..ebb6ad1 100644
--- a/test/leaderkill.c
+++ b/test/leaderkill.c
@@ -13,52 +13,52 @@
#include <stdio.h>
#include <sys/wait.h>
-static void *start0 (void *arg)
+static void *start0(void *arg)
{
- sleep (1);
-
- exit (42);
+ sleep(1);
+ exit(42);
}
-static void *start1 (void *arg)
+static void *start1(void *arg)
{
- pause ();
- /* NOTREACHED */
- assert (0);
+ pause();
+ /* NOTREACHED */
+ assert(0);
}
-int main (void)
+int main(int argc, char *argv[])
{
- pthread_t thread0;
- pthread_t thread1;
- int i;
- pid_t child, got_pid;
- int status;
+ pthread_t thread0;
+ pthread_t thread1;
+ pid_t child, got_pid;
+ int status;
+ int i;
+
+ sleep(2);
+
+ child = fork();
- sleep (2);
+ switch(child) {
+ case -1:
+ abort();
+ case 0:
+ i = pthread_create(&thread0, NULL, start0, NULL);
+ assert(i == 0);
+ i = pthread_create(&thread1, NULL, start1, NULL);
+ assert(i == 0);
+ pause();
+ /* NOTREACHED */
+ assert(0);
+ break;
+ default:
+ got_pid = waitpid(child, &status, 0);
+ assert(got_pid == child);
+ assert(WIFEXITED(status));
+ assert(WEXITSTATUS(status) == 42);
+ puts("OK");
+ exit(0);
+ }
- child = fork ();
- switch (child)
- {
- case -1:
- abort ();
- case 0:
- i = pthread_create (&thread0, NULL, start0, NULL);
- assert (i == 0);
- i = pthread_create (&thread1, NULL, start1, NULL);
- assert (i == 0);
- pause ();
/* NOTREACHED */
- assert (0);
- break;
- default:
- got_pid = waitpid (child, &status, 0);
- assert (got_pid == child);
- assert (WIFEXITED (status));
- assert (WEXITSTATUS (status) == 42);
- puts ("OK");
- exit (0);
- }
- /* NOTREACHED */
- abort ();
+ abort();
}
diff --git a/test/many_looping_threads.c b/test/many_looping_threads.c
index d8f7f8d..1f1fe05 100644
--- a/test/many_looping_threads.c
+++ b/test/many_looping_threads.c
@@ -17,7 +17,7 @@ static void *sub_thd(void *c)
return NULL;
}
-int main(int argc, char **argv)
+int main(int argc, char *argv[])
{
int i;
pthread_t *thd;
@@ -28,10 +28,12 @@ int main(int argc, char **argv)
thd = malloc(num_threads * sizeof(thd[0]));
fprintf(stderr, "test start, num_threads:%d...\n", num_threads);
+
for (i = 0; i < num_threads; i++) {
pthread_create(&thd[i], NULL, sub_thd, NULL);
fprintf(stderr, "after pthread_create\n");
}
+
/* Exit. This kills all threads */
return 0;
}
diff --git a/test/procpollable.c b/test/procpollable.c
index fc599b5..a841af1 100644
--- a/test/procpollable.c
+++ b/test/procpollable.c
@@ -1,9 +1,11 @@
#include <stdio.h>
+#include <stdlib.h>
#include <signal.h>
#include <sys/procfs.h>
#include <sys/stropts.h>
#include <poll.h>
-main()
+
+int main(int argc, char *argv[])
{
int pid;
char proc[32];
@@ -14,17 +16,24 @@ main()
pause();
exit(0);
}
+
sprintf(proc, "/proc/%d", pid);
+
if ((pfp = fopen(proc, "r+")) == NULL)
goto fail;
+
if (ioctl(fileno(pfp), PIOCSTOP, NULL) < 0)
goto fail;
+
pfd.fd = fileno(pfp);
pfd.events = POLLPRI;
+
if (poll(&pfd, 1, 0) < 0)
goto fail;
+
if (!(pfd.revents & POLLPRI))
goto fail;
+
kill(pid, SIGKILL);
exit(0);
fail:
diff --git a/test/sfd.c b/test/sfd.c
index 081de01..b5ff847 100644
--- a/test/sfd.c
+++ b/test/sfd.c
@@ -1,6 +1,7 @@
#include <fcntl.h>
#include <stdio.h>
-main(int argc, char *argv[])
+
+int main(int argc, char *argv[])
{
int pid = atoi(argv[1]);
int sfd;
@@ -11,22 +12,28 @@ main(int argc, char *argv[])
int signal, blocked, ignore, caught;
sprintf(sname, "/proc/%d/stat", pid);
+
if ((sfd = open(sname, O_RDONLY)) == -1) {
perror(sname);
return 1;
}
+
i = read(sfd, buf, 1024);
buf[i] = '\0';
+
for (i = 0, s = buf; i < 30; i++) {
while (*++s != ' ') {
if (!*s)
break;
}
}
+
if (sscanf(s, "%d%d%d%d", &signal, &blocked, &ignore, &caught) != 4) {
fprintf(stderr, "/proc/pid/stat format error\n");
return 1;
}
+
printf("%8x %8x %8x %8x\n", signal, blocked, ignore, caught);
- return 1;
+
+ return 0;
}
diff --git a/test/sig.c b/test/sig.c
index 930a177..60a9dc9 100644
--- a/test/sig.c
+++ b/test/sig.c
@@ -1,16 +1,18 @@
+#include <stdlib.h>
#include <signal.h>
-main()
+
+void interrupt()
+{
+ write(2, "xyzzy\n", 6);
+}
+
+int main(int argc, char *argv[])
{
char buf[1024];
- void interrupt();
signal(SIGINT, interrupt);
read(0, buf, 1024);
write(2, "qwerty\n", 7);
- exit(0);
-}
-interrupt()
-{
- write(2, "xyzzy\n", 6);
+ return 0;
}
diff --git a/test/sigkill_rain.c b/test/sigkill_rain.c
index 4306a8a..dd83a69 100644
--- a/test/sigkill_rain.c
+++ b/test/sigkill_rain.c
@@ -1,14 +1,16 @@
/* This test is not yet added to Makefile */
+#include <stdlib.h>
#include <stddef.h>
#include <unistd.h>
#include <signal.h>
#include <sys/types.h>
#include <sys/socket.h>
+
static const struct sockaddr sa;
-int main(int argc, char **argv)
+int main(int argc, char *argv[])
{
int loops;
int pid;
@@ -24,7 +26,10 @@ int main(int argc, char **argv)
while (--loops >= 0) {
pid = fork();
- if (pid < 0) _exit(1);
+
+ if (pid < 0)
+ exit(1);
+
if (!pid) {
/* child */
int child = getpid();
@@ -32,12 +37,16 @@ int main(int argc, char **argv)
loops = 99;
while (--loops) {
pid = fork();
- if (pid < 0) _exit(1);
+
+ if (pid < 0)
+ exit(1);
+
if (!pid) {
/* grandchild: kill child */
kill(child, SIGKILL);
- _exit(0);
+ exit(0);
}
+
/* Add various syscalls you want to test here.
* strace will decode them and suddenly find
* process disappearing.
@@ -47,16 +56,23 @@ int main(int argc, char **argv)
* decode syscall number before process dies.
*/
switch (loops & 1) {
- case 0: /* empty */ break;
- case 1: sendto(-1, "Hello cruel world", 17, 0, &sa, sizeof(sa)); break;
+ case 0:
+ break; /* intentional empty */
+ case 1:
+ sendto(-1, "Hello cruel world", 17, 0, &sa, sizeof(sa));
+ break;
}
+
/* kill grandchild */
kill(pid, SIGKILL);
}
- _exit(0);
+
+ exit(0);
}
+
/* parent */
wait(NULL);
}
+
return 0;
}
diff --git a/test/skodic.c b/test/skodic.c
index 1495578..09967bd 100644
--- a/test/skodic.c
+++ b/test/skodic.c
@@ -6,28 +6,33 @@
#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
#include <unistd.h>
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
-int
-main(void)
+int main(int argc, char *argv[])
{
- char *c = (char*)0x94000000;
- int fd;
- open( "/tmp/delme", O_RDWR );
- mmap( c, 4096, PROT_READ | PROT_WRITE, MAP_FIXED | MAP_SHARED, 3, 0 );
- *c = 0;
- if (fork()) {
- while(1) {
- strcpy( c, "/etc/passwd" );
- strcpy( c, "/etc/shadow" );
- }
- } else
- while (1)
- if ((fd=open( c, 0 ))!=-1)
- close(fd);
- return 0;
+ /* XXX: x86 specific stuff? */
+ char *c = (char*) 0x94000000;
+ int fd;
+
+ open("/tmp/delme", O_RDWR);
+ mmap(c, 4096, PROT_READ | PROT_WRITE, MAP_FIXED | MAP_SHARED, 3, 0);
+ *c = 0;
+
+ if (fork()) {
+ while(1) {
+ strcpy(c, "/etc/passwd");
+ strcpy(c, "/etc/shadow");
+ }
+ } else {
+ while (1)
+ if ((fd = open(c, 0)) != -1)
+ close(fd);
+ }
+
+ return 0;
}
diff --git a/test/vfork.c b/test/vfork.c
index 2c2d603..367dc01 100644
--- a/test/vfork.c
+++ b/test/vfork.c
@@ -1,10 +1,14 @@
-main()
+#include <stdlib.h>
+#include <unistd.h>
+
+int main(int argc, char *argv[])
{
- if (vfork() == 0)
+ if (vfork() == 0) {
write(1, "child\n", 6);
- else {
+ } else {
wait(0);
write(1, "parent\n", 7);
}
+
exit(0);
}