source: mainline/uspace/srv/ns/ns.c@ facacc71

Last change on this file since facacc71 was 84a1a54, checked in by Jiří Zárevúcky <zarevucky.jiri@…>, 8 years ago

Wrap returns of errno from main() with EXIT_RC().

Returns of error code from main() prevent type checking when errno_t
and int are considered incompatible. In order to avoid the philosophical
discussion of what should and shouldn't be returned for main(), we simply
wrap the error values and leave the answer to the question for future
generations to decide.

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