source: mainline/uspace/app/init/init.c@ d50db30

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since d50db30 was d50db30, checked in by Vojtech Horky <vojtechhorky@…>, 13 years ago

Start remote console automatically

  • Property mode set to 100644
File size: 8.4 KB
Line 
1/*
2 * Copyright (c) 2005 Martin Decky
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 init Init
30 * @brief Init process for user space environment configuration.
31 * @{
32 */
33/**
34 * @file
35 */
36
37#include <stdio.h>
38#include <unistd.h>
39#include <vfs/vfs.h>
40#include <bool.h>
41#include <errno.h>
42#include <fcntl.h>
43#include <sys/stat.h>
44#include <task.h>
45#include <malloc.h>
46#include <macros.h>
47#include <str.h>
48#include <loc.h>
49#include <str_error.h>
50#include "init.h"
51
52#define ROOT_DEVICE "bd/initrd"
53#define ROOT_MOUNT_POINT "/"
54
55#define LOCFS_FS_TYPE "locfs"
56#define LOCFS_MOUNT_POINT "/loc"
57
58#define TMPFS_FS_TYPE "tmpfs"
59#define TMPFS_MOUNT_POINT "/tmp"
60
61#define DATA_FS_TYPE "fat"
62#define DATA_DEVICE "bd/ata1disk0"
63#define DATA_MOUNT_POINT "/data"
64
65#define SRV_CONSOLE "/srv/console"
66#define APP_GETTERM "/app/getterm"
67
68/** Print banner */
69static void info_print(void)
70{
71 printf("%s: HelenOS init\n", NAME);
72}
73
74/** Report mount operation success */
75static bool mount_report(const char *desc, const char *mntpt,
76 const char *fstype, const char *dev, int rc)
77{
78 switch (rc) {
79 case EOK:
80 if (dev != NULL)
81 printf("%s: %s mounted on %s (%s at %s)\n", NAME, desc, mntpt,
82 fstype, dev);
83 else
84 printf("%s: %s mounted on %s (%s)\n", NAME, desc, mntpt, fstype);
85 break;
86 case EBUSY:
87 printf("%s: %s already mounted on %s\n", NAME, desc, mntpt);
88 return false;
89 case ELIMIT:
90 printf("%s: %s limit exceeded\n", NAME, desc);
91 return false;
92 case ENOENT:
93 printf("%s: %s unknown type (%s)\n", NAME, desc, fstype);
94 return false;
95 default:
96 printf("%s: %s not mounted on %s (%s)\n", NAME, desc, mntpt,
97 str_error(rc));
98 return false;
99 }
100
101 return true;
102}
103
104/** Mount root filesystem
105 *
106 * The operation blocks until the root filesystem
107 * server is ready for mounting.
108 *
109 * @param[in] fstype Root filesystem type.
110 *
111 * @return True on success.
112 * @return False on failure.
113 *
114 */
115static bool mount_root(const char *fstype)
116{
117 const char *opts = "";
118
119 if (str_cmp(fstype, "tmpfs") == 0)
120 opts = "restore";
121
122 int rc = mount(fstype, ROOT_MOUNT_POINT, ROOT_DEVICE, opts,
123 IPC_FLAG_BLOCKING, 0);
124 return mount_report("Root filesystem", ROOT_MOUNT_POINT, fstype,
125 ROOT_DEVICE, rc);
126}
127
128/** Mount locfs filesystem
129 *
130 * The operation blocks until the locfs filesystem
131 * server is ready for mounting.
132 *
133 * @return True on success.
134 * @return False on failure.
135 *
136 */
137static bool mount_locfs(void)
138{
139 int rc = mount(LOCFS_FS_TYPE, LOCFS_MOUNT_POINT, "", "",
140 IPC_FLAG_BLOCKING, 0);
141 return mount_report("Location service filesystem", LOCFS_MOUNT_POINT,
142 LOCFS_FS_TYPE, NULL, rc);
143}
144
145static void spawn(const char *fname)
146{
147 int rc;
148 struct stat s;
149
150 if (stat(fname, &s) == ENOENT)
151 return;
152
153 printf("%s: Spawning %s\n", NAME, fname);
154 rc = task_spawnl(NULL, fname, fname, NULL);
155 if (rc != EOK) {
156 printf("%s: Error spawning %s (%s)\n", NAME, fname,
157 str_error(rc));
158 }
159}
160
161static void srv_start(const char *fname)
162{
163 task_id_t id;
164 task_exit_t texit;
165 int rc, retval;
166 struct stat s;
167
168 if (stat(fname, &s) == ENOENT)
169 return;
170
171 printf("%s: Starting %s\n", NAME, fname);
172 rc = task_spawnl(&id, fname, fname, NULL);
173 if (!id) {
174 printf("%s: Error spawning %s (%s)\n", NAME, fname,
175 str_error(rc));
176 return;
177 }
178
179 rc = task_wait(id, &texit, &retval);
180 if (rc != EOK) {
181 printf("%s: Error waiting for %s (%s)\n", NAME, fname,
182 str_error(rc));
183 return;
184 }
185
186 if (texit != TASK_EXIT_NORMAL) {
187 printf("%s: Server %s failed to start (unexpectedly "
188 "terminated)\n", NAME, fname);
189 return;
190 }
191
192 if (retval != 0) {
193 printf("%s: Server %s failed to start (exit code %d)\n", NAME,
194 fname, retval);
195 }
196}
197
198static void console(const char *isvc, const char *fbsvc)
199{
200 printf("%s: Spawning %s %s %s\n", NAME, SRV_CONSOLE, isvc, fbsvc);
201
202 /* Wait for the input service to be ready */
203 service_id_t service_id;
204 int rc = loc_service_get_id(isvc, &service_id, IPC_FLAG_BLOCKING);
205 if (rc != EOK) {
206 printf("%s: Error waiting on %s (%s)\n", NAME, isvc,
207 str_error(rc));
208 return;
209 }
210
211 /* Wait for the framebuffer service to be ready */
212 rc = loc_service_get_id(fbsvc, &service_id, IPC_FLAG_BLOCKING);
213 if (rc != EOK) {
214 printf("%s: Error waiting on %s (%s)\n", NAME, fbsvc,
215 str_error(rc));
216 return;
217 }
218
219 rc = task_spawnl(NULL, SRV_CONSOLE, SRV_CONSOLE, isvc, fbsvc, NULL);
220 if (rc != EOK) {
221 printf("%s: Error spawning %s %s %s (%s)\n", NAME, SRV_CONSOLE,
222 isvc, fbsvc, str_error(rc));
223 }
224}
225
226static void getterm(const char *svc, const char *app, bool wmsg)
227{
228 char term[LOC_NAME_MAXLEN];
229 int rc;
230
231 snprintf(term, LOC_NAME_MAXLEN, "%s/%s", LOCFS_MOUNT_POINT, svc);
232
233 printf("%s: Spawning %s %s %s\n", NAME, APP_GETTERM, term, app);
234
235 /* Wait for the terminal service to be ready */
236 service_id_t service_id;
237 rc = loc_service_get_id(svc, &service_id, IPC_FLAG_BLOCKING);
238 if (rc != EOK) {
239 printf("%s: Error waiting on %s (%s)\n", NAME, term,
240 str_error(rc));
241 return;
242 }
243
244 if (wmsg) {
245 rc = task_spawnl(NULL, APP_GETTERM, APP_GETTERM, "-w", term,
246 app, NULL);
247 if (rc != EOK) {
248 printf("%s: Error spawning %s -w %s %s (%s)\n", NAME,
249 APP_GETTERM, term, app, str_error(rc));
250 }
251 } else {
252 rc = task_spawnl(NULL, APP_GETTERM, APP_GETTERM, term, app,
253 NULL);
254 if (rc != EOK) {
255 printf("%s: Error spawning %s %s %s (%s)\n", NAME,
256 APP_GETTERM, term, app, str_error(rc));
257 }
258 }
259}
260
261static bool mount_tmpfs(void)
262{
263 int rc = mount(TMPFS_FS_TYPE, TMPFS_MOUNT_POINT, "", "", 0, 0);
264 return mount_report("Temporary filesystem", TMPFS_MOUNT_POINT,
265 TMPFS_FS_TYPE, NULL, rc);
266}
267
268static bool mount_data(void)
269{
270 int rc = mount(DATA_FS_TYPE, DATA_MOUNT_POINT, DATA_DEVICE, "wtcache", 0, 0);
271 return mount_report("Data filesystem", DATA_MOUNT_POINT, DATA_FS_TYPE,
272 DATA_DEVICE, rc);
273}
274
275int main(int argc, char *argv[])
276{
277 info_print();
278
279 if (!mount_root(STRING(RDFMT))) {
280 printf("%s: Exiting\n", NAME);
281 return -1;
282 }
283
284 /* Make sure tmpfs is running. */
285 if (str_cmp(STRING(RDFMT), "tmpfs") != 0) {
286 spawn("/srv/tmpfs");
287 }
288
289 spawn("/srv/locfs");
290 spawn("/srv/taskmon");
291
292 if (!mount_locfs()) {
293 printf("%s: Exiting\n", NAME);
294 return -2;
295 }
296
297 mount_tmpfs();
298
299 spawn("/srv/devman");
300 spawn("/srv/apic");
301 spawn("/srv/i8259");
302 spawn("/srv/obio");
303 srv_start("/srv/cuda_adb");
304 srv_start("/srv/s3c24ser");
305 srv_start("/srv/s3c24ts");
306
307 spawn("/srv/net");
308
309 spawn("/srv/fb");
310 spawn("/srv/input");
311 console("hid/input", "hid/fb0");
312
313 spawn("/srv/clip");
314 spawn("/srv/remcons");
315
316 /*
317 * Start these synchronously so that mount_data() can be
318 * non-blocking.
319 */
320#ifdef CONFIG_START_BD
321 srv_start("/srv/ata_bd");
322 srv_start("/srv/gxe_bd");
323#else
324 (void) srv_start;
325#endif
326
327#ifdef CONFIG_MOUNT_DATA
328 /* Make sure fat is running. */
329 if (str_cmp(STRING(RDFMT), "fat") != 0) {
330 srv_start("/srv/fat");
331 }
332 mount_data();
333#else
334 (void) mount_data;
335#endif
336
337 getterm("term/vc0", "/app/bdsh", true);
338 getterm("term/vc1", "/app/bdsh", false);
339 getterm("term/vc2", "/app/bdsh", false);
340 getterm("term/vc3", "/app/bdsh", false);
341 getterm("term/vc4", "/app/bdsh", false);
342 getterm("term/vc5", "/app/bdsh", false);
343 getterm("term/vc6", "/app/klog", false);
344
345 return 0;
346}
347
348/** @}
349 */
Note: See TracBrowser for help on using the repository browser.