]> granicus.if.org Git - strace/commitdiff
By Hans-Christian Egtvedt (hans-christian.egtvedt AT atmel.com):
authorDenys Vlasenko <dvlasenk@redhat.com>
Wed, 25 Feb 2009 14:24:02 +0000 (14:24 +0000)
committerDenys Vlasenko <dvlasenk@redhat.com>
Wed, 25 Feb 2009 14:24:02 +0000 (14:24 +0000)
strace.c: suppress "warning: unused static" message by adding #ifdef's around
 a variable
.gitignore: trivial
test/*.c: cleanup (suppress warnings, much better style).

13 files changed:
.gitignore
strace.c
test/childthread.c
test/clone.c
test/fork.c
test/leaderkill.c
test/many_looping_threads.c
test/procpollable.c
test/sfd.c
test/sig.c
test/sigkill_rain.c
test/skodic.c
test/vfork.c

index 7977f446a7e242014d81309ed93668e783a62995..96160779c5f04103209c971def35ded39563d4d9 100644 (file)
@@ -1,6 +1,8 @@
+*~
 *.o
 .deps
 .libs
+.*.swp
 
 Makefile
 Makefile.in
index cded401e66b3ce471db72ad87af8dfb15e070140..1acecf281ecd926ccb23956eb12faa4eeac348a4 100644 (file)
--- 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;
index bd0174b83223cde6a80e1dc8807d49fd2cbdc43a..e89fb1454011ee69a963a31f3b1584f9773a1789 100644 (file)
 #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);
 }
index 75bc54516c5bd32770f62d0f3d914ecff370a668..335086fcb70723dd53cc1fc4f99b5147ed16061a 100644 (file)
@@ -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);
index 3f68f6722ab7543f671e414e1b63c55fc5cd38c4..9bed1fe48668426d50e00f6d2b32b4be1e7e6f8f 100644 (file)
@@ -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);
 }
index 18d6e1230e1a6664d7e0d2294ca91782a3bdec5c..ebb6ad1cf4eb621e006c08cf7f1ee0489ca69b64 100644 (file)
 #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();
 }
index d8f7f8d878a7b36d88c8f6104cbd7eb484a8a44d..1f1fe05221860711f4ebdb021e820267787743b9 100644 (file)
@@ -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;
 }
index fc599b566451a59ae3600ee0460fb37f9a6f274f..a841af147c9eb3f118fe76b71567628bac7c64d4 100644 (file)
@@ -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:
index 081de01e20d8e804765edf0091686d270bcc18e3..b5ff847a41a228d2f7a10386e5f744594bd0f2e0 100644 (file)
@@ -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;
 }
index 930a177f5d46b06712d43f270dbe908a31a35edb..60a9dc9e3dc097cab9127ee533029be0b2212004 100644 (file)
@@ -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;
 }
index 4306a8ac4c5255e21fcffb9f20f7c8c610c8d129..dd83a6922d06a12e4b1966e56bc3fd0851c4bd6a 100644 (file)
@@ -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;
 }
index 1495578355aa0a292c178723a53d1cae8a40e737..09967bdd4730e20bbdbf5b684f39169a88902e1d 100644 (file)
@@ -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;
 }
index 2c2d60321d18f69d8b39e001f78dba280d8a2732..367dc0194eaf6f040873152ad01aaf4fcd7730bf 100644 (file)
@@ -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);
 }