Changeset 593e023 in mainline for uspace/app
- Timestamp:
- 2014-08-12T17:14:32Z (11 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- c3bdc92
- Parents:
- ce3efa0
- Location:
- uspace/app
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/getterm/getterm.c
rce3efa0 r593e023 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"); 113 146 114 147 if (stdin == NULL) 115 return -2;148 return 4; 116 149 117 150 if (stdout == NULL) 118 return -3;151 return 5; 119 152 120 153 if (stderr == NULL) 121 return -4;154 return 6; 122 155 123 156 /* … … 128 161 129 162 version_print(term); 130 if (print_ wmsg)163 if (print_msg) 131 164 welcome_msg_print(); 132 133 rc = task_spawnv(&id, fname, (const char * const *) cmd_args); 165 166 task_id_t id; 167 168 int rc = task_spawnv(&id, cmd, (const char * const *) args); 134 169 if (rc != EOK) { 135 printf("%s: Error spawning %s (%s)\n", APP_NAME, fname,170 printf("%s: Error spawning %s (%s)\n", APP_NAME, cmd, 136 171 str_error(rc)); 137 return -5;172 return rc; 138 173 } 139 174 175 task_exit_t texit; 176 int retval; 140 177 rc = task_wait(id, &texit, &retval); 141 178 if (rc != EOK) { 142 printf("%s: Error waiting for %s (%s)\n", APP_NAME, fname,179 printf("%s: Error waiting for %s (%s)\n", APP_NAME, cmd, 143 180 str_error(rc)); 144 return -6;181 return rc; 145 182 } 146 183 147 184 return 0; 148 185 } -
uspace/app/init/init.c
rce3efa0 r593e023 272 272 } 273 273 274 static void getterm(const char *svc, const char *app, bool wmsg) 275 { 276 char term[LOC_NAME_MAXLEN]; 277 snprintf(term, LOC_NAME_MAXLEN, "%s/%s", LOCFS_MOUNT_POINT, svc); 278 279 printf("%s: Spawning %s %s %s\n", NAME, APP_GETTERM, term, app); 280 281 /* Wait for the terminal service to be ready */ 282 service_id_t service_id; 283 int rc = loc_service_get_id(svc, &service_id, IPC_FLAG_BLOCKING); 284 if (rc != EOK) { 285 printf("%s: Error waiting on %s (%s)\n", NAME, term, 286 str_error(rc)); 287 return; 288 } 289 290 if (wmsg) { 291 rc = task_spawnl(NULL, APP_GETTERM, APP_GETTERM, "-w", term, 292 app, NULL); 293 if (rc != EOK) { 294 printf("%s: Error spawning %s -w %s %s (%s)\n", NAME, 295 APP_GETTERM, term, app, str_error(rc)); 296 } 274 static void getterm(const char *svc, const char *app, bool msg) 275 { 276 if (msg) { 277 printf("%s: Spawning %s %s %s --msg --wait -- %s\n", NAME, 278 APP_GETTERM, svc, LOCFS_MOUNT_POINT, app); 279 280 int rc = task_spawnl(NULL, APP_GETTERM, APP_GETTERM, svc, 281 LOCFS_MOUNT_POINT, "--msg", "--wait", "--", app, NULL); 282 if (rc != EOK) 283 printf("%s: Error spawning %s %s %s --msg --wait -- %s\n", 284 NAME, APP_GETTERM, svc, LOCFS_MOUNT_POINT, app); 297 285 } else { 298 rc = task_spawnl(NULL, APP_GETTERM, APP_GETTERM, term, app, 299 NULL); 300 if (rc != EOK) { 301 printf("%s: Error spawning %s %s %s (%s)\n", NAME, 302 APP_GETTERM, term, app, str_error(rc)); 303 } 286 printf("%s: Spawning %s %s %s --wait -- %s\n", NAME, 287 APP_GETTERM, svc, LOCFS_MOUNT_POINT, app); 288 289 int rc = task_spawnl(NULL, APP_GETTERM, APP_GETTERM, svc, 290 LOCFS_MOUNT_POINT, "--wait", "--", app, NULL); 291 if (rc != EOK) 292 printf("%s: Error spawning %s %s %s --wait -- %s\n", 293 NAME, APP_GETTERM, svc, LOCFS_MOUNT_POINT, app); 304 294 } 305 295 } … … 364 354 gui_start("/app/vlaunch", HID_COMPOSITOR_SERVER); 365 355 gui_start("/app/vterm", HID_COMPOSITOR_SERVER); 366 } else { 367 rc = console(HID_INPUT, HID_OUTPUT); 368 if (rc == EOK) { 369 getterm("term/vc0", "/app/bdsh", true); 370 getterm("term/vc1", "/app/bdsh", false); 371 getterm("term/vc2", "/app/bdsh", false); 372 getterm("term/vc3", "/app/bdsh", false); 373 getterm("term/vc4", "/app/bdsh", false); 374 getterm("term/vc5", "/app/bdsh", false); 375 getterm("term/vc6", "/app/klog", false); 376 } 356 } 357 358 rc = console(HID_INPUT, HID_OUTPUT); 359 if (rc == EOK) { 360 getterm("term/vc0", "/app/bdsh", true); 361 getterm("term/vc1", "/app/bdsh", false); 362 getterm("term/vc2", "/app/bdsh", false); 363 getterm("term/vc3", "/app/bdsh", false); 364 getterm("term/vc4", "/app/bdsh", false); 365 getterm("term/vc5", "/app/bdsh", false); 377 366 } 378 367
Note:
See TracChangeset
for help on using the changeset viewer.