Changeset 90ee338 in mainline for uspace/app/sysinst/sysinst.c
- Timestamp:
- 2025-04-06T17:08:19Z (27 hours ago)
- Branches:
- master
- Parents:
- 59e32fb
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/sysinst/sysinst.c
r59e32fb r90ee338 47 47 #include <str.h> 48 48 #include <str_error.h> 49 #include <system.h> 49 50 #include <vfs/vfs.h> 50 51 #include <vol.h> … … 94 95 NULL 95 96 }; 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_failed 111 }; 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 } 96 142 97 143 /** Check the if the destination device exists. … … 487 533 } 488 534 535 /** Restart the system. 536 * 537 * @return EOK on success or an error code 538 */ 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 489 586 /** Install system to a device. 490 587 * … … 526 623 return rc; 527 624 625 rc = sysinst_restart(); 626 if (rc != EOK) 627 return rc; 628 528 629 return EOK; 529 630 } … … 533 634 unsigned i; 534 635 errno_t rc; 636 637 if (argc > 1 && str_cmp(argv[1], "-r") == 0) 638 restart = true; 535 639 536 640 i = 0; … … 539 643 if (rc == EOK) 540 644 break; 645 ++i; 541 646 } 542 647
Note:
See TracChangeset
for help on using the changeset viewer.