Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[usb-moded] Tune global variables
If variables are used only from one source file, make them static.

If variables are truly global, put extern declaration to relevant header.

Drop completely unused variables.

Explicitly initialize variables to sane defaults.

Signed-off-by: Simo Piiroinen <simo.piiroinen@jollamobile.com>
  • Loading branch information
spiiroin committed Mar 28, 2018
1 parent b38ec22 commit cd8d5d2
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 23 deletions.
2 changes: 1 addition & 1 deletion src/usb_moded-appsync.c
Expand Up @@ -52,7 +52,7 @@ static void cancel_enumerate_usb_timer(void);
static GList *sync_list = NULL;

static guint enumerate_usb_id = 0;
static struct timeval sync_tv;
static struct timeval sync_tv = {0, 0};
#ifdef APP_SYNC_DBUS
static int no_dbus = 0;
#else
Expand Down
2 changes: 0 additions & 2 deletions src/usb_moded-dbus.c
Expand Up @@ -47,8 +47,6 @@
static DBusConnection *dbus_connection_sys = NULL;
static gboolean have_service_name = FALSE;

extern gboolean rescue_mode;

/**
* Issues "sig_usb_config_ind" signal.
*/
Expand Down
3 changes: 0 additions & 3 deletions src/usb_moded-modules-android.c
Expand Up @@ -38,9 +38,6 @@
#include "usb_moded-config.h"
#include "usb_moded-modesetting.h"

/* kmod context - initialized at start in usb_moded_init */
struct kmod_ctx *ctx;

/** load module
*
* @param module Name of the module to load
Expand Down
2 changes: 1 addition & 1 deletion src/usb_moded-network.c
Expand Up @@ -52,7 +52,7 @@
#define UDHCP_CONFIG_DIR "/run/usb-moded"
#define UDHCP_CONFIG_LINK "/etc/udhcpd.conf"

const char default_interface[] = "usb0";
static const char default_interface[] = "usb0";

/** IP forwarding configuration block */
typedef struct ipforward_data
Expand Down
2 changes: 1 addition & 1 deletion src/usb_moded-trigger.c
Expand Up @@ -47,7 +47,7 @@ static struct udev *udev = 0;
static struct udev_monitor *mon = 0;
static GIOChannel *iochannel = 0;
static guint watch_id = 0;
static const char *dev_name;
static const char *dev_name = 0;

/* static function definitions */
static gboolean monitor_udev(GIOChannel *iochannel G_GNUC_UNUSED, GIOCondition cond,
Expand Down
8 changes: 4 additions & 4 deletions src/usb_moded-udev.c
Expand Up @@ -40,10 +40,10 @@
#include "usb_moded-modes.h"

/* global variables */
static struct udev *udev;
static struct udev_monitor *mon;
static GIOChannel *iochannel;
static guint watch_id;
static struct udev *udev = 0;
static struct udev_monitor *mon = 0;
static GIOChannel *iochannel = 0;
static guint watch_id = 0;
static char *dev_name = 0;
static int cleanup = 0;
/* track cable and charger connects disconnects */
Expand Down
5 changes: 2 additions & 3 deletions src/usb_moded-util.c
Expand Up @@ -29,8 +29,7 @@

#include "usb_moded-dbus.h"

DBusError error;
DBusConnection *conn = 0;
static DBusConnection *conn = 0;

static int query_mode (void)
{
Expand Down Expand Up @@ -408,7 +407,7 @@ int main (int argc, char *argv[])
}

/* init dbus */
dbus_error_init(&error);
DBusError error = DBUS_ERROR_INIT;

conn = dbus_bus_get_private(DBUS_BUS_SYSTEM, &error);
if (!conn)
Expand Down
24 changes: 16 additions & 8 deletions src/usb_moded.c
Expand Up @@ -83,11 +83,11 @@ static int usb_moded_exitcode = EXIT_FAILURE;
static GMainLoop *usb_moded_mainloop = NULL;

gboolean rescue_mode = FALSE;
gboolean diag_mode = FALSE;
gboolean hw_fallback = FALSE;
gboolean android_broken_usb = FALSE;
gboolean android_ignore_udev_events = FALSE;
gboolean android_ignore_next_udev_disconnect_event = FALSE;
static gboolean diag_mode = FALSE;
static gboolean hw_fallback = FALSE;
static gboolean android_broken_usb = FALSE;
static gboolean android_ignore_udev_events = FALSE;
static gboolean android_ignore_next_udev_disconnect_event = FALSE;
#ifdef SYSTEMD
static gboolean systemd_notify = FALSE;
#endif
Expand Down Expand Up @@ -132,9 +132,17 @@ static void set_cable_connection_delay(int delay_ms)
}
}

struct usb_mode current_mode;
guint charging_timeout = 0;
static GList *modelist;
static struct usb_mode current_mode = {
.connected = FALSE,
.mounted = FALSE,
.android_usb_broken = FALSE,
.mode = NULL,
.module = NULL,
.data = NULL,
};

static guint charging_timeout = 0;
static GList *modelist = 0;

/* static helper functions */
static gboolean set_disconnected(gpointer data);
Expand Down
1 change: 1 addition & 0 deletions src/usb_moded.h
Expand Up @@ -88,6 +88,7 @@ void allow_suspend(void);
void delay_suspend(void);

extern int cable_connection_delay;
extern gboolean rescue_mode;

void usb_moded_stop(int exitcode);

Expand Down

0 comments on commit cd8d5d2

Please sign in to comment.