Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(145)

Side by Side Diff: dhcpcd-dbus.c

Issue 3060016: Added a D-Bus filter to find out when flimflamd dies, so that we can clean up and exit. (Closed) Base URL: ssh://git@chromiumos-git/dhcpcd.git
Patch Set: Created 10 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * dhcpcd-dbus 2 * dhcpcd-dbus
3 * Copyright 2009 Roy Marples <roy@marples.name> 3 * Copyright 2009 Roy Marples <roy@marples.name>
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 455 matching lines...) Expand 10 before | Expand all | Expand 10 after
466 dbus_message_unref(reply); 466 dbus_message_unref(reply);
467 return DBUS_HANDLER_RESULT_HANDLED; 467 return DBUS_HANDLER_RESULT_HANDLED;
468 } 468 }
469 469
470 static DBusHandlerResult 470 static DBusHandlerResult
471 msg_handler(DBusConnection *con, DBusMessage *msg, _unused void *data) 471 msg_handler(DBusConnection *con, DBusMessage *msg, _unused void *data)
472 { 472 {
473 #define IsMethod(msg, method) \ 473 #define IsMethod(msg, method) \
474 dbus_message_is_method_call(msg, DHCPCD_SERVICE, method) 474 dbus_message_is_method_call(msg, DHCPCD_SERVICE, method)
475 if (dbus_message_is_method_call(msg, DBUS_INTERFACE_INTROSPECTABLE, 475 if (dbus_message_is_method_call(msg, DBUS_INTERFACE_INTROSPECTABLE,
476 "Introspect")) { 476 » » » » » "Introspect")) {
477 return introspect(con, msg); 477 return introspect(con, msg);
478 } else if (IsMethod(msg, "GetVersion")) { 478 } else if (IsMethod(msg, "GetVersion")) {
479 return version(con, msg, VERSION); 479 return version(con, msg, VERSION);
480 } else if (IsMethod(msg, "GetInterfaces")) { 480 } else if (IsMethod(msg, "GetInterfaces")) {
481 return dhcpcd_get_interfaces(con, msg); 481 return dhcpcd_get_interfaces(con, msg);
482 } else if (IsMethod(msg, "GetStatus")) { 482 } else if (IsMethod(msg, "GetStatus")) {
483 return return_status(con, msg); 483 return return_status(con, msg);
484 } else if (IsMethod(msg, "Rebind")) { 484 } else if (IsMethod(msg, "Rebind")) {
485 start_interface(ifaces); 485 start_interface(ifaces);
486 return dbus_ack(con, msg); 486 return dbus_ack(con, msg);
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
545 545
546 static void 546 static void
547 remove_watch(DBusWatch *watch, _unused void *data) 547 remove_watch(DBusWatch *watch, _unused void *data)
548 { 548 {
549 int fd; 549 int fd;
550 550
551 fd = dbus_watch_get_unix_fd(watch); 551 fd = dbus_watch_get_unix_fd(watch);
552 delete_event(fd); 552 delete_event(fd);
553 } 553 }
554 554
555 static DBusHandlerResult dhcpcd_dbus_filter(DBusConnection *conn,
556 DBusMessage *msg,
557 void *user_data)
558 {
559 const char *service = NULL;
560 const char *old_owner = NULL;
561 const char *new_owner = NULL;
562
563 if (!dbus_message_is_signal(msg, DBUS_INTERFACE_DBUS,
564 "NameOwnerChanged"))
565 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
566
567 if (!dbus_message_get_args(msg, NULL,
568 DBUS_TYPE_STRING, &service,
569 DBUS_TYPE_STRING, &old_owner,
570 DBUS_TYPE_STRING, &new_owner,
571 DBUS_TYPE_INVALID)) {
572 syslog(LOG_ERR,
573 "Invalid arguments for NameOwnerChanged signal");
574 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
575 }
576 if (strcmp(service, "org.chromium.flimflam") == 0 &&
577 strlen(new_owner) == 0) {
kobi 2010/07/27 18:07:02 I think it is better to check new_owner against nu
578 syslog(LOG_INFO, "exiting because flimflamd has died");
579 stop_interface(ifaces);
580 exit(EXIT_FAILURE);
581 }
582 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
583 }
584
585 static const char *service_watch_rule = "interface=" DBUS_INTERFACE_DBUS
586 ",type=signal,member=NameOwnerChanged";
587
555 void 588 void
556 dhcpcd_dbus_close(void) 589 dhcpcd_dbus_close(void)
557 { 590 {
558 if (connection) { 591 if (connection) {
592 dbus_bus_remove_match(connection, service_watch_rule, NULL);
593 dbus_connection_remove_filter(connection,
594 dhcpcd_dbus_filter,
595 NULL);
559 dbus_connection_unref(connection); 596 dbus_connection_unref(connection);
560 connection = NULL; 597 connection = NULL;
561 } 598 }
562 } 599 }
563 600
564 int 601 int
565 dhcpcd_dbus_init(void) 602 dhcpcd_dbus_init(void)
566 { 603 {
567 DBusObjectPathVTable vt = { 604 DBusObjectPathVTable vt = {
568 NULL, &msg_handler, NULL, NULL, NULL, NULL 605 NULL, &msg_handler, NULL, NULL, NULL, NULL
(...skipping 17 matching lines...) Expand all
586 { 623 {
587 syslog(LOG_ERR, "dbus: failed to set watch functions"); 624 syslog(LOG_ERR, "dbus: failed to set watch functions");
588 return -1; 625 return -1;
589 } 626 }
590 if (!dbus_connection_register_object_path(connection, 627 if (!dbus_connection_register_object_path(connection,
591 DHCPCD_PATH, &vt, NULL)) 628 DHCPCD_PATH, &vt, NULL))
592 { 629 {
593 syslog(LOG_ERR, "dbus: failed to register object path"); 630 syslog(LOG_ERR, "dbus: failed to register object path");
594 return -1; 631 return -1;
595 } 632 }
633 dbus_connection_add_filter(connection, dhcpcd_dbus_filter, NULL, NULL);
634 dbus_bus_add_match(connection, service_watch_rule, &err);
635 if (dbus_error_is_set(&err)) {
636 syslog(LOG_ERR, "Cannot add rule: %s", err.message);
637 return -1;
638 }
596 return 0; 639 return 0;
597 } 640 }
598 641
599 int 642 int
600 configure(struct interface *ifp) 643 configure(struct interface *ifp)
601 { 644 {
602 if (ifp->state->new != NULL) { 645 if (ifp->state->new != NULL) {
603 /* push state over d-bus */ 646 /* push state over d-bus */
604 dhcpcd_dbus_configure(ifp, ifp->state->reason); 647 dhcpcd_dbus_configure(ifp, ifp->state->reason);
605 648
606 if (write_lease(ifp, ifp->state->new) == -1) 649 if (write_lease(ifp, ifp->state->new) == -1)
607 syslog(LOG_ERR, "write_lease: %m"); 650 syslog(LOG_ERR, "write_lease: %m");
608 } 651 }
609 return 0; 652 return 0;
610 } 653 }
611 654
612 int 655 int
613 run_script(const struct interface *ifp) 656 run_script(const struct interface *ifp)
614 { 657 {
615 return 0; 658 return 0;
616 } 659 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698