source: mainline/uspace/lib/c/generic/io/logctl.c@ dc5aa568

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since dc5aa568 was 80d8885, checked in by Vojtech Horky <vojtechhorky@…>, 13 years ago

Set levels for individual contexts

  • Property mode set to 100644
File size: 4.1 KB
Line 
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>
38#include <sysinfo.h>
39#include <ns.h>
40#include <str.h>
41
42#define SYSINFO_LOGGGER_BOOT_ARGUMENT "init_args.logger"
43
44/** IPC session with the logger service. */
45static async_sess_t *logger_session = NULL;
46
47static int start_logger_exchange(async_exch_t **exchange_out)
48{
49 assert(exchange_out != NULL);
50
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)
62 return ENOMEM;
63
64 *exchange_out = exchange;
65
66 return EOK;
67}
68
69
70int logctl_set_default_level(log_level_t new_level)
71{
72 async_exch_t *exchange = NULL;
73 int rc = start_logger_exchange(&exchange);
74 if (rc != EOK)
75 return rc;
76
77 rc = (int) async_req_1_0(exchange,
78 LOGGER_CTL_SET_DEFAULT_LEVEL, new_level);
79
80 async_exchange_end(exchange);
81
82 return rc;
83}
84
85int logctl_set_namespace_level(const char *namespace, log_level_t new_level)
86{
87 async_exch_t *exchange = NULL;
88 int rc = start_logger_exchange(&exchange);
89 if (rc != EOK)
90 return rc;
91
92 aid_t reg_msg = async_send_1(exchange, LOGGER_CTL_SET_NAMESPACE_LEVEL,
93 new_level, NULL);
94 rc = async_data_write_start(exchange, namespace, str_size(namespace));
95 sysarg_t reg_msg_rc;
96 async_wait_for(reg_msg, &reg_msg_rc);
97
98 async_exchange_end(exchange);
99
100 if (rc != EOK) {
101 return rc;
102 }
103
104 return (int) reg_msg_rc;
105}
106
107int logctl_set_context_level(const char *namespace, const char *context, log_level_t new_level)
108{
109 async_exch_t *exchange = NULL;
110 int rc = start_logger_exchange(&exchange);
111 if (rc != EOK)
112 return rc;
113
114 aid_t reg_msg = async_send_1(exchange, LOGGER_CTL_SET_CONTEXT_LEVEL,
115 new_level, NULL);
116 rc = async_data_write_start(exchange, namespace, str_size(namespace));
117 int rc2 = async_data_write_start(exchange, context, str_size(context));
118 sysarg_t reg_msg_rc;
119 async_wait_for(reg_msg, &reg_msg_rc);
120
121 async_exchange_end(exchange);
122
123 if (rc != EOK)
124 return rc;
125
126 if (rc2 != EOK)
127 return rc2;
128
129 return (int) reg_msg_rc;
130}
131
132
133int logctl_get_boot_level(log_level_t *level)
134{
135 size_t argument_size;
136 void *argument = sysinfo_get_data(SYSINFO_LOGGGER_BOOT_ARGUMENT, &argument_size);
137 if (argument == NULL)
138 return EINVAL;
139
140 char level_str[20];
141 str_cpy(level_str, 20, (const char *) argument);
142
143 log_level_t boot_level;
144 int rc = log_level_from_str(level_str, &boot_level);
145 if (rc != EOK)
146 return rc;
147
148 if (level != NULL)
149 *level = (log_level_t) boot_level;
150
151 return EOK;
152}
153
154/** @}
155 */
Note: See TracBrowser for help on using the repository browser.