Commit 709e49a7 authored by spiiroin's avatar spiiroin

[usb_moded] Make init-done state generally available

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: spiiroin's avatarSimo Piiroinen <simo.piiroinen@jollamobile.com>
parent aaaa8494
......@@ -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;
......@@ -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);
......
......@@ -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
......@@ -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
......@@ -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();
......
......@@ -25,6 +25,7 @@
#define USB_MODED_H_
#include <stdlib.h>
#include <stdbool.h>
#include <unistd.h>
#include <stdio.h>
#include <string.h>
......@@ -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 */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment