Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge branch 'jb44679_configfs_configuration' into 'master'
Stop writing to /etc and add settings for configfs details

See merge request mer-core/usb-moded!45
  • Loading branch information
spiiroin committed Feb 22, 2019
2 parents fb3e0a2 + 97107d1 commit c4a9898
Show file tree
Hide file tree
Showing 30 changed files with 1,352 additions and 295 deletions.
5 changes: 5 additions & 0 deletions rpm/usb-moded.spec
Expand Up @@ -353,6 +353,8 @@ install -m 644 -D config/diag/* %{buildroot}/%{_sysconfdir}/usb-moded/diag/
install -m 644 -D config/run/* %{buildroot}/%{_sysconfdir}/usb-moded/run/
install -m 644 -D config/run-diag/* %{buildroot}/%{_sysconfdir}/usb-moded/run-diag/
install -m 644 -D config/mass-storage-jolla.ini %{buildroot}/%{_sysconfdir}/usb-moded/
install -d %{buildroot}/%{_sharedstatedir}/usb-moded


touch %{buildroot}/%{_sysconfdir}/modprobe.d/g_ether.conf
touch %{buildroot}/%{_sysconfdir}/udhcpd.conf
Expand Down Expand Up @@ -386,11 +388,14 @@ systemctl daemon-reload || :
%config(noreplace) %{_sysconfdir}/modprobe.d/usb_moded.conf
%ghost %config(noreplace) %{_sysconfdir}/modprobe.d/g_ether.conf
%ghost %{_sysconfdir}/udhcpd.conf
%ghost %{_sysconfdir}/usb-moded/usb-moded.ini
%{_sbindir}/usb_moded
%{_sbindir}/usb_moded_util
/lib/systemd/system/%{name}.service
/lib/systemd/system/basic.target.wants/%{name}.service
%config %{_sysconfdir}/tmpfiles.d/usb-moded.conf
%dir %{_sharedstatedir}/usb-moded
%ghost %{_sharedstatedir}/usb-moded/usb-moded.ini

%files devel
%defattr(-,root,root,-)
Expand Down
37 changes: 35 additions & 2 deletions src/usb_moded-android.c
Expand Up @@ -42,7 +42,8 @@
bool android_in_use (void);
static bool android_probe (void);
gchar *android_get_serial (void);
bool android_init_values (void);
bool android_init (void);
void android_quit (void);
bool android_set_enabled (bool enable);
bool android_set_charging_mode(void);
bool android_set_function (const char *function);
Expand All @@ -63,6 +64,8 @@ static int android_probed = -1;
static bool
android_write_file(const char *path, const char *text)
{
LOG_REGISTER_CONTEXT;

bool ack = false;

if( !path || !text )
Expand All @@ -86,6 +89,8 @@ android_write_file(const char *path, const char *text)
bool
android_in_use(void)
{
LOG_REGISTER_CONTEXT;

if( android_probed < 0 )
log_debug("android_in_use() called before android_probe()");

Expand All @@ -95,6 +100,8 @@ android_in_use(void)
static bool
android_probe(void)
{
LOG_REGISTER_CONTEXT;

if( android_probed <= 0 ) {
android_probed = access(ANDROID0_ENABLE, F_OK) == 0;
log_warning("ANDROID0 %sdetected", android_probed ? "" : "not ");
Expand All @@ -108,6 +115,8 @@ android_probe(void)
gchar *
android_get_serial(void)
{
LOG_REGISTER_CONTEXT;

static const char path[] = "/proc/cmdline";
static const char find[] = "androidboot.serialno=";
static const char pbrk[] = " \t\r\n,";
Expand Down Expand Up @@ -153,10 +162,14 @@ android_get_serial(void)
}

/** initialize the basic android values
*
* @return true if android usb backend is ready for use, false otherwise
*/
bool
android_init_values(void)
android_init(void)
{
LOG_REGISTER_CONTEXT;

gchar *text;

if( !android_probe() )
Expand Down Expand Up @@ -214,9 +227,19 @@ android_init_values(void)
return android_in_use();
}

/** Cleanup resources allocated by android usb backend
*/
void
android_quit(void)
{
/* For now this exists for symmetry with other backends only */
}

bool
android_set_enabled(bool enable)
{
LOG_REGISTER_CONTEXT;

bool ack = false;
if( android_in_use() ) {
const char *val = enable ? "1" : "0";
Expand All @@ -233,6 +256,8 @@ android_set_enabled(bool enable)
bool
android_set_charging_mode(void)
{
LOG_REGISTER_CONTEXT;

bool ack = false;

if( !android_in_use() )
Expand Down Expand Up @@ -262,6 +287,8 @@ android_set_charging_mode(void)
bool
android_set_function(const char *function)
{
LOG_REGISTER_CONTEXT;

bool ack = false;

if( !function )
Expand Down Expand Up @@ -293,6 +320,8 @@ android_set_function(const char *function)
bool
android_set_productid(const char *id)
{
LOG_REGISTER_CONTEXT;

bool ack = false;

if( id && android_in_use() ) {
Expand All @@ -316,6 +345,8 @@ android_set_productid(const char *id)
bool
android_set_vendorid(const char *id)
{
LOG_REGISTER_CONTEXT;

bool ack = false;
if( id && android_in_use() ) {
char str[16];
Expand All @@ -338,6 +369,8 @@ android_set_vendorid(const char *id)
bool
android_set_attr(const char *function, const char *attr, const char *value)
{
LOG_REGISTER_CONTEXT;

bool ack = false;

if( function && attr && value && android_in_use() ) {
Expand Down
3 changes: 2 additions & 1 deletion src/usb_moded-android.h
Expand Up @@ -48,7 +48,8 @@

bool android_in_use (void);
gchar *android_get_serial (void);
bool android_init_values (void);
bool android_init (void);
void android_quit (void);
bool android_set_enabled (bool enable);
bool android_set_charging_mode(void);
bool android_set_function (const char *function);
Expand Down
18 changes: 18 additions & 0 deletions src/usb_moded-appsync-dbus.c
Expand Up @@ -64,6 +64,8 @@ static gboolean dbus_connection_disc = FALSE; // got disconnected

static void dbusappsync_release_name(void)
{
LOG_REGISTER_CONTEXT;

/* Drop the service name - if we have it */
if( dbus_connection_ses && dbus_connection_name )
{
Expand Down Expand Up @@ -96,6 +98,8 @@ static void dbusappsync_release_name(void)

static gboolean dbusappsync_obtain_name(void)
{
LOG_REGISTER_CONTEXT;

DBusError error = DBUS_ERROR_INIT;

int ret;
Expand Down Expand Up @@ -150,6 +154,8 @@ static gboolean dbusappsync_obtain_name(void)

static DBusHandlerResult dbusappsync_msg_handler(DBusConnection *const connection, DBusMessage *const msg, gpointer const user_data)
{
LOG_REGISTER_CONTEXT;

DBusHandlerResult status = DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
int type = dbus_message_get_type(msg);
const char *interface = dbus_message_get_interface(msg);
Expand Down Expand Up @@ -221,6 +227,8 @@ static DBusHandlerResult dbusappsync_msg_handler(DBusConnection *const connectio
*/
static DBusHandlerResult dbusappsync_handle_disconnect(DBusConnection *conn, DBusMessage *msg, void *user_data)
{
LOG_REGISTER_CONTEXT;

if( dbus_message_is_signal(msg, DBUS_INTERFACE_LOCAL, "Disconnected") )
{
log_warning("disconnected from session bus - expecting restart/stop soon\n");
Expand All @@ -235,6 +243,8 @@ static DBusHandlerResult dbusappsync_handle_disconnect(DBusConnection *conn, DBu
*/
static void dbusappsync_cleanup_connection(void)
{
LOG_REGISTER_CONTEXT;

if( dbus_connection_ses != 0 )
{
/* Remove message filters */
Expand All @@ -259,6 +269,8 @@ static void dbusappsync_cleanup_connection(void)
*/
gboolean dbusappsync_init_connection(void)
{
LOG_REGISTER_CONTEXT;

gboolean result = FALSE;
DBusError error = DBUS_ERROR_INIT;

Expand Down Expand Up @@ -316,6 +328,8 @@ gboolean dbusappsync_init_connection(void)
*/
gboolean dbusappsync_init(void)
{
LOG_REGISTER_CONTEXT;

gboolean status = FALSE;

if( !dbusappsync_init_connection() )
Expand All @@ -336,6 +350,8 @@ gboolean dbusappsync_init(void)
*/
void dbusappsync_cleanup(void)
{
LOG_REGISTER_CONTEXT;

dbusappsync_cleanup_connection();
// NOP
}
Expand All @@ -345,6 +361,8 @@ void dbusappsync_cleanup(void)
*/
int dbusappsync_launch_app(char *launch)
{
LOG_REGISTER_CONTEXT;

int ret = -1; // assume failure

if( dbus_connection_ses == 0 )
Expand Down
30 changes: 30 additions & 0 deletions src/usb_moded-appsync.c
Expand Up @@ -82,6 +82,8 @@ static int appsync_no_dbus = 1; // always disabled

static void appsync_free_elem(list_elem_t *elem)
{
LOG_REGISTER_CONTEXT;

g_free(elem->name);
g_free(elem->launch);
g_free(elem->mode);
Expand All @@ -90,12 +92,16 @@ static void appsync_free_elem(list_elem_t *elem)

static void appsync_free_elem_cb(gpointer elem, gpointer user_data)
{
LOG_REGISTER_CONTEXT;

(void)user_data;
appsync_free_elem(elem);
}

void appsync_free_appsync_list(void)
{
LOG_REGISTER_CONTEXT;

if( appsync_sync_list != 0 )
{
/*g_list_free_full(appsync_sync_list, appsync_free_elem); */
Expand All @@ -108,11 +114,15 @@ void appsync_free_appsync_list(void)

static gint appsync_list_sort_func(gconstpointer a, gconstpointer b)
{
LOG_REGISTER_CONTEXT;

return strcasecmp( (char*)a, (char*)b );
}

void appsync_read_list(int diag)
{
LOG_REGISTER_CONTEXT;

GDir *confdir = 0;

const gchar *dirname;
Expand Down Expand Up @@ -160,6 +170,8 @@ void appsync_read_list(int diag)

static list_elem_t *appsync_read_file(const gchar *filename, int diag)
{
LOG_REGISTER_CONTEXT;

gchar *full_filename = NULL;
GKeyFile *settingsfile = NULL;
list_elem_t *list_item = NULL;
Expand Down Expand Up @@ -215,6 +227,8 @@ static list_elem_t *appsync_read_file(const gchar *filename, int diag)
/* @return 0 on succes, 1 if there is a failure */
int appsync_activate_sync(const char *mode)
{
LOG_REGISTER_CONTEXT;

GList *iter;
int count = 0;

Expand Down Expand Up @@ -316,6 +330,8 @@ int appsync_activate_sync(const char *mode)

int appsync_activate_sync_post(const char *mode)
{
LOG_REGISTER_CONTEXT;

GList *iter;

log_debug("activate post sync");
Expand Down Expand Up @@ -374,6 +390,8 @@ int appsync_activate_sync_post(const char *mode)

int appsync_mark_active(const gchar *name, int post)
{
LOG_REGISTER_CONTEXT;

int ret = -1; // assume name not found
int missing = 0;

Expand Down Expand Up @@ -417,6 +435,8 @@ int appsync_mark_active(const gchar *name, int post)
#ifdef APP_SYNC_DBUS
static gboolean appsync_enumerate_usb_cb(gpointer data)
{
LOG_REGISTER_CONTEXT;

(void)data;
appsync_enumerate_usb_id = 0;
log_debug("handling enumeration timeout");
Expand All @@ -427,6 +447,8 @@ static gboolean appsync_enumerate_usb_cb(gpointer data)

static void appsync_start_enumerate_usb_timer(void)
{
LOG_REGISTER_CONTEXT;

log_debug("scheduling enumeration timeout");
if( appsync_enumerate_usb_id )
g_source_remove(appsync_enumerate_usb_id), appsync_enumerate_usb_id = 0;
Expand All @@ -441,6 +463,8 @@ static void appsync_start_enumerate_usb_timer(void)

static void appsync_cancel_enumerate_usb_timer(void)
{
LOG_REGISTER_CONTEXT;

if( appsync_enumerate_usb_id )
{
log_debug("canceling enumeration timeout");
Expand All @@ -450,6 +474,8 @@ static void appsync_cancel_enumerate_usb_timer(void)

static void appsync_enumerate_usb(void)
{
LOG_REGISTER_CONTEXT;

struct timeval tv;

log_debug("Enumerating");
Expand All @@ -469,6 +495,8 @@ static void appsync_enumerate_usb(void)

void appsync_stop_apps(int post)
{
LOG_REGISTER_CONTEXT;

GList *iter = 0;

for( iter = appsync_sync_list; iter; iter = g_list_next(iter) )
Expand All @@ -487,6 +515,8 @@ void appsync_stop_apps(int post)

int appsync_stop(gboolean force)
{
LOG_REGISTER_CONTEXT;

/* If force arg is used, stop all applications that
* could have been started by usb-moded */
if(force)
Expand Down

0 comments on commit c4a9898

Please sign in to comment.