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