annotate loadtools/clmain.c @ 1016:a6ca9ee289f7

gsm-fw feature tch-reroute: uplink substitution implemented
author Mychaela Falconia <falcon@ivan.Harhan.ORG>
date Mon, 21 Mar 2016 02:27:51 +0000
parents 837ba1b47478
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
42
5da0cbee2b89 fc-xram tool written, compiles, now needs to be debugged
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1 /*
5da0cbee2b89 fc-xram tool written, compiles, now needs to be debugged
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
2 * This module contains the main() function for the XRAM chain-loading
5da0cbee2b89 fc-xram tool written, compiles, now needs to be debugged
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
3 * utility fc-xram.
5da0cbee2b89 fc-xram tool written, compiles, now needs to be debugged
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
4 */
5da0cbee2b89 fc-xram tool written, compiles, now needs to be debugged
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
5
5da0cbee2b89 fc-xram tool written, compiles, now needs to be debugged
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
6 #include <sys/types.h>
5da0cbee2b89 fc-xram tool written, compiles, now needs to be debugged
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
7 #include <stdint.h>
5da0cbee2b89 fc-xram tool written, compiles, now needs to be debugged
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
8 #include <stdio.h>
5da0cbee2b89 fc-xram tool written, compiles, now needs to be debugged
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
9 #include <stdlib.h>
53
604648026e9c fc-xram: baud rate switching implemented per original intent
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 45
diff changeset
10 #include <termios.h>
42
5da0cbee2b89 fc-xram tool written, compiles, now needs to be debugged
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
11 #include <unistd.h>
53
604648026e9c fc-xram: baud rate switching implemented per original intent
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 45
diff changeset
12 #include "baudrate.h"
42
5da0cbee2b89 fc-xram tool written, compiles, now needs to be debugged
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
13 #include "srecreader.h"
5da0cbee2b89 fc-xram tool written, compiles, now needs to be debugged
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
14
5da0cbee2b89 fc-xram tool written, compiles, now needs to be debugged
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
15 extern char *target_ttydev;
5da0cbee2b89 fc-xram tool written, compiles, now needs to be debugged
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
16 extern struct srecreader iramimage;
5da0cbee2b89 fc-xram tool written, compiles, now needs to be debugged
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
17 extern char default_loadagent_image[];
5da0cbee2b89 fc-xram tool written, compiles, now needs to be debugged
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
18 extern struct srecreader xramimage;
45
16315ed6401a init-script logic implemented in fc-xram
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 42
diff changeset
19 extern char hw_init_script[];
53
604648026e9c fc-xram: baud rate switching implemented per original intent
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 45
diff changeset
20 extern struct baudrate baud_rate_table[];
604648026e9c fc-xram: baud rate switching implemented per original intent
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 45
diff changeset
21 extern struct baudrate *current_baud_rate;
84
ccc5161848c7 loadtools: support building for GTA0x AP
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 55
diff changeset
22 extern int gta_modem_poweron;
53
604648026e9c fc-xram: baud rate switching implemented per original intent
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 45
diff changeset
23
604648026e9c fc-xram: baud rate switching implemented per original intent
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 45
diff changeset
24 extern struct baudrate *find_baudrate_by_name();
604648026e9c fc-xram: baud rate switching implemented per original intent
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 45
diff changeset
25
604648026e9c fc-xram: baud rate switching implemented per original intent
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 45
diff changeset
26 struct baudrate *xram_load_baudrate;
604648026e9c fc-xram: baud rate switching implemented per original intent
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 45
diff changeset
27 struct baudrate *xram_run_baudrate = baud_rate_table; /* 1st entry default */
42
5da0cbee2b89 fc-xram tool written, compiles, now needs to be debugged
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
28
135
e4257294102b fc-xram: execvp of secondary program implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 84
diff changeset
29 char **passon_argv;
e4257294102b fc-xram: execvp of secondary program implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 84
diff changeset
30 int passon_argc;
e4257294102b fc-xram: execvp of secondary program implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 84
diff changeset
31
42
5da0cbee2b89 fc-xram tool written, compiles, now needs to be debugged
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
32 main(argc, argv)
5da0cbee2b89 fc-xram tool written, compiles, now needs to be debugged
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
33 char **argv;
5da0cbee2b89 fc-xram tool written, compiles, now needs to be debugged
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
34 {
5da0cbee2b89 fc-xram tool written, compiles, now needs to be debugged
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
35 extern char *optarg;
5da0cbee2b89 fc-xram tool written, compiles, now needs to be debugged
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
36 extern int optind;
5da0cbee2b89 fc-xram tool written, compiles, now needs to be debugged
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
37 int c;
53
604648026e9c fc-xram: baud rate switching implemented per original intent
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 45
diff changeset
38 struct baudrate *br;
42
5da0cbee2b89 fc-xram tool written, compiles, now needs to be debugged
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
39
381
837ba1b47478 fc-xram: compalstage support hooked in
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
40 while ((c = getopt(argc, argv, "+a:b:B:c:C:h:H:i:nr:")) != EOF)
42
5da0cbee2b89 fc-xram tool written, compiles, now needs to be debugged
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
41 switch (c) {
5da0cbee2b89 fc-xram tool written, compiles, now needs to be debugged
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
42 case 'a':
5da0cbee2b89 fc-xram tool written, compiles, now needs to be debugged
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
43 iramimage.filename = optarg;
5da0cbee2b89 fc-xram tool written, compiles, now needs to be debugged
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
44 continue;
53
604648026e9c fc-xram: baud rate switching implemented per original intent
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 45
diff changeset
45 case 'b':
604648026e9c fc-xram: baud rate switching implemented per original intent
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 45
diff changeset
46 set_romload_baudrate(optarg);
604648026e9c fc-xram: baud rate switching implemented per original intent
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 45
diff changeset
47 continue;
604648026e9c fc-xram: baud rate switching implemented per original intent
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 45
diff changeset
48 case 'B':
604648026e9c fc-xram: baud rate switching implemented per original intent
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 45
diff changeset
49 br = find_baudrate_by_name(optarg);
604648026e9c fc-xram: baud rate switching implemented per original intent
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 45
diff changeset
50 if (!br)
604648026e9c fc-xram: baud rate switching implemented per original intent
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 45
diff changeset
51 exit(1); /* error msg already printed */
604648026e9c fc-xram: baud rate switching implemented per original intent
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 45
diff changeset
52 xram_load_baudrate = br;
604648026e9c fc-xram: baud rate switching implemented per original intent
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 45
diff changeset
53 continue;
381
837ba1b47478 fc-xram: compalstage support hooked in
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
54 case 'c':
837ba1b47478 fc-xram: compalstage support hooked in
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
55 set_compalstage_short(optarg);
837ba1b47478 fc-xram: compalstage support hooked in
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
56 continue;
837ba1b47478 fc-xram: compalstage support hooked in
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
57 case 'C':
837ba1b47478 fc-xram: compalstage support hooked in
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
58 set_compalstage_fullpath(optarg);
837ba1b47478 fc-xram: compalstage support hooked in
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
59 continue;
42
5da0cbee2b89 fc-xram tool written, compiles, now needs to be debugged
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
60 case 'h':
5da0cbee2b89 fc-xram tool written, compiles, now needs to be debugged
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
61 read_hwparam_file_shortname(optarg);
5da0cbee2b89 fc-xram tool written, compiles, now needs to be debugged
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
62 continue;
5da0cbee2b89 fc-xram tool written, compiles, now needs to be debugged
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
63 case 'H':
5da0cbee2b89 fc-xram tool written, compiles, now needs to be debugged
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
64 read_hwparam_file_fullpath(optarg);
5da0cbee2b89 fc-xram tool written, compiles, now needs to be debugged
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
65 continue;
5da0cbee2b89 fc-xram tool written, compiles, now needs to be debugged
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
66 case 'i':
5da0cbee2b89 fc-xram tool written, compiles, now needs to be debugged
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
67 set_beacon_interval(optarg);
5da0cbee2b89 fc-xram tool written, compiles, now needs to be debugged
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
68 continue;
84
ccc5161848c7 loadtools: support building for GTA0x AP
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 55
diff changeset
69 case 'n':
ccc5161848c7 loadtools: support building for GTA0x AP
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 55
diff changeset
70 gta_modem_poweron = 0;
ccc5161848c7 loadtools: support building for GTA0x AP
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 55
diff changeset
71 continue;
135
e4257294102b fc-xram: execvp of secondary program implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 84
diff changeset
72 case 'r':
e4257294102b fc-xram: execvp of secondary program implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 84
diff changeset
73 br = find_baudrate_by_name(optarg);
e4257294102b fc-xram: execvp of secondary program implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 84
diff changeset
74 if (!br)
e4257294102b fc-xram: execvp of secondary program implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 84
diff changeset
75 exit(1); /* error msg already printed */
e4257294102b fc-xram: execvp of secondary program implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 84
diff changeset
76 xram_run_baudrate = br;
e4257294102b fc-xram: execvp of secondary program implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 84
diff changeset
77 continue;
42
5da0cbee2b89 fc-xram tool written, compiles, now needs to be debugged
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
78 case '?':
5da0cbee2b89 fc-xram tool written, compiles, now needs to be debugged
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
79 default:
5da0cbee2b89 fc-xram tool written, compiles, now needs to be debugged
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
80 usage: fprintf(stderr,
135
e4257294102b fc-xram: execvp of secondary program implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 84
diff changeset
81 "usage: fc-xram [options] ttyport xramimage.srec [2ndprog]\n");
42
5da0cbee2b89 fc-xram tool written, compiles, now needs to be debugged
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
82 exit(1);
5da0cbee2b89 fc-xram tool written, compiles, now needs to be debugged
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
83 }
53
604648026e9c fc-xram: baud rate switching implemented per original intent
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 45
diff changeset
84 if (argc - optind < 2)
42
5da0cbee2b89 fc-xram tool written, compiles, now needs to be debugged
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
85 goto usage;
5da0cbee2b89 fc-xram tool written, compiles, now needs to be debugged
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
86 target_ttydev = argv[optind];
5da0cbee2b89 fc-xram tool written, compiles, now needs to be debugged
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
87 xramimage.filename = argv[optind+1];
5da0cbee2b89 fc-xram tool written, compiles, now needs to be debugged
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
88 if (!iramimage.filename)
5da0cbee2b89 fc-xram tool written, compiles, now needs to be debugged
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
89 iramimage.filename = default_loadagent_image;
53
604648026e9c fc-xram: baud rate switching implemented per original intent
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 45
diff changeset
90 if (argc - optind >= 3) {
135
e4257294102b fc-xram: execvp of secondary program implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 84
diff changeset
91 passon_argv = argv + optind + 2;
e4257294102b fc-xram: execvp of secondary program implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 84
diff changeset
92 passon_argc = argc - optind - 2;
53
604648026e9c fc-xram: baud rate switching implemented per original intent
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 45
diff changeset
93 }
42
5da0cbee2b89 fc-xram tool written, compiles, now needs to be debugged
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
94
5da0cbee2b89 fc-xram tool written, compiles, now needs to be debugged
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
95 open_target_serial();
381
837ba1b47478 fc-xram: compalstage support hooked in
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
96 perform_compal_stage(1);
42
5da0cbee2b89 fc-xram tool written, compiles, now needs to be debugged
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
97 perform_romload();
5da0cbee2b89 fc-xram tool written, compiles, now needs to be debugged
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
98 /* loadagent should be running now */
5da0cbee2b89 fc-xram tool written, compiles, now needs to be debugged
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
99 if (tpinterf_pass_output(1) < 0)
5da0cbee2b89 fc-xram tool written, compiles, now needs to be debugged
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
100 exit(1);
45
16315ed6401a init-script logic implemented in fc-xram
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 42
diff changeset
101 if (hw_init_script[0]) {
16315ed6401a init-script logic implemented in fc-xram
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 42
diff changeset
102 printf("Executing init script %s\n", hw_init_script);
16315ed6401a init-script logic implemented in fc-xram
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 42
diff changeset
103 c = exec_init_script(hw_init_script);
16315ed6401a init-script logic implemented in fc-xram
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 42
diff changeset
104 if (c)
16315ed6401a init-script logic implemented in fc-xram
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 42
diff changeset
105 exit(1);
16315ed6401a init-script logic implemented in fc-xram
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 42
diff changeset
106 }
53
604648026e9c fc-xram: baud rate switching implemented per original intent
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 45
diff changeset
107 if (xram_load_baudrate && xram_load_baudrate != current_baud_rate) {
604648026e9c fc-xram: baud rate switching implemented per original intent
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 45
diff changeset
108 c = loadagent_switch_baud(xram_load_baudrate);
604648026e9c fc-xram: baud rate switching implemented per original intent
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 45
diff changeset
109 if (c)
604648026e9c fc-xram: baud rate switching implemented per original intent
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 45
diff changeset
110 exit(1);
604648026e9c fc-xram: baud rate switching implemented per original intent
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 45
diff changeset
111 }
42
5da0cbee2b89 fc-xram tool written, compiles, now needs to be debugged
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
112 printf("Sending XRAM image to loadagent\n");
5da0cbee2b89 fc-xram tool written, compiles, now needs to be debugged
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
113 perform_chain_load();
135
e4257294102b fc-xram: execvp of secondary program implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 84
diff changeset
114 if (passon_argv)
e4257294102b fc-xram: execvp of secondary program implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 84
diff changeset
115 exec_2nd_prog();
42
5da0cbee2b89 fc-xram tool written, compiles, now needs to be debugged
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
116 tty_passthru();
5da0cbee2b89 fc-xram tool written, compiles, now needs to be debugged
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
117 exit(0);
5da0cbee2b89 fc-xram tool written, compiles, now needs to be debugged
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
118 }
135
e4257294102b fc-xram: execvp of secondary program implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 84
diff changeset
119
e4257294102b fc-xram: execvp of secondary program implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 84
diff changeset
120 exec_2nd_prog()
e4257294102b fc-xram: execvp of secondary program implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 84
diff changeset
121 {
e4257294102b fc-xram: execvp of secondary program implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 84
diff changeset
122 char **execp_argv;
e4257294102b fc-xram: execvp of secondary program implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 84
diff changeset
123 char **sp, **dp;
e4257294102b fc-xram: execvp of secondary program implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 84
diff changeset
124 extern int target_fd;
e4257294102b fc-xram: execvp of secondary program implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 84
diff changeset
125 char desc_arg[16];
e4257294102b fc-xram: execvp of secondary program implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 84
diff changeset
126
e4257294102b fc-xram: execvp of secondary program implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 84
diff changeset
127 sprintf(desc_arg, "-d%d", target_fd);
e4257294102b fc-xram: execvp of secondary program implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 84
diff changeset
128 execp_argv = (char **) malloc(sizeof(char *) * (passon_argc + 2));
e4257294102b fc-xram: execvp of secondary program implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 84
diff changeset
129 if (!execp_argv) {
e4257294102b fc-xram: execvp of secondary program implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 84
diff changeset
130 perror("malloc argv for execvp");
e4257294102b fc-xram: execvp of secondary program implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 84
diff changeset
131 exit(1);
e4257294102b fc-xram: execvp of secondary program implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 84
diff changeset
132 }
e4257294102b fc-xram: execvp of secondary program implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 84
diff changeset
133 sp = passon_argv;
e4257294102b fc-xram: execvp of secondary program implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 84
diff changeset
134 dp = execp_argv;
e4257294102b fc-xram: execvp of secondary program implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 84
diff changeset
135 *dp++ = *sp++;
e4257294102b fc-xram: execvp of secondary program implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 84
diff changeset
136 *dp++ = desc_arg;
e4257294102b fc-xram: execvp of secondary program implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 84
diff changeset
137 while (*sp)
e4257294102b fc-xram: execvp of secondary program implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 84
diff changeset
138 *dp++ = *sp++;
e4257294102b fc-xram: execvp of secondary program implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 84
diff changeset
139 *dp = NULL;
e4257294102b fc-xram: execvp of secondary program implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 84
diff changeset
140 execvp(execp_argv[0], execp_argv);
e4257294102b fc-xram: execvp of secondary program implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 84
diff changeset
141 fprintf(stderr, "Unable to execvp %s\n", passon_argv[0]);
e4257294102b fc-xram: execvp of secondary program implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 84
diff changeset
142 exit(1);
e4257294102b fc-xram: execvp of secondary program implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 84
diff changeset
143 }