diff options
author | LRN <lrn1986@gmail.com> | 2013-04-30 04:38:47 +0000 |
---|---|---|
committer | LRN <lrn1986@gmail.com> | 2013-04-30 04:38:47 +0000 |
commit | 265eecb642f0056c455f48dc3be4c4b342158114 (patch) | |
tree | 3fa805cabe7d600833a10461877105df9874c796 /src/util | |
parent | 85f905805b3f5e72d06b9138b1e63db77b20cb11 (diff) | |
download | gnunet-265eecb642f0056c455f48dc3be4c4b342158114.tar.gz gnunet-265eecb642f0056c455f48dc3be4c4b342158114.zip |
Fix test_os_startprocess
Previous code wrongly assumed that the message will be read from the pipe
completely in one go. It does not happen like that _every_ time.
Diffstat (limited to 'src/util')
-rw-r--r-- | src/util/test_os_start_process.c | 29 |
1 files changed, 19 insertions, 10 deletions
diff --git a/src/util/test_os_start_process.c b/src/util/test_os_start_process.c index 7005c11a4..124b364fb 100644 --- a/src/util/test_os_start_process.c +++ b/src/util/test_os_start_process.c | |||
@@ -52,6 +52,14 @@ static struct GNUNET_DISK_PipeHandle *hello_pipe_stdout; | |||
52 | 52 | ||
53 | static GNUNET_SCHEDULER_TaskIdentifier die_task; | 53 | static GNUNET_SCHEDULER_TaskIdentifier die_task; |
54 | 54 | ||
55 | struct read_context | ||
56 | { | ||
57 | char buf[16]; | ||
58 | int buf_offset; | ||
59 | const struct GNUNET_DISK_FileHandle *stdout_read_handle; | ||
60 | }; | ||
61 | |||
62 | struct read_context rc; | ||
55 | 63 | ||
56 | static void | 64 | static void |
57 | end_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 65 | end_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
@@ -71,13 +79,10 @@ end_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
71 | static void | 79 | static void |
72 | read_call (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 80 | read_call (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
73 | { | 81 | { |
74 | struct GNUNET_DISK_FileHandle *stdout_read_handle = cls; | ||
75 | char buf[16]; | ||
76 | |||
77 | memset (&buf, 0, sizeof (buf)); | ||
78 | int bytes; | 82 | int bytes; |
79 | 83 | ||
80 | bytes = GNUNET_DISK_file_read (stdout_read_handle, &buf, sizeof (buf)); | 84 | bytes = GNUNET_DISK_file_read (rc.stdout_read_handle, &rc.buf[rc.buf_offset], \ |
85 | sizeof (rc.buf) - rc.buf_offset); | ||
81 | 86 | ||
82 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "bytes is %d\n", bytes); | 87 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "bytes is %d\n", bytes); |
83 | 88 | ||
@@ -90,8 +95,10 @@ read_call (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
90 | return; | 95 | return; |
91 | } | 96 | } |
92 | 97 | ||
93 | ok = strncmp (&buf[0], test_phrase, strlen (test_phrase)); | 98 | ok = strncmp (rc.buf, test_phrase, strlen (test_phrase)); |
94 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "read %s\n", &buf[0]); | 99 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "read %s\n", &rc.buf[rc.buf_offset]); |
100 | rc.buf_offset += bytes; | ||
101 | |||
95 | if (0 == ok) | 102 | if (0 == ok) |
96 | { | 103 | { |
97 | GNUNET_SCHEDULER_cancel (die_task); | 104 | GNUNET_SCHEDULER_cancel (die_task); |
@@ -100,8 +107,8 @@ read_call (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
100 | } | 107 | } |
101 | 108 | ||
102 | GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, | 109 | GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, |
103 | stdout_read_handle, &read_call, | 110 | rc.stdout_read_handle, &read_call, |
104 | stdout_read_handle); | 111 | NULL); |
105 | 112 | ||
106 | } | 113 | } |
107 | 114 | ||
@@ -163,9 +170,11 @@ run_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
163 | (GNUNET_TIME_UNIT_MINUTES, 1), &end_task, | 170 | (GNUNET_TIME_UNIT_MINUTES, 1), &end_task, |
164 | NULL); | 171 | NULL); |
165 | 172 | ||
173 | memset (&rc, 0, sizeof (rc)); | ||
174 | rc.stdout_read_handle = stdout_read_handle; | ||
166 | GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, | 175 | GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, |
167 | stdout_read_handle, &read_call, | 176 | stdout_read_handle, &read_call, |
168 | (void *) stdout_read_handle); | 177 | NULL); |
169 | } | 178 | } |
170 | 179 | ||
171 | 180 | ||