Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Huge code cleanup + implementation of the background commands. Damn thing, that was...
[simgrid.git] / tools / tesh / run_context.h
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 #ifndef TESH_RUN_CONTEXT_H
12 #define TESH_RUN_CONTEXT_H
13
14 #include "tesh.h"
15
16 typedef struct {
17   /* kind of job */
18   char *cmd;
19   int pid;
20   int is_background:1;
21   int is_empty:1;
22   int is_stoppable:1;
23   int check_output:1;
24   
25   int brokenpipe:1;
26   int timeout:1;
27
28   int reader_done:1; /* reader set this to true when he's done because
29                         the child is dead. The main thread use it to detect
30                         that the child is not dead before the end of timeout */
31
32   /* expected results */
33   int end_time; /* begin_time + timeout, as epoch */
34   char* expected_signal; /* name of signal to raise (or NULL if none) */
35   int expected_return; /* the exepeted return code of following command */
36
37   /* buffers */
38   buff_t input;
39   buff_t output_wanted;
40   buff_t output_got;
41
42   /* Threads */
43   xbt_thread_t writer, reader; /* IO handlers */
44
45   /* Pipes from/to the child */
46   int child_to, child_from;
47
48 } s_rctx_t, *rctx_t;
49
50 /* module mgmt */
51 void rctx_init(void);
52 void rctx_exit(void);
53    
54 /* wait for all currently running background jobs */
55 void rctx_wait_bg(void);
56
57 /* create a new empty running context */
58 rctx_t rctx_new(void);
59 void rctx_free(rctx_t rctx);
60 void rctx_empty(rctx_t rc); /*reset to empty*/
61 void rctx_dump(rctx_t rctx,const char *str);
62    
63    
64 /* Launch the current command */
65 void rctx_start(void);
66 /* Wait till the end of this command */
67 void *rctx_wait(void* rctx);
68
69 /* Parse a line comming from the suite file, and add this into the rctx */
70 void rctx_pushline(const char* filepos, char kind ,char *line);
71
72 #endif /* TESH_RUN_CONTEXT_H */