Changeset 593e023 in mainline for uspace/app/getterm/getterm.c


Ignore:
Timestamp:
2014-08-12T17:14:32Z (10 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
c3bdc92
Parents:
ce3efa0
Message:

allow compositor and console to coexist side-by-side, use the input server as a poor man's seat arbitrator

  • kernel console notifies both about the release and grab events
  • input server arbitrates the seat selection between kernel console and any number of user space UIs (currently the console server and the compositor server)
  • input port yield and reclaim methods have been removed (they are used only on Ski and Niagara, both already need a more generic mechanism for the kernel/user space cooperation)
  • console and compositor server keep track of the kernel console via the input arbitration
  • move the waiting for a character device from init and terminal widget to getterm
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/getterm/getterm.c

    rce3efa0 r593e023  
    4242#include <str_error.h>
    4343#include <errno.h>
     44#include <loc.h>
    4445#include "version.h"
    4546#include "welcome.h"
     
    4950static void usage(void)
    5051{
    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");
    5258}
    5359
    54 static void reopen(FILE **stream, int fd, const char *path, int flags, const char *mode)
     60static void reopen(FILE **stream, int fd, const char *path, int flags,
     61    const char *mode)
    5562{
    5663        if (fclose(*stream))
     
    7683int main(int argc, char *argv[])
    7784{
    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 
    8685        argv++;
    8786        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       
    88117        if (argc < 1) {
    89118                usage();
    90                 return -1;
     119                return 3;
    91120        }
    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                }
    99138        }
    100 
    101         if (argc < 2) {
    102                 usage();
    103                 return -1;
    104         }
    105 
    106         term = *argv++;
    107         fname = *argv;
    108         cmd_args = argv;
    109139       
    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");
    113146       
    114147        if (stdin == NULL)
    115                 return -2;
     148                return 4;
    116149       
    117150        if (stdout == NULL)
    118                 return -3;
     151                return 5;
    119152       
    120153        if (stderr == NULL)
    121                 return -4;
     154                return 6;
    122155       
    123156        /*
     
    128161       
    129162        version_print(term);
    130         if (print_wmsg)
     163        if (print_msg)
    131164                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);
    134169        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,
    136171                    str_error(rc));
    137                 return -5;
     172                return rc;
    138173        }
    139 
     174       
     175        task_exit_t texit;
     176        int retval;
    140177        rc = task_wait(id, &texit, &retval);
    141178        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,
    143180                    str_error(rc));
    144                 return -6;
     181                return rc;
    145182        }
    146 
     183       
    147184        return 0;
    148185}
Note: See TracChangeset for help on using the changeset viewer.