[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 <errno.h>
|
---|
| 35 | #include <io/logctl.h>
|
---|
| 36 | #include <ipc/logger.h>
|
---|
[b52dd1de] | 37 | #include <sysinfo.h>
|
---|
[669f5cae] | 38 | #include <ns.h>
|
---|
[04da852] | 39 | #include <str.h>
|
---|
[8e9b2534] | 40 | #include <vfs/vfs.h>
|
---|
[669f5cae] | 41 |
|
---|
| 42 | /** IPC session with the logger service. */
|
---|
| 43 | static async_sess_t *logger_session = NULL;
|
---|
| 44 |
|
---|
[b7fd2a0] | 45 | static errno_t start_logger_exchange(async_exch_t **exchange_out)
|
---|
[669f5cae] | 46 | {
|
---|
[7034b443] | 47 | assert(exchange_out != NULL);
|
---|
[669f5cae] | 48 |
|
---|
[7034b443] | 49 | if (logger_session == NULL) {
|
---|
[01900b6] | 50 | errno_t rc;
|
---|
[f9b2cb4c] | 51 | logger_session = service_connect_blocking(SERVICE_LOGGER,
|
---|
[01900b6] | 52 | INTERFACE_LOGGER_CONTROL, 0, &rc);
|
---|
[7034b443] | 53 | if (logger_session == NULL)
|
---|
[01900b6] | 54 | return rc;
|
---|
[7034b443] | 55 | }
|
---|
| 56 |
|
---|
| 57 | assert(logger_session != NULL);
|
---|
| 58 |
|
---|
| 59 | async_exch_t *exchange = async_exchange_begin(logger_session);
|
---|
| 60 | if (exchange == NULL)
|
---|
[669f5cae] | 61 | return ENOMEM;
|
---|
| 62 |
|
---|
[7034b443] | 63 | *exchange_out = exchange;
|
---|
| 64 |
|
---|
[669f5cae] | 65 | return EOK;
|
---|
| 66 | }
|
---|
| 67 |
|
---|
[e0c836e8] | 68 | /** Set default reported log level (global setting).
|
---|
| 69 | *
|
---|
| 70 | * This setting affects all logger clients whose reporting level was
|
---|
| 71 | * not yet changed.
|
---|
| 72 | *
|
---|
| 73 | * If logging level of client A is changed with logctl_set_log_level()
|
---|
| 74 | * to some level, this call will have no effect at that client's reporting
|
---|
| 75 | * level. Even if the actual value of the reporting level of client A is
|
---|
| 76 | * the same as current (previous) default log level.
|
---|
| 77 | *
|
---|
| 78 | * @param new_level New reported logging level.
|
---|
| 79 | * @return Error code of the conversion or EOK on success.
|
---|
| 80 | */
|
---|
[b7fd2a0] | 81 | errno_t logctl_set_default_level(log_level_t new_level)
|
---|
[669f5cae] | 82 | {
|
---|
[7034b443] | 83 | async_exch_t *exchange = NULL;
|
---|
[b7fd2a0] | 84 | errno_t rc = start_logger_exchange(&exchange);
|
---|
[669f5cae] | 85 | if (rc != EOK)
|
---|
| 86 | return rc;
|
---|
| 87 |
|
---|
[b7fd2a0] | 88 | rc = (errno_t) async_req_1_0(exchange,
|
---|
[6e596bd] | 89 | LOGGER_CONTROL_SET_DEFAULT_LEVEL, new_level);
|
---|
[669f5cae] | 90 |
|
---|
| 91 | async_exchange_end(exchange);
|
---|
| 92 |
|
---|
| 93 | return rc;
|
---|
| 94 | }
|
---|
| 95 |
|
---|
[e0c836e8] | 96 | /** Set reported log level of a single log.
|
---|
| 97 | *
|
---|
| 98 | * @see logctl_set_default_level
|
---|
| 99 | *
|
---|
| 100 | * @param logname Log name.
|
---|
| 101 | * @param new_level New reported logging level.
|
---|
| 102 | * @return Error code of the conversion or EOK on success.
|
---|
| 103 | */
|
---|
[b7fd2a0] | 104 | errno_t logctl_set_log_level(const char *logname, log_level_t new_level)
|
---|
[80d8885] | 105 | {
|
---|
| 106 | async_exch_t *exchange = NULL;
|
---|
[b7fd2a0] | 107 | errno_t rc = start_logger_exchange(&exchange);
|
---|
[80d8885] | 108 | if (rc != EOK)
|
---|
| 109 | return rc;
|
---|
| 110 |
|
---|
[6e596bd] | 111 | aid_t reg_msg = async_send_1(exchange, LOGGER_CONTROL_SET_LOG_LEVEL,
|
---|
[80d8885] | 112 | new_level, NULL);
|
---|
[f039dba] | 113 | rc = async_data_write_start(exchange, logname, str_size(logname));
|
---|
[b7fd2a0] | 114 | errno_t reg_msg_rc;
|
---|
[80d8885] | 115 | async_wait_for(reg_msg, ®_msg_rc);
|
---|
| 116 |
|
---|
| 117 | async_exchange_end(exchange);
|
---|
| 118 |
|
---|
| 119 | if (rc != EOK)
|
---|
| 120 | return rc;
|
---|
| 121 |
|
---|
[b7fd2a0] | 122 | return (errno_t) reg_msg_rc;
|
---|
[80d8885] | 123 | }
|
---|
| 124 |
|
---|
[8e9b2534] | 125 | /** Set logger's VFS root.
|
---|
| 126 | *
|
---|
| 127 | * @return Error code or EOK on success.
|
---|
| 128 | */
|
---|
[b7fd2a0] | 129 | errno_t logctl_set_root(void)
|
---|
[8e9b2534] | 130 | {
|
---|
| 131 | async_exch_t *exchange = NULL;
|
---|
[b7fd2a0] | 132 | errno_t rc = start_logger_exchange(&exchange);
|
---|
[8e9b2534] | 133 | if (rc != EOK)
|
---|
| 134 | return rc;
|
---|
| 135 |
|
---|
| 136 | aid_t reg_msg = async_send_0(exchange, LOGGER_CONTROL_SET_ROOT, NULL);
|
---|
| 137 | async_exch_t *vfs_exch = vfs_exchange_begin();
|
---|
| 138 | rc = vfs_pass_handle(vfs_exch, vfs_root(), exchange);
|
---|
| 139 | vfs_exchange_end(vfs_exch);
|
---|
[b7fd2a0] | 140 | errno_t reg_msg_rc;
|
---|
[8e9b2534] | 141 | async_wait_for(reg_msg, ®_msg_rc);
|
---|
| 142 |
|
---|
| 143 | async_exchange_end(exchange);
|
---|
| 144 |
|
---|
| 145 | if (rc != EOK)
|
---|
| 146 | return rc;
|
---|
| 147 |
|
---|
[b7fd2a0] | 148 | return (errno_t) reg_msg_rc;
|
---|
[8e9b2534] | 149 | }
|
---|
| 150 |
|
---|
[669f5cae] | 151 | /** @}
|
---|
| 152 | */
|
---|