aboutsummaryrefslogtreecommitdiff
path: root/src/testzzuf/socat.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2008-04-13 02:54:58 +0000
committerChristian Grothoff <christian@grothoff.org>2008-04-13 02:54:58 +0000
commit72c08272fdbb426830363b0903224241157deb18 (patch)
tree7be7c5198f18edfe4b441744ff2e6ea83b896123 /src/testzzuf/socat.c
parent359fcdda235f8ce9c625e1789e6b22bb30d592fd (diff)
downloadlibmicrohttpd-72c08272fdbb426830363b0903224241157deb18.tar.gz
libmicrohttpd-72c08272fdbb426830363b0903224241157deb18.zip
formatting
Diffstat (limited to 'src/testzzuf/socat.c')
-rw-r--r--src/testzzuf/socat.c71
1 files changed, 33 insertions, 38 deletions
diff --git a/src/testzzuf/socat.c b/src/testzzuf/socat.c
index b8948575..0933010b 100644
--- a/src/testzzuf/socat.c
+++ b/src/testzzuf/socat.c
@@ -33,9 +33,10 @@
33static pid_t zzuf_pid; 33static pid_t zzuf_pid;
34 34
35static void 35static void
36zzuf_socat_start() { 36zzuf_socat_start ()
37{
37 int status; 38 int status;
38 char * const args[] = { 39 char *const args[] = {
39 "zzuf", 40 "zzuf",
40 "--ratio=0.0:0.75", 41 "--ratio=0.0:0.75",
41 "-n", 42 "-n",
@@ -45,54 +46,48 @@ zzuf_socat_start() {
45 "TCP4:127.0.0.1:11080", 46 "TCP4:127.0.0.1:11080",
46 NULL, 47 NULL,
47 }; 48 };
48 zzuf_pid = fork(); 49 zzuf_pid = fork ();
49 if (zzuf_pid == -1) { 50 if (zzuf_pid == -1)
50 fprintf(stderr, 51 {
51 "fork failed: %s\n", 52 fprintf (stderr, "fork failed: %s\n", strerror (errno));
52 strerror(errno)); 53 exit (1);
53 exit(1); 54 }
54 }
55 if (zzuf_pid != 0) 55 if (zzuf_pid != 0)
56 { 56 {
57 sleep(1); /* allow zzuf and socat to start */ 57 sleep (1); /* allow zzuf and socat to start */
58 status = 0; 58 status = 0;
59 if (0 < waitpid(zzuf_pid, &status, WNOHANG)) 59 if (0 < waitpid (zzuf_pid, &status, WNOHANG))
60 { 60 {
61 if (WIFEXITED(status)) 61 if (WIFEXITED (status))
62 fprintf(stderr, 62 fprintf (stderr,
63 "zzuf died with status code %d!\n", 63 "zzuf died with status code %d!\n",
64 WEXITSTATUS(status)); 64 WEXITSTATUS (status));
65 if (WIFSIGNALED(status)) 65 if (WIFSIGNALED (status))
66 fprintf(stderr, 66 fprintf (stderr,
67 "zzuf died from signal %d!\n", 67 "zzuf died from signal %d!\n", WTERMSIG (status));
68 WTERMSIG(status)); 68 exit (1);
69 exit(1); 69 }
70 }
71 return; 70 return;
72 } 71 }
73 setpgrp(); 72 setpgrp ();
74 execvp("zzuf", 73 execvp ("zzuf", args);
75 args); 74 fprintf (stderr, "execution of `zzuf' failed: %s\n", strerror (errno));
76 fprintf(stderr, 75 zzuf_pid = 0; /* fork failed */
77 "execution of `zzuf' failed: %s\n", 76 exit (1);
78 strerror(errno));
79 zzuf_pid = 0; /* fork failed */
80 exit(1);
81} 77}
82 78
83 79
84static void 80static void
85zzuf_socat_stop() { 81zzuf_socat_stop ()
82{
86 int status; 83 int status;
87 if (zzuf_pid != 0) 84 if (zzuf_pid != 0)
88 { 85 {
89 if (0 != killpg(zzuf_pid, SIGINT)) 86 if (0 != killpg (zzuf_pid, SIGINT))
90 fprintf(stderr, 87 fprintf (stderr, "Failed to killpg: %s\n", strerror (errno));
91 "Failed to killpg: %s\n", 88 kill (zzuf_pid, SIGINT);
92 strerror(errno)); 89 waitpid (zzuf_pid, &status, 0);
93 kill(zzuf_pid, SIGINT); 90 sleep (1); /* allow socat to also die in peace */
94 waitpid(zzuf_pid, &status, 0);
95 sleep(1); /* allow socat to also die in peace */
96 } 91 }
97} 92}
98 93