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
RevLine 
[3eddaff]1/*
[df4ed85]2 * Copyright (c) 2005 Martin Decky
[3eddaff]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
[b2951e2]29/** @addtogroup init Init
[c91c9fb]30 * @brief Init process for user space environment configuration.
[b2951e2]31 * @{
[c91c9fb]32 */
[b2951e2]33/**
34 * @file
35 */
36
[00c4994]37#include <stdio.h>
[860271d4]38#include <unistd.h>
39#include <vfs/vfs.h>
40#include <bool.h>
41#include <errno.h>
42#include <fcntl.h>
[1757ffce]43#include <sys/stat.h>
[860271d4]44#include <task.h>
45#include <malloc.h>
[c91c9fb]46#include <macros.h>
[19f857a]47#include <str.h>
[15f3c3f]48#include <loc.h>
[d9fae235]49#include <str_error.h>
[860271d4]50#include "init.h"
51
[d9fae235]52#define ROOT_DEVICE "bd/initrd"
53#define ROOT_MOUNT_POINT "/"
54
[15f3c3f]55#define LOCFS_FS_TYPE "locfs"
56#define LOCFS_MOUNT_POINT "/loc"
[47a350f]57
[1ab0852]58#define TMPFS_FS_TYPE "tmpfs"
59#define TMPFS_MOUNT_POINT "/tmp"
[d9fae235]60
61#define DATA_FS_TYPE "fat"
[e092dc5]62#define DATA_DEVICE "bd/ata1disk0"
[d9fae235]63#define DATA_MOUNT_POINT "/data"
64
[47a350f]65#define SRV_CONSOLE "/srv/console"
[df747bd8]66#define APP_GETTERM "/app/getterm"
[47a350f]67
[53d6ac3d]68/** Print banner */
[36b8100a]69static void info_print(void)
70{
[d9fae235]71 printf("%s: HelenOS init\n", NAME);
[36b8100a]72}
73
[53d6ac3d]74/** Report mount operation success */
[d9fae235]75static bool mount_report(const char *desc, const char *mntpt,
76 const char *fstype, const char *dev, int rc)
[860271d4]77{
[f49cf64]78 switch (rc) {
79 case EOK:
[d9fae235]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);
[f49cf64]85 break;
86 case EBUSY:
[d9fae235]87 printf("%s: %s already mounted on %s\n", NAME, desc, mntpt);
[f49cf64]88 return false;
89 case ELIMIT:
[d9fae235]90 printf("%s: %s limit exceeded\n", NAME, desc);
[f49cf64]91 return false;
92 case ENOENT:
[d9fae235]93 printf("%s: %s unknown type (%s)\n", NAME, desc, fstype);
[f49cf64]94 return false;
95 default:
[d9fae235]96 printf("%s: %s not mounted on %s (%s)\n", NAME, desc, mntpt,
97 str_error(rc));
[f49cf64]98 return false;
[860271d4]99 }
100
101 return true;
102}
103
[53d6ac3d]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 */
[d9fae235]115static bool mount_root(const char *fstype)
[a095d20]116{
[d9fae235]117 const char *opts = "";
[f49cf64]118
[d9fae235]119 if (str_cmp(fstype, "tmpfs") == 0)
120 opts = "restore";
[a095d20]121
[d9fae235]122 int rc = mount(fstype, ROOT_MOUNT_POINT, ROOT_DEVICE, opts,
[4979403]123 IPC_FLAG_BLOCKING, 0);
[d9fae235]124 return mount_report("Root filesystem", ROOT_MOUNT_POINT, fstype,
125 ROOT_DEVICE, rc);
126}
127
[53d6ac3d]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 */
[15f3c3f]137static bool mount_locfs(void)
[d9fae235]138{
[15f3c3f]139 int rc = mount(LOCFS_FS_TYPE, LOCFS_MOUNT_POINT, "", "",
[4979403]140 IPC_FLAG_BLOCKING, 0);
[15f3c3f]141 return mount_report("Location service filesystem", LOCFS_MOUNT_POINT,
142 LOCFS_FS_TYPE, NULL, rc);
[a095d20]143}
144
[a000878c]145static void spawn(const char *fname)
[860271d4]146{
[0485135]147 int rc;
[1757ffce]148 struct stat s;
149
150 if (stat(fname, &s) == ENOENT)
151 return;
[c91c9fb]152
[d9fae235]153 printf("%s: Spawning %s\n", NAME, fname);
[0485135]154 rc = task_spawnl(NULL, fname, fname, NULL);
155 if (rc != EOK) {
[d9fae235]156 printf("%s: Error spawning %s (%s)\n", NAME, fname,
[0485135]157 str_error(rc));
158 }
[b27a97bb]159}
160
[a000878c]161static void srv_start(const char *fname)
[95bc57c]162{
163 task_id_t id;
164 task_exit_t texit;
165 int rc, retval;
[1757ffce]166 struct stat s;
167
168 if (stat(fname, &s) == ENOENT)
169 return;
[95bc57c]170
[d9fae235]171 printf("%s: Starting %s\n", NAME, fname);
[0485135]172 rc = task_spawnl(&id, fname, fname, NULL);
[95bc57c]173 if (!id) {
[d9fae235]174 printf("%s: Error spawning %s (%s)\n", NAME, fname,
[0485135]175 str_error(rc));
[95bc57c]176 return;
177 }
[d9fae235]178
[95bc57c]179 rc = task_wait(id, &texit, &retval);
180 if (rc != EOK) {
[53d6ac3d]181 printf("%s: Error waiting for %s (%s)\n", NAME, fname,
[0485135]182 str_error(rc));
[95bc57c]183 return;
184 }
[d9fae235]185
[0485135]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);
[95bc57c]195 }
196}
197
[7c014d1]198static void console(const char *isvc, const char *fbsvc)
[47a350f]199{
[7c014d1]200 printf("%s: Spawning %s %s %s\n", NAME, SRV_CONSOLE, isvc, fbsvc);
[47a350f]201
[15f3c3f]202 /* Wait for the input service to be ready */
203 service_id_t service_id;
[7c014d1]204 int rc = loc_service_get_id(isvc, &service_id, IPC_FLAG_BLOCKING);
[0485135]205 if (rc != EOK) {
[7c014d1]206 printf("%s: Error waiting on %s (%s)\n", NAME, isvc,
[d9fae235]207 str_error(rc));
[0485135]208 return;
209 }
210
[7c014d1]211 /* Wait for the framebuffer service to be ready */
212 rc = loc_service_get_id(fbsvc, &service_id, IPC_FLAG_BLOCKING);
[0485135]213 if (rc != EOK) {
[7c014d1]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));
[0485135]223 }
[47a350f]224}
225
[15f3c3f]226static void getterm(const char *svc, const char *app, bool wmsg)
[36b8100a]227{
[15f3c3f]228 char term[LOC_NAME_MAXLEN];
[62140db]229 int rc;
[36b8100a]230
[15f3c3f]231 snprintf(term, LOC_NAME_MAXLEN, "%s/%s", LOCFS_MOUNT_POINT, svc);
[36b8100a]232
[d9fae235]233 printf("%s: Spawning %s %s %s\n", NAME, APP_GETTERM, term, app);
[36b8100a]234
[15f3c3f]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);
[0485135]238 if (rc != EOK) {
[d9fae235]239 printf("%s: Error waiting on %s (%s)\n", NAME, term,
240 str_error(rc));
[0485135]241 return;
242 }
243
[4deb8b5]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 }
[0485135]258 }
[36b8100a]259}
260
[1ab0852]261static bool mount_tmpfs(void)
[03333bc]262{
[4979403]263 int rc = mount(TMPFS_FS_TYPE, TMPFS_MOUNT_POINT, "", "", 0, 0);
[1ab0852]264 return mount_report("Temporary filesystem", TMPFS_MOUNT_POINT,
265 TMPFS_FS_TYPE, NULL, rc);
[03333bc]266}
267
[d9fae235]268static bool mount_data(void)
[00fe6bb]269{
[4979403]270 int rc = mount(DATA_FS_TYPE, DATA_MOUNT_POINT, DATA_DEVICE, "wtcache", 0, 0);
[d9fae235]271 return mount_report("Data filesystem", DATA_MOUNT_POINT, DATA_FS_TYPE,
272 DATA_DEVICE, rc);
[00fe6bb]273}
274
[5106e98]275int main(int argc, char *argv[])
276{
[860271d4]277 info_print();
278
[36b8100a]279 if (!mount_root(STRING(RDFMT))) {
[d9fae235]280 printf("%s: Exiting\n", NAME);
[860271d4]281 return -1;
282 }
[d9fae235]283
[03333bc]284 /* Make sure tmpfs is running. */
285 if (str_cmp(STRING(RDFMT), "tmpfs") != 0) {
286 spawn("/srv/tmpfs");
287 }
[860271d4]288
[15f3c3f]289 spawn("/srv/locfs");
[a074b4f]290 spawn("/srv/taskmon");
[a095d20]291
[15f3c3f]292 if (!mount_locfs()) {
[d9fae235]293 printf("%s: Exiting\n", NAME);
[a095d20]294 return -2;
295 }
[d9fae235]296
[1ab0852]297 mount_tmpfs();
[a095d20]298
[3acb285a]299 spawn("/srv/devman");
[acc7ce4]300 spawn("/srv/apic");
301 spawn("/srv/i8259");
[bb2dbf8]302 spawn("/srv/obio");
[3a2f8aa]303 srv_start("/srv/cuda_adb");
[a9b5b5f]304 srv_start("/srv/s3c24ser");
[527298a]305 srv_start("/srv/s3c24ts");
[d9fae235]306
[00d7e1b]307 spawn("/srv/net");
308
[de9c5cb]309 spawn("/srv/fb");
[5f88293]310 spawn("/srv/input");
[7c014d1]311 console("hid/input", "hid/fb0");
[47a350f]312
[fb623e2]313 spawn("/srv/clip");
[d50db30]314 spawn("/srv/remcons");
[d9fae235]315
[95bc57c]316 /*
317 * Start these synchronously so that mount_data() can be
318 * non-blocking.
319 */
[1641eb0]320#ifdef CONFIG_START_BD
[95bc57c]321 srv_start("/srv/ata_bd");
322 srv_start("/srv/gxe_bd");
[f019cc07]323#else
324 (void) srv_start;
325#endif
[d9fae235]326
[1641eb0]327#ifdef CONFIG_MOUNT_DATA
[1bfae13]328 /* Make sure fat is running. */
329 if (str_cmp(STRING(RDFMT), "fat") != 0) {
330 srv_start("/srv/fat");
331 }
[f49cf64]332 mount_data();
[f019cc07]333#else
334 (void) mount_data;
[1641eb0]335#endif
[d9fae235]336
[4deb8b5]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);
[d9fae235]344
[3eddaff]345 return 0;
346}
[b2951e2]347
348/** @}
349 */
Note: See TracBrowser for help on using the repository browser.