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