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

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

Use user-defined labels instead of phone hashes

This commit changes the way how the async framework maps incomming calls
to connections. Instead of abusing the kernel addresses of attached
phones as identifiers, the IPC_M_CONNECT_TO_ME and IPC_M_CONNECT_ME_TO
messages allow the server to specify an arbitrary label which is
remembered in the connected phone and consequently imprinted on each
call which is routed through this phone.

The async framework uses the address of the connection structure as the
label. This removes the need for a connection hash table because each
incoming call already remembers the connection in its label.

To disambiguate this new label and the other user-defined label used for
answers, the call structure now has the request_label member for the
former and answer_label member for the latter.

This commit also moves the kernel definition of ipc_data_t to abi/ and
removes the uspace redefinition thereof. Finally, when forwarding the
IPC_M_CONNECT_TO_ME call, the phone capability and the kernel object
allocated in request_process are now correctly disposed of.

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