Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/system/system.c

    ra188131 rad9e225  
    11/*
    2  * Copyright (c) 2025 Jiri Svoboda
     2 * Copyright (c) 2024 Jiri Svoboda
    33 * Copyright (c) 2005 Martin Decky
    44 * All rights reserved.
     
    3535 */
    3636
    37 #include <devman.h>
    3837#include <fibril.h>
    3938#include <futil.h>
     
    4948#include <str.h>
    5049#include <loc.h>
    51 #include <shutdown.h>
    5250#include <str_error.h>
    5351#include <config.h>
     
    8684
    8785static void system_srv_conn(ipc_call_t *, void *);
    88 static errno_t system_srv_poweroff(void *);
    89 static errno_t system_srv_restart(void *);
     86static errno_t system_srv_shutdown(void *);
    9087
    9188system_ops_t system_srv_ops = {
    92         .poweroff = system_srv_poweroff,
    93         .restart = system_srv_restart
     89        .shutdown = system_srv_shutdown
    9490};
    9591
     
    328324        size_t nparts;
    329325        bool sv_mounted;
    330         futil_t *futil = NULL;
    331326        size_t i;
    332327        errno_t rc;
     
    381376
    382377                /* Copy initial configuration files */
    383                 rc = futil_create(NULL, NULL, &futil);
     378                rc = futil_rcopy_contents("/cfg", "/w/cfg");
    384379                if (rc != EOK)
    385380                        goto error;
    386 
    387                 rc = futil_rcopy_contents(futil, "/cfg", "/w/cfg");
    388                 if (rc != EOK)
    389                         goto error;
    390 
    391                 futil_destroy(futil);
    392                 futil = NULL;
    393381        } else {
    394382                printf("%s: System volume is configured.\n", NAME);
    395383
    396                 /* Verify that system volume is mounted */
     384                /* Wait until system volume is mounted */
    397385                sv_mounted = false;
    398386
    399                 rc = vol_get_parts(vol, &part_ids, &nparts);
    400                 if (rc != EOK) {
    401                         printf("Error getting list of volumes.\n");
    402                         goto error;
    403                 }
    404 
    405                 for (i = 0; i < nparts; i++) {
    406                         rc = vol_part_info(vol, part_ids[i], &pinfo);
     387                while (true) {
     388                        rc = vol_get_parts(vol, &part_ids, &nparts);
    407389                        if (rc != EOK) {
    408                                 printf("Error getting partition "
    409                                     "information.\n");
    410                                 rc = EIO;
     390                                printf("Error getting list of volumes.\n");
    411391                                goto error;
    412392                        }
    413393
    414                         if (str_cmp(pinfo.cur_mp, "/w") == 0) {
    415                                 sv_mounted = true;
     394                        for (i = 0; i < nparts; i++) {
     395                                rc = vol_part_info(vol, part_ids[i], &pinfo);
     396                                if (rc != EOK) {
     397                                        printf("Error getting partition "
     398                                            "information.\n");
     399                                        rc = EIO;
     400                                        goto error;
     401                                }
     402
     403                                if (str_cmp(pinfo.cur_mp, "/w") == 0) {
     404                                        sv_mounted = true;
     405                                        break;
     406                                }
     407                        }
     408
     409                        if (sv_mounted)
    416410                                break;
    417                         }
    418                 }
    419 
    420                 if (sv_mounted == false) {
    421                         printf("System volume not found.\n");
    422                         rc = EIO;
    423                         goto error;
    424                 }
    425 
    426                 free(part_ids);
    427                 part_ids = NULL;
    428 
     411
     412                        free(part_ids);
     413                        part_ids = NULL;
     414
     415                        fibril_sleep(1);
     416                        printf("Sleeping(1) for system volume.\n");
     417                }
    429418        }
    430419
     
    437426        if (part_ids != NULL)
    438427                free(part_ids);
    439         if (futil != NULL)
    440                 futil_destroy(futil);
    441428
    442429        return rc;
     
    533520        /* Eject all volumes. */
    534521
    535         log_msg(LOG_DEFAULT, LVL_NOTE, "Ejecting volumes.");
    536 
    537522        rc = vol_create(&vol);
    538523        if (rc != EOK) {
     
    549534
    550535        for (i = 0; i < nparts; i++) {
    551                 rc = vol_part_eject(vol, part_ids[i], vef_none);
     536                rc = vol_part_eject(vol, part_ids[i]);
    552537                if (rc != EOK) {
    553538                        log_msg(LOG_DEFAULT, LVL_ERROR, "Error ejecting "
     
    559544        free(part_ids);
    560545        vol_destroy(vol);
    561 
    562546        return EOK;
    563547error:
     
    626610}
    627611
    628 /** System poweroff request.
     612/** System shutdown request.
    629613 *
    630614 * @param arg Argument (sys_srv_t *)
    631615 */
    632 static errno_t system_srv_poweroff(void *arg)
     616static errno_t system_srv_shutdown(void *arg)
    633617{
    634618        sys_srv_t *syssrv = (sys_srv_t *)arg;
    635619        errno_t rc;
    636620
    637         log_msg(LOG_DEFAULT, LVL_NOTE, "system_srv_poweroff");
     621        log_msg(LOG_DEFAULT, LVL_NOTE, "system_srv_shutdown");
    638622
    639623        rc = system_sys_shutdown();
    640624        if (rc != EOK) {
    641                 log_msg(LOG_DEFAULT, LVL_NOTE, "system_srv_poweroff failed");
     625                log_msg(LOG_DEFAULT, LVL_NOTE, "system_srv_shutdown failed");
    642626                system_srv_shutdown_failed(&syssrv->srv);
    643627        }
    644628
    645         log_msg(LOG_DEFAULT, LVL_NOTE, "system_srv_poweroff complete");
    646         system_srv_shutdown_complete(&syssrv->srv);
    647         return EOK;
    648 }
    649 
    650 /** System restart request.
    651  *
    652  * @param arg Argument (sys_srv_t *)
    653  */
    654 static errno_t system_srv_restart(void *arg)
    655 {
    656         sys_srv_t *syssrv = (sys_srv_t *)arg;
    657         errno_t rc;
    658 
    659         log_msg(LOG_DEFAULT, LVL_NOTE, "system_srv_restart");
    660 
    661         rc = system_sys_shutdown();
    662         if (rc != EOK) {
    663                 log_msg(LOG_DEFAULT, LVL_NOTE, "system_srv_restart failed");
    664                 system_srv_shutdown_failed(&syssrv->srv);
    665         }
    666 
    667         /* Quiesce the device tree. */
    668 
    669         log_msg(LOG_DEFAULT, LVL_NOTE, "Quiescing devices.");
    670 
    671         rc = devman_quiesce_devices("/hw");
    672         if (rc != EOK) {
    673                 log_msg(LOG_DEFAULT, LVL_ERROR,
    674                     "Failed to quiesce device tree.");
    675                 return rc;
    676         }
    677 
    678         sys_reboot();
    679 
    680         log_msg(LOG_DEFAULT, LVL_NOTE, "system_srv_restart complete");
     629        log_msg(LOG_DEFAULT, LVL_NOTE, "system_srv_shutdown complete");
    681630        system_srv_shutdown_complete(&syssrv->srv);
    682631        return EOK;
Note: See TracChangeset for help on using the changeset viewer.