Skip to content

Commit

Permalink
Merge pull request #10 from plundstr/master
Browse files Browse the repository at this point in the history
[systemd] Notify systemd when booted up. JB#11788
  • Loading branch information
Pekka Lundstrom committed Jan 20, 2014
2 parents 3968b79 + fbc10dc commit 84cd5ea
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 6 deletions.
8 changes: 8 additions & 0 deletions configure.ac
Expand Up @@ -102,6 +102,14 @@ AC_ARG_ENABLE([connman], AS_HELP_STRING([--enable-connman], [Enable connman supp
esac],[connman=false])
AM_CONDITIONAL([CONNMAN], [test x$connman = xtrue])

AC_ARG_ENABLE([systemd], AS_HELP_STRING([--enable-systemd], [Enable systemd notify interface @<:@default=false@:>@]),
[case "${enableval}" in
yes) systemd=true ; CFLAGS="-DSYSTEMD -lsystemd-daemon $CFLAGS" ;;
no) systemd=false ;;
*) AC_MSG_ERROR([bad value ${enableval} for --enable-systemd]) ;;
esac],[systemd=false])
AM_CONDITIONAL([SYSTEMD], [test x$systemd = xtrue])

#TODO: Figure out how to check for this depending on the gconf flag
# gconf-2.0 >= 2.16.0
PKG_CHECK_MODULES([USB_MODED], [
Expand Down
6 changes: 3 additions & 3 deletions rpm/usb-moded.service
Expand Up @@ -7,11 +7,11 @@ After=local-fs.target dbus.socket systemd-udev-settle.service
Conflicts=shutdown.target

[Service]
Type=simple
RemainAfterExit=no
Type=notify
TimeoutSec=15
EnvironmentFile=-/var/lib/environment/usb-moded/*.conf
EnvironmentFile=-/run/usb-moded/*.conf
ExecStart=/usr/sbin/usb_moded $USB_MODED_ARGS
ExecStart=/usr/sbin/usb_moded --systemd $USB_MODED_ARGS
Restart=always

[Install]
Expand Down
3 changes: 2 additions & 1 deletion rpm/usb-moded.spec
Expand Up @@ -15,6 +15,7 @@ BuildRequires: pkgconfig(glib-2.0)
BuildRequires: pkgconfig(udev)
BuildRequires: pkgconfig(libkmod)
BuildRequires: doxygen
BuildRequires: pkgconfig(libsystemd-daemon)

Requires: lsof
Requires: usb-moded-configs
Expand Down Expand Up @@ -240,7 +241,7 @@ with the android gadget driver.

%build
%autogen
%configure --enable-app-sync --enable-udev --enable-n900 --enable-meegodevlock --enable-debug --enable-connman
%configure --enable-app-sync --enable-udev --enable-n900 --enable-meegodevlock --enable-debug --enable-connman --enable-systemd
make all doc %{?_smp_mflags}

%install
Expand Down
27 changes: 25 additions & 2 deletions src/usb_moded.c
Expand Up @@ -34,6 +34,9 @@
#endif

#include <libkmod.h>
#ifdef SYSTEMD
#include <systemd/sd-daemon.h>
#endif

#include "usb_moded.h"
#include "usb_moded-modes.h"
Expand Down Expand Up @@ -68,6 +71,9 @@ gboolean rescue_mode = FALSE;
gboolean diag_mode = FALSE;
gboolean hw_fallback = FALSE;
gboolean charging_mode_set = FALSE;
#ifdef SYSTEMD
static gboolean systemd_notify = FALSE;
#endif

struct usb_mode current_mode;
guint charging_timeout = 0;
Expand Down Expand Up @@ -617,6 +623,9 @@ static void usage(void)
" -d, --diag turn on diag mode\n"
" -h, --help display this help and exit\n"
" -r, --rescue rescue mode\n"
#ifdef SYSTEMD
" -n, --systemd notify systemd when started up\n"
#endif
" -v, --version output version information and exit\n"
"\n");
}
Expand All @@ -634,14 +643,15 @@ int main(int argc, char* argv[])
{ "diag", no_argument, 0, 'd' },
{ "help", no_argument, 0, 'h' },
{ "rescue", no_argument, 0, 'r' },
{ "systemd", no_argument, 0, 'n' },
{ "version", no_argument, 0, 'v' },
{ 0, 0, 0, 0 }
};

log_name = basename(*argv);

/* Parse the command-line options */
while ((opt = getopt_long(argc, argv, "fsTDdhrv", options, &opt_idx)) != -1)
while ((opt = getopt_long(argc, argv, "fsTDdhrnv", options, &opt_idx)) != -1)
{
switch (opt)
{
Expand Down Expand Up @@ -671,7 +681,11 @@ int main(int argc, char* argv[])
case 'r':
rescue_mode = TRUE;
break;

#ifdef SYSTEMD
case 'n':
systemd_notify = TRUE;
break;
#endif
case 'v':
printf("USB mode daemon version: %s\n", VERSION);
exit(0);
Expand Down Expand Up @@ -724,6 +738,15 @@ int main(int argc, char* argv[])
signal(SIGINT, sigint_handler);
signal(SIGHUP, sigint_handler);

#ifdef SYSTEMD
/* Tell systemd that we have started up */
if( systemd_notify )
{
log_debug("notifying systemd\n");
sd_notify(0, "READY=1");
}
#endif /* SYSTEMD */

/* init succesful, run main loop */
result = EXIT_SUCCESS;
g_main_loop_run(mainloop);
Expand Down

0 comments on commit 84cd5ea

Please sign in to comment.