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

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

Read properly boot log level

  • Property mode set to 100644
File size: 2.8 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 connect_to_logger()
48{
49 if (logger_session != NULL)
50 return EOK;
51
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 return EOK;
58}
59
60
61int logctl_set_default_level(log_level_t new_level)
62{
63 int rc = connect_to_logger();
64 if (rc != EOK)
65 return rc;
66
67 async_exch_t *exchange = async_exchange_begin(logger_session);
68 if (exchange == NULL)
69 return ENOMEM;
70
71 rc = (int) async_req_1_0(exchange,
72 LOGGER_CTL_SET_DEFAULT_LEVEL, new_level);
73
74 async_exchange_end(exchange);
75
76 return rc;
77}
78
79int logctl_get_boot_level(log_level_t *level)
80{
81 size_t argument_size;
82 void *argument = sysinfo_get_data(SYSINFO_LOGGGER_BOOT_ARGUMENT, &argument_size);
83 if (argument == NULL)
84 return EINVAL;
85
86 char level_str[10];
87 str_cpy(level_str, 10, (const char *) argument);
88
89 int level_int = strtol(level_str, NULL, 0);
90
91 log_level_t boot_level = (log_level_t) level_int;
92 if (boot_level >= LVL_LIMIT)
93 return EINVAL;
94
95 if (level != NULL)
96 *level = (log_level_t) boot_level;
97
98 return EOK;
99}
100
101/** @}
102 */
Note: See TracBrowser for help on using the repository browser.