Changeset 90ee338 in mainline


Ignore:
Timestamp:
2025-04-06T17:08:19Z (22 hours ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
master
Parents:
59e32fb
Message:

Allow sysinst to restart the system at the end of installation.

When -r option is passed.

Location:
uspace/app/sysinst
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/sysinst/meson.build

    r59e32fb r90ee338  
    2727#
    2828
    29 deps = [ 'block', 'fdisk', 'futil', 'sif' ]
     29deps = [ 'block', 'fdisk', 'futil', 'sif', 'system' ]
    3030src = files(
    3131        'rdimg.c',
  • uspace/app/sysinst/sysinst.c

    r59e32fb r90ee338  
    4747#include <str.h>
    4848#include <str_error.h>
     49#include <system.h>
    4950#include <vfs/vfs.h>
    5051#include <vol.h>
     
    9495        NULL
    9596};
     97
     98static bool restart = false;
     99
     100static fibril_mutex_t shutdown_lock;
     101static fibril_condvar_t shutdown_cv;
     102static bool shutdown_stopped;
     103static bool shutdown_failed;
     104
     105static void sysinst_shutdown_complete(void *);
     106static void sysinst_shutdown_failed(void *);
     107
     108static system_cb_t sysinst_system_cb = {
     109        .shutdown_complete = sysinst_shutdown_complete,
     110        .shutdown_failed = sysinst_shutdown_failed
     111};
     112
     113/** System shutdown complete.
     114 *
     115 * @param arg Argument (shutdown_t *)
     116 */
     117static void sysinst_shutdown_complete(void *arg)
     118{
     119        (void)arg;
     120
     121        fibril_mutex_lock(&shutdown_lock);
     122        shutdown_stopped = true;
     123        shutdown_failed = false;
     124        fibril_condvar_broadcast(&shutdown_cv);
     125        fibril_mutex_unlock(&shutdown_lock);
     126}
     127
     128/** System shutdown failed.
     129 *
     130 * @param arg Argument (not used)
     131 */
     132static void sysinst_shutdown_failed(void *arg)
     133{
     134        (void)arg;
     135
     136        fibril_mutex_lock(&shutdown_lock);
     137        shutdown_stopped = true;
     138        shutdown_failed = true;
     139        fibril_condvar_broadcast(&shutdown_cv);
     140        fibril_mutex_unlock(&shutdown_lock);
     141}
    96142
    97143/** Check the if the destination device exists.
     
    487533}
    488534
     535/** Restart the system.
     536 *
     537 * @return EOK on success or an error code
     538 */
     539static errno_t sysinst_restart(void)
     540{
     541        errno_t rc;
     542        system_t *system;
     543
     544        fibril_mutex_initialize(&shutdown_lock);
     545        fibril_condvar_initialize(&shutdown_cv);
     546        shutdown_stopped = false;
     547        shutdown_failed = false;
     548
     549        rc = system_open(SYSTEM_DEFAULT, &sysinst_system_cb, NULL, &system);
     550        if (rc != EOK) {
     551                printf("Failed opening system control service.\n");
     552                return rc;
     553        }
     554
     555        rc = system_restart(system);
     556        if (rc != EOK) {
     557                system_close(system);
     558                printf("Failed requesting system restart.\n");
     559                return rc;
     560        }
     561
     562        fibril_mutex_lock(&shutdown_lock);
     563        printf("The system is shutting down...\n");
     564        while (!shutdown_stopped)
     565                fibril_condvar_wait(&shutdown_cv, &shutdown_lock);
     566
     567        if (shutdown_failed) {
     568                printf("Shutdown failed.\n");
     569                system_close(system);
     570                return rc;
     571        }
     572
     573        printf("Shutdown complete. It is now safe to remove power.\n");
     574
     575        /* Sleep forever */
     576        while (true)
     577                fibril_condvar_wait(&shutdown_cv, &shutdown_lock);
     578
     579        fibril_mutex_unlock(&shutdown_lock);
     580
     581        system_close(system);
     582        return 0;
     583
     584}
     585
    489586/** Install system to a device.
    490587 *
     
    526623                return rc;
    527624
     625        rc = sysinst_restart();
     626        if (rc != EOK)
     627                return rc;
     628
    528629        return EOK;
    529630}
     
    533634        unsigned i;
    534635        errno_t rc;
     636
     637        if (argc > 1 && str_cmp(argv[1], "-r") == 0)
     638                restart = true;
    535639
    536640        i = 0;
     
    539643                if (rc == EOK)
    540644                        break;
     645                ++i;
    541646        }
    542647
Note: See TracChangeset for help on using the changeset viewer.