| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame^] | 1 | #include <stdio.h> |
| 2 | #include <unistd.h> |
| 3 | #include <errno.h> |
| 4 | #include <string.h> |
| 5 | |
| 6 | #include "ltrace.h" |
| 7 | #include "options.h" |
| 8 | #include "output.h" |
| 9 | #include "sysdep.h" |
| 10 | |
| 11 | void execute_program(struct process * sp, char **argv) |
| 12 | { |
| 13 | int pid; |
| 14 | |
| 15 | if (opt_d) { |
| 16 | output_line(0, "Executing `%s'...", sp->filename); |
| 17 | } |
| 18 | |
| 19 | pid = fork(); |
| 20 | if (pid<0) { |
| 21 | perror("fork"); |
| 22 | exit(1); |
| 23 | } else if (!pid) { /* child */ |
| 24 | trace_me(); |
| 25 | execvp(sp->filename, argv); |
| 26 | fprintf(stderr, "Can't execute `%s': %s\n", sp->filename, strerror(errno)); |
| 27 | exit(1); |
| 28 | } |
| 29 | |
| 30 | if (opt_d) { |
| 31 | output_line(0, "PID=%d", pid); |
| 32 | } |
| 33 | |
| 34 | sp->pid = pid; |
| 35 | |
| 36 | return; |
| 37 | } |