Changeset ad9e225 in mainline
- Timestamp:
- 2024-10-24T18:20:37Z (5 weeks ago)
- Branches:
- master
- Children:
- 0d00e53, aeef65a2, c06a58c
- Parents:
- a72f3b8
- Location:
- uspace
- Files:
-
- 4 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/meson.build
ra72f3b8 rad9e225 77 77 'redir', 78 78 'sbi', 79 'shutdown', 79 80 'sportdmp', 80 81 'stats', -
uspace/srv/system/meson.build
ra72f3b8 rad9e225 27 27 # 28 28 29 deps = [ 'device', 'futil' ]29 deps = [ 'device', 'futil', 'system' ] 30 30 src = files('system.c') -
uspace/srv/system/system.c
ra72f3b8 rad9e225 37 37 #include <fibril.h> 38 38 #include <futil.h> 39 #include <io/log.h> 39 40 #include <stdio.h> 40 41 #include <stdarg.h> … … 52 53 #include <vfs/vfs.h> 53 54 #include <vol.h> 55 #include <system.h> 56 #include <system_srv.h> 54 57 #include "system.h" 55 58 … … 78 81 "/w/data", 79 82 NULL, 83 }; 84 85 static void system_srv_conn(ipc_call_t *, void *); 86 static errno_t system_srv_shutdown(void *); 87 88 system_ops_t system_srv_ops = { 89 .shutdown = system_srv_shutdown 80 90 }; 81 91 … … 420 430 } 421 431 422 int main(int argc, char *argv[]) 432 /** Perform sytem startup tasks. 433 * 434 * @return EOK on success or an error code 435 */ 436 static errno_t system_startup(void) 423 437 { 424 438 errno_t rc; 425 426 info_print();427 439 428 440 /* Make sure file systems are running. */ … … 441 453 if (!mount_locfs()) { 442 454 printf("%s: Exiting\n", NAME); 443 return 2;455 return EIO; 444 456 } 445 457 … … 491 503 } 492 504 505 return EOK; 506 } 507 508 /** Perform sytem shutdown tasks. 509 * 510 * @return EOK on success or an error code 511 */ 512 static errno_t system_sys_shutdown(void) 513 { 514 vol_t *vol = NULL; 515 service_id_t *part_ids = NULL; 516 size_t nparts; 517 size_t i; 518 errno_t rc; 519 520 /* Eject all volumes. */ 521 522 rc = vol_create(&vol); 523 if (rc != EOK) { 524 log_msg(LOG_DEFAULT, LVL_ERROR, "Error contacting volume " 525 "service."); 526 goto error; 527 } 528 529 rc = vol_get_parts(vol, &part_ids, &nparts); 530 if (rc != EOK) { 531 log_msg(LOG_DEFAULT, LVL_ERROR, "Error getting volume list."); 532 goto error; 533 } 534 535 for (i = 0; i < nparts; i++) { 536 rc = vol_part_eject(vol, part_ids[i]); 537 if (rc != EOK) { 538 log_msg(LOG_DEFAULT, LVL_ERROR, "Error ejecting " 539 "volume %zu", (size_t)part_ids[i]); 540 goto error; 541 } 542 } 543 544 free(part_ids); 545 vol_destroy(vol); 546 return EOK; 547 error: 548 if (part_ids != NULL) 549 free(part_ids); 550 if (vol != NULL) 551 vol_destroy(vol); 552 return rc; 553 } 554 555 /** Initialize system control service. */ 556 static errno_t system_srv_init(sys_srv_t *syssrv) 557 { 558 port_id_t port; 559 loc_srv_t *srv = NULL; 560 service_id_t sid = 0; 561 errno_t rc; 562 563 (void)system; 564 565 log_msg(LOG_DEFAULT, LVL_DEBUG, "system_srv_init()"); 566 567 rc = async_create_port(INTERFACE_SYSTEM, system_srv_conn, syssrv, 568 &port); 569 if (rc != EOK) 570 goto error; 571 572 rc = loc_server_register(NAME, &srv); 573 if (rc != EOK) { 574 log_msg(LOG_DEFAULT, LVL_ERROR, 575 "Failed registering server: %s.", str_error(rc)); 576 rc = EEXIST; 577 goto error; 578 } 579 580 rc = loc_service_register(srv, SYSTEM_DEFAULT, &sid); 581 if (rc != EOK) { 582 log_msg(LOG_DEFAULT, LVL_ERROR, 583 "Failed registering service: %s.", str_error(rc)); 584 rc = EEXIST; 585 goto error; 586 } 587 588 return EOK; 589 error: 590 if (sid != 0) 591 loc_service_unregister(srv, sid); 592 if (srv != NULL) 593 loc_server_unregister(srv); 594 // XXX destroy port 595 return rc; 596 } 597 598 /** Handle connection to system server. */ 599 static void system_srv_conn(ipc_call_t *icall, void *arg) 600 { 601 sys_srv_t *syssrv = (sys_srv_t *)arg; 602 603 /* Set up protocol structure */ 604 system_srv_initialize(&syssrv->srv); 605 syssrv->srv.ops = &system_srv_ops; 606 syssrv->srv.arg = syssrv; 607 608 /* Handle connection */ 609 system_conn(icall, &syssrv->srv); 610 } 611 612 /** System shutdown request. 613 * 614 * @param arg Argument (sys_srv_t *) 615 */ 616 static errno_t system_srv_shutdown(void *arg) 617 { 618 sys_srv_t *syssrv = (sys_srv_t *)arg; 619 errno_t rc; 620 621 log_msg(LOG_DEFAULT, LVL_NOTE, "system_srv_shutdown"); 622 623 rc = system_sys_shutdown(); 624 if (rc != EOK) { 625 log_msg(LOG_DEFAULT, LVL_NOTE, "system_srv_shutdown failed"); 626 system_srv_shutdown_failed(&syssrv->srv); 627 } 628 629 log_msg(LOG_DEFAULT, LVL_NOTE, "system_srv_shutdown complete"); 630 system_srv_shutdown_complete(&syssrv->srv); 631 return EOK; 632 } 633 634 int main(int argc, char *argv[]) 635 { 636 errno_t rc; 637 sys_srv_t srv; 638 639 info_print(); 640 641 if (log_init(NAME) != EOK) { 642 printf(NAME ": Failed to initialize logging.\n"); 643 return 1; 644 } 645 646 /* Perform startup tasks. */ 647 rc = system_startup(); 648 if (rc != EOK) 649 return 1; 650 651 rc = system_srv_init(&srv); 652 if (rc != EOK) 653 return 1; 654 655 printf(NAME ": Accepting connections.\n"); 656 task_retval(0); 657 async_manager(); 658 493 659 return 0; 494 660 } -
uspace/srv/system/system.h
ra72f3b8 rad9e225 38 38 #define SYSTEM_H 39 39 40 #include <system_srv.h> 41 40 42 #define NAME "system" 43 44 typedef struct { 45 system_srv_t srv; 46 } sys_srv_t; 41 47 42 48 #endif
Note:
See TracChangeset
for help on using the changeset viewer.