Skip to content

Commit

Permalink
[usb_moded] Make init-done state generally available
Browse files Browse the repository at this point in the history
There are situations where usb-moded needs to behave in slightly different
manner depending on whether it is executed as a part of device starup
sequence or (restarted) after the device is already fully booted up.

Make the related init-done functions available to all modules within
usb-moded source tree.

Signed-off-by: Simo Piiroinen <simo.piiroinen@jollamobile.com>
  • Loading branch information
spiiroin committed Jun 5, 2018
1 parent aaaa849 commit 709e49a
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 3 deletions.
6 changes: 6 additions & 0 deletions src/usb_moded-dbus.c
Expand Up @@ -194,6 +194,9 @@ static DBusHandlerResult msg_handler(DBusConnection *const connection, DBusMessa
if( type == DBUS_MESSAGE_TYPE_SIGNAL )
{
if( !strcmp(interface, INIT_DONE_INTERFACE) && !strcmp(member, INIT_DONE_SIGNAL) ) {
/* Update the cached state value */
set_init_done(true);

/* Auto-disable rescue mode when bootup is finished */
if( rescue_mode ) {
rescue_mode = FALSE;
Expand Down Expand Up @@ -598,6 +601,9 @@ gboolean usb_moded_dbus_init_connection(void)
/* Listen to init-done signals */
dbus_bus_add_match(dbus_connection_sys, INIT_DONE_MATCH, 0);

/* Re-check flag file after adding signal listener */
probe_init_done();

/* Connect D-Bus to the mainloop */
dbus_connection_setup_with_g_main(dbus_connection_sys, NULL);

Expand Down
30 changes: 27 additions & 3 deletions src/usb_moded.c
Expand Up @@ -150,7 +150,6 @@ static gboolean set_disconnected_silent(gpointer data);
static void usb_moded_init(void);
static gboolean charging_fallback(gpointer data);
static void usage(void);
static bool init_done_p(void);

/* ============= Implementation starts here =========================================== */
/** set the usb connection status
Expand Down Expand Up @@ -1192,13 +1191,35 @@ void delay_suspend(void)
allow_suspend_cb, 0);
}

/** Path to init-done flag file */
static const char init_done_flagfile[] = "/run/systemd/boot-status/init-done";

/** cached init-done-reached state */
static bool init_done_reached = false;

/** Check if system has already been successfully booted up
*
* @return true if init-done has been reached, or false otherwise
*/
static bool init_done_p(void)
bool init_done_p(void)
{
return init_done_reached;
}

/** Update cached init-done-reached state */
void set_init_done(bool reached)
{
return access("/run/systemd/boot-status/init-done", F_OK) == 0;
if( init_done_reached != reached ) {
init_done_reached = reached;
log_debug("init_done -> %s",
init_done_reached ? "reached" : "not reached");
}
}

/** Check whether init-done flag file exists */
void probe_init_done(void)
{
set_init_done(access(init_done_flagfile, F_OK) == 0);
}

/** Request orderly exit from mainloop
Expand Down Expand Up @@ -1394,6 +1415,9 @@ int main(int argc, char* argv[])
g_thread_init(NULL);
#endif

/* Check if we are in mid-bootup */
probe_init_done();

/* Must be the 1st libdbus call that is made */
dbus_threads_init_default();

Expand Down
5 changes: 5 additions & 0 deletions src/usb_moded.h
Expand Up @@ -25,6 +25,7 @@
#define USB_MODED_H_

#include <stdlib.h>
#include <stdbool.h>
#include <unistd.h>
#include <stdio.h>
#include <string.h>
Expand Down Expand Up @@ -103,4 +104,8 @@ void usb_moded_usleep_(const char *file, int line, const char *func, useconds_t
#define usb_moded_msleep(msec) usb_moded_usleep_(__FILE__,__LINE__,__FUNCTION__,(msec)*1000)
#define usb_moded_sleep(sec) usb_moded_usleep_(__FILE__,__LINE__,__FUNCTION__,(sec)*1000000)

bool init_done_p(void);
void set_init_done(bool reached);
void probe_init_done(void);

#endif /* USB_MODED_H */

0 comments on commit 709e49a

Please sign in to comment.