Changes in uspace/app/getvc/getvc.c [adb49f58:c7dc8ad] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/getvc/getvc.c
radb49f58 rc7dc8ad 36 36 37 37 #include <sys/types.h> 38 #include <fcntl.h> 38 39 #include <unistd.h> 39 40 #include <stdio.h> … … 46 47 } 47 48 48 static void closeall(void)49 static void reopen(FILE **stream, int fd, const char *path, int flags, const char *mode) 49 50 { 50 fclose(stdin); 51 fclose(stdout); 52 fclose(stderr); 51 if (fclose(*stream)) 52 return; 53 53 54 close(0); 55 close(1); 56 close(2); 54 *stream = NULL; 55 56 int oldfd = open(path, flags); 57 if (oldfd < 0) 58 return; 59 60 if (oldfd != fd) { 61 if (dup2(oldfd, fd) != fd) 62 return; 63 64 if (close(oldfd)) 65 return; 66 } 67 68 *stream = fdopen(fd, mode); 57 69 } 58 70 59 71 static task_id_t spawn(char *fname) 60 72 { 61 char *arg v[2];73 char *args[2]; 62 74 63 arg v[0] = fname;64 arg v[1] = NULL;75 args[0] = fname; 76 args[1] = NULL; 65 77 66 task_id_t id = task_spawn(fname, arg v);78 task_id_t id = task_spawn(fname, args); 67 79 68 80 if (id == 0) … … 74 86 int main(int argc, char *argv[]) 75 87 { 76 task_exit_t texit;77 int retval;78 79 88 if (argc < 3) { 80 89 usage(); … … 82 91 } 83 92 84 closeall(); 93 reopen(&stdin, 0, argv[1], O_RDONLY, "r"); 94 reopen(&stdout, 1, argv[1], O_WRONLY, "w"); 95 reopen(&stderr, 2, argv[1], O_WRONLY, "w"); 85 96 86 stdin = fopen(argv[1], "r");87 stdout = fopen(argv[1], "w");88 stderr = fopen(argv[1], "w");89 90 97 /* 91 * FIXME: f open() should actually detect that we are opening a console98 * FIXME: fdopen() should actually detect that we are opening a console 92 99 * and it should set line-buffering mode automatically. 93 100 */ 94 101 setvbuf(stdout, NULL, _IOLBF, BUFSIZ); 95 102 96 if ((stdin == NULL) 97 || (stdout == NULL) 98 || (stderr == NULL)) 103 if (stdin == NULL) 99 104 return -2; 105 106 if (stdout == NULL) 107 return -3; 108 109 if (stderr == NULL) 110 return -4; 100 111 101 112 version_print(argv[1]); 102 113 task_id_t id = spawn(argv[2]); 103 task_wait(id, &texit, &retval);104 114 105 return 0; 115 if (id != 0) { 116 task_exit_t texit; 117 int retval; 118 task_wait(id, &texit, &retval); 119 120 return 0; 121 } 122 123 return -5; 106 124 } 107 125
Note:
See TracChangeset
for help on using the changeset viewer.