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

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 38d150e was 582a0b8, checked in by Jakub Jermar <jakub@…>, 8 years ago

Remove unistd.h

  • Rename usleep() and sleep() to thread_usleep() and thread_sleep() and move to thread.[hc].
  • Include stddef.h in order to provide NULL.
  • Move getpagesize() to libposix.
  • Sync uspace/dist/src/c/demos with originals.
  • Property mode set to 100644
File size: 4.2 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 <errno.h>
35#include <io/logctl.h>
36#include <ipc/logger.h>
37#include <sysinfo.h>
38#include <ns.h>
39#include <str.h>
40#include <vfs/vfs.h>
41
42/** IPC session with the logger service. */
43static async_sess_t *logger_session = NULL;
44
45static int start_logger_exchange(async_exch_t **exchange_out)
46{
47 assert(exchange_out != NULL);
48
49 if (logger_session == NULL) {
50 logger_session = service_connect_blocking(SERVICE_LOGGER,
51 INTERFACE_LOGGER_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)
60 return ENOMEM;
61
62 *exchange_out = exchange;
63
64 return EOK;
65}
66
67/** Set default reported log level (global setting).
68 *
69 * This setting affects all logger clients whose reporting level was
70 * not yet changed.
71 *
72 * If logging level of client A is changed with logctl_set_log_level()
73 * to some level, this call will have no effect at that client's reporting
74 * level. Even if the actual value of the reporting level of client A is
75 * the same as current (previous) default log level.
76 *
77 * @param new_level New reported logging level.
78 * @return Error code of the conversion or EOK on success.
79 */
80int logctl_set_default_level(log_level_t new_level)
81{
82 async_exch_t *exchange = NULL;
83 int rc = start_logger_exchange(&exchange);
84 if (rc != EOK)
85 return rc;
86
87 rc = (int) async_req_1_0(exchange,
88 LOGGER_CONTROL_SET_DEFAULT_LEVEL, new_level);
89
90 async_exchange_end(exchange);
91
92 return rc;
93}
94
95/** Set reported log level of a single log.
96 *
97 * @see logctl_set_default_level
98 *
99 * @param logname Log name.
100 * @param new_level New reported logging level.
101 * @return Error code of the conversion or EOK on success.
102 */
103int logctl_set_log_level(const char *logname, log_level_t new_level)
104{
105 async_exch_t *exchange = NULL;
106 int rc = start_logger_exchange(&exchange);
107 if (rc != EOK)
108 return rc;
109
110 aid_t reg_msg = async_send_1(exchange, LOGGER_CONTROL_SET_LOG_LEVEL,
111 new_level, NULL);
112 rc = async_data_write_start(exchange, logname, str_size(logname));
113 sysarg_t reg_msg_rc;
114 async_wait_for(reg_msg, &reg_msg_rc);
115
116 async_exchange_end(exchange);
117
118 if (rc != EOK)
119 return rc;
120
121 return (int) reg_msg_rc;
122}
123
124/** Set logger's VFS root.
125 *
126 * @return Error code or EOK on success.
127 */
128int logctl_set_root(void)
129{
130 async_exch_t *exchange = NULL;
131 int rc = start_logger_exchange(&exchange);
132 if (rc != EOK)
133 return rc;
134
135 aid_t reg_msg = async_send_0(exchange, LOGGER_CONTROL_SET_ROOT, NULL);
136 async_exch_t *vfs_exch = vfs_exchange_begin();
137 rc = vfs_pass_handle(vfs_exch, vfs_root(), exchange);
138 vfs_exchange_end(vfs_exch);
139 sysarg_t reg_msg_rc;
140 async_wait_for(reg_msg, &reg_msg_rc);
141
142 async_exchange_end(exchange);
143
144 if (rc != EOK)
145 return rc;
146
147 return (int) reg_msg_rc;
148}
149
150/** @}
151 */
Note: See TracBrowser for help on using the repository browser.