source: mainline/uspace/srv/ns/ns.c@ 63d46341

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 63d46341 was 984a9ba, checked in by Martin Decky <martin@…>, 7 years ago

do not expose the call capability handler from the async framework

Keep the call capability handler encapsulated within the async framework
and do not expose it explicitly via its API. Use the pointer to
ipc_call_t as the sole object identifying an IPC call in the code that
uses the async framework.

This plugs a major leak in the abstraction and also simplifies both the
async framework (slightly) and all IPC servers.

  • Property mode set to 100644
File size: 3.6 KB
Line 
1/*
2 * Copyright (c) 2006 Ondrej Palkovsky
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 ns
30 * @{
31 */
32
33/**
34 * @file ns.c
35 * @brief Naming service for HelenOS IPC.
36 */
37
38#include <abi/ipc/methods.h>
39#include <async.h>
40#include <ipc/ns.h>
41#include <ipc/services.h>
42#include <abi/ipc/interfaces.h>
43#include <stdio.h>
44#include <errno.h>
45#include <macros.h>
46#include "ns.h"
47#include "service.h"
48#include "clonable.h"
49#include "task.h"
50
51static void ns_connection(ipc_call_t *icall, void *arg)
52{
53 ipc_call_t call;
54 iface_t iface;
55 service_t service;
56
57 iface = IPC_GET_ARG1(*icall);
58 service = IPC_GET_ARG2(*icall);
59 if (service != 0) {
60 /*
61 * Client requests to be connected to a service.
62 */
63 if (service_clonable(service)) {
64 connect_to_clonable(service, iface, icall);
65 } else {
66 connect_to_service(service, iface, icall);
67 }
68 return;
69 }
70
71 async_answer_0(icall, EOK);
72
73 while (true) {
74 process_pending_conn();
75
76 async_get_call(&call);
77 if (!IPC_GET_IMETHOD(call))
78 break;
79
80 task_id_t id;
81 errno_t retval;
82
83 service_t service;
84 sysarg_t phone;
85
86 switch (IPC_GET_IMETHOD(call)) {
87 case NS_REGISTER:
88 service = IPC_GET_ARG1(call);
89 phone = IPC_GET_ARG5(call);
90
91 /*
92 * Server requests service registration.
93 */
94 if (service_clonable(service)) {
95 register_clonable(service, phone, &call);
96 continue;
97 } else {
98 retval = register_service(service, phone, &call);
99 }
100
101 break;
102 case NS_PING:
103 retval = EOK;
104 break;
105 case NS_TASK_WAIT:
106 id = (task_id_t)
107 MERGE_LOUP32(IPC_GET_ARG1(call), IPC_GET_ARG2(call));
108 wait_for_task(id, &call);
109 continue;
110 case NS_ID_INTRO:
111 retval = ns_task_id_intro(&call);
112 break;
113 case NS_RETVAL:
114 retval = ns_task_retval(&call);
115 break;
116 default:
117 printf("ns: method not supported\n");
118 retval = ENOTSUP;
119 break;
120 }
121
122 async_answer_0(&call, retval);
123 }
124
125 (void) ns_task_disconnect(&call);
126}
127
128int main(int argc, char **argv)
129{
130 printf("%s: HelenOS IPC Naming Service\n", NAME);
131
132 errno_t rc = service_init();
133 if (rc != EOK)
134 return rc;
135
136 rc = clonable_init();
137 if (rc != EOK)
138 return rc;
139
140 rc = task_init();
141 if (rc != EOK)
142 return rc;
143
144 async_set_fallback_port_handler(ns_connection, NULL);
145
146 printf("%s: Accepting connections\n", NAME);
147 async_manager();
148
149 /* Not reached */
150 return 0;
151}
152
153/**
154 * @}
155 */
Note: See TracBrowser for help on using the repository browser.