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

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since a35b458 was a35b458, checked in by Jiří Zárevúcky <zarevucky.jiri@…>, 7 years ago

style: Remove trailing whitespace on _all_ lines, including empty ones, for particular file types.

Command used: tools/srepl '\s\+$' '' -- *.c *.h *.py *.sh *.s *.S *.ag

Currently, whitespace on empty lines is very inconsistent.
There are two basic choices: Either remove the whitespace, or keep empty lines
indented to the level of surrounding code. The former is AFAICT more common,
and also much easier to do automatically.

Alternatively, we could write script for automatic indentation, and use that
instead. However, if such a script exists, it's possible to use the indented
style locally, by having the editor apply relevant conversions on load/save,
without affecting remote repository. IMO, it makes more sense to adopt
the simpler rule.

  • Property mode set to 100644
File size: 9.6 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>
[6d5e378]38#include <stdarg.h>
[860271d4]39#include <vfs/vfs.h>
[3e6a98c5]40#include <stdbool.h>
[860271d4]41#include <errno.h>
42#include <task.h>
[38d150e]43#include <stdlib.h>
[c91c9fb]44#include <macros.h>
[19f857a]45#include <str.h>
[15f3c3f]46#include <loc.h>
[d9fae235]47#include <str_error.h>
[73d8600]48#include <config.h>
[8e9b2534]49#include <io/logctl.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
[47a350f]61#define SRV_CONSOLE "/srv/console"
[df747bd8]62#define APP_GETTERM "/app/getterm"
[47a350f]63
[6d5e378]64#define SRV_COMPOSITOR "/srv/compositor"
65
66#define HID_INPUT "hid/input"
67#define HID_OUTPUT "hid/output"
68#define HID_COMPOSITOR_SERVER ":0"
69
70#define srv_start(path, ...) \
71 srv_startl(path, path, ##__VA_ARGS__, NULL)
72
[53d6ac3d]73/** Print banner */
[36b8100a]74static void info_print(void)
75{
[d9fae235]76 printf("%s: HelenOS init\n", NAME);
[36b8100a]77}
78
[53d6ac3d]79/** Report mount operation success */
[d9fae235]80static bool mount_report(const char *desc, const char *mntpt,
[b7fd2a0]81 const char *fstype, const char *dev, errno_t rc)
[860271d4]82{
[f49cf64]83 switch (rc) {
84 case EOK:
[d9fae235]85 if (dev != NULL)
86 printf("%s: %s mounted on %s (%s at %s)\n", NAME, desc, mntpt,
87 fstype, dev);
88 else
89 printf("%s: %s mounted on %s (%s)\n", NAME, desc, mntpt, fstype);
[f49cf64]90 break;
91 case EBUSY:
[d9fae235]92 printf("%s: %s already mounted on %s\n", NAME, desc, mntpt);
[f49cf64]93 return false;
94 case ELIMIT:
[d9fae235]95 printf("%s: %s limit exceeded\n", NAME, desc);
[f49cf64]96 return false;
97 case ENOENT:
[d9fae235]98 printf("%s: %s unknown type (%s)\n", NAME, desc, fstype);
[f49cf64]99 return false;
100 default:
[d9fae235]101 printf("%s: %s not mounted on %s (%s)\n", NAME, desc, mntpt,
102 str_error(rc));
[f49cf64]103 return false;
[860271d4]104 }
[a35b458]105
[860271d4]106 return true;
107}
108
[53d6ac3d]109/** Mount root filesystem
110 *
111 * The operation blocks until the root filesystem
112 * server is ready for mounting.
113 *
114 * @param[in] fstype Root filesystem type.
115 *
116 * @return True on success.
117 * @return False on failure.
118 *
119 */
[d9fae235]120static bool mount_root(const char *fstype)
[a095d20]121{
[d9fae235]122 const char *opts = "";
[a35b458]123
[d9fae235]124 if (str_cmp(fstype, "tmpfs") == 0)
125 opts = "restore";
[a35b458]126
[b7fd2a0]127 errno_t rc = vfs_mount_path(ROOT_MOUNT_POINT, fstype, ROOT_DEVICE, opts,
[4979403]128 IPC_FLAG_BLOCKING, 0);
[8e9b2534]129 if (rc == EOK)
130 logctl_set_root();
[d9fae235]131 return mount_report("Root filesystem", ROOT_MOUNT_POINT, fstype,
132 ROOT_DEVICE, rc);
133}
134
[53d6ac3d]135/** Mount locfs filesystem
136 *
137 * The operation blocks until the locfs filesystem
138 * server is ready for mounting.
139 *
140 * @return True on success.
141 * @return False on failure.
142 *
143 */
[15f3c3f]144static bool mount_locfs(void)
[d9fae235]145{
[b7fd2a0]146 errno_t rc = vfs_mount_path(LOCFS_MOUNT_POINT, LOCFS_FS_TYPE, "", "",
[4979403]147 IPC_FLAG_BLOCKING, 0);
[15f3c3f]148 return mount_report("Location service filesystem", LOCFS_MOUNT_POINT,
149 LOCFS_FS_TYPE, NULL, rc);
[a095d20]150}
151
[b7fd2a0]152static errno_t srv_startl(const char *path, ...)
[860271d4]153{
[39330200]154 vfs_stat_t s;
[23a0368]155 if (vfs_stat_path(path, &s) != EOK) {
[6d5e378]156 printf("%s: Unable to stat %s\n", NAME, path);
157 return ENOENT;
158 }
[a35b458]159
[6d5e378]160 printf("%s: Starting %s\n", NAME, path);
[a35b458]161
[6d5e378]162 va_list ap;
163 const char *arg;
164 int cnt = 0;
[a35b458]165
[6d5e378]166 va_start(ap, path);
167 do {
168 arg = va_arg(ap, const char *);
169 cnt++;
170 } while (arg != NULL);
171 va_end(ap);
[a35b458]172
[6d5e378]173 va_start(ap, path);
174 task_id_t id;
[1c635d6]175 task_wait_t wait;
[b7fd2a0]176 errno_t rc = task_spawn(&id, &wait, path, cnt, ap);
[6d5e378]177 va_end(ap);
[a35b458]178
[0485135]179 if (rc != EOK) {
[6d5e378]180 printf("%s: Error spawning %s (%s)\n", NAME, path,
[0485135]181 str_error(rc));
[6d5e378]182 return rc;
[0485135]183 }
[a35b458]184
[95bc57c]185 if (!id) {
[6d5e378]186 printf("%s: Error spawning %s (invalid task id)\n", NAME,
187 path);
188 return EINVAL;
[95bc57c]189 }
[a35b458]190
[6d5e378]191 task_exit_t texit;
192 int retval;
[1c635d6]193 rc = task_wait(&wait, &texit, &retval);
[95bc57c]194 if (rc != EOK) {
[6d5e378]195 printf("%s: Error waiting for %s (%s)\n", NAME, path,
[0485135]196 str_error(rc));
[6d5e378]197 return rc;
[95bc57c]198 }
[a35b458]199
[0485135]200 if (texit != TASK_EXIT_NORMAL) {
201 printf("%s: Server %s failed to start (unexpectedly "
[6d5e378]202 "terminated)\n", NAME, path);
203 return EINVAL;
[0485135]204 }
[a35b458]205
[6d5e378]206 if (retval != 0)
[0485135]207 printf("%s: Server %s failed to start (exit code %d)\n", NAME,
[6d5e378]208 path, retval);
[a35b458]209
[1569a9b]210 return retval == 0 ? EOK : EPARTY;
[95bc57c]211}
212
[b7fd2a0]213static errno_t console(const char *isvc, const char *osvc)
[47a350f]214{
[15f3c3f]215 /* Wait for the input service to be ready */
216 service_id_t service_id;
[b7fd2a0]217 errno_t rc = loc_service_get_id(isvc, &service_id, IPC_FLAG_BLOCKING);
[0485135]218 if (rc != EOK) {
[7c014d1]219 printf("%s: Error waiting on %s (%s)\n", NAME, isvc,
[d9fae235]220 str_error(rc));
[6d5e378]221 return rc;
[0485135]222 }
[a35b458]223
[6d5e378]224 /* Wait for the output service to be ready */
225 rc = loc_service_get_id(osvc, &service_id, IPC_FLAG_BLOCKING);
[0485135]226 if (rc != EOK) {
[6d5e378]227 printf("%s: Error waiting on %s (%s)\n", NAME, osvc,
[7c014d1]228 str_error(rc));
[6d5e378]229 return rc;
230 }
[a35b458]231
[6d5e378]232 return srv_start(SRV_CONSOLE, isvc, osvc);
233}
234
[b7fd2a0]235static errno_t compositor(const char *isvc, const char *name)
[6d5e378]236{
237 /* Wait for the input service to be ready */
238 service_id_t service_id;
[b7fd2a0]239 errno_t rc = loc_service_get_id(isvc, &service_id, IPC_FLAG_BLOCKING);
[6d5e378]240 if (rc != EOK) {
241 printf("%s: Error waiting on %s (%s)\n", NAME, isvc,
242 str_error(rc));
243 return rc;
[7c014d1]244 }
[a35b458]245
[6d5e378]246 return srv_start(SRV_COMPOSITOR, isvc, name);
247}
248
249static int gui_start(const char *app, const char *srv_name)
250{
251 char winreg[50];
252 snprintf(winreg, sizeof(winreg), "%s%s%s", "comp", srv_name, "/winreg");
[a35b458]253
[6d5e378]254 printf("%s: Spawning %s %s\n", NAME, app, winreg);
[a35b458]255
[6d5e378]256 task_id_t id;
[1c635d6]257 task_wait_t wait;
[b7fd2a0]258 errno_t rc = task_spawnl(&id, &wait, app, app, winreg, NULL);
[7c014d1]259 if (rc != EOK) {
[6d5e378]260 printf("%s: Error spawning %s %s (%s)\n", NAME, app,
261 winreg, str_error(rc));
262 return -1;
[0485135]263 }
[a35b458]264
[6d5e378]265 task_exit_t texit;
266 int retval;
[1c635d6]267 rc = task_wait(&wait, &texit, &retval);
[6d5e378]268 if ((rc != EOK) || (texit != TASK_EXIT_NORMAL)) {
269 printf("%s: Error retrieving retval from %s (%s)\n", NAME,
270 app, str_error(rc));
271 return -1;
[0485135]272 }
[a35b458]273
[6d5e378]274 return retval;
[47a350f]275}
276
[593e023]277static void getterm(const char *svc, const char *app, bool msg)
[36b8100a]278{
[593e023]279 if (msg) {
280 printf("%s: Spawning %s %s %s --msg --wait -- %s\n", NAME,
281 APP_GETTERM, svc, LOCFS_MOUNT_POINT, app);
[a35b458]282
[b7fd2a0]283 errno_t rc = task_spawnl(NULL, NULL, APP_GETTERM, APP_GETTERM, svc,
[593e023]284 LOCFS_MOUNT_POINT, "--msg", "--wait", "--", app, NULL);
285 if (rc != EOK)
286 printf("%s: Error spawning %s %s %s --msg --wait -- %s\n",
287 NAME, APP_GETTERM, svc, LOCFS_MOUNT_POINT, app);
[4deb8b5]288 } else {
[593e023]289 printf("%s: Spawning %s %s %s --wait -- %s\n", NAME,
290 APP_GETTERM, svc, LOCFS_MOUNT_POINT, app);
[a35b458]291
[b7fd2a0]292 errno_t rc = task_spawnl(NULL, NULL, APP_GETTERM, APP_GETTERM, svc,
[593e023]293 LOCFS_MOUNT_POINT, "--wait", "--", app, NULL);
294 if (rc != EOK)
295 printf("%s: Error spawning %s %s %s --wait -- %s\n",
296 NAME, APP_GETTERM, svc, LOCFS_MOUNT_POINT, app);
[0485135]297 }
[36b8100a]298}
299
[1ab0852]300static bool mount_tmpfs(void)
[03333bc]301{
[b7fd2a0]302 errno_t rc = vfs_mount_path(TMPFS_MOUNT_POINT, TMPFS_FS_TYPE, "", "", 0, 0);
[1ab0852]303 return mount_report("Temporary filesystem", TMPFS_MOUNT_POINT,
304 TMPFS_FS_TYPE, NULL, rc);
[03333bc]305}
306
[5106e98]307int main(int argc, char *argv[])
308{
[b7fd2a0]309 errno_t rc;
[73d8600]310
[860271d4]311 info_print();
[a35b458]312
[36b8100a]313 if (!mount_root(STRING(RDFMT))) {
[d9fae235]314 printf("%s: Exiting\n", NAME);
[6d5e378]315 return 1;
[860271d4]316 }
[a35b458]317
[395df52]318 /* Make sure file systems are running. */
[6d5e378]319 if (str_cmp(STRING(RDFMT), "tmpfs") != 0)
320 srv_start("/srv/tmpfs");
[395df52]321 if (str_cmp(STRING(RDFMT), "exfat") != 0)
322 srv_start("/srv/exfat");
323 if (str_cmp(STRING(RDFMT), "fat") != 0)
324 srv_start("/srv/fat");
325 srv_start("/srv/cdfs");
[d2c8533]326 srv_start("/srv/mfs");
[a35b458]327
[ca05e9b]328 srv_start("/srv/klog");
[6d5e378]329 srv_start("/srv/locfs");
[5cd1eb9a]330 srv_start("/srv/taskmon");
[a35b458]331
[15f3c3f]332 if (!mount_locfs()) {
[d9fae235]333 printf("%s: Exiting\n", NAME);
[6d5e378]334 return 2;
[a095d20]335 }
[a35b458]336
[1ab0852]337 mount_tmpfs();
[a35b458]338
[6d5e378]339 srv_start("/srv/devman");
[f7cbc6f]340 srv_start("/srv/s3c24xx_uart");
341 srv_start("/srv/s3c24xx_ts");
[a35b458]342
[dc2d582]343 srv_start("/srv/vbd");
344 srv_start("/srv/volsrv");
[a35b458]345
[6d5e378]346 srv_start("/srv/loopip");
347 srv_start("/srv/ethip");
348 srv_start("/srv/inetsrv");
349 srv_start("/srv/tcp");
350 srv_start("/srv/udp");
[31e9fe0]351 srv_start("/srv/dnsrsrv");
[bd88bee]352 srv_start("/srv/dhcp");
353 srv_start("/srv/nconfsrv");
[a35b458]354
[6d5e378]355 srv_start("/srv/clipboard");
356 srv_start("/srv/remcons");
[a35b458]357
[6d5e378]358 srv_start("/srv/input", HID_INPUT);
359 srv_start("/srv/output", HID_OUTPUT);
[2e2c18a1]360 srv_start("/srv/hound");
[a35b458]361
[73d8600]362 if (!config_key_exists("console")) {
363 rc = compositor(HID_INPUT, HID_COMPOSITOR_SERVER);
364 if (rc == EOK) {
365 gui_start("/app/barber", HID_COMPOSITOR_SERVER);
366 gui_start("/app/vlaunch", HID_COMPOSITOR_SERVER);
367 gui_start("/app/vterm", HID_COMPOSITOR_SERVER);
368 }
[593e023]369 }
[a35b458]370
[593e023]371 rc = console(HID_INPUT, HID_OUTPUT);
372 if (rc == EOK) {
373 getterm("term/vc0", "/app/bdsh", true);
374 getterm("term/vc1", "/app/bdsh", false);
375 getterm("term/vc2", "/app/bdsh", false);
376 getterm("term/vc3", "/app/bdsh", false);
377 getterm("term/vc4", "/app/bdsh", false);
378 getterm("term/vc5", "/app/bdsh", false);
[6d5e378]379 }
[a35b458]380
[3eddaff]381 return 0;
382}
[b2951e2]383
384/** @}
385 */
Note: See TracBrowser for help on using the repository browser.