Changes in uspace/app/sysinst/sysinst.c [90ee338:ca127f37] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/sysinst/sysinst.c
r90ee338 rca127f37 1 1 /* 2 * Copyright (c) 202 5Jiri Svoboda2 * Copyright (c) 2024 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 47 47 #include <str.h> 48 48 #include <str_error.h> 49 #include <system.h>50 49 #include <vfs/vfs.h> 51 50 #include <vol.h> … … 64 63 */ 65 64 #define DEFAULT_DEV_0 "devices/\\hw\\sys\\00:01.1\\c0d0" 66 #define DEFAULT_DEV_1 "devices/\\hw\\sys\\00:01.0\\ ide1\\c0d0"65 #define DEFAULT_DEV_1 "devices/\\hw\\sys\\00:01.0\\ata1\\c0d0" 67 66 //#define DEFAULT_DEV "devices/\\hw\\pci0\\00:01.2\\uhci_rh\\usb01_a1\\mass-storage0\\l0" 68 67 /** Volume label for the new file system */ … … 95 94 NULL 96 95 }; 97 98 static bool restart = false;99 100 static fibril_mutex_t shutdown_lock;101 static fibril_condvar_t shutdown_cv;102 static bool shutdown_stopped;103 static bool shutdown_failed;104 105 static void sysinst_shutdown_complete(void *);106 static void sysinst_shutdown_failed(void *);107 108 static system_cb_t sysinst_system_cb = {109 .shutdown_complete = sysinst_shutdown_complete,110 .shutdown_failed = sysinst_shutdown_failed111 };112 113 /** System shutdown complete.114 *115 * @param arg Argument (shutdown_t *)116 */117 static 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 */132 static 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 }142 96 143 97 /** Check the if the destination device exists. … … 521 475 } 522 476 523 rc = vol_part_eject(vol, part_id , vef_physical);477 rc = vol_part_eject(vol, part_id); 524 478 if (rc != EOK) { 525 479 printf("Error ejecting volume.\n"); … … 533 487 } 534 488 535 /** Restart the system.536 *537 * @return EOK on success or an error code538 */539 static 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 586 489 /** Install system to a device. 587 490 * … … 623 526 return rc; 624 527 625 rc = sysinst_restart();626 if (rc != EOK)627 return rc;628 629 528 return EOK; 630 529 } … … 634 533 unsigned i; 635 534 errno_t rc; 636 637 if (argc > 1 && str_cmp(argv[1], "-r") == 0)638 restart = true;639 535 640 536 i = 0; … … 643 539 if (rc == EOK) 644 540 break; 645 ++i;646 541 } 647 542
Note:
See TracChangeset
for help on using the changeset viewer.