Changes in uspace/srv/system/system.c [ca48672:ad9e225] in mainline
- File:
-
- 1 edited
-
uspace/srv/system/system.c (modified) (14 diffs)
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/system/system.c
rca48672 rad9e225 1 1 /* 2 * Copyright (c) 202 5Jiri Svoboda2 * Copyright (c) 2024 Jiri Svoboda 3 3 * Copyright (c) 2005 Martin Decky 4 4 * All rights reserved. … … 35 35 */ 36 36 37 #include <devman.h>38 37 #include <fibril.h> 39 38 #include <futil.h> … … 49 48 #include <str.h> 50 49 #include <loc.h> 51 #include <shutdown.h>52 50 #include <str_error.h> 53 51 #include <config.h> … … 86 84 87 85 static void system_srv_conn(ipc_call_t *, void *); 88 static errno_t system_srv_poweroff(void *); 89 static errno_t system_srv_restart(void *); 86 static errno_t system_srv_shutdown(void *); 90 87 91 88 system_ops_t system_srv_ops = { 92 .poweroff = system_srv_poweroff, 93 .restart = system_srv_restart 89 .shutdown = system_srv_shutdown 94 90 }; 95 91 … … 328 324 size_t nparts; 329 325 bool sv_mounted; 330 futil_t *futil = NULL;331 326 size_t i; 332 327 errno_t rc; … … 381 376 382 377 /* Copy initial configuration files */ 383 rc = futil_ create(NULL, NULL, &futil);378 rc = futil_rcopy_contents("/cfg", "/w/cfg"); 384 379 if (rc != EOK) 385 380 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;393 381 } else { 394 382 printf("%s: System volume is configured.\n", NAME); 395 383 396 /* Verify thatsystem volume is mounted */384 /* Wait until system volume is mounted */ 397 385 sv_mounted = false; 398 386 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); 407 389 if (rc != EOK) { 408 printf("Error getting partition " 409 "information.\n"); 410 rc = EIO; 390 printf("Error getting list of volumes.\n"); 411 391 goto error; 412 392 } 413 393 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) 416 410 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 } 429 418 } 430 419 … … 437 426 if (part_ids != NULL) 438 427 free(part_ids); 439 if (futil != NULL)440 futil_destroy(futil);441 428 442 429 return rc; … … 533 520 /* Eject all volumes. */ 534 521 535 log_msg(LOG_DEFAULT, LVL_NOTE, "Ejecting volumes.");536 537 522 rc = vol_create(&vol); 538 523 if (rc != EOK) { … … 549 534 550 535 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]); 552 537 if (rc != EOK) { 553 538 log_msg(LOG_DEFAULT, LVL_ERROR, "Error ejecting " … … 559 544 free(part_ids); 560 545 vol_destroy(vol); 561 562 546 return EOK; 563 547 error: … … 572 556 static errno_t system_srv_init(sys_srv_t *syssrv) 573 557 { 574 port_id_t port = 0;558 port_id_t port; 575 559 loc_srv_t *srv = NULL; 576 560 service_id_t sid = 0; … … 594 578 } 595 579 596 rc = loc_service_register(srv, SYSTEM_DEFAULT, port,&sid);580 rc = loc_service_register(srv, SYSTEM_DEFAULT, &sid); 597 581 if (rc != EOK) { 598 582 log_msg(LOG_DEFAULT, LVL_ERROR, … … 608 592 if (srv != NULL) 609 593 loc_server_unregister(srv); 610 if (port != 0) 611 async_port_destroy(port); 594 // XXX destroy port 612 595 return rc; 613 596 } … … 627 610 } 628 611 629 /** System poweroffrequest.612 /** System shutdown request. 630 613 * 631 614 * @param arg Argument (sys_srv_t *) 632 615 */ 633 static errno_t system_srv_ poweroff(void *arg)616 static errno_t system_srv_shutdown(void *arg) 634 617 { 635 618 sys_srv_t *syssrv = (sys_srv_t *)arg; 636 619 errno_t rc; 637 620 638 log_msg(LOG_DEFAULT, LVL_NOTE, "system_srv_ poweroff");621 log_msg(LOG_DEFAULT, LVL_NOTE, "system_srv_shutdown"); 639 622 640 623 rc = system_sys_shutdown(); 641 624 if (rc != EOK) { 642 log_msg(LOG_DEFAULT, LVL_NOTE, "system_srv_ powerofffailed");625 log_msg(LOG_DEFAULT, LVL_NOTE, "system_srv_shutdown failed"); 643 626 system_srv_shutdown_failed(&syssrv->srv); 644 627 } 645 628 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"); 629 log_msg(LOG_DEFAULT, LVL_NOTE, "system_srv_shutdown complete"); 682 630 system_srv_shutdown_complete(&syssrv->srv); 683 631 return EOK;
Note:
See TracChangeset
for help on using the changeset viewer.
