fix compilation warnings, add -Werror 49/212849/4
authorMaciej Slodczyk <m.slodczyk2@partner.samsung.com>
Tue, 27 Aug 2019 08:50:51 +0000 (10:50 +0200)
committerMaciej Slodczyk <m.slodczyk2@partner.samsung.com>
Tue, 27 Aug 2019 12:49:14 +0000 (14:49 +0200)
Change-Id: I4dca3549fc20713f7996469bc99341e845c9dc3f
Signed-off-by: Maciej Slodczyk <m.slodczyk2@partner.samsung.com>
Makefile.am
include/common.h
include/decision_made_event.h
src/action/unit_start.c
src/decision_makers/unit_control_dm.c
src/libactd/unit_control.c
src/listeners/unit_control_api.c
src/util/common.c
src/util/systemd_dbus.c
tests/unit_tests.c

index 1fdb0034d5f3ec7296ba285a770f5ab103ca3f98..03010a003b371f70d423b418c13f56f8ca42c9aa 100644 (file)
@@ -28,6 +28,7 @@ name_fix = $(subst $(comma),_,$(subst -,_,$1))
 
 AM_CFLAGS = \
        -Wall \
+       -Werror \
        -Wchar-subscripts \
        -Wformat-security \
        -Wmissing-declarations \
index 28942d39ba7a78720a0aeaf53ca8297a58ff235d..3e856ffe060da29846a9864944a89a16c45808c7 100644 (file)
@@ -150,7 +150,7 @@ void epc_object_init(struct epc_object *obj);
 void epc_object_destroy(struct epc_object *obj);
 
 int epc_object_append_new(struct epc_object *parent, const char *key,
-                                                        int type, void *val);
+                                                        int type, const void *val);
 
 int epc_object_append_string(struct epc_object *obj, const char *key,
                                                                const char *val);
index c296b19d204fedf9b926630935ae9433c49f904c..9a96ab11a3b3e59be1183e2429b2138906152940 100644 (file)
@@ -31,7 +31,9 @@
 #define DM_EV_ACTION_DATA "actd"
 #define DM_EV_REASON "rsn"
 
-typedef void (*on_action_finished_cb)(struct action_executed_event *ev, int result);
+struct decision_made_event;
+
+typedef void (*on_action_finished_cb)(struct decision_made_event *ev, int result);
 
 struct decision_made_event {
        struct epc_event event;
index 7e322533789a25a6db60330281a7eeb8e9bc8955..d65acd1b878084840a02036e59b941be87e82d3d 100644 (file)
@@ -61,7 +61,6 @@ static void on_job_removed(GDBusConnection *connection,
 {
        struct unit_action_data *data = userdata;
        char *job;
-       int ret;
 
        assert(data);
 
@@ -71,39 +70,44 @@ static void on_job_removed(GDBusConnection *connection,
                 finish_action(data, 0, NULL);
 }
 
-
-static int unit_action_handler(GVariant *var, void *userdata, GError *err)
+static void unit_action_handler(GVariant *var, void *userdata, GError *err)
 {
        struct unit_action_data *data = userdata;
        dbus_handle_h bus;
        int ret;
-       char *s;
 
-       if (err)
-               return finish_action(data, -err->code, err->message);
+       if (err) {
+               finish_action(data, -err->code, err->message);
+               return;
+       }
 
        if (!data)
-               return -EINVAL;
+               return;
 
        bus = dbus_handle_get_connection(G_BUS_TYPE_SYSTEM, 0);
-       if (!bus)
-               return finish_action(data, -EINVAL, "Could not acquire systemd bus");
+       if (!bus) {
+               finish_action(data, -EINVAL, "Could not acquire systemd bus");
+               return;
+       }
 
        if (data->wait_for_unit) {
-               ret = subscribe_dbus_signal(bus, NULL,
+               ret = subscribe_dbus_signal(bus,
                                "sender='org.freedesktop.systemd1",
                                "org.freedesktop.systemd1.Manager",
                                "JobRemoved",
                                on_job_removed,
-                               data);
+                               data,
+                               NULL);
                if (ret < 0) {
-                       return finish_action(data, ret, "Could not register for JobRemoved signal");
+                       finish_action(data, ret, "Could not register for JobRemoved signal");
+                       return;
                }
 
-               return 0;
+               return;
        }
 
-       return finish_action(data, 0, NULL);
+       finish_action(data, 0, NULL);
+       return;
 }
 
 static int start_unit(struct epc_action *action,
index 8ed0833981aa51d6395f65e0cfdeff9954c2f1f7..568539cc5e9b24a4dddc22f7e97f1a839e83cd09 100644 (file)
@@ -123,7 +123,7 @@ static int parse_unit_list(GVariant *reply, struct list_head *units)
        g_variant_get(reply, "a(ssssssouso)", &iter);
 
        while ((child = g_variant_iter_next_value(&iter))) {
-               parse_unit_list(child, &name);
+               parse_unit_info(child, &name);
                u = calloc(1, sizeof(*u));
 
                if (!u) {
@@ -146,7 +146,6 @@ static int parse_unit_list(GVariant *reply, struct list_head *units)
 static void unit_control_executed(struct decision_made_event *dm_ev, int result)
 {
        struct unit_control_event *event = to_unit_control_event(dm_ev->reason);
-       int ret;
 
        if (result < 0)
                event->err_code = result;
index 24370b65352559f28989a53d452f3413bf2a2659..576e1801c466ce96452b3da92e163c1e38738a33 100644 (file)
@@ -20,6 +20,8 @@
 #include <gio/gio.h>
 #include <errno.h>
 #include <stdbool.h>
+#include <stdlib.h>
+#include <string.h>
 
 #include "unit_control.h"
 
@@ -37,6 +39,7 @@ enum {
 };
 
 struct generic_user_data {
+       GDBusConnection *bus;
        actd_unit_cb cb;
        void *user_data;
        int call_type;
@@ -59,7 +62,7 @@ static void generic_callback(GObject *source_object, GAsyncResult *res, gpointer
        if (!data)
                return;
 
-       var = g_dbus_connection_call_finish(source_object, res, &err);
+       var = g_dbus_connection_call_finish(data->bus, res, &err);
 
        if (err && err->code == G_IO_ERROR_TIMED_OUT) {
                status = UNIT_CONTROL_TIMEOUT;
@@ -95,7 +98,7 @@ static void generic_callback(GObject *source_object, GAsyncResult *res, gpointer
        free(data);
 }
 
-const char *translate_to_systemd(const char *method)
+static const char *translate_to_systemd(const char *method)
 {
        if (strcmp(method, "Start") == 0)
                return "StartUnit";
@@ -134,7 +137,7 @@ static int call_uc(GBusType bus_type, const char *method, const char *unit, int
                        goto out;
        } else {
                /* we assume that activationd runs on system bus and can be used as a proxy */
-               const char *result = NULL;
+               char *result = NULL;
 
                msg = g_dbus_connection_call_sync(bus,
                                UNIT_CONTROL_NAME,
@@ -186,6 +189,7 @@ static int call_uc_async(GBusType bus_type, const char *method, const char *unit
 
        data->user_data = user_data;
        data->cb = cb;
+       data->bus = bus;
 
        if (bus_type == G_BUS_TYPE_SESSION) {
                data->call_type = CALL_TYPE_SYSTEMD;
index 02b29649d0962239741e7be1a81ff29fffd39fca..cb6e944d3df93a3c65d5d7112420e044727a7a43 100644 (file)
@@ -28,7 +28,9 @@
 #define ACTD_DBUS_API_SERVICE_NAME "org.tizen.activationd"
 #define ACTD_DBUS_API_OBJECT_PATH "/org/tizen/activationd"
 
-static int method_generic_callback(GVariant *param, GDBusMethodInvocation *invocation,
+#define STRING_VARIANT ((const GVariantType *) "(s)")
+
+static GVariant *method_generic_callback(GVariant *param, GDBusMethodInvocation *invocation,
                void *userdata, const char *method)
 {
        int r;
@@ -44,7 +46,7 @@ static int method_generic_callback(GVariant *param, GDBusMethodInvocation *invoc
                goto fail;
        }
 
-       if (!g_variant_is_of_type(param, "(s)")) {
+       if (!g_variant_is_of_type(param, STRING_VARIANT)) {
                log_error("Invalid parameter type passed to %s method.  "
                          "Expected: (s), got: %s\n", method, g_variant_get_type_string(param));
                r = -EINVAL;
index 80dcb720bcfe42c5ac46174e183f35c5cce9a7f0..2cc92c28773e6b60037987f767d47023527a2ddf 100644 (file)
@@ -73,7 +73,7 @@ char* fo_type_to_str(unsigned type)
                return NULL;
 }
 
-static inline void copy_obj_val(struct epc_object *obj, void *val)
+static inline void copy_obj_val(struct epc_object *obj, const void *val)
 {
        memcpy(&obj->val, val, data_size[obj->type]);
 }
@@ -86,7 +86,7 @@ static void release_epc_object(struct uref *uref)
        free(obj);
 }
 
-static inline void init_obj(struct epc_object *obj, int type, void *val)
+static inline void init_obj(struct epc_object *obj, int type, const void *val)
 {
        assert(val != NULL || type == TYPE_OBJECT);
 
@@ -101,7 +101,7 @@ static inline void init_obj(struct epc_object *obj, int type, void *val)
                copy_obj_val(obj, val);
 }
 
-static struct epc_object *new_object_node(int type, void *val)
+static struct epc_object *new_object_node(int type, const void *val)
 {
        struct epc_object *obj;
 
@@ -172,7 +172,7 @@ static int object_append(struct epc_object *obj, const char *key, struct epc_obj
 }
 
 int epc_object_append_new(struct epc_object *parent, const char *key,
-                                                        int type, void *val)
+                                                        int type, const void *val)
 {
        struct epc_object *child;
        int ret;
index 6a183189264aca7fa0a705ff4cefce1ed38b9da7..5bf992aac8bcd5c44ba56d6467fafd04c84e10de 100644 (file)
@@ -35,7 +35,6 @@ int epc_dbus_call_async(char *service, char *obj, char *interface, char *method,
                                         void *user_data, char *types, ...)
 {
        dbus_handle_h bus = NULL;
-       int ret;
        GVariant *var = NULL;
 
        bus = dbus_handle_get_connection(G_BUS_TYPE_SYSTEM, 0);
@@ -58,7 +57,6 @@ int epc_dbus_call(char *service, char *obj, char *interface, char *method,
                                         char *types, ...)
 {
        dbus_handle_h bus = NULL;
-       int ret;
        GVariant *var = NULL;
 
        bus = dbus_handle_get_connection(G_BUS_TYPE_SYSTEM, 0);
index 96d678d2280ce5373b1f4a179e6e15d396d186ff..dda922710dfed3aea6fc2c2ea7409d89ed5aa306 100644 (file)
@@ -24,8 +24,8 @@ struct context {
        GMainLoop *loop;
        guint func_timeout, test_timeout;
        int result;
-       int (*func_sync)(GBusType bus_type, const char *unit, int timeout);
-       int (*func_async)(GBusType bus_type, const char *unit, actd_unit_cb cb, void *user_data, int timeout);
+       int (*func_sync)(BusType bus_type, const char *unit, int timeout);
+       int (*func_async)(BusType bus_type, const char *unit, actd_unit_cb cb, void *user_data, int timeout);
 };
 
 struct unit_test {
@@ -33,7 +33,7 @@ struct unit_test {
        int (*func)(struct context *);
 };
 
-int translate_unit_state(const gchar *value)
+static int translate_unit_state(const gchar *value)
 {
        if (!g_strcmp0(value, "active"))
                return UNIT_ON;
@@ -43,7 +43,7 @@ int translate_unit_state(const gchar *value)
 }
 
 
-int get_unit_state(GVariant *dictionary)
+static int get_unit_state(GVariant *dictionary)
 {
        GVariantIter iter;
        GVariant *value;
@@ -65,7 +65,6 @@ static void on_properties_changed(GDBusConnection *connection,
 {
        GVariantIter iter;
        GVariant *child;
-       gchar *key;
        int state;
        struct context *ctx = (struct context *)user_data;
 
@@ -89,7 +88,7 @@ static void on_properties_changed(GDBusConnection *connection,
        }
 }
 
-GDBusConnection *get_bus(GBusType bus_type)
+static GDBusConnection *get_bus(GBusType bus_type)
 {
        GDBusConnection *bus = NULL;
        bus = g_bus_get_sync(bus_type, NULL, NULL);
@@ -142,7 +141,7 @@ static guint signal_subscribe(struct context *ctx)
                                G_DBUS_SIGNAL_FLAGS_NONE,
                                on_properties_changed,
                                (gpointer)ctx,
-                               &error
+                               NULL
                        );
        if (ctx->subscription_id == 0) {
                printf("signal subscription error: %s\n", error->message);
@@ -154,7 +153,7 @@ cleanup:
        return ctx->subscription_id;
 }
 
-gboolean test_timeout(gpointer user_data)
+static gboolean test_timeout(gpointer user_data)
 {
        struct context *ctx = (struct context *)user_data;
 
@@ -163,7 +162,7 @@ gboolean test_timeout(gpointer user_data)
        return FALSE;
 }
 
-gboolean func_start(gpointer user_data)
+static gboolean func_start(gpointer user_data)
 {
        struct context *ctx = (struct context *)user_data;
        int ret = ctx->func_sync(ctx->bus_type, TEST_SERVICE, UNIT_CONTROL_TIMEOUT_DEFAULT);
@@ -175,7 +174,7 @@ gboolean func_start(gpointer user_data)
        return FALSE;
 }
 
-int test_sync_action(struct context *ctx)
+static int test_sync_action(struct context *ctx)
 {
        assert(ctx);
 
@@ -198,7 +197,7 @@ finish_run_sync_test:
        return ctx->result;
 }
 
-int test_unit_start(struct context *ctx)
+static int test_unit_start(struct context *ctx)
 {
        assert(ctx);
 
@@ -210,7 +209,7 @@ int test_unit_start(struct context *ctx)
        return test_sync_action(ctx);
 }
 
-int test_unit_stop(struct context *ctx)
+static int test_unit_stop(struct context *ctx)
 {
        assert(ctx);
 
@@ -222,7 +221,7 @@ int test_unit_stop(struct context *ctx)
        return test_sync_action(ctx);
 }
 
-int test_unit_restart(struct context *ctx)
+static int test_unit_restart(struct context *ctx)
 {
        assert(ctx);
 
@@ -235,7 +234,7 @@ int test_unit_restart(struct context *ctx)
        return test_sync_action(ctx);
 }
 
-void handler(int status, void *user_data, GError *err)
+static void handler(int status, void *user_data)
 {
        struct context *ctx = (struct context *)user_data;
        ctx->result = status;
@@ -243,7 +242,7 @@ void handler(int status, void *user_data, GError *err)
                g_main_loop_quit(ctx->loop);
 }
 
-int test_async_action(struct context *ctx)
+static int test_async_action(struct context *ctx)
 {
        assert(ctx);
        assert(ctx->func_async);
@@ -262,7 +261,7 @@ int test_async_action(struct context *ctx)
        return ctx->result;
 }
 
-int test_unit_start_async(struct context *ctx)
+static int test_unit_start_async(struct context *ctx)
 {
        assert(ctx);
 
@@ -274,7 +273,7 @@ int test_unit_start_async(struct context *ctx)
        return test_async_action(ctx);
 }
 
-int test_unit_stop_async(struct context *ctx)
+static int test_unit_stop_async(struct context *ctx)
 {
        ctx->unit_state[0] = UNIT_OFF;
        ctx->unit_state_pos = 0;
@@ -284,7 +283,7 @@ int test_unit_stop_async(struct context *ctx)
        return test_async_action(ctx);
 }
 
-int test_unit_restart_async(struct context *ctx)
+static int test_unit_restart_async(struct context *ctx)
 {
        ctx->unit_state[0] = UNIT_OFF;
        ctx->unit_state[1] = UNIT_ON;
@@ -313,7 +312,7 @@ static const char *retval2string(int r)
        }
 }
 
-void test(GBusType bus_type, struct unit_test tests[])
+static void test(GBusType bus_type, struct unit_test tests[])
 {
        assert(bus_type == G_BUS_TYPE_SYSTEM || bus_type == G_BUS_TYPE_SESSION);
        int ret;
@@ -340,7 +339,7 @@ void test(GBusType bus_type, struct unit_test tests[])
        return;
 }
 
-int main()
+int main(int argc, char *argv[])
 {
        struct unit_test tests[] = {
                {"UnitStart", test_unit_start},