Fork us on GitHub Follow us on Facebook Follow us on Twitter

Changeset 7034b443 in mainline


Ignore:
Timestamp:
2012-08-16T12:02:53Z (8 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
master
Children:
717a0aa
Parents:
494f417
Message:

Move common code to separate function

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/generic/io/logctl.c

    r494f417 r7034b443  
    4545static async_sess_t *logger_session = NULL;
    4646
    47 static int connect_to_logger()
     47static int start_logger_exchange(async_exch_t **exchange_out)
    4848{
    49         if (logger_session != NULL)
    50                 return EOK;
     49        assert(exchange_out != NULL);
    5150
    52         logger_session = service_connect_blocking(EXCHANGE_SERIALIZE,
    53             SERVICE_LOGGER, LOGGER_INTERFACE_CONTROL, 0);
    54         if (logger_session == NULL)
     51        if (logger_session == NULL) {
     52                logger_session = service_connect_blocking(EXCHANGE_SERIALIZE,
     53                    SERVICE_LOGGER, LOGGER_INTERFACE_CONTROL, 0);
     54                if (logger_session == NULL)
     55                        return ENOMEM;
     56        }
     57
     58        assert(logger_session != NULL);
     59
     60        async_exch_t *exchange = async_exchange_begin(logger_session);
     61        if (exchange == NULL)
    5562                return ENOMEM;
     63
     64        *exchange_out = exchange;
    5665
    5766        return EOK;
     
    6170int logctl_set_default_level(log_level_t new_level)
    6271{
    63         int rc = connect_to_logger();
     72        async_exch_t *exchange = NULL;
     73        int rc = start_logger_exchange(&exchange);
    6474        if (rc != EOK)
    6575                return rc;
    66 
    67         async_exch_t *exchange = async_exchange_begin(logger_session);
    68         if (exchange == NULL)
    69                 return ENOMEM;
    7076
    7177        rc = (int) async_req_1_0(exchange,
     
    7985int logctl_set_namespace_level(const char *namespace, log_level_t new_level)
    8086{
    81         int rc = connect_to_logger();
     87        async_exch_t *exchange = NULL;
     88        int rc = start_logger_exchange(&exchange);
    8289        if (rc != EOK)
    8390                return rc;
    84 
    85         async_exch_t *exchange = async_exchange_begin(logger_session);
    86         if (exchange == NULL)
    87                 return ENOMEM;
    8891
    8992        aid_t reg_msg = async_send_1(exchange, LOGGER_CTL_SET_NAMESPACE_LEVEL,
Note: See TracChangeset for help on using the changeset viewer.