Logo AND Algorithmique Numérique Distribuée

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