[669f5cae] | 1 | /*
|
---|
| 2 | * Copyright (c) 2012 Vojtech Horky
|
---|
| 3 | * All rights reserved.
|
---|
| 4 | *
|
---|
| 5 | * Redistribution and use in source and binary forms, with or without
|
---|
| 6 | * modification, are permitted provided that the following conditions
|
---|
| 7 | * are met:
|
---|
| 8 | *
|
---|
| 9 | * - Redistributions of source code must retain the above copyright
|
---|
| 10 | * notice, this list of conditions and the following disclaimer.
|
---|
| 11 | * - Redistributions in binary form must reproduce the above copyright
|
---|
| 12 | * notice, this list of conditions and the following disclaimer in the
|
---|
| 13 | * documentation and/or other materials provided with the distribution.
|
---|
| 14 | * - The name of the author may not be used to endorse or promote products
|
---|
| 15 | * derived from this software without specific prior written permission.
|
---|
| 16 | *
|
---|
| 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
| 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
| 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
| 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
| 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
| 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
| 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
| 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
| 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
| 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
| 27 | */
|
---|
| 28 |
|
---|
| 29 | /** @addtogroup libc
|
---|
| 30 | * @{
|
---|
| 31 | */
|
---|
| 32 |
|
---|
| 33 | #include <assert.h>
|
---|
| 34 | #include <unistd.h>
|
---|
| 35 | #include <errno.h>
|
---|
| 36 | #include <io/logctl.h>
|
---|
| 37 | #include <ipc/logger.h>
|
---|
[b52dd1de] | 38 | #include <sysinfo.h>
|
---|
[669f5cae] | 39 | #include <ns.h>
|
---|
[04da852] | 40 | #include <str.h>
|
---|
[669f5cae] | 41 |
|
---|
| 42 | /** IPC session with the logger service. */
|
---|
| 43 | static async_sess_t *logger_session = NULL;
|
---|
| 44 |
|
---|
[7034b443] | 45 | static int start_logger_exchange(async_exch_t **exchange_out)
|
---|
[669f5cae] | 46 | {
|
---|
[7034b443] | 47 | assert(exchange_out != NULL);
|
---|
[669f5cae] | 48 |
|
---|
[7034b443] | 49 | if (logger_session == NULL) {
|
---|
| 50 | logger_session = service_connect_blocking(EXCHANGE_SERIALIZE,
|
---|
| 51 | SERVICE_LOGGER, LOGGER_INTERFACE_CONTROL, 0);
|
---|
| 52 | if (logger_session == NULL)
|
---|
| 53 | return ENOMEM;
|
---|
| 54 | }
|
---|
| 55 |
|
---|
| 56 | assert(logger_session != NULL);
|
---|
| 57 |
|
---|
| 58 | async_exch_t *exchange = async_exchange_begin(logger_session);
|
---|
| 59 | if (exchange == NULL)
|
---|
[669f5cae] | 60 | return ENOMEM;
|
---|
| 61 |
|
---|
[7034b443] | 62 | *exchange_out = exchange;
|
---|
| 63 |
|
---|
[669f5cae] | 64 | return EOK;
|
---|
| 65 | }
|
---|
| 66 |
|
---|
| 67 |
|
---|
| 68 | int logctl_set_default_level(log_level_t new_level)
|
---|
| 69 | {
|
---|
[7034b443] | 70 | async_exch_t *exchange = NULL;
|
---|
| 71 | int rc = start_logger_exchange(&exchange);
|
---|
[669f5cae] | 72 | if (rc != EOK)
|
---|
| 73 | return rc;
|
---|
| 74 |
|
---|
| 75 | rc = (int) async_req_1_0(exchange,
|
---|
| 76 | LOGGER_CTL_SET_DEFAULT_LEVEL, new_level);
|
---|
| 77 |
|
---|
| 78 | async_exchange_end(exchange);
|
---|
| 79 |
|
---|
| 80 | return rc;
|
---|
| 81 | }
|
---|
| 82 |
|
---|
[f50a756] | 83 | int logctl_set_top_log_level(const char *namespace, log_level_t new_level)
|
---|
[494f417] | 84 | {
|
---|
[7034b443] | 85 | async_exch_t *exchange = NULL;
|
---|
| 86 | int rc = start_logger_exchange(&exchange);
|
---|
[494f417] | 87 | if (rc != EOK)
|
---|
| 88 | return rc;
|
---|
| 89 |
|
---|
[cba45af] | 90 | aid_t reg_msg = async_send_1(exchange, LOGGER_CTL_SET_TOP_LOG_LEVEL,
|
---|
[494f417] | 91 | new_level, NULL);
|
---|
| 92 | rc = async_data_write_start(exchange, namespace, str_size(namespace));
|
---|
| 93 | sysarg_t reg_msg_rc;
|
---|
| 94 | async_wait_for(reg_msg, ®_msg_rc);
|
---|
| 95 |
|
---|
| 96 | async_exchange_end(exchange);
|
---|
| 97 |
|
---|
| 98 | if (rc != EOK) {
|
---|
| 99 | return rc;
|
---|
| 100 | }
|
---|
| 101 |
|
---|
| 102 | return (int) reg_msg_rc;
|
---|
| 103 | }
|
---|
| 104 |
|
---|
[f50a756] | 105 | int logctl_set_log_level(const char *namespace, const char *context, log_level_t new_level)
|
---|
[80d8885] | 106 | {
|
---|
| 107 | async_exch_t *exchange = NULL;
|
---|
| 108 | int rc = start_logger_exchange(&exchange);
|
---|
| 109 | if (rc != EOK)
|
---|
| 110 | return rc;
|
---|
| 111 |
|
---|
[cba45af] | 112 | aid_t reg_msg = async_send_1(exchange, LOGGER_CTL_SET_LOG_LEVEL,
|
---|
[80d8885] | 113 | new_level, NULL);
|
---|
| 114 | rc = async_data_write_start(exchange, namespace, str_size(namespace));
|
---|
| 115 | int rc2 = async_data_write_start(exchange, context, str_size(context));
|
---|
| 116 | sysarg_t reg_msg_rc;
|
---|
| 117 | async_wait_for(reg_msg, ®_msg_rc);
|
---|
| 118 |
|
---|
| 119 | async_exchange_end(exchange);
|
---|
| 120 |
|
---|
| 121 | if (rc != EOK)
|
---|
| 122 | return rc;
|
---|
| 123 |
|
---|
| 124 | if (rc2 != EOK)
|
---|
| 125 | return rc2;
|
---|
| 126 |
|
---|
| 127 | return (int) reg_msg_rc;
|
---|
| 128 | }
|
---|
| 129 |
|
---|
[669f5cae] | 130 | /** @}
|
---|
| 131 | */
|
---|