From 40463c7aade2053b2187795ec5e2e5b9863f692c Mon Sep 17 00:00:00 2001 From: Simo Piiroinen Date: Mon, 7 Nov 2016 10:03:02 +0200 Subject: [PATCH] [systemd] Change systemd_control_service() return value and type The systemd_control_service() function looks like it should return a boolean success/failure, but it is returning integer zero on success and integer one on failure - which is confusing. Make it return gboolean value so that success is TRUE and failure FALSE. Signed-off-by: Simo Piiroinen --- src/usb_moded-appsync.c | 7 +++---- src/usb_moded-systemd.c | 17 +++++++++-------- src/usb_moded-systemd.h | 5 +++-- 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/usb_moded-appsync.c b/src/usb_moded-appsync.c index 95baec4..eac7a77 100644 --- a/src/usb_moded-appsync.c +++ b/src/usb_moded-appsync.c @@ -262,9 +262,8 @@ int activate_sync(const char *mode) if(data->systemd) { if(!systemd_control_service(data->name, SYSTEMD_START)) - mark_active(data->name, 0); - else goto error; + mark_active(data->name, 0); } else if(data->launch) { @@ -323,7 +322,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)) goto error; mark_active(data->name, 1); } @@ -445,7 +444,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)) 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..c5c7371 100644 --- a/src/usb_moded-systemd.c +++ b/src/usb_moded-systemd.c @@ -1,19 +1,20 @@ /** - @file usb_moded-systemd.c + @file usb_moded-systemd.c - Copyright (C) 2013 Jolla oy. All rights reserved. + Copyright (C) 2013-2016 Jolla oy. All rights reserved. @author: Philippe De Swert + @author: Simo Piiroinen 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. + 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 @@ -57,13 +58,13 @@ static DBusConnection * get_systemd_dbus_connection(void) // mode = replace // method = StartUnit or StopUnit -int systemd_control_service(const char *name, const char *method) +gboolean systemd_control_service(const char *name, const char *method) { DBusConnection *bus; DBusError error; DBusMessage *msg = NULL, *reply = NULL; - int ret = 1; + gboolean ret = FALSE; const char * replace = "replace"; dbus_error_init(&error); @@ -88,7 +89,7 @@ int systemd_control_service(const char *name, const char *method) if(reply) { dbus_message_unref(reply); - ret = 0; + ret = TRUE; } dbus_message_unref(msg); } diff --git a/src/usb_moded-systemd.h b/src/usb_moded-systemd.h index 495d3bd..d7475a3 100644 --- a/src/usb_moded-systemd.h +++ b/src/usb_moded-systemd.h @@ -1,8 +1,9 @@ /* - Copyright (C) 2013 Jolla Oy. All rights reserved. + Copyright (C) 2013-2016 Jolla Oy. All rights reserved. author: Philippe De Swert + author: Simo Piiroinen This program is free software; you can redistribute it and/or modify it under the terms of the Lesser GNU General Public License @@ -22,4 +23,4 @@ #define SYSTEMD_STOP "StopUnit" #define SYSTEMD_START "StartUnit" -int systemd_control_service(const char *name, const char *method); +gboolean systemd_control_service(const char *name, const char *method);