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

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since a63966d was a63966d, checked in by Jakub Jermar <jakub@…>, 7 years ago

Provide doc/doxygroups.h for most apps

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