aboutsummaryrefslogtreecommitdiff
path: root/src/util/test_os_start_process.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/util/test_os_start_process.c')
-rw-r--r--src/util/test_os_start_process.c99
1 files changed, 55 insertions, 44 deletions
diff --git a/src/util/test_os_start_process.c b/src/util/test_os_start_process.c
index f82860e83..4137118fa 100644
--- a/src/util/test_os_start_process.c
+++ b/src/util/test_os_start_process.c
@@ -39,8 +39,10 @@ static char *test_phrase = "HELLO WORLD";
39static int ok; 39static int ok;
40 40
41static struct GNUNET_OS_Process *proc; 41static struct GNUNET_OS_Process *proc;
42
42/* Pipe to write to started processes stdin (on write end) */ 43/* Pipe to write to started processes stdin (on write end) */
43static struct GNUNET_DISK_PipeHandle *hello_pipe_stdin; 44static struct GNUNET_DISK_PipeHandle *hello_pipe_stdin;
45
44/* Pipe to read from started processes stdout (on read end) */ 46/* Pipe to read from started processes stdout (on read end) */
45static struct GNUNET_DISK_PipeHandle *hello_pipe_stdout; 47static struct GNUNET_DISK_PipeHandle *hello_pipe_stdout;
46 48
@@ -51,14 +53,14 @@ end_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
51{ 53{
52 54
53 if (0 != GNUNET_OS_process_kill (proc, SIGTERM)) 55 if (0 != GNUNET_OS_process_kill (proc, SIGTERM))
54 { 56 {
55 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); 57 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
56 } 58 }
57 GNUNET_OS_process_wait (proc); 59 GNUNET_OS_process_wait (proc);
58 GNUNET_OS_process_close (proc); 60 GNUNET_OS_process_close (proc);
59 proc = NULL; 61 proc = NULL;
60 GNUNET_DISK_pipe_close(hello_pipe_stdout); 62 GNUNET_DISK_pipe_close (hello_pipe_stdout);
61 GNUNET_DISK_pipe_close(hello_pipe_stdin); 63 GNUNET_DISK_pipe_close (hello_pipe_stdin);
62} 64}
63 65
64static void 66static void
@@ -66,36 +68,39 @@ read_call (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
66{ 68{
67 struct GNUNET_DISK_FileHandle *stdout_read_handle = cls; 69 struct GNUNET_DISK_FileHandle *stdout_read_handle = cls;
68 char buf[16]; 70 char buf[16];
69 memset(&buf, 0, sizeof(buf)); 71
72 memset (&buf, 0, sizeof (buf));
70 int bytes; 73 int bytes;
71 bytes = GNUNET_DISK_file_read(stdout_read_handle, &buf, sizeof(buf)); 74
75 bytes = GNUNET_DISK_file_read (stdout_read_handle, &buf, sizeof (buf));
72 76
73#if VERBOSE 77#if VERBOSE
74 fprintf(stderr, "bytes is %d\n", bytes); 78 fprintf (stderr, "bytes is %d\n", bytes);
75#endif 79#endif
76 80
77 if (bytes < 1) 81 if (bytes < 1)
78 { 82 {
79 GNUNET_break (0); 83 GNUNET_break (0);
80 ok = 1; 84 ok = 1;
81 GNUNET_SCHEDULER_cancel(die_task); 85 GNUNET_SCHEDULER_cancel (die_task);
82 GNUNET_SCHEDULER_add_now(&end_task, NULL); 86 GNUNET_SCHEDULER_add_now (&end_task, NULL);
83 return; 87 return;
84 } 88 }
85 89
86 ok = strncmp(&buf[0], test_phrase, strlen(test_phrase)); 90 ok = strncmp (&buf[0], test_phrase, strlen (test_phrase));
87#if VERBOSE 91#if VERBOSE
88 fprintf(stderr, "read %s\n", &buf[0]); 92 fprintf (stderr, "read %s\n", &buf[0]);
89#endif 93#endif
90 if (ok == 0) 94 if (ok == 0)
91 { 95 {
92 GNUNET_SCHEDULER_cancel(die_task); 96 GNUNET_SCHEDULER_cancel (die_task);
93 GNUNET_SCHEDULER_add_now(&end_task, NULL); 97 GNUNET_SCHEDULER_add_now (&end_task, NULL);
94 return; 98 return;
95 } 99 }
96 100
97 GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, 101 GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
98 stdout_read_handle, &read_call, stdout_read_handle); 102 stdout_read_handle, &read_call,
103 stdout_read_handle);
99 104
100} 105}
101 106
@@ -107,47 +112,53 @@ task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
107 const struct GNUNET_DISK_FileHandle *stdout_read_handle; 112 const struct GNUNET_DISK_FileHandle *stdout_read_handle;
108 const struct GNUNET_DISK_FileHandle *wh; 113 const struct GNUNET_DISK_FileHandle *wh;
109 114
110 GNUNET_asprintf(&fn, "cat"); 115 GNUNET_asprintf (&fn, "cat");
111 116
112 hello_pipe_stdin = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_YES, GNUNET_NO); 117 hello_pipe_stdin = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_YES, GNUNET_NO);
113 hello_pipe_stdout = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_NO, GNUNET_YES); 118 hello_pipe_stdout = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_NO, GNUNET_YES);
114 119
115 if ((hello_pipe_stdout == NULL) || (hello_pipe_stdin == NULL)) 120 if ((hello_pipe_stdout == NULL) || (hello_pipe_stdin == NULL))
116 { 121 {
117 GNUNET_break (0); 122 GNUNET_break (0);
118 ok = 1; 123 ok = 1;
119 GNUNET_free (fn); 124 GNUNET_free (fn);
120 return; 125 return;
121 } 126 }
122 127
123 proc = GNUNET_OS_start_process (hello_pipe_stdin, hello_pipe_stdout, fn, 128 proc = GNUNET_OS_start_process (hello_pipe_stdin, hello_pipe_stdout, fn,
124 "test_gnunet_echo_hello", "-", NULL); 129 "test_gnunet_echo_hello", "-", NULL);
125 GNUNET_free (fn); 130 GNUNET_free (fn);
126 131
127 /* Close the write end of the read pipe */ 132 /* Close the write end of the read pipe */
128 GNUNET_DISK_pipe_close_end(hello_pipe_stdout, GNUNET_DISK_PIPE_END_WRITE); 133 GNUNET_DISK_pipe_close_end (hello_pipe_stdout, GNUNET_DISK_PIPE_END_WRITE);
129 /* Close the read end of the write pipe */ 134 /* Close the read end of the write pipe */
130 GNUNET_DISK_pipe_close_end(hello_pipe_stdin, GNUNET_DISK_PIPE_END_READ); 135 GNUNET_DISK_pipe_close_end (hello_pipe_stdin, GNUNET_DISK_PIPE_END_READ);
131 136
132 wh = GNUNET_DISK_pipe_handle (hello_pipe_stdin, GNUNET_DISK_PIPE_END_WRITE); 137 wh = GNUNET_DISK_pipe_handle (hello_pipe_stdin, GNUNET_DISK_PIPE_END_WRITE);
133 138
134 /* Write the test_phrase to the cat process */ 139 /* Write the test_phrase to the cat process */
135 if (GNUNET_DISK_file_write(wh, test_phrase, strlen(test_phrase) + 1) != strlen(test_phrase) + 1) 140 if (GNUNET_DISK_file_write (wh, test_phrase, strlen (test_phrase) + 1) !=
136 { 141 strlen (test_phrase) + 1)
137 GNUNET_break (0); 142 {
138 ok = 1; 143 GNUNET_break (0);
139 return; 144 ok = 1;
140 } 145 return;
146 }
141 147
142 /* Close the write end to end the cycle! */ 148 /* Close the write end to end the cycle! */
143 GNUNET_DISK_pipe_close_end(hello_pipe_stdin, GNUNET_DISK_PIPE_END_WRITE); 149 GNUNET_DISK_pipe_close_end (hello_pipe_stdin, GNUNET_DISK_PIPE_END_WRITE);
144 150
145 stdout_read_handle = GNUNET_DISK_pipe_handle(hello_pipe_stdout, GNUNET_DISK_PIPE_END_READ); 151 stdout_read_handle =
152 GNUNET_DISK_pipe_handle (hello_pipe_stdout, GNUNET_DISK_PIPE_END_READ);
146 153
147 die_task = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 1), &end_task, NULL); 154 die_task =
155 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
156 (GNUNET_TIME_UNIT_MINUTES, 1), &end_task,
157 NULL);
148 158
149 GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, 159 GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
150 stdout_read_handle, &read_call, (void *)stdout_read_handle); 160 stdout_read_handle, &read_call,
161 (void *) stdout_read_handle);
151 162
152} 163}
153 164