Changes in uspace/app/init/init.c [514108e:e229148] in mainline


Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/init/init.c

    r514108e re229148  
    11/*
    2  * Copyright (c) 2024 Jiri Svoboda
    32 * Copyright (c) 2005 Martin Decky
    43 * All rights reserved.
     
    3534 */
    3635
     36#include <fibril.h>
    3737#include <stdio.h>
    3838#include <stdarg.h>
     
    4646#include <loc.h>
    4747#include <str_error.h>
     48#include <config.h>
    4849#include <io/logctl.h>
    4950#include <vfs/vfs.h>
     51#include <vol.h>
    5052#include "untar.h"
    5153#include "init.h"
     
    5759#define ROOT_MOUNT_POINT  "/"
    5860
     61#define LOCFS_FS_TYPE      "locfs"
     62#define LOCFS_MOUNT_POINT  "/loc"
     63
     64#define TMPFS_FS_TYPE      "tmpfs"
     65#define TMPFS_MOUNT_POINT  "/tmp"
     66
     67#define SRV_CONSOLE  "/srv/hid/console"
     68#define APP_GETTERM  "/app/getterm"
     69
     70#define SRV_DISPLAY  "/srv/hid/display"
     71
     72#define HID_INPUT              "hid/input"
     73#define HID_OUTPUT             "hid/output"
     74
    5975#define srv_start(path, ...) \
    6076        srv_startl(path, path, ##__VA_ARGS__, NULL)
     77
     78static const char *sys_dirs[] = {
     79        "/w/cfg",
     80        "/w/data"
     81};
    6182
    6283/** Print banner */
     
    150171}
    151172
     173/** Mount locfs file system
     174 *
     175 * The operation blocks until the locfs file system
     176 * server is ready for mounting.
     177 *
     178 * @return True on success.
     179 * @return False on failure.
     180 *
     181 */
     182static bool mount_locfs(void)
     183{
     184        errno_t rc = vfs_mount_path(LOCFS_MOUNT_POINT, LOCFS_FS_TYPE, "", "",
     185            IPC_FLAG_BLOCKING, 0);
     186        return mount_report("Location service file system", LOCFS_MOUNT_POINT,
     187            LOCFS_FS_TYPE, NULL, rc);
     188}
     189
    152190static errno_t srv_startl(const char *path, ...)
    153191{
     
    212250}
    213251
     252static errno_t console(const char *isvc, const char *osvc)
     253{
     254        /* Wait for the input service to be ready */
     255        service_id_t service_id;
     256        errno_t rc = loc_service_get_id(isvc, &service_id, IPC_FLAG_BLOCKING);
     257        if (rc != EOK) {
     258                printf("%s: Error waiting on %s (%s)\n", NAME, isvc,
     259                    str_error(rc));
     260                return rc;
     261        }
     262
     263        /* Wait for the output service to be ready */
     264        rc = loc_service_get_id(osvc, &service_id, IPC_FLAG_BLOCKING);
     265        if (rc != EOK) {
     266                printf("%s: Error waiting on %s (%s)\n", NAME, osvc,
     267                    str_error(rc));
     268                return rc;
     269        }
     270
     271        return srv_start(SRV_CONSOLE, isvc, osvc);
     272}
     273
     274#ifdef CONFIG_WINSYS
     275
     276static errno_t display_server(void)
     277{
     278        return srv_start(SRV_DISPLAY);
     279}
     280
     281static int app_start(const char *app, const char *arg)
     282{
     283        printf("%s: Spawning %s\n", NAME, app);
     284
     285        task_id_t id;
     286        task_wait_t wait;
     287        errno_t rc = task_spawnl(&id, &wait, app, app, arg, NULL);
     288        if (rc != EOK) {
     289                oom_check(rc, app);
     290                printf("%s: Error spawning %s (%s)\n", NAME, app,
     291                    str_error(rc));
     292                return -1;
     293        }
     294
     295        task_exit_t texit;
     296        int retval;
     297        rc = task_wait(&wait, &texit, &retval);
     298        if ((rc != EOK) || (texit != TASK_EXIT_NORMAL)) {
     299                printf("%s: Error retrieving retval from %s (%s)\n", NAME,
     300                    app, str_error(rc));
     301                return rc;
     302        }
     303
     304        return retval;
     305}
     306
     307#endif
     308
     309static void getterm(const char *svc, const char *app, bool msg)
     310{
     311        if (msg) {
     312                printf("%s: Spawning %s %s %s --msg --wait -- %s\n", NAME,
     313                    APP_GETTERM, svc, LOCFS_MOUNT_POINT, app);
     314
     315                errno_t rc = task_spawnl(NULL, NULL, APP_GETTERM, APP_GETTERM, svc,
     316                    LOCFS_MOUNT_POINT, "--msg", "--wait", "--", app, NULL);
     317                if (rc != EOK) {
     318                        oom_check(rc, APP_GETTERM);
     319                        printf("%s: Error spawning %s %s %s --msg --wait -- %s\n",
     320                            NAME, APP_GETTERM, svc, LOCFS_MOUNT_POINT, app);
     321                }
     322        } else {
     323                printf("%s: Spawning %s %s %s --wait -- %s\n", NAME,
     324                    APP_GETTERM, svc, LOCFS_MOUNT_POINT, app);
     325
     326                errno_t rc = task_spawnl(NULL, NULL, APP_GETTERM, APP_GETTERM, svc,
     327                    LOCFS_MOUNT_POINT, "--wait", "--", app, NULL);
     328                if (rc != EOK) {
     329                        oom_check(rc, APP_GETTERM);
     330                        printf("%s: Error spawning %s %s %s --wait -- %s\n",
     331                            NAME, APP_GETTERM, svc, LOCFS_MOUNT_POINT, app);
     332                }
     333        }
     334}
     335
     336static bool mount_tmpfs(void)
     337{
     338        errno_t rc = vfs_mount_path(TMPFS_MOUNT_POINT, TMPFS_FS_TYPE, "", "", 0, 0);
     339        return mount_report("Temporary file system", TMPFS_MOUNT_POINT,
     340            TMPFS_FS_TYPE, NULL, rc);
     341}
     342
     343/** Init system volume.
     344 *
     345 * See if system volume is configured. If so, try to wait for it to become
     346 * available. If not, create basic directories for live image omde.
     347 */
     348static errno_t init_sysvol(void)
     349{
     350        vol_t *vol = NULL;
     351        vol_info_t vinfo;
     352        volume_id_t *volume_ids = NULL;
     353        size_t nvols;
     354        size_t i;
     355        errno_t rc;
     356        bool found_cfg;
     357        const char **cp;
     358
     359        rc = vol_create(&vol);
     360        if (rc != EOK) {
     361                printf("Error contacting volume service.\n");
     362                goto error;
     363        }
     364
     365        rc = vol_get_volumes(vol, &volume_ids, &nvols);
     366        if (rc != EOK) {
     367                printf("Error getting list of volumes.\n");
     368                goto error;
     369        }
     370
     371        /* XXX This could be handled more efficiently by volsrv itself */
     372        found_cfg = false;
     373        for (i = 0; i < nvols; i++) {
     374                rc = vol_info(vol, volume_ids[i], &vinfo);
     375                if (rc != EOK) {
     376                        printf("Error getting volume information.\n");
     377                        rc = EIO;
     378                        goto error;
     379                }
     380
     381                if (str_cmp(vinfo.path, "/w") == 0) {
     382                        found_cfg = true;
     383                        break;
     384                }
     385        }
     386
     387        vol_destroy(vol);
     388        free(volume_ids);
     389
     390        if (!found_cfg) {
     391                /* Prepare directory structure for live image mode */
     392                printf("%s: Creating live image directory structure.\n", NAME);
     393                cp = sys_dirs;
     394                while (*cp != NULL) {
     395                        rc = vfs_link_path(*cp, KIND_DIRECTORY, NULL);
     396                        if (rc != EOK) {
     397                                printf("%s: Error creating directory '%s'.\n",
     398                                    NAME, *cp);
     399                                return rc;
     400                        }
     401
     402                        ++cp;
     403                }
     404        } else {
     405                printf("%s: System volume is configured.\n", NAME);
     406        }
     407
     408        return EOK;
     409error:
     410        vol_destroy(vol);
     411        if (volume_ids != NULL)
     412                free(volume_ids);
     413
     414        return rc;
     415}
     416
    214417int main(int argc, char *argv[])
    215418{
     419        errno_t rc;
     420
    216421        info_print();
    217422
     
    221426        }
    222427
    223         /* System server takes over once root is mounted */
    224         srv_start("/srv/system");
     428        /* Make sure file systems are running. */
     429        if (str_cmp(STRING(RDFMT), "tmpfs") != 0)
     430                srv_start("/srv/fs/tmpfs");
     431        if (str_cmp(STRING(RDFMT), "exfat") != 0)
     432                srv_start("/srv/fs/exfat");
     433        if (str_cmp(STRING(RDFMT), "fat") != 0)
     434                srv_start("/srv/fs/fat");
     435        srv_start("/srv/fs/cdfs");
     436        srv_start("/srv/fs/mfs");
     437
     438        srv_start("/srv/klog");
     439        srv_start("/srv/fs/locfs");
     440        srv_start("/srv/taskmon");
     441
     442        if (!mount_locfs()) {
     443                printf("%s: Exiting\n", NAME);
     444                return 2;
     445        }
     446
     447        mount_tmpfs();
     448
     449        srv_start("/srv/devman");
     450        srv_start("/srv/hid/s3c24xx_uart");
     451        srv_start("/srv/hid/s3c24xx_ts");
     452
     453        srv_start("/srv/bd/vbd");
     454        srv_start("/srv/volsrv");
     455
     456        srv_start("/srv/net/loopip");
     457        srv_start("/srv/net/ethip");
     458        srv_start("/srv/net/inetsrv");
     459        srv_start("/srv/net/tcp");
     460        srv_start("/srv/net/udp");
     461        srv_start("/srv/net/dnsrsrv");
     462        srv_start("/srv/net/dhcp");
     463        srv_start("/srv/net/nconfsrv");
     464
     465        srv_start("/srv/clipboard");
     466        srv_start("/srv/hid/remcons");
     467
     468        srv_start("/srv/hid/input", HID_INPUT);
     469        srv_start("/srv/hid/output", HID_OUTPUT);
     470        srv_start("/srv/audio/hound");
     471
     472        init_sysvol();
     473
     474#ifdef CONFIG_WINSYS
     475        if (!config_key_exists("console")) {
     476                rc = display_server();
     477                if (rc == EOK) {
     478                        app_start("/app/taskbar", NULL);
     479                        app_start("/app/terminal", "-topleft");
     480                }
     481        }
     482#endif
     483        rc = console(HID_INPUT, HID_OUTPUT);
     484        if (rc == EOK) {
     485                getterm("term/vc0", "/app/bdsh", true);
     486                getterm("term/vc1", "/app/bdsh", false);
     487                getterm("term/vc2", "/app/bdsh", false);
     488                getterm("term/vc3", "/app/bdsh", false);
     489                getterm("term/vc4", "/app/bdsh", false);
     490                getterm("term/vc5", "/app/bdsh", false);
     491        }
     492
    225493        return 0;
    226494}
Note: See TracChangeset for help on using the changeset viewer.