summaryrefslogtreecommitdiff
path: root/src/testzzuf/socat.c
diff options
context:
space:
mode:
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 @@
static pid_t zzuf_pid;
static void
-zzuf_socat_start() {
+zzuf_socat_start ()
+{
int status;
- char * const args[] = {
+ char *const args[] = {
"zzuf",
"--ratio=0.0:0.75",
"-n",
@@ -45,54 +46,48 @@ zzuf_socat_start() {
"TCP4:127.0.0.1:11080",
NULL,
};
- zzuf_pid = fork();
- if (zzuf_pid == -1) {
- fprintf(stderr,
- "fork failed: %s\n",
- strerror(errno));
- exit(1);
- }
+ zzuf_pid = fork ();
+ if (zzuf_pid == -1)
+ {
+ fprintf (stderr, "fork failed: %s\n", strerror (errno));
+ exit (1);
+ }
if (zzuf_pid != 0)
{
- sleep(1); /* allow zzuf and socat to start */
+ sleep (1); /* allow zzuf and socat to start */
status = 0;
- if (0 < waitpid(zzuf_pid, &status, WNOHANG))
- {
- if (WIFEXITED(status))
- fprintf(stderr,
- "zzuf died with status code %d!\n",
- WEXITSTATUS(status));
- if (WIFSIGNALED(status))
- fprintf(stderr,
- "zzuf died from signal %d!\n",
- WTERMSIG(status));
- exit(1);
- }
+ if (0 < waitpid (zzuf_pid, &status, WNOHANG))
+ {
+ if (WIFEXITED (status))
+ fprintf (stderr,
+ "zzuf died with status code %d!\n",
+ WEXITSTATUS (status));
+ if (WIFSIGNALED (status))
+ fprintf (stderr,
+ "zzuf died from signal %d!\n", WTERMSIG (status));
+ exit (1);
+ }
return;
}
- setpgrp();
- execvp("zzuf",
- args);
- fprintf(stderr,
- "execution of `zzuf' failed: %s\n",
- strerror(errno));
- zzuf_pid = 0; /* fork failed */
- exit(1);
+ setpgrp ();
+ execvp ("zzuf", args);
+ fprintf (stderr, "execution of `zzuf' failed: %s\n", strerror (errno));
+ zzuf_pid = 0; /* fork failed */
+ exit (1);
}
static void
-zzuf_socat_stop() {
+zzuf_socat_stop ()
+{
int status;
if (zzuf_pid != 0)
{
- if (0 != killpg(zzuf_pid, SIGINT))
- fprintf(stderr,
- "Failed to killpg: %s\n",
- strerror(errno));
- kill(zzuf_pid, SIGINT);
- waitpid(zzuf_pid, &status, 0);
- sleep(1); /* allow socat to also die in peace */
+ if (0 != killpg (zzuf_pid, SIGINT))
+ fprintf (stderr, "Failed to killpg: %s\n", strerror (errno));
+ kill (zzuf_pid, SIGINT);
+ waitpid (zzuf_pid, &status, 0);
+ sleep (1); /* allow socat to also die in peace */
}
}