9 #define HOME "/home/julia/coccinelle/tools/distributed/"
12 void do_child(int id
, unsigned int argc
, char **argv
, int max
,
15 char **new_args
= malloc(sizeof(char*) * (argc
+ 5));
16 char string1
[50],string2
[50];
17 for(i
=1; i
!=argc
; i
++) {
18 new_args
[i
+4] = argv
[i
];
21 new_args
[0] = "nothing";
22 new_args
[1] = new_args
[5]; // cocci file must be first
23 new_args
[2] = "-index";
24 sprintf(string1
, "%d", id
);
25 new_args
[3] = string1
; // processor number must be third
27 sprintf(string2
, "%d", max
);
28 new_args
[5] = string2
;
29 execvp(script
,new_args
);
30 printf("tried to execute %s\n",HOME
"spatch_linux_script");
31 perror("exec failure");
35 void cleanup(char **argv
) {
36 char **new_args
= malloc(sizeof(char*) * 3);
37 new_args
[0] = "nothing";
38 new_args
[1] = argv
[1];
40 printf ("doing cleanup on %s\n",argv
[1]);
41 execvp(HOME
"cleanup",new_args
);
44 int main(unsigned int argc
, char **argv
) {
47 // interpret the arguments
49 if (!strcmp(argv
[1],"-processes")) {max
= atoi(argv
[2]); start
= 2;}
50 if (!strcmp(argv
[1],"-script")) {
52 strcat(script
,argv
[2]);
54 } else strcpy(script
,HOME
"spatch_linux_script");
55 if (!strcmp(argv
[1],"--help")) {
56 printf("spatch_linux [-processes n] foo.cocci ...\n");
60 // run the child processes
65 do_child(i
,argc
-start
,&argv
[start
],max
,script
);
68 // printf("Child born: %d\n", pid);
71 printf("*** forking error ***\n");
76 // printf("Child dead: %d -- %d\n", pid,status);
78 cleanup(&argv
[start
]);