Skip to content

Commit

Permalink
* small memory usage fixes, split out meego devlock, Switch to g_mass…
Browse files Browse the repository at this point in the history
…_storage for more recent kernels, Go to undefined if no matching mode is found, so non-existing modes are not set silently
  • Loading branch information
Philippe De Swert committed Jan 13, 2012
1 parent 10347e8 commit 77679b7
Show file tree
Hide file tree
Showing 14 changed files with 205 additions and 37 deletions.
11 changes: 9 additions & 2 deletions configure.ac
@@ -1,4 +1,4 @@
AC_INIT([usb_moded], [0.47])
AC_INIT([usb_moded], [0.49])
AM_INIT_AUTOMAKE([-Wall -Werror foreign])

AM_CONFIG_HEADER([config.h])
Expand Down Expand Up @@ -51,6 +51,14 @@ AC_ARG_ENABLE([nokia], AS_HELP_STRING([--enable-nokia], [Enable Nokia extra's @<
esac],[nokia=false])
AM_CONDITIONAL([NOKIA], [test x$nokia = xtrue])

AC_ARG_ENABLE([meegodevlock], AS_HELP_STRING([--enable-meegodevlock], [Enable Meego devicelock @<:@default=false@:>@]),
[case "${enableval}" in
yes) meegodevlock=true ; CFLAGS="-DMLOCK $CFLAGS" ;;
no) meegodevlock=false ;;
*) AC_MSG_ERROR([bad value ${enableval} for --enable-meegodevlock]) ;;
esac],[meegodevlock=false])
AM_CONDITIONAL([MLOCK], [test x$meegodevlock = xtrue])

AC_ARG_ENABLE([n900], AS_HELP_STRING([--enable-n900], [Enable N900 extra's @<:@default=false@:>@]),
[case "${enableval}" in
yes) n900=true ; CFLAGS="-DN900 $CFLAGS" ;;
Expand All @@ -59,7 +67,6 @@ AC_ARG_ENABLE([n900], AS_HELP_STRING([--enable-n900], [Enable N900 extra's @<:@d
esac],[n900=false])
AM_CONDITIONAL([N900], [test x$n900 = xtrue])


AC_ARG_ENABLE([bme], AS_HELP_STRING([--enable-bme], [Enable Nokia bme cable connection interface @<:@default=false@:>@]),
[case "${enableval}" in
yes) bme=true ; CFLAGS="-DBME $CFLAGS" ;;
Expand Down
15 changes: 15 additions & 0 deletions debian/changelog
@@ -1,3 +1,18 @@
usb-moded (0.49) unstable; urgency=low

* small memory usage fixes
* split out meego devlock

-- Philippe De Swert <philippe.de-swert@nokia.com> Fri, 13 Jan 2012 16:45:52 +0200

usb-moded (0.48) unstable; urgency=low

* Switch to g_mass_storage for more recent kernels
* Set network through convience functions
* Go to undefined if no matching mode is found, so non-existing modes are not set silently

-- Philippe De Swert <philippe.de-swert@nokia.com> Fri, 28 Oct 2011 12:21:22 +0300

usb-moded (0.47) unstable; urgency=low

* Make it possible to use the ini file for the mode setting also. This removes
Expand Down
4 changes: 3 additions & 1 deletion src/Makefile.am
Expand Up @@ -24,6 +24,8 @@ usb_moded_SOURCES = \
usb_moded-log.c \
usb_moded-config.c \
usb_moded-config.h \
usb_moded-network.c \
usb_moded-network.h \
usb_moded-modesetting.c \
usb_moded-modesetting.h

Expand All @@ -49,7 +51,7 @@ usb_moded_SOURCES += \
usb_moded-trigger.c
endif

if NOKIA
if MLOCK
usb_moded_SOURCES += \
usb_moded-devicelock.h \
usb_moded-devicelock.c
Expand Down
5 changes: 5 additions & 0 deletions src/usb_moded-config.c
Expand Up @@ -66,6 +66,11 @@ const char * find_udev_path(void)
{
return(get_conf_string(UDEV_PATH_ENTRY, UDEV_PATH_KEY));
}

const char * find_udev_subsystem(void)
{
return(get_conf_string(UDEV_PATH_ENTRY, UDEV_SUBSYSTEM_KEY));
}
#endif /* UDEV */

#ifdef NOKIA
Expand Down
2 changes: 2 additions & 0 deletions src/usb_moded-config.h
Expand Up @@ -33,6 +33,7 @@
#define ALT_MOUNT_KEY "mount"
#define UDEV_PATH_ENTRY "udev"
#define UDEV_PATH_KEY "path"
#define UDEV_SUBSYSTEM_KEY "subsystem"
#define CDROM_ENTRY "cdrom"
#define CDROM_PATH_KEY "path"
#define CDROM_TIMEOUT_KEY "timeout"
Expand All @@ -49,6 +50,7 @@ const char * find_alt_mount(void);

#ifdef UDEV
const char * find_udev_path(void);
const char * find_udev_subsystem(void);
#endif

#ifdef NOKIA
Expand Down
4 changes: 2 additions & 2 deletions src/usb_moded-log.c
Expand Up @@ -142,7 +142,7 @@ void log_debugf(const char *fmt, ...)
*
* @return The current log level
*/
int log_get_level(void)
inline int log_get_level(void)
{
return log_level;
}
Expand All @@ -151,7 +151,7 @@ int log_get_level(void)
*
* @param The wanted log level
*/
void log_set_level(int lev)
inline void log_set_level(int lev)
{
log_level = lev;
}
Expand Down
12 changes: 10 additions & 2 deletions src/usb_moded-modesetting.c
Expand Up @@ -37,6 +37,7 @@
#include "usb_moded-appsync.h"
#include "usb_moded-config.h"
#include "usb_moded-modesetting.h"
#include "usb_moded-network.h"

static void report_mass_storage_blocker(const char *mountpoint, int try);

Expand Down Expand Up @@ -141,6 +142,7 @@ umount: command = g_strconcat("mount | grep ", mounts[i], NULL);
g_free(command);
if(!ret)
{
/* no check for / needed as that will fail to umount anyway */
command = g_strconcat("umount ", mounts[i], NULL);
log_debug("unmount command = %s\n", command);
ret = system(command);
Expand Down Expand Up @@ -185,6 +187,7 @@ umount: command = g_strconcat("mount | grep ", mounts[i], NULL);
write_to_file(command2, mounts[i]);
}
g_strfreev(mounts);
g_free((gpointer *)mount);
}

/* only send data in use signal in case we actually succeed */
Expand Down Expand Up @@ -245,7 +248,8 @@ int set_ovi_suite_mode(void)
write_to_file("/sys/devices/platform/musb_hdrc/gadget/softconnect", "1");
#endif /* APP_SYNC */
/* bring network interface up in case no other network is up */
system("ifdown usb0 ; ifup usb0");
/* system("ifdown usb0 ; ifup usb0"); */
usb_network_up();

#ifdef NOKIA
/* timeout for exporting CDROM image */
Expand Down Expand Up @@ -291,6 +295,7 @@ gboolean export_cdrom(gpointer data)
}
else
log_debug("Cdrom image file does not exist => no export.\n");
g_free((gpointer *)path);

return(FALSE);
}
Expand Down Expand Up @@ -333,6 +338,7 @@ int usb_moded_mode_cleanup(const char *module)
{
log_err("Mounting %s failed\n", mount);
usb_moded_send_error_signal(RE_MOUNT_FAILED);
g_free((gpointer *)mount);
mount = find_alt_mount();
if(mount)
{
Expand All @@ -358,6 +364,7 @@ int usb_moded_mode_cleanup(const char *module)
system(command2);
}
g_strfreev(mounts);
g_free((gpointer *)mount);
}

}
Expand All @@ -367,8 +374,9 @@ int usb_moded_mode_cleanup(const char *module)
/* preventive sync in case of bad quality mtp clients */
sync();
/* bring network down immediately */
system("ifdown usb0");
/*system("ifdown usb0"); */
/* do soft disconnect */
usb_network_down();
write_to_file("/sys/devices/platform/musb_hdrc/gadget/softconnect", "0");
/* DIRTY WORKAROUND: acm/phonet does not work as it should, remove when it does */
system("killall -SIGTERM acm");
Expand Down
1 change: 1 addition & 0 deletions src/usb_moded-modules.c
Expand Up @@ -179,6 +179,7 @@ int usb_moded_module_cleanup(const char *module)
system("for i in `lsof -t /dev/ttyGS*`; do kill -s SIGTERM $i ; done");
system("for i in `lsof -t /dev/gc*`; do kill -s SIGTERM $i ; done");
system("for i in `lsof -t /dev/mtp*`; do kill -s SIGTERM $i ; done");
system("kill -s SIGTERM $(lsof -t /dev/usbacm");
// SP: three passes and for loops in sh?
// SP: system("kill -s SIGTERM $(lsof -t /dev/ttyGS* /dev/gc* /dev/mtp*") ?
// SP: or popen + kill loop?
Expand Down
4 changes: 2 additions & 2 deletions src/usb_moded-modules.h
Expand Up @@ -25,8 +25,8 @@
#else
#define MODULE_NETWORK_MTP "g_nokia"
#endif /* NOKIA */
#define MODULE_MASS_STORAGE "g_file_storage"
#define MODULE_CHARGING "g_file_storage luns=1 stall=0 removable=1"
#define MODULE_MASS_STORAGE "g_mass_storage"
#define MODULE_CHARGING "g_mass_storage luns=1 stall=0 removable=1"
#define MODULE_NONE "none"
#define MODULE_WINDOWS_NET "g_ether"

Expand Down
86 changes: 86 additions & 0 deletions src/usb_moded-network.c
@@ -0,0 +1,86 @@
/*
@file usb-moded_network.c : (De)activates network depending on the network setting system.
Copyright (C) 2011 Nokia Corporation. All rights reserved.
Author: Philippe De Swert <philippe.de-swert@nokia.com>
This program is free software; you can redistribute it and/or
modify it under the terms of the Lesser GNU General Public License
version 2 as published by the Free Software Foundation.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the Lesser GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
02110-1301 USA
*/

/*============================================================================= */

#include <stdio.h>
#include <stdlib.h>

#include "usb_moded-network.h"

#if CONNMAN
#include <dbus/dbus.h>
#include <dbus/dbus-glib.h>
#include <dbus/dbus-glib-lowlevel.h>


#endif

/**
* Activate the network interface
*
*/
int usb_network_up(void)
{
#if CONNMAN
DBusConnection *dbus_conn_connman = NULL;
DBusMessage *msg = NULL, *reply = NULL;
DBusError error;

dbus_error_init(&error);

if( (dbus_conn_connman = dbus_bus_get(DBUS_BUS_SYSTEM, &error)) == 0 )
{
log_err("Could not connect to dbus for connman\n");
}

if ((msg = dbus_message_new_method_call("net.connman", "/", "net.connman.Service", connect)) != NULL)
{
if ((reply = dbus_connection_send_with_reply_and_block(dbus_conn_connman, msg, -1, NULL)) != NULL)
{
dbus_message_get_args(reply, NULL, DBUS_TYPE_INT32, &ret, DBUS_TYPE_INVALID);
dbus_message_unref(reply);
}
dbus_message_unref(msg);
}
dbus_connection_unref(dbus_conn_connman);

log_debug("connman state = %d\n", ret);
return(ret);

#else
system("ifdown usb0 && ifup usb0");
return(0);
#endif /* CONNMAN */
}

/**
* Deactivate the network interface
*
*/
int usb_network_down(void)
{
#if CONNMAN
#else
system("ifdown usb0 down");
return(0);
#endif /* CONNMAN */
}
26 changes: 26 additions & 0 deletions src/usb_moded-network.h
@@ -0,0 +1,26 @@
/*
Copyright (C) 2011 Nokia Corporation. All rights reserved.
Author: Philippe De Swert <philippe.de-swert@nokia.com>
This program is free software; you can redistribute it and/or
modify it under the terms of the Lesser GNU General Public License
version 2 as published by the Free Software Foundation.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the Lesser GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
02110-1301 USA
usb-moded_network : (De)activates network depending on the network setting system.
*/

/*============================================================================= */

int usb_network_up(void);
int usb_network_down(void);
12 changes: 6 additions & 6 deletions src/usb_moded-trigger.c
Expand Up @@ -38,9 +38,9 @@
#include "usb_moded-hw-ab.h"
#include "usb_moded-modesetting.h"
#include "usb_moded-trigger.h"
#ifdef NOKIA
#ifdef MLOCK
#include "usb_moded-devicelock.h"
#endif /* NOKIA */
#endif /* MLOCK */

/* global variables */
static struct udev *udev;
Expand Down Expand Up @@ -186,9 +186,9 @@ static void udev_parse(struct udev_device *dev)
{
if(!strcmp(tmp, get_trigger_value()))
{
#ifdef NOKIA
#ifdef MLOCK
if(!usb_moded_get_export_permission())
#endif /* NOKIA */
#endif /* MLOCK */
if(strcmp(get_trigger_mode(), get_usb_mode()) != 0)
{
usb_moded_mode_cleanup(get_usb_module());
Expand All @@ -201,9 +201,9 @@ static void udev_parse(struct udev_device *dev)
else
/* for triggers without trigger value */
{
#ifdef NOKIA
#ifdef MLOCK
if(!usb_moded_get_export_permission())
#endif /* NOKIA */
#endif /* MLOCK */
if(strcmp(get_trigger_mode(), get_usb_mode()) != 0)
{
usb_moded_mode_cleanup(get_usb_module());
Expand Down

0 comments on commit 77679b7

Please sign in to comment.