Mercurial > dropbear
comparison scp.c @ 273:02a80ce2ead4
Merge of the uClinux-dist patch, should work in inetd mode
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Tue, 28 Feb 2006 04:03:49 +0000 |
parents | 161557a9dde8 |
children | 92cc938b59a2 |
comparison
equal
deleted
inserted
replaced
266:e37b160c414c | 273:02a80ce2ead4 |
---|---|
164 | 164 |
165 /* Free the reserved descriptors. */ | 165 /* Free the reserved descriptors. */ |
166 close(reserved[0]); | 166 close(reserved[0]); |
167 close(reserved[1]); | 167 close(reserved[1]); |
168 | 168 |
169 // uClinux needs to build the args here before vforking, | |
170 // otherwise we do it later on. | |
171 #ifdef __uClinux__ | |
172 args.list[0] = ssh_program; | |
173 if (remuser != NULL) | |
174 addargs(&args, "-l%s", remuser); | |
175 addargs(&args, "%s", host); | |
176 addargs(&args, "%s", cmd); | |
177 #endif /* __uClinux__ */ | |
178 | |
169 /* Fork a child to execute the command on the remote host using ssh. */ | 179 /* Fork a child to execute the command on the remote host using ssh. */ |
180 #ifdef __uClinux__ | |
181 do_cmd_pid = vfork(); | |
182 #else | |
170 do_cmd_pid = fork(); | 183 do_cmd_pid = fork(); |
184 #endif /* __uClinux__ */ | |
171 if (do_cmd_pid == 0) { | 185 if (do_cmd_pid == 0) { |
172 /* Child. */ | 186 /* Child. */ |
173 close(pin[1]); | 187 close(pin[1]); |
174 close(pout[0]); | 188 close(pout[0]); |
175 dup2(pin[0], 0); | 189 dup2(pin[0], 0); |
176 dup2(pout[1], 1); | 190 dup2(pout[1], 1); |
177 close(pin[0]); | 191 close(pin[0]); |
178 close(pout[1]); | 192 close(pout[1]); |
179 | 193 |
194 #ifndef __uClinux__ | |
180 args.list[0] = ssh_program; | 195 args.list[0] = ssh_program; |
181 if (remuser != NULL) { | 196 if (remuser != NULL) { |
182 addargs(&args, "-l"); | 197 addargs(&args, "-l"); |
183 addargs(&args, "%s", remuser); | 198 addargs(&args, "%s", remuser); |
184 } | 199 } |
185 addargs(&args, "%s", host); | 200 addargs(&args, "%s", host); |
186 addargs(&args, "%s", cmd); | 201 addargs(&args, "%s", cmd); |
202 #endif | |
187 | 203 |
188 execvp(ssh_program, args.list); | 204 execvp(ssh_program, args.list); |
189 perror(ssh_program); | 205 perror(ssh_program); |
190 exit(1); | 206 exit(1); |
191 } else if (do_cmd_pid == -1) { | 207 } else if (do_cmd_pid == -1) { |
192 fprintf(stderr, "Fatal error: fork: %s\n", strerror(errno)); | 208 fprintf(stderr, "Fatal error: fork: %s\n", strerror(errno)); |
193 exit(1); | 209 exit(1); |
194 } | 210 } |
211 | |
212 #ifdef __uClinux__ | |
213 /* clean up command */ | |
214 /* pop cmd */ | |
215 free(args->list[--args->num]); | |
216 args->list[args->num]=NULL; | |
217 /* pop host */ | |
218 free(args->list[--args->num-1]); | |
219 args->list[args->num]=NULL; | |
220 /* pop user */ | |
221 if (remuser != NULL) { | |
222 free(args->list[--args->num-1]); | |
223 args->list[args->num]=NULL; | |
224 } | |
225 #endif /* __uClinux__ | |
226 | |
195 /* Parent. Close the other side, and return the local side. */ | 227 /* Parent. Close the other side, and return the local side. */ |
196 close(pin[0]); | 228 close(pin[0]); |
197 *fdout = pin[1]; | 229 *fdout = pin[1]; |
198 close(pout[1]); | 230 close(pout[1]); |
199 *fdin = pout[0]; | 231 *fdin = pout[0]; |