Changeset 7259317 in mainline


Ignore:
Timestamp:
2016-12-23T21:21:20Z (7 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
00130656
Parents:
a91d719
Message:

Wait only for the serial console service specified by the user

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/hid/output/port/chardev.c

    ra91d719 r7259317  
    3939#include <errno.h>
    4040#include <str.h>
     41#include <sysinfo.h>
    4142#include "../ctl/serial.h"
    4243#include "../output.h"
    4344#include "chardev.h"
     45
     46static char *console;
    4447
    4548static async_sess_t *sess;
     
    6164}
    6265
     66/*
     67 * This callback scans all the services in the 'serial' category, hoping to see
     68 * the single one the user wishes to use as a serial console. If it spots it, it
     69 * connects to it and registers it as an output device. Then it ublocks the
     70 * fibril blocked in chardev_init().
     71 */
    6372static void check_for_dev(void)
    6473{
    6574        int rc;
    6675
    67         if (sess)
     76        fibril_mutex_lock(&discovery_lock);
     77        if (discovery_finished) {
     78                // TODO: no need to receive these callbacks anymore
     79                fibril_mutex_unlock(&discovery_lock);
    6880                return;
     81        }
    6982
    7083        service_id_t *svc;
     
    7285        rc = loc_category_get_svcs(serial_cat_id, &svc, &svcs);
    7386        if (rc != EOK) {
     87                fibril_mutex_unlock(&discovery_lock);
    7488                printf("%s: Failed to get services\n", NAME);
    7589                return;
    7690        }
    7791
    78         if (svcs < 1) {
    79                 free(svc);
     92        service_id_t sid;
     93        bool found = false;
     94
     95        for (size_t i = 0; i < svcs && !found; i++) {
     96                char *name;
     97               
     98                rc = loc_service_get_name(svc[i], &name);
     99                if (rc != EOK)
     100                        continue;
     101
     102                if (!str_cmp(console, name)) {
     103                        /*
     104                         * This is the serial console service that the user
     105                         * wanted to use.
     106                         */
     107                        found = true;
     108                        sid = svc[i];
     109                }
     110                       
     111                free(name);
     112        }
     113
     114        free(svc);
     115
     116        if (!found) {
     117                fibril_mutex_unlock(&discovery_lock);
    80118                return;
    81119        }
    82120
    83         service_id_t sid = svc[0];
    84         free(svc);
    85 
    86121        sess = loc_service_connect(sid, INTERFACE_DDF, IPC_FLAG_BLOCKING);
    87122        if (!sess) {
     123                fibril_mutex_unlock(&discovery_lock);
    88124                printf("%s: Failed connecting to device\n", NAME);
    89125                return;
     
    91127        serial_init(chardev_putchar, chardev_control_puts);
    92128
    93         fibril_mutex_lock(&discovery_lock);
    94129        discovery_finished = true;
    95130        fibril_condvar_signal(&discovery_cv);
     
    99134int chardev_init(void)
    100135{
     136        char *boot_args;
     137        size_t size;
    101138        int rc;
     139
     140        boot_args = sysinfo_get_data("boot_args", &size);
     141        if (!boot_args || !size) {
     142                /*
     143                 * Ok, there is nothing in the boot arguments. That means that
     144                 * the user did not specify a serial console device.
     145                 */
     146                return EOK;
     147        }
     148
     149        char *args = boot_args;
     150        char *arg;
     151#define ARG_CONSOLE     "console="
     152        while ((arg = str_tok(args, " ", &args)) != NULL) {
     153                if (!str_lcmp(arg, ARG_CONSOLE, str_length(ARG_CONSOLE))) {
     154                        console = arg + str_length(ARG_CONSOLE);
     155                        break;
     156                }
     157        }
    102158
    103159        rc = loc_category_get_id("serial", &serial_cat_id, IPC_FLAG_BLOCKING);
Note: See TracChangeset for help on using the changeset viewer.