source: mainline/uspace/srv/ns/ns.c@ 613d644

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 613d644 was 1c635d6, checked in by Martin Sucha <sucha14@…>, 11 years ago

Do not hold a task's return value after it has disconnected.

Holding the task's return value meant that if nobody waited
for task's result, it polluted NS's memory. This was apparently
done because of a race between spawning a task and waiting for it.

We solve this problem in another way: ns discards the return value
as soon as the task disconnects from it. This typically happens
when the task finishes its execution. In order to avoid the race,
we send the wait request to ns while spawning the task (i.e. when
we talk to the loader), but before we allow the loaded program
to run.

Fixes #132

  • Property mode set to 100644
File size: 3.4 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 <ipc/ipc.h>
39#include <ipc/ns.h>
40#include <stdio.h>
41#include <errno.h>
42#include <macros.h>
43#include "ns.h"
44#include "service.h"
45#include "clonable.h"
46#include "task.h"
47
48int main(int argc, char **argv)
49{
50 printf("%s: HelenOS IPC Naming Service\n", NAME);
51
52 int rc = service_init();
53 if (rc != EOK)
54 return rc;
55
56 rc = clonable_init();
57 if (rc != EOK)
58 return rc;
59
60 rc = task_init();
61 if (rc != EOK)
62 return rc;
63
64 printf("%s: Accepting connections\n", NAME);
65
66 while (true) {
67 process_pending_conn();
68
69 ipc_call_t call;
70 ipc_callid_t callid = ipc_wait_for_call(&call);
71
72 task_id_t id;
73 sysarg_t retval;
74
75 switch (IPC_GET_IMETHOD(call)) {
76 case IPC_M_PHONE_HUNGUP:
77 retval = ns_task_disconnect(&call);
78 break;
79 case IPC_M_CONNECT_TO_ME:
80 /*
81 * Server requests service registration.
82 */
83 if (service_clonable(IPC_GET_ARG1(call))) {
84 register_clonable(IPC_GET_ARG1(call),
85 IPC_GET_ARG5(call), &call, callid);
86 continue;
87 } else {
88 retval = register_service(IPC_GET_ARG1(call),
89 IPC_GET_ARG5(call), &call);
90 }
91 break;
92 case IPC_M_CONNECT_ME_TO:
93 /*
94 * Client requests to be connected to a service.
95 */
96 if (service_clonable(IPC_GET_ARG1(call))) {
97 connect_to_clonable(IPC_GET_ARG1(call),
98 &call, callid);
99 continue;
100 } else {
101 connect_to_service(IPC_GET_ARG1(call), &call,
102 callid);
103 continue;
104 }
105 break;
106 case NS_PING:
107 retval = EOK;
108 break;
109 case NS_TASK_WAIT:
110 id = (task_id_t)
111 MERGE_LOUP32(IPC_GET_ARG1(call), IPC_GET_ARG2(call));
112 wait_for_task(id, &call, callid);
113 continue;
114 case NS_ID_INTRO:
115 retval = ns_task_id_intro(&call);
116 break;
117 case NS_RETVAL:
118 retval = ns_task_retval(&call);
119 break;
120 default:
121 retval = ENOENT;
122 break;
123 }
124
125 if (!(callid & IPC_CALLID_NOTIFICATION))
126 ipc_answer_0(callid, retval);
127 }
128
129 /* Not reached */
130 return 0;
131}
132
133/**
134 * @}
135 */
Note: See TracBrowser for help on using the repository browser.