Changeset 51da086 in mainline


Ignore:
Timestamp:
2020-01-21T15:13:57Z (5 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
14b5c30f
Parents:
01900b6
Message:

fail fast the boot process if we encounter an out-of-memory condition

There is no point in continuing the boot process if we encounter an
out-of-memory condition while spawning the essential system tasks.
Failing fast in such cases should improve the user experience.

File:
1 edited

Legend:

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

    r01900b6 r51da086  
    5151#include "init.h"
    5252
     53#define BANNER_LEFT   "######> "
     54#define BANNER_RIGHT  " <######"
     55
    5356#define ROOT_DEVICE       "bd/initrd"
    5457#define ROOT_MOUNT_POINT  "/"
     
    8184{
    8285        printf("%s: HelenOS init\n", NAME);
     86}
     87
     88static void oom_check(errno_t rc, const char *path)
     89{
     90        if (rc == ENOMEM) {
     91                printf("%sOut-of-memory condition detected%s\n", BANNER_LEFT,
     92                    BANNER_RIGHT);
     93                printf("%sBailing out of the boot process after %s%s\n",
     94                    BANNER_LEFT, path, BANNER_RIGHT);
     95                printf("%sMore physical memory is required%s\n", BANNER_LEFT,
     96                    BANNER_RIGHT);
     97                exit(ENOMEM);
     98        }
    8399}
    84100
     
    199215
    200216        if (rc != EOK) {
     217                oom_check(rc, path);
    201218                printf("%s: Error spawning %s (%s)\n", NAME, path,
    202219                    str_error(rc));
     
    279296        errno_t rc = task_spawnl(&id, &wait, app, app, winreg, NULL);
    280297        if (rc != EOK) {
     298                oom_check(rc, app);
    281299                printf("%s: Error spawning %s %s (%s)\n", NAME, app,
    282300                    winreg, str_error(rc));
    283                 return -1;
     301                return rc;
    284302        }
    285303
     
    290308                printf("%s: Error retrieving retval from %s (%s)\n", NAME,
    291309                    app, str_error(rc));
    292                 return -1;
     310                return rc;
    293311        }
    294312
     
    304322                errno_t rc = task_spawnl(NULL, NULL, APP_GETTERM, APP_GETTERM, svc,
    305323                    LOCFS_MOUNT_POINT, "--msg", "--wait", "--", app, NULL);
    306                 if (rc != EOK)
     324                if (rc != EOK) {
     325                        oom_check(rc, APP_GETTERM);
    307326                        printf("%s: Error spawning %s %s %s --msg --wait -- %s\n",
    308327                            NAME, APP_GETTERM, svc, LOCFS_MOUNT_POINT, app);
     328                }
    309329        } else {
    310330                printf("%s: Spawning %s %s %s --wait -- %s\n", NAME,
     
    313333                errno_t rc = task_spawnl(NULL, NULL, APP_GETTERM, APP_GETTERM, svc,
    314334                    LOCFS_MOUNT_POINT, "--wait", "--", app, NULL);
    315                 if (rc != EOK)
     335                if (rc != EOK) {
     336                        oom_check(rc, APP_GETTERM);
    316337                        printf("%s: Error spawning %s %s %s --wait -- %s\n",
    317338                            NAME, APP_GETTERM, svc, LOCFS_MOUNT_POINT, app);
     339                }
    318340        }
    319341}
Note: See TracChangeset for help on using the changeset viewer.