Skip to content

Instantly share code, notes, and snippets.

@karolhrdina
Last active April 4, 2018 15:57
Show Gist options
  • Save karolhrdina/235d5971f353d1b8296a013f200bc7dd to your computer and use it in GitHub Desktop.
Save karolhrdina/235d5971f353d1b8296a013f200bc7dd to your computer and use it in GitHub Desktop.
czmq/zproc_t: `zproc_set_stdin ()` breaks everything
#!/bin/bash
rm -f run_test
gcc -Wall -Werror -lczmq -DCZMQ_BUILD_DRAFT_API=1 zproc_issue.c -o run_test
#!/bin/bash
#
# TODO
#
echo "Hello World!"
while read line
do
sleep 1
echo "$line"
done
#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