comparison loadtools/secondprog.c @ 204:064d4eedb3a6

loadtools: second program invokation support added to fc-iram like in fc-xram
author Mychaela Falconia <falcon@freecalypso.org>
date Mon, 01 May 2017 21:54:58 +0000
parents
children
comparison
equal deleted inserted replaced
203:f2dde45ba378 204:064d4eedb3a6
1 /*
2 * This module contains the code for passing the serial channel to a
3 * second program, used by fc-iram and fc-xram.
4 */
5
6 #include <stdio.h>
7 #include <stdlib.h>
8 #include <unistd.h>
9
10 extern char **passon_argv;
11 extern int passon_argc;
12
13 exec_2nd_prog()
14 {
15 char **execp_argv;
16 char **sp, **dp;
17 extern int target_fd;
18 char desc_arg[16];
19
20 sprintf(desc_arg, "-d%d", target_fd);
21 execp_argv = (char **) malloc(sizeof(char *) * (passon_argc + 2));
22 if (!execp_argv) {
23 perror("malloc argv for execvp");
24 exit(1);
25 }
26 sp = passon_argv;
27 dp = execp_argv;
28 *dp++ = *sp++;
29 *dp++ = desc_arg;
30 while (*sp)
31 *dp++ = *sp++;
32 *dp = NULL;
33 execvp(execp_argv[0], execp_argv);
34 fprintf(stderr, "Unable to execvp %s\n", passon_argv[0]);
35 exit(1);
36 }