Changes in uspace/app/getterm/getterm.c [9d58539:1c635d6] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/getterm/getterm.c
r9d58539 r1c635d6 42 42 #include <str_error.h> 43 43 #include <errno.h> 44 #include <loc.h> 44 45 #include "version.h" 45 46 #include "welcome.h" … … 49 50 static void usage(void) 50 51 { 51 printf("Usage: %s <terminal> [-w] <command> [<arguments...>]\n", APP_NAME); 52 printf("Usage: %s <terminal> <locfs> [--msg] [--wait] -- " 53 "<command> [<arguments...>]\n", APP_NAME); 54 printf(" <terminal> Terminal device\n"); 55 printf(" <locfs> Mount point of locfs\n"); 56 printf(" --msg Print welcome message\n"); 57 printf(" --wait Wait for the terminal to be ready\n"); 52 58 } 53 59 54 static void reopen(FILE **stream, int fd, const char *path, int flags, const char *mode) 60 static void reopen(FILE **stream, int fd, const char *path, int flags, 61 const char *mode) 55 62 { 56 63 if (fclose(*stream)) … … 76 83 int main(int argc, char *argv[]) 77 84 { 78 int rc;79 task_exit_t texit;80 int retval;81 task_id_t id;82 char *fname, *term;83 char **cmd_args;84 bool print_wmsg;85 86 85 argv++; 87 86 argc--; 87 if (argc < 4) { 88 usage(); 89 return 1; 90 } 91 92 char *term = *argv; 93 argv++; 94 argc--; 95 96 char *locfs = *argv; 97 argv++; 98 argc--; 99 100 bool print_msg = false; 101 bool wait = false; 102 103 while ((argc > 0) && (str_cmp(*argv, "--") != 0)) { 104 if (str_cmp(*argv, "--msg") == 0) { 105 print_msg = true; 106 } else if (str_cmp(*argv, "--wait") == 0) { 107 wait = true; 108 } else { 109 usage(); 110 return 2; 111 } 112 113 argv++; 114 argc--; 115 } 116 88 117 if (argc < 1) { 89 118 usage(); 90 return -1;119 return 3; 91 120 } 92 93 if (str_cmp(*argv, "-w") == 0) { 94 print_wmsg = true; 95 argv++; 96 argc--; 97 } else { 98 print_wmsg = false; 121 122 /* Skip "--" */ 123 argv++; 124 argc--; 125 126 char *cmd = *argv; 127 char **args = argv; 128 129 if (wait) { 130 /* Wait for the terminal service to be ready */ 131 service_id_t service_id; 132 int rc = loc_service_get_id(term, &service_id, IPC_FLAG_BLOCKING); 133 if (rc != EOK) { 134 printf("%s: Error waiting on %s (%s)\n", APP_NAME, term, 135 str_error(rc)); 136 return rc; 137 } 99 138 } 100 101 if (argc < 2) {102 usage();103 return -1;104 }105 106 term = *argv++;107 fname = *argv;108 cmd_args = argv;109 139 110 reopen(&stdin, 0, term, O_RDONLY, "r"); 111 reopen(&stdout, 1, term, O_WRONLY, "w"); 112 reopen(&stderr, 2, term, O_WRONLY, "w"); 140 char term_node[LOC_NAME_MAXLEN]; 141 snprintf(term_node, LOC_NAME_MAXLEN, "%s/%s", locfs, term); 142 143 reopen(&stdin, 0, term_node, O_RDONLY, "r"); 144 reopen(&stdout, 1, term_node, O_WRONLY, "w"); 145 reopen(&stderr, 2, term_node, O_WRONLY, "w"); 146 147 if (stdin == NULL) 148 return 4; 149 150 if (stdout == NULL) 151 return 5; 152 153 if (stderr == NULL) 154 return 6; 113 155 114 156 /* … … 118 160 setvbuf(stdout, NULL, _IOLBF, BUFSIZ); 119 161 120 if (stdin == NULL) 121 return -2; 162 version_print(term); 163 if (print_msg) 164 welcome_msg_print(); 122 165 123 if (stdout == NULL)124 return -3;166 task_id_t id; 167 task_wait_t twait; 125 168 126 if (stderr == NULL) 127 return -4; 169 int rc = task_spawnv(&id, &twait, cmd, (const char * const *) args); 170 if (rc != EOK) { 171 printf("%s: Error spawning %s (%s)\n", APP_NAME, cmd, 172 str_error(rc)); 173 return rc; 174 } 128 175 129 version_print(term); 130 if (print_wmsg) 131 welcome_msg_print(); 132 133 rc = task_spawnv(&id, fname, (const char * const *) cmd_args); 176 task_exit_t texit; 177 int retval; 178 rc = task_wait(&twait, &texit, &retval); 134 179 if (rc != EOK) { 135 printf("%s: Error spawning %s (%s)\n", APP_NAME, fname,180 printf("%s: Error waiting for %s (%s)\n", APP_NAME, cmd, 136 181 str_error(rc)); 137 return -5;182 return rc; 138 183 } 139 140 rc = task_wait(id, &texit, &retval); 141 if (rc != EOK) { 142 printf("%s: Error waiting for %s (%s)\n", APP_NAME, fname, 143 str_error(rc)); 144 return -6; 145 } 146 184 147 185 return 0; 148 186 }
Note:
See TracChangeset
for help on using the changeset viewer.