Commit 6d4934e0 authored by Florent Revest's avatar Florent Revest

usb-moded: Only use a timeout when stopping services

parent 0a2c852b
From 7fb45319984663efd4412eb6df6dc0c3925b8844 Mon Sep 17 00:00:00 2001
From: Florent Revest <revestflo@gmail.com>
Date: Wed, 17 May 2017 12:39:51 +0200
Subject: [PATCH] [systemd] Use a default timeout of 2sec for StopUnit
On my devices, I noticed that adding udhcpd-developer-mode.ini to
/etc/usb-moded/run/ would totally prevent USB from working. It turned
out that usb-moded was trying to call StopUnit on udhcpd.service and
the blocking call would never stop. I had to introduce this timeout to
make sure usb-moded would start properly.
---
src/usb_moded-appsync.c | 6 +++---
src/usb_moded-systemd.c | 4 ++--
src/usb_moded-systemd.h | 2 +-
3 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/src/usb_moded-appsync.c b/src/usb_moded-appsync.c
index bfb10b9..9ca6550 100644
--- a/src/usb_moded-appsync.c
+++ b/src/usb_moded-appsync.c
@@ -258,7 +258,7 @@ int activate_sync(const char *mode)
log_debug("launching pre-enum-app %s\n", data->name);
if(data->systemd)
{
- if(!systemd_control_service(data->name, SYSTEMD_START))
+ if(!systemd_control_service(data->name, SYSTEMD_START, -1))
mark_active(data->name, 0);
else
goto error;
@@ -320,7 +320,7 @@ int activate_sync_post(const char *mode)
log_debug("launching post-enum-app %s\n", data->name);
if(data->systemd)
{
- if(systemd_control_service(data->name, SYSTEMD_START))
+ if(systemd_control_service(data->name, SYSTEMD_START, -1))
goto error;
mark_active(data->name, 1);
}
@@ -442,7 +442,7 @@ static void appsync_stop_apps(int post)
if(data->systemd && data->state == APP_STATE_ACTIVE && data->post == post)
{
log_debug("stopping %s-enum-app %s", post ? "post" : "pre", data->name);
- if(systemd_control_service(data->name, SYSTEMD_STOP))
+ if(systemd_control_service(data->name, SYSTEMD_STOP, 2000))
log_debug("Failed to stop %s\n", data->name);
data->state = APP_STATE_DONTCARE;
}
diff --git a/src/usb_moded-systemd.c b/src/usb_moded-systemd.c
index 4a27cfb..9c1ee29 100644
--- a/src/usb_moded-systemd.c
+++ b/src/usb_moded-systemd.c
@@ -57,7 +57,7 @@ static DBusConnection * get_systemd_dbus_connection(void)
// mode = replace
// method = StartUnit or StopUnit
-int systemd_control_service(const char *name, const char *method)
+int systemd_control_service(const char *name, const char *method, int timeout)
{
DBusConnection *bus;
@@ -84,7 +84,7 @@ int systemd_control_service(const char *name, const char *method)
dbus_message_unref(msg);
goto quit;
}
- reply = dbus_connection_send_with_reply_and_block(bus, msg, -1, &error);
+ reply = dbus_connection_send_with_reply_and_block(bus, msg, timeout, &error);
if(reply)
{
dbus_message_unref(reply);
diff --git a/src/usb_moded-systemd.h b/src/usb_moded-systemd.h
index 495d3bd..3343c37 100644
--- a/src/usb_moded-systemd.h
+++ b/src/usb_moded-systemd.h
@@ -22,4 +22,4 @@
#define SYSTEMD_STOP "StopUnit"
#define SYSTEMD_START "StartUnit"
-int systemd_control_service(const char *name, const char *method);
+int systemd_control_service(const char *name, const char *method, int timeout);
--
2.11.0
From a09feee6d7768d0e91e9359bd73e461ab3b0e8c7 Mon Sep 17 00:00:00 2001
From: Florent Revest <revestflo@gmail.com>
Date: Wed, 10 May 2017 20:26:55 +0200
Subject: [PATCH] [systemd] Use a default timeout of 2sec to StartUnit and
StopUnit
On my devices, I noticed that adding udhcpd-developer-mode.ini to
/etc/usb-moded/run/ would totally prevent USB from working. It turned
out that usb-moded was trying to call StopUnit on udhcpd.service and
the blocking call would never stop. I had to introduce this timeout to
make sure usb-moded would start properly. It may break the starting and
stopping time of other services though.
---
src/usb_moded-systemd.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/usb_moded-systemd.c b/src/usb_moded-systemd.c
index 4a27cfb..a59ab69 100644
--- a/src/usb_moded-systemd.c
+++ b/src/usb_moded-systemd.c
@@ -84,7 +84,7 @@ int systemd_control_service(const char *name, const char *method)
dbus_message_unref(msg);
goto quit;
}
- reply = dbus_connection_send_with_reply_and_block(bus, msg, -1, &error);
+ reply = dbus_connection_send_with_reply_and_block(bus, msg, 2000, &error);
if(reply)
{
dbus_message_unref(reply);
--
2.11.0
...@@ -8,7 +8,7 @@ SRC_URI = "git://github.com/philippedeswert/usb-moded.git;protocol=https \ ...@@ -8,7 +8,7 @@ SRC_URI = "git://github.com/philippedeswert/usb-moded.git;protocol=https \
file://usb-moded.ini \ file://usb-moded.ini \
file://com.meego.usb_moded.service \ file://com.meego.usb_moded.service \
file://udhcpd.service \ file://udhcpd.service \
file://0001-systemd-Use-a-default-timeout-of-2sec-to-StartUnit-a.patch \ file://0001-systemd-Use-a-default-timeout-of-2sec-for-StopUnit.patch \
file://init_ffs" file://init_ffs"
SRCREV = "b2bcc5ba8d1bf3179c73a916f01ab4e0cf0a3526" SRCREV = "b2bcc5ba8d1bf3179c73a916f01ab4e0cf0a3526"
PR = "r1" PR = "r1"
......
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