Changes in uspace/srv/system/system.c [ad9e225:ca48672] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/system/system.c
rad9e225 rca48672 1 1 /* 2 * Copyright (c) 202 4Jiri Svoboda2 * Copyright (c) 2025 Jiri Svoboda 3 3 * Copyright (c) 2005 Martin Decky 4 4 * All rights reserved. … … 35 35 */ 36 36 37 #include <devman.h> 37 38 #include <fibril.h> 38 39 #include <futil.h> … … 48 49 #include <str.h> 49 50 #include <loc.h> 51 #include <shutdown.h> 50 52 #include <str_error.h> 51 53 #include <config.h> … … 84 86 85 87 static void system_srv_conn(ipc_call_t *, void *); 86 static errno_t system_srv_shutdown(void *); 88 static errno_t system_srv_poweroff(void *); 89 static errno_t system_srv_restart(void *); 87 90 88 91 system_ops_t system_srv_ops = { 89 .shutdown = system_srv_shutdown 92 .poweroff = system_srv_poweroff, 93 .restart = system_srv_restart 90 94 }; 91 95 … … 324 328 size_t nparts; 325 329 bool sv_mounted; 330 futil_t *futil = NULL; 326 331 size_t i; 327 332 errno_t rc; … … 376 381 377 382 /* Copy initial configuration files */ 378 rc = futil_ rcopy_contents("/cfg", "/w/cfg");383 rc = futil_create(NULL, NULL, &futil); 379 384 if (rc != EOK) 380 385 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; 381 393 } else { 382 394 printf("%s: System volume is configured.\n", NAME); 383 395 384 /* Wait untilsystem volume is mounted */396 /* Verify that system volume is mounted */ 385 397 sv_mounted = false; 386 398 387 while (true) { 388 rc = vol_get_parts(vol, &part_ids, &nparts); 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); 389 407 if (rc != EOK) { 390 printf("Error getting list of volumes.\n"); 408 printf("Error getting partition " 409 "information.\n"); 410 rc = EIO; 391 411 goto error; 392 412 } 393 413 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 } 414 if (str_cmp(pinfo.cur_mp, "/w") == 0) { 415 sv_mounted = true; 416 break; 407 417 } 408 409 if (sv_mounted) 410 break; 411 412 free(part_ids); 413 part_ids = NULL; 414 415 fibril_sleep(1); 416 printf("Sleeping(1) for system volume.\n"); 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 418 429 } 419 430 … … 426 437 if (part_ids != NULL) 427 438 free(part_ids); 439 if (futil != NULL) 440 futil_destroy(futil); 428 441 429 442 return rc; … … 520 533 /* Eject all volumes. */ 521 534 535 log_msg(LOG_DEFAULT, LVL_NOTE, "Ejecting volumes."); 536 522 537 rc = vol_create(&vol); 523 538 if (rc != EOK) { … … 534 549 535 550 for (i = 0; i < nparts; i++) { 536 rc = vol_part_eject(vol, part_ids[i] );551 rc = vol_part_eject(vol, part_ids[i], vef_none); 537 552 if (rc != EOK) { 538 553 log_msg(LOG_DEFAULT, LVL_ERROR, "Error ejecting " … … 544 559 free(part_ids); 545 560 vol_destroy(vol); 561 546 562 return EOK; 547 563 error: … … 556 572 static errno_t system_srv_init(sys_srv_t *syssrv) 557 573 { 558 port_id_t port ;574 port_id_t port = 0; 559 575 loc_srv_t *srv = NULL; 560 576 service_id_t sid = 0; … … 578 594 } 579 595 580 rc = loc_service_register(srv, SYSTEM_DEFAULT, &sid);596 rc = loc_service_register(srv, SYSTEM_DEFAULT, port, &sid); 581 597 if (rc != EOK) { 582 598 log_msg(LOG_DEFAULT, LVL_ERROR, … … 592 608 if (srv != NULL) 593 609 loc_server_unregister(srv); 594 // XXX destroy port 610 if (port != 0) 611 async_port_destroy(port); 595 612 return rc; 596 613 } … … 610 627 } 611 628 612 /** System shutdownrequest.629 /** System poweroff request. 613 630 * 614 631 * @param arg Argument (sys_srv_t *) 615 632 */ 616 static errno_t system_srv_ shutdown(void *arg)633 static errno_t system_srv_poweroff(void *arg) 617 634 { 618 635 sys_srv_t *syssrv = (sys_srv_t *)arg; 619 636 errno_t rc; 620 637 621 log_msg(LOG_DEFAULT, LVL_NOTE, "system_srv_ shutdown");638 log_msg(LOG_DEFAULT, LVL_NOTE, "system_srv_poweroff"); 622 639 623 640 rc = system_sys_shutdown(); 624 641 if (rc != EOK) { 625 log_msg(LOG_DEFAULT, LVL_NOTE, "system_srv_ shutdownfailed");642 log_msg(LOG_DEFAULT, LVL_NOTE, "system_srv_poweroff failed"); 626 643 system_srv_shutdown_failed(&syssrv->srv); 627 644 } 628 645 629 log_msg(LOG_DEFAULT, LVL_NOTE, "system_srv_shutdown complete"); 646 log_msg(LOG_DEFAULT, LVL_NOTE, "system_srv_poweroff complete"); 647 system_srv_shutdown_complete(&syssrv->srv); 648 return EOK; 649 } 650 651 /** System restart request. 652 * 653 * @param arg Argument (sys_srv_t *) 654 */ 655 static errno_t system_srv_restart(void *arg) 656 { 657 sys_srv_t *syssrv = (sys_srv_t *)arg; 658 errno_t rc; 659 660 log_msg(LOG_DEFAULT, LVL_NOTE, "system_srv_restart"); 661 662 rc = system_sys_shutdown(); 663 if (rc != EOK) { 664 log_msg(LOG_DEFAULT, LVL_NOTE, "system_srv_restart failed"); 665 system_srv_shutdown_failed(&syssrv->srv); 666 } 667 668 /* Quiesce the device tree. */ 669 670 log_msg(LOG_DEFAULT, LVL_NOTE, "Quiescing devices."); 671 672 rc = devman_quiesce_devices("/hw"); 673 if (rc != EOK) { 674 log_msg(LOG_DEFAULT, LVL_ERROR, 675 "Failed to quiesce device tree."); 676 return rc; 677 } 678 679 sys_reboot(); 680 681 log_msg(LOG_DEFAULT, LVL_NOTE, "system_srv_restart complete"); 630 682 system_srv_shutdown_complete(&syssrv->srv); 631 683 return EOK;
Note:
See TracChangeset
for help on using the changeset viewer.