Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Fight for better integration of mmalloc, mc and xbt
[simgrid.git] / tools / tesh / run_context.c
1 /* run_context -- stuff in which TESH runs a command                        */
2
3 /* Copyright (c) 2007, 2008, 2009, 2010. The SimGrid Team.
4  * All rights reserved.                                                     */
5
6 /* This program is free software; you can redistribute it and/or modify it
7  * under the terms of the license (GNU LGPL) which comes with this package. */
8
9 #include "tesh.h"
10
11 #include <sys/types.h>
12 #include <sys/wait.h>
13 #include <sys/stat.h>
14 #include <unistd.h>
15
16 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(tesh);
17
18 xbt_dynar_t bg_jobs = NULL;
19 rctx_t armageddon_initiator = NULL;
20 xbt_os_mutex_t armageddon_mutex = NULL;
21
22 /*
23  * Module management
24  */
25
26 static void kill_it(void *r)
27 {
28   rctx_t rctx = *(rctx_t *) r;
29
30   VERB2("Join thread %p which were running background cmd <%s>", rctx->runner,
31         rctx->filepos);
32   xbt_os_thread_join(rctx->runner, NULL);
33   rctx_free(rctx);
34 }
35
36 void rctx_init(void)
37 {
38   bg_jobs = xbt_dynar_new_sync(sizeof(rctx_t), kill_it);
39   armageddon_mutex = xbt_os_mutex_init();
40   armageddon_initiator = NULL;
41 }
42
43 void rctx_exit(void)
44 {
45   if (bg_jobs) {
46     /* Do not use xbt_dynar_free or it will lock the dynar, preventing armageddon from working */
47     while (xbt_dynar_length(bg_jobs)) {
48       rctx_t rctx;
49       xbt_dynar_pop(bg_jobs, &rctx);
50       kill_it(&rctx);
51     }
52     xbt_dynar_free(&bg_jobs);
53   }
54   xbt_os_mutex_destroy(armageddon_mutex);
55 }
56
57 void rctx_wait_bg(void)
58 {
59   if (bg_jobs) {
60     /* Do not use xbt_dynar_free or it will lock the dynar, preventing armageddon from working */
61     while (xbt_dynar_length(bg_jobs)) {
62       rctx_t rctx;
63       xbt_dynar_pop(bg_jobs, &rctx);
64       kill_it(&rctx);
65     }
66     xbt_dynar_free(&bg_jobs);
67   }
68   bg_jobs = xbt_dynar_new_sync(sizeof(rctx_t), kill_it);
69 }
70
71 void rctx_armageddon(rctx_t initiator, int exitcode)
72 {
73   rctx_t rctx;
74
75   DEBUG2("Armageddon request by <%s> (exit=%d)", initiator->filepos,
76          exitcode);
77   xbt_os_mutex_acquire(armageddon_mutex);
78   if (armageddon_initiator != NULL) {
79     VERB0("Armageddon already started. Let it go");
80     xbt_os_mutex_release(initiator->interruption);
81     xbt_os_mutex_release(armageddon_mutex);
82     return;
83   }
84   DEBUG1("Armageddon request by <%s> got the lock. Let's go amok",
85          initiator->filepos);
86   armageddon_initiator = initiator;
87   xbt_os_mutex_release(armageddon_mutex);
88
89   /* Kill any background commands */
90   while (xbt_dynar_length(bg_jobs)) {
91     xbt_dynar_pop(bg_jobs, &rctx);
92     if (rctx != initiator) {
93       INFO2("Kill <%s> because <%s> failed", rctx->filepos,
94             initiator->filepos);
95       xbt_os_mutex_acquire(rctx->interruption);
96       rctx->interrupted = 1;
97       xbt_os_mutex_release(rctx->interruption);
98       if (!rctx->reader_done) {
99         kill(rctx->pid, SIGTERM);
100         usleep(100);
101         kill(rctx->pid, SIGKILL);
102       }
103     }
104   }
105
106   VERB0("Shut everything down!");
107   exit(exitcode);
108 }
109
110 /*
111  * Memory management
112  */
113
114 void rctx_empty(rctx_t rc)
115 {
116   int i;
117   char **env_it = environ;
118
119   if (rc->cmd)
120     free(rc->cmd);
121   rc->cmd = NULL;
122   if (rc->filepos)
123     free(rc->filepos);
124   if (rc->env)
125     free(rc->env);
126
127   for (i = 0; *env_it; i++, env_it++);
128   i++;
129   rc->env_size = i;
130   rc->env = malloc(i * sizeof(char *));
131   memcpy(rc->env, environ, i * sizeof(char *));
132
133   rc->filepos = NULL;
134   rc->is_empty = 1;
135   rc->is_background = 0;
136   rc->is_stoppable = 0;
137   rc->output = e_output_check;
138   rc->brokenpipe = 0;
139   rc->timeout = 0;
140   rc->interrupted = 0;
141   xbt_strbuff_empty(rc->input);
142   xbt_strbuff_empty(rc->output_wanted);
143   xbt_strbuff_empty(rc->output_got);
144 }
145
146
147 rctx_t rctx_new()
148 {
149   rctx_t res = xbt_new0(s_rctx_t, 1);
150
151   res->input = xbt_strbuff_new();
152   res->output_wanted = xbt_strbuff_new();
153   res->output_got = xbt_strbuff_new();
154   res->interruption = xbt_os_mutex_init();
155   rctx_empty(res);
156   return res;
157 }
158
159 void rctx_free(rctx_t rctx)
160 {
161   DEBUG1("RCTX: Free %p", rctx);
162   rctx_dump(rctx, "free");
163   if (!rctx)
164     return;
165
166   if (rctx->cmd)
167     free(rctx->cmd);
168   if (rctx->filepos)
169     free(rctx->filepos);
170   if (rctx->env)
171     free(rctx->env);
172   xbt_os_mutex_destroy(rctx->interruption);
173   xbt_strbuff_free(rctx->input);
174   xbt_strbuff_free(rctx->output_got);
175   xbt_strbuff_free(rctx->output_wanted);
176   free(rctx);
177 }
178
179 void rctx_dump(rctx_t rctx, const char *str)
180 {
181   DEBUG9("%s RCTX %p={in%p={%d,%10s}, want={%d,%10s}, out={%d,%10s}}",
182          str, rctx,
183          rctx->input, rctx->input->used, rctx->input->data,
184          rctx->output_wanted->used, rctx->output_wanted->data,
185          rctx->output_got->used, rctx->output_got->data);
186   DEBUG5("%s RCTX %p=[cmd%p=%10s, pid=%d]",
187          str, rctx, rctx->cmd, rctx->cmd, rctx->pid);
188
189 }
190
191 /*
192  * Getting instructions from the file
193  */
194
195 void rctx_pushline(const char *filepos, char kind, char *line)
196 {
197
198   switch (kind) {
199   case '$':
200   case '&':
201     if (rctx->cmd) {
202       if (!rctx->is_empty) {
203         ERROR2
204           ("[%s] More than one command in this chunk of lines (previous: %s).\n"
205            " Cannot guess which input/output belongs to which command.",
206            filepos, rctx->cmd);
207         ERROR1("Test suite `%s': NOK (syntax error)", testsuite_name);
208         rctx_armageddon(rctx, 1);
209         return;
210       }
211       rctx_start();
212       VERB1("[%s] More than one command in this chunk of lines", filepos);
213     }
214     if (kind == '&')
215       rctx->is_background = 1;
216     else
217       rctx->is_background = 0;
218
219     rctx->cmd = xbt_strdup(line);
220     rctx->filepos = xbt_strdup(filepos);
221     INFO3("[%s] %s%s", filepos, rctx->cmd,
222           ((rctx->is_background) ? " (background command)" : ""));
223
224     break;
225
226   case '<':
227     rctx->is_empty = 0;
228     xbt_strbuff_append(rctx->input, line);
229     xbt_strbuff_append(rctx->input, "\n");
230     break;
231
232   case '>':
233     rctx->is_empty = 0;
234     xbt_strbuff_append(rctx->output_wanted, line);
235     xbt_strbuff_append(rctx->output_wanted, "\n");
236     break;
237
238   case '!':
239     if (rctx->cmd)
240       rctx_start();
241
242     if (!strncmp(line, "timeout no", strlen("timeout no"))) {
243       VERB1("[%s] (disable timeout)", filepos);
244       timeout_value = -1;
245     } else if (!strncmp(line, "timeout ", strlen("timeout "))) {
246       timeout_value = atoi(line + strlen("timeout"));
247       VERB2("[%s] (new timeout value: %d)", filepos, timeout_value);
248
249     } else if (!strncmp(line, "expect signal ", strlen("expect signal "))) {
250       rctx->expected_signal = strdup(line + strlen("expect signal "));
251       xbt_str_trim(rctx->expected_signal, " \n");
252       VERB2("[%s] (next command must raise signal %s)",
253             filepos, rctx->expected_signal);
254
255     } else if (!strncmp(line, "expect return ", strlen("expect return "))) {
256       rctx->expected_return = atoi(line + strlen("expect return "));
257       VERB2("[%s] (next command must return code %d)",
258             filepos, rctx->expected_return);
259
260     } else if (!strncmp(line, "output ignore", strlen("output ignore"))) {
261       rctx->output = e_output_ignore;
262       VERB1("[%s] (ignore output of next command)", filepos);
263
264     } else if (!strncmp(line, "output display", strlen("output display"))) {
265       rctx->output = e_output_display;
266       VERB1("[%s] (ignore output of next command)", filepos);
267
268     } else if (!strncmp(line, "setenv ", strlen("setenv "))) {
269       int len = strlen("setenv ");
270       char *eq = strchr(line + len, '=');
271       char *key = bprintf("%.*s", (int) (eq - line - len), line + len);
272       xbt_dict_set(env, key, xbt_strdup(eq + 1), xbt_free_f);
273
274       rctx->env = realloc(rctx->env, ++(rctx->env_size) * sizeof(char *));
275       rctx->env[rctx->env_size - 2] = xbt_strdup(line + len);
276       rctx->env[rctx->env_size - 1] = NULL;
277       VERB2("[%s] setenv %s", filepos, line + len);
278
279     } else {
280       ERROR2("%s: Malformed metacommand: %s", filepos, line);
281       ERROR1("Test suite `%s': NOK (syntax error)", testsuite_name);
282       rctx_armageddon(rctx, 1);
283       return;
284     }
285     break;
286   }
287 }
288
289 /*
290  * Actually doing the job
291  */
292
293 /* The IO of the childs are handled by the two following threads
294    (one pair per child) */
295
296 static void *thread_writer(void *r)
297 {
298   int posw;
299   rctx_t rctx = (rctx_t) r;
300   for (posw = 0; posw < rctx->input->used && !rctx->brokenpipe;) {
301     int got;
302     DEBUG1("Still %d chars to write", rctx->input->used - posw);
303     got =
304       write(rctx->child_to, rctx->input->data + posw,
305             rctx->input->used - posw);
306     if (got > 0)
307       posw += got;
308     if (got < 0) {
309       if (errno == EPIPE) {
310         rctx->brokenpipe = 1;
311       } else if (errno != EINTR && errno != EAGAIN && errno != EPIPE) {
312         perror("Error while writing input to child");
313         ERROR1("Test suite `%s': NOK (system error)", testsuite_name);
314         rctx_armageddon(rctx, 4);
315         return NULL;
316       }
317     }
318     DEBUG1("written %d chars so far", posw);
319
320     if (got <= 0)
321       usleep(100);
322   }
323   rctx->input->data[0] = '\0';
324   rctx->input->used = 0;
325   close(rctx->child_to);
326
327   return NULL;
328 }
329
330 static void *thread_reader(void *r)
331 {
332   rctx_t rctx = (rctx_t) r;
333   char *buffout = malloc(4096);
334   int posr, got_pid;
335
336   do {
337     posr = read(rctx->child_from, buffout, 4095);
338     if (posr < 0 && errno != EINTR && errno != EAGAIN) {
339       perror("Error while reading output of child");
340       ERROR1("Test suite `%s': NOK (system error)", testsuite_name);
341       rctx_armageddon(rctx, 4);
342       return NULL;
343     }
344     if (posr > 0) {
345       buffout[posr] = '\0';
346       xbt_strbuff_append(rctx->output_got, buffout);
347     } else {
348       usleep(100);
349     }
350   } while (!rctx->timeout && posr != 0);
351   free(buffout);
352
353   /* let this thread wait for the child so that the main thread can detect the timeout without blocking on the wait */
354   got_pid = waitpid(rctx->pid, &rctx->status, 0);
355   if (got_pid != rctx->pid) {
356     perror(bprintf("(%s) Cannot wait for the child %s (got pid %d where pid %d were expected;rctx=%p;status=%d)",
357                    xbt_thread_self_name(), rctx->cmd, (int)got_pid, (int)rctx->pid,rctx,rctx->status));
358     ERROR1("Test suite `%s': NOK (system error)", testsuite_name);
359     rctx_armageddon(rctx, 4);
360     return NULL;
361   }
362
363   rctx->reader_done = 1;
364   return NULL;
365 }
366
367 /* Special command: mkfile is a building creating a file with the input data as content */
368 static void rctx_mkfile(void)
369 {
370   char *filename = xbt_strdup(rctx->cmd + strlen("mkfile "));
371   FILE *OUT;
372   xbt_str_trim(filename, NULL);
373   OUT = fopen(filename, "w");
374   if (!OUT) {
375     free(filename);
376     THROW3(system_error, errno, "%s: Cannot create file %s: %s",
377            rctx->filepos, filename, strerror(errno));
378   }
379   fprintf(OUT, "%s", rctx->input->data);
380   fclose(OUT);
381 }
382
383 /* function to be called from the child to start the actual process */
384 static void start_command(rctx_t rctx)
385 {
386   xbt_dynar_t cmd = xbt_str_split_quoted(rctx->cmd);
387   char *binary_name = NULL;
388   unsigned int it;
389   char *str;
390   xbt_dynar_get_cpy(cmd, 0, &binary_name);
391   char **args = xbt_new(char *, xbt_dynar_length(cmd) + 1);
392   int errcode;
393
394   if (!strncmp(rctx->cmd, "mkfile ", strlen("mkfile "))) {
395     rctx_mkfile();
396     exit(0);                    /* end the working child */
397   }
398
399   xbt_dynar_foreach(cmd, it, str) {
400     args[it] = xbt_strdup(str);
401   }
402   args[it] = NULL;
403
404   /* To search for the right executable path when not trivial */
405   struct stat stat_buf;
406
407   /* build the command line */
408   if (stat(binary_name, &stat_buf)) {
409     /* Damn. binary not in current dir. We'll have to dig the PATH to find it */
410     int i;
411
412     for (i = 0; environ[i]; i++) {
413       if (!strncmp("PATH=", environ[i], 5)) {
414         xbt_dynar_t path = xbt_str_split(environ[i] + 5, ":");
415
416         xbt_dynar_foreach(path, it, str) {
417           if (binary_name)
418             free(binary_name);
419           binary_name = bprintf("%s/%s", str, args[0]);
420           if (!stat(binary_name, &stat_buf)) {
421             /* Found. */
422             DEBUG1("Looked in the PATH for the binary. Found %s",
423                    binary_name);
424             xbt_dynar_free(&path);
425             break;
426           }
427         }
428         xbt_dynar_free(&path);
429         if (stat(binary_name, &stat_buf)) {
430           /* not found */
431           printf("TESH_ERROR Command %s not found\n", args[0]);
432           exit(127);
433         }
434         break;
435       }
436     }
437   } else {
438     binary_name = xbt_strdup(args[0]);
439   }
440
441   errcode = execve(binary_name, args, rctx->env);
442   printf("TESH_ERROR %s: Cannot start %s: %s\n", rctx->filepos, rctx->cmd,
443          strerror(errcode));
444   exit(127);
445 }
446
447 /* Start a new child, plug the pipes as expected and fire up the
448    helping threads. Is also waits for the child to end if this is a
449    foreground job, or fire up a thread to wait otherwise. */
450 void rctx_start(void)
451 {
452   int child_in[2];
453   int child_out[2];
454
455   DEBUG1("Cmd before rewriting %s", rctx->cmd);
456   rctx->cmd = xbt_str_varsubst(rctx->cmd, env);
457   VERB2("Start %s %s", rctx->cmd,
458         (rctx->is_background ? "(background job)" : ""));
459   if (pipe(child_in) || pipe(child_out)) {
460     perror("Cannot open the pipes");
461     ERROR1("Test suite `%s': NOK (system error)", testsuite_name);
462     rctx_armageddon(rctx, 4);
463   }
464
465   rctx->pid = fork();
466   if (rctx->pid < 0) {
467     perror("Cannot fork the command");
468     ERROR1("Test suite `%s': NOK (system error)", testsuite_name);
469     rctx_armageddon(rctx, 4);
470     return;
471   }
472
473   if (rctx->pid) {              /* father */
474     close(child_in[0]);
475     rctx->child_to = child_in[1];
476
477     close(child_out[1]);
478     rctx->child_from = child_out[0];
479
480     if (timeout_value > 0)
481       rctx->end_time = time(NULL) + timeout_value;
482     else
483       rctx->end_time = -1;
484
485     rctx->reader_done = 0;
486     rctx->reader =
487       xbt_os_thread_create("reader", thread_reader, (void *) rctx);
488     rctx->writer =
489       xbt_os_thread_create("writer", thread_writer, (void *) rctx);
490
491   } else {                      /* child */
492
493     close(child_in[1]);
494     dup2(child_in[0], 0);
495     close(child_in[0]);
496
497     close(child_out[0]);
498     dup2(child_out[1], 1);
499     dup2(child_out[1], 2);
500     close(child_out[1]);
501
502     start_command(rctx);
503   }
504
505   rctx->is_stoppable = 1;
506
507   if (!rctx->is_background) {
508     rctx_wait(rctx);
509   } else {
510     /* Damn. Copy the rctx and launch a thread to handle it */
511     rctx_t old = rctx;
512     xbt_os_thread_t runner;
513
514     rctx = rctx_new();
515     DEBUG2("RCTX: new bg=%p, new fg=%p", old, rctx);
516
517     DEBUG2("Launch a thread to wait for %s %d", old->cmd, old->pid);
518     runner = xbt_os_thread_create(old->cmd, rctx_wait, (void *) old);
519     old->runner = runner;
520     VERB3("Launched thread %p to wait for %s %d", runner, old->cmd, old->pid);
521     xbt_dynar_push(bg_jobs, &old);
522   }
523 }
524
525 /* Waits for the child to end (or to timeout), and check its
526    ending conditions. This is launched from rctx_start but either in main
527    thread (for foreground jobs) or in a separate one for background jobs.
528    That explains the prototype, forced by xbt_os_thread_create. */
529
530 void *rctx_wait(void *r)
531 {
532   rctx_t rctx = (rctx_t) r;
533   int errcode = 0;
534   int now = time(NULL);
535
536   rctx_dump(rctx, "wait");
537
538   if (!rctx->is_stoppable)
539     THROW1(unknown_error, 0, "Cmd '%s' not started yet. Cannot wait it",
540            rctx->cmd);
541
542   /* Wait for the child to die or the timeout to happen (or an armageddon to happen) */
543   while (!rctx->interrupted && !rctx->reader_done
544          && (rctx->end_time < 0 || rctx->end_time >= now)) {
545     usleep(100);
546     now = time(NULL);
547   }
548
549   xbt_os_mutex_acquire(rctx->interruption);
550   if (!rctx->interrupted && rctx->end_time > 0 && rctx->end_time < now) {
551     INFO1("<%s> timeouted. Kill the process.", rctx->filepos);
552     rctx->timeout = 1;
553     kill(rctx->pid, SIGTERM);
554     usleep(100);
555     kill(rctx->pid, SIGKILL);
556     rctx->reader_done = 1;
557   }
558
559   /* Make sure helper threads die.
560      Cannot block since they wait for the child we just killed
561      if not already dead. */
562   xbt_os_thread_join(rctx->writer, NULL);
563   xbt_os_thread_join(rctx->reader, NULL);
564
565   /*  xbt_os_mutex_release(rctx->interruption);
566      if (rctx->interrupted)
567      return NULL;
568      xbt_os_mutex_acquire(rctx->interruption); */
569
570   xbt_strbuff_chomp(rctx->output_got);
571   xbt_strbuff_chomp(rctx->output_wanted);
572   xbt_strbuff_trim(rctx->output_got);
573   xbt_strbuff_trim(rctx->output_wanted);
574
575   /* Check for broken pipe */
576   if (rctx->brokenpipe)
577     VERB0("Warning: Child did not consume all its input (I got broken pipe)");
578
579   /* Check for timeouts */
580   if (rctx->timeout) {
581     if (rctx->output_got->data[0])
582       INFO2("<%s> Output on timeout:\n%s",
583             rctx->filepos, rctx->output_got->data);
584     else
585       INFO1("<%s> No output before timeout", rctx->filepos);
586     ERROR3("Test suite `%s': NOK (<%s> timeout after %d sec)",
587            testsuite_name, rctx->filepos, timeout_value);
588     DEBUG2("<%s> Interrupted = %d", rctx->filepos, rctx->interrupted);
589     if (!rctx->interrupted) {
590       rctx_armageddon(rctx, 3);
591       return NULL;
592     }
593   }
594
595   DEBUG2("RCTX=%p (pid=%d)", rctx, rctx->pid);
596   DEBUG3("Status(%s|%d)=%d", rctx->cmd, rctx->pid, rctx->status);
597
598   if (!rctx->interrupted) {
599     if (WIFSIGNALED(rctx->status) && !rctx->expected_signal) {
600       ERROR3("Test suite `%s': NOK (<%s> got signal %s)",
601              testsuite_name, rctx->filepos,
602              signal_name(WTERMSIG(rctx->status), NULL));
603       errcode = WTERMSIG(rctx->status) + 4;
604     }
605
606     if (WIFSIGNALED(rctx->status) && rctx->expected_signal &&
607         strcmp(signal_name(WTERMSIG(rctx->status), rctx->expected_signal),
608                rctx->expected_signal)) {
609       ERROR4("Test suite `%s': NOK (%s got signal %s instead of %s)",
610              testsuite_name, rctx->filepos,
611              signal_name(WTERMSIG(rctx->status), rctx->expected_signal),
612              rctx->expected_signal);
613       errcode = WTERMSIG(rctx->status) + 4;
614     }
615
616     if (!WIFSIGNALED(rctx->status) && rctx->expected_signal) {
617       ERROR3("Test suite `%s': NOK (child %s expected signal %s)",
618              testsuite_name, rctx->filepos, rctx->expected_signal);
619       errcode = 5;
620     }
621
622     if (WIFEXITED(rctx->status)
623         && WEXITSTATUS(rctx->status) != rctx->expected_return) {
624       if (rctx->expected_return)
625         ERROR4("Test suite `%s': NOK (<%s> returned code %d instead of %d)",
626                testsuite_name, rctx->filepos,
627                WEXITSTATUS(rctx->status), rctx->expected_return);
628       else
629         ERROR3("Test suite `%s': NOK (<%s> returned code %d)",
630                testsuite_name, rctx->filepos, WEXITSTATUS(rctx->status));
631       errcode = 40 + WEXITSTATUS(rctx->status);
632
633     }
634     rctx->expected_return = 0;
635
636     if (rctx->expected_signal) {
637       free(rctx->expected_signal);
638       rctx->expected_signal = NULL;
639     }
640   }
641   while (rctx->output_got->used
642          && !strncmp(rctx->output_got->data, "TESH_ERROR ",
643                      strlen("TESH_ERROR "))) {
644     int marklen = strlen("TESH_ERROR ");
645     char *endline = strchr(rctx->output_got->data, '\n');
646
647     CRITICAL2("%.*s", (int) (endline - rctx->output_got->data - marklen),
648               rctx->output_got->data + marklen);
649     memmove(rctx->output_got->data, rctx->output_got->data + marklen,
650             rctx->output_got->used - marklen);
651     rctx->output_got->used -= endline - rctx->output_got->data + 1;
652     rctx->output_got->data[rctx->output_got->used] = '\0';
653     errcode = 1;
654   }
655
656   if (rctx->output == e_output_check
657       && (rctx->output_got->used != rctx->output_wanted->used
658           || strcmp(rctx->output_got->data, rctx->output_wanted->data))) {
659     if (XBT_LOG_ISENABLED(tesh, xbt_log_priority_info)) {
660       char *diff =
661         xbt_str_diff(rctx->output_wanted->data, rctx->output_got->data);
662       ERROR2("Output of <%s> mismatch:\n%s", rctx->filepos, diff);
663       free(diff);
664     }
665     ERROR2("Test suite `%s': NOK (<%s> output mismatch)",
666            testsuite_name, rctx->filepos);
667
668     errcode = 2;
669   } else if (rctx->output == e_output_ignore) {
670     INFO1("(ignoring the output of <%s> as requested)", rctx->filepos);
671   } else if (rctx->output == e_output_display) {
672     xbt_dynar_t a = xbt_str_split(rctx->output_got->data, "\n");
673     char *out = xbt_str_join(a, "\n||");
674     xbt_dynar_free(&a);
675     INFO1("Here is the (ignored) command output: \n||%s", out);
676     free(out);
677   } else if ((errcode && errcode != 1) || rctx->interrupted) {
678     /* checking output, and matching */
679     xbt_dynar_t a = xbt_str_split(rctx->output_got->data, "\n");
680     char *out = xbt_str_join(a, "\n||");
681     xbt_dynar_free(&a);
682     INFO2("Output of <%s> so far: \n||%s", rctx->filepos, out);
683     free(out);
684   }
685
686   if (!rctx->is_background) {
687     rctx_empty(rctx);
688   }
689   if (errcode) {
690     if (!rctx->interrupted) {
691       rctx_armageddon(rctx, errcode);
692       return NULL;
693     }
694   }
695
696   xbt_os_mutex_release(rctx->interruption);
697   return NULL;
698 }