source: mainline/uspace/srv/logger/writer.c@ b83c5e4

ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since b83c5e4 was fafb8e5, checked in by Jiří Zárevúcky <zarevucky.jiri@…>, 6 years ago

Mechanically lowercase IPC_SET_*/IPC_GET_*

  • Property mode set to 100644
File size: 3.6 KB
RevLine 
[e005f92]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/**
[4122410]30 * @addtogroup logger
[e005f92]31 * @{
32 */
33
34/** @file
35 */
36
37#include <ipc/services.h>
38#include <ipc/logger.h>
39#include <io/log.h>
40#include <io/logctl.h>
[bd6ff94]41#include <io/klog.h>
[e005f92]42#include <ns.h>
43#include <async.h>
44#include <errno.h>
[38d150e]45#include <stdio.h>
46#include <stdlib.h>
[e005f92]47#include <str_error.h>
48#include "logger.h"
49
[f039dba]50static logger_log_t *handle_create_log(sysarg_t parent)
[e005f92]51{
52 void *name;
[b7fd2a0]53 errno_t rc = async_data_write_accept(&name, true, 1, 0, 0, NULL);
[cba45af]54 if (rc != EOK)
[e005f92]55 return NULL;
56
[1dec7cb]57 logger_log_t *log = find_or_create_log_and_lock(name, parent);
[e005f92]58
59 free(name);
60
[cba45af]61 return log;
[e005f92]62}
63
[b7fd2a0]64static errno_t handle_receive_message(sysarg_t log_id, sysarg_t level)
[e005f92]65{
[1dec7cb]66 logger_log_t *log = find_log_by_id_and_lock(log_id);
[cba45af]67 if (log == NULL)
68 return ENOENT;
69
[3cf862f]70 void *message = NULL;
[b7fd2a0]71 errno_t rc = async_data_write_accept(&message, true, 1, 0, 0, NULL);
[cba45af]72 if (rc != EOK)
[3cf862f]73 goto leave;
[cba45af]74
[f039dba]75 if (!shall_log_message(log, level)) {
[3cf862f]76 rc = EOK;
77 goto leave;
[e005f92]78 }
79
[4c6de4f]80 KLOG_PRINTF(level, "[%s] %s: %s",
[f039dba]81 log->full_name, log_level_str(level),
[cba45af]82 (const char *) message);
[90dc458]83 write_to_log(log, level, message);
[e005f92]84
[3cf862f]85 rc = EOK;
86
87leave:
[1dec7cb]88 log_unlock(log);
[e005f92]89 free(message);
90
[3cf862f]91 return rc;
[e005f92]92}
93
[984a9ba]94void logger_connection_handler_writer(ipc_call_t *icall)
[e005f92]95{
[338d54a7]96 logger_log_t *log;
97 errno_t rc;
98
[cba45af]99 /* Acknowledge the connection. */
[beb83c1]100 async_accept_0(icall);
[e005f92]101
[42bde6a]102 logger_log("writer: new client.\n");
[e005f92]103
[131d9a4]104 logger_registered_logs_t registered_logs;
105 registered_logs_init(&registered_logs);
106
[e005f92]107 while (true) {
108 ipc_call_t call;
[984a9ba]109 async_get_call(&call);
[e005f92]110
[fafb8e5]111 if (!ipc_get_imethod(&call)) {
[889cdb1]112 async_answer_0(&call, EOK);
[e005f92]113 break;
[889cdb1]114 }
[e005f92]115
[fafb8e5]116 switch (ipc_get_imethod(&call)) {
[338d54a7]117 case LOGGER_WRITER_CREATE_LOG:
[fafb8e5]118 log = handle_create_log(ipc_get_arg1(&call));
[cba45af]119 if (log == NULL) {
[984a9ba]120 async_answer_0(&call, ENOMEM);
[cba45af]121 break;
122 }
[131d9a4]123 if (!register_log(&registered_logs, log)) {
124 log_unlock(log);
[984a9ba]125 async_answer_0(&call, ELIMIT);
[131d9a4]126 break;
127 }
[1dec7cb]128 log_unlock(log);
[984a9ba]129 async_answer_1(&call, EOK, (sysarg_t) log);
[e005f92]130 break;
[338d54a7]131 case LOGGER_WRITER_MESSAGE:
[fafb8e5]132 rc = handle_receive_message(ipc_get_arg1(&call),
133 ipc_get_arg2(&call));
[984a9ba]134 async_answer_0(&call, rc);
[e005f92]135 break;
136 default:
[984a9ba]137 async_answer_0(&call, EINVAL);
[e005f92]138 break;
139 }
140 }
141
[131d9a4]142 unregister_logs(&registered_logs);
[42bde6a]143 logger_log("writer: client terminated.\n");
[e005f92]144}
145
146/**
147 * @}
148 */
Note: See TracBrowser for help on using the repository browser.