Last active
April 4, 2018 15:57
-
-
Save karolhrdina/235d5971f353d1b8296a013f200bc7dd to your computer and use it in GitHub Desktop.
czmq/zproc_t: `zproc_set_stdin ()` breaks everything
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
rm -f run_test | |
gcc -Wall -Werror -lczmq -DCZMQ_BUILD_DRAFT_API=1 zproc_issue.c -o run_test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# TODO | |
# | |
echo "Hello World!" | |
while read line | |
do | |
sleep 1 | |
echo "$line" | |
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <czmq.h> | |
int | |
main () | |
{ | |
// Test #1: This Works | |
puts ("Test #1:"); | |
{ | |
zproc_t *proc = zproc_new (); | |
assert (proc); | |
zproc_set_verbose (proc, true); | |
zproc_set_stdout (proc, NULL); | |
zlist_t *arguments = zlist_new (); | |
assert (arguments); | |
zlist_append (arguments, (void *) "./script.sh"); | |
zproc_set_args (proc, &arguments); | |
int rv = zproc_run (proc); | |
assert (rv == 0); | |
// Expecting just one line 'Hello World!\n' | |
zframe_t *frame = NULL; | |
zsock_brecv (zproc_stdout (proc), "f", &frame); | |
printf ("Received '%s'\n", (char *) zframe_data (frame)); | |
assert (zframe_streq (frame, "Hello World!\n")); | |
zproc_kill (proc, SIGTERM); | |
zclock_sleep (200); | |
if (zproc_running (proc)) | |
zproc_kill (proc, SIGKILL); | |
zclock_sleep (200); | |
zproc_destroy (&proc); | |
} | |
puts ("Test #1: Successfull"); | |
// Test #2: Just by adding stdin pipe previous example stops working | |
puts (""); | |
puts ("Test #2:"); | |
{ | |
zproc_t *proc = zproc_new (); | |
assert (proc); | |
zproc_set_verbose (proc, true); | |
zproc_set_stdout (proc, NULL); | |
zproc_set_stdin (proc, NULL); // <<<---- THIS BREAKS EVERYTHING !!!! | |
zlist_t *arguments = zlist_new (); | |
assert (arguments); | |
zlist_append (arguments, (void *) "./script.sh"); | |
zproc_set_args (proc, &arguments); | |
int rv = zproc_run (proc); | |
assert (rv == 0); | |
// Expecting just one line 'Hello World!\n' | |
zframe_t *frame = NULL; | |
zsock_brecv (zproc_stdout (proc), "f", &frame); | |
printf ("Received '%s'\n", (char *) zframe_data (frame)); | |
assert (zframe_streq (frame, "Hello World!\n")); | |
zproc_kill (proc, SIGTERM); | |
zclock_sleep (200); | |
if (zproc_running (proc)) | |
zproc_kill (proc, SIGKILL); | |
zclock_sleep (200); | |
zproc_destroy (&proc); | |
} | |
puts ("Test #2: Successfull"); | |
return EXIT_SUCCESS; | |
} | |
"zproc_issue.c" 73L, 2078C 19,0-1 Top |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment