Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #58 from plundstr/next
[dbus] Reboot system if dbus fails. JB#14621
  • Loading branch information
Pekka Lundstrom committed Feb 27, 2014
2 parents 0bb0995 + 7ab6cf8 commit 508702b
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 15 deletions.
26 changes: 16 additions & 10 deletions modules/bootreasonlogger.c
Expand Up @@ -44,6 +44,7 @@
typedef enum {
SD_REASON_UNKNOWN,
SD_SW_REBOOT,
SD_DBUS_FAILED_REBOOT,
SD_SW_SHUTDOWN,
SD_DEVICE_OVERHEAT,
SD_BATTERY_EMPTY,
Expand All @@ -55,6 +56,7 @@ typedef enum {
static const char* const shutdown_reason_string[SD_REASON_COUNT] = {
"Reason Unknown",
"SW reboot request",
"Dbus failed, reboot",
"SW shutdown request",
"Device overheated",
"Battery empty",
Expand Down Expand Up @@ -102,20 +104,20 @@ static const char* state_name(dsme_state_t state)

static bool sw_update_running(void)
{
if (access("/tmp/os-update-running", F_OK) == 0)
return TRUE;
else
return FALSE;
return (access("/tmp/os-update-running", F_OK) == 0);
}

static bool system_still_booting(void)
{
/* Once system boot is over, init-done flag is set */
/* If file is not there, we are still booting */
if (access("/run/systemd/boot-status/init-done", F_OK) != 0)
return TRUE;
else
return FALSE;
return (access("/run/systemd/boot-status/init-done", F_OK) != 0);
}

static bool dbus_has_failed(void)
{
/* If dbus fails, dsme dbus has noticed it, marked and requested reboot */
return (access("/run/systemd/boot-status/dbus-failed", F_OK) == 0);
}

static const char * get_timestamp(void)
Expand Down Expand Up @@ -280,8 +282,12 @@ DSME_HANDLER(DSM_MSGTYPE_REBOOT_REQ, conn, msg)
char* sender = endpoint_name(conn);

write_log("Received: reboot request from", sender ? sender : "(unknown)");
if (saved_shutdown_reason == SD_REASON_UNKNOWN)
saved_shutdown_reason = SD_SW_REBOOT;
if (saved_shutdown_reason == SD_REASON_UNKNOWN) {
if (dbus_has_failed())
saved_shutdown_reason = SD_DBUS_FAILED_REBOOT;
else
saved_shutdown_reason = SD_SW_REBOOT;
}
free(sender);
}

Expand Down
12 changes: 9 additions & 3 deletions modules/dsme_dbus.c
Expand Up @@ -31,6 +31,7 @@
#include "dsme/logging.h"
#include "dsme/modules.h"
#include "dsme/modulebase.h"
#include "dsme/state.h"

#include <glib.h>
#include <dbus/dbus.h>
Expand Down Expand Up @@ -82,13 +83,18 @@ static bool dsme_dbus_check_arg_type(DBusMessageIter* iter, int want_type)
return false;
}


static DBusHandlerResult
dsme_dbus_filter(DBusConnection *con, DBusMessage *msg, void *aptr)
{
FILE* f;

if( dbus_message_is_signal(msg, DBUS_INTERFACE_LOCAL, "Disconnected") ) {
dsme_log(LOG_CRIT, "Disconnected from system bus; terminating");
dsme_exit(EXIT_FAILURE);
dsme_log(LOG_CRIT, "Disconnected from system bus; rebooting");
/* mark failure and request reboot */
if ((f = fopen(DBUS_FAILED_FILE, "w+")) != NULL)
fclose(f);
DSM_MSGTYPE_REBOOT_REQ req = DSME_MSG_INIT(DSM_MSGTYPE_REBOOT_REQ);
broadcast_internally(&req);
}
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
}
Expand Down
3 changes: 3 additions & 0 deletions modules/dsme_dbus.h
Expand Up @@ -28,6 +28,9 @@
#include <stdbool.h>
#include <dbus/dbus.h>


#define DBUS_FAILED_FILE "/run/systemd/boot-status/dbus-failed"

typedef struct DsmeDbusMessage DsmeDbusMessage;

typedef void DsmeDbusMethod(const DsmeDbusMessage* request,
Expand Down
4 changes: 2 additions & 2 deletions rpm/dsme.service
@@ -1,15 +1,15 @@
[Unit]
Description=DSME
DefaultDependencies=no
After=local-fs.target usb-moded.service
Requires=dbus.service
After=local-fs.target usb-moded.service dbus.service
Conflicts=shutdown.target

[Service]
Type=notify
# When starting dsme gets initial runlevel from the bootstate file
# If it doesn't exist, we default to USER
# This works because EnvironmentFile overrides Environment
ControlGroup=cpu:/
Environment=BOOTSTATE=USER
EnvironmentFile=-/run/systemd/boot-status/bootstate
EnvironmentFile=-/var/lib/environment/dsme/*.conf
Expand Down

0 comments on commit 508702b

Please sign in to comment.