Changeset 593e023 in mainline for uspace/app/getterm/getterm.c
- 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
- File:
-
- 1 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 }
Note:
See TracChangeset
for help on using the changeset viewer.