From 4692efb77264357ce5549a3b0dc6912b8b211a04 Mon Sep 17 00:00:00 2001 From: INSUN PYO Date: Mon, 25 Jan 2021 13:12:12 +0900 Subject: [PATCH 01/16] libsyscommon: add "Requires:pkgconfig(dlog)" to libsyscommon-devel Change-Id: I7ab05dfddbf864490c191775a380cf639bfe4a54 --- packaging/libsyscommon.spec | 1 + 1 file changed, 1 insertion(+) diff --git a/packaging/libsyscommon.spec b/packaging/libsyscommon.spec index 45a25ce..3b6869f 100644 --- a/packaging/libsyscommon.spec +++ b/packaging/libsyscommon.spec @@ -29,6 +29,7 @@ License: Apache-2.0 Requires: libsyscommon = %{version} Requires: pkgconfig(gio-2.0) Requires: pkgconfig(gio-unix-2.0) +Requires: pkgconfig(dlog) %description -n libsyscommon-devel Development header files for system common library. -- 2.7.4 From e5f7bf6a01844c6f0cee95fccf00205b070e822b Mon Sep 17 00:00:00 2001 From: Karol Lewandowski Date: Mon, 25 Jan 2021 17:57:49 +0100 Subject: [PATCH 02/16] libgdbus: Return null when dbus connection fails When libgdbus fails to get bus for one of global busses (system, session) it still returns vaild pointer. It's because global busses are cached in g_dh[2] which always exist. This commit changes the get_connection function to return null for all the checks like following to detect and fail in the case where getting bus was unsuccessfull (ie. dbus-daemon isn't running in early boot/special targets) dh = _dbus_handle_get_default_connection(); if (!dh) { _E("failed to get default connection, bustype:%d", (int)dbus_handle_get_default_bus_type()); ... Change-Id: If85fe8e6cb7a5f95618df8f7f3fefa923e3e271a --- src/libgdbus/dbus-system.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/libgdbus/dbus-system.c b/src/libgdbus/dbus-system.c index a78fe4d..f1278bf 100644 --- a/src/libgdbus/dbus-system.c +++ b/src/libgdbus/dbus-system.c @@ -212,10 +212,12 @@ static dbus_handle_s *_dbus_handle_get_connection(GBusType bus_type) if (!dh->conn) { dh->conn = _get_bus(bus_type); + if (!dh->conn) { + dbus_handle_unlock(dh); + return NULL; + } dh->priv = FALSE; dh->bus_type = bus_type; - if (!dh->conn) - dh = NULL; } dbus_handle_unlock(dh); -- 2.7.4 From 272f782905c1f8ada08811021d528c312cdb38ab Mon Sep 17 00:00:00 2001 From: lokilee73 Date: Fri, 5 Feb 2021 09:50:02 +0900 Subject: [PATCH 03/16] Change dbus method name for pass SetScenario Change-Id: I963a064da7d8f7a4cef14c2b4df30139d742c963 Signed-off-by: lokilee73 --- src/libgdbus/dbus-system-iface.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libgdbus/dbus-system-iface.h b/src/libgdbus/dbus-system-iface.h index 98cd7de..e65384a 100644 --- a/src/libgdbus/dbus-system-iface.h +++ b/src/libgdbus/dbus-system-iface.h @@ -281,7 +281,7 @@ #define PASS_PATH_PMQOS PASS_OBJECT_PATH"/Pmqos" #define PASS_INTERFACE_PMQOS PASS_INTERFACE_NAME".pmqos" -#define PASS_METHOD_DOZE "SetScenario" +#define PASS_METHOD_SET_SCENARIO "SetScenario" /***************************************************************/ /* Experimental for Specific device - contact to deviced owner */ -- 2.7.4 From aba7291822af3d99430d15e74d53eac1976e7c54 Mon Sep 17 00:00:00 2001 From: lokilee73 Date: Fri, 5 Feb 2021 17:35:15 +0900 Subject: [PATCH 04/16] Fix svace Change-Id: I5397a386b95ed5fbaccda82a02a2b70026766044 Signed-off-by: lokilee73 --- src/libcommon/ini-parser.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/libcommon/ini-parser.c b/src/libcommon/ini-parser.c index 11093cc..f3ed8c7 100644 --- a/src/libcommon/ini-parser.c +++ b/src/libcommon/ini-parser.c @@ -36,10 +36,13 @@ static inline char *trim_str(char *s) s += strspn(s, WHITESPACE); /* right trim */ - for (t = strchr(s, 0); t > s; t--) + for (t = strchr(s, 0); (t != NULL) && (t > s); t--) if (!strchr(WHITESPACE, t[-1])) break; - *t = 0; + + if (t) + *t = 0; + return s; } -- 2.7.4 From baebe9cfdb9d0e6e9c644b8ee229279b93a8fec0 Mon Sep 17 00:00:00 2001 From: Hyotaek Shim Date: Thu, 4 Mar 2021 11:08:12 +0900 Subject: [PATCH 05/16] Remove unused gdbus APIs based on va_list Change-Id: I0d858522fda0f49e0bda8f4b4b7178b9ca770429 Signed-off-by: Hyotaek Shim --- src/libgdbus/dbus-system.c | 176 --------------------------------------------- src/libgdbus/dbus-system.h | 26 +------ 2 files changed, 1 insertion(+), 201 deletions(-) diff --git a/src/libgdbus/dbus-system.c b/src/libgdbus/dbus-system.c index f1278bf..5df1959 100644 --- a/src/libgdbus/dbus-system.c +++ b/src/libgdbus/dbus-system.c @@ -2243,110 +2243,6 @@ int dbus_handle_method_sync_timeout(const char *dest, return result; } -int dbus_handle_method_sync_pairs(const char *dest, - const char *path, - const char *iface, - const char *method, - int num, - va_list args) -{ - GError *err = NULL; - GVariant * reply = NULL; - char *key, *value; - int ret = 0; - GVariant *var; - GVariantBuilder *builder; - dbus_handle_s *dh = NULL; - - if (!dest || !path || !iface || !method) { - _E("wrong parameters dest(%s) path(%s) iface(%s) method(%s)", dest, path, iface, method); - return -1; - } - - dh = _dbus_handle_get_default_connection(); - if (!dh) { - _E("failed to get default connection, bustype:%d", (int)dbus_handle_get_default_bus_type()); - return -1; - } - - builder = g_variant_builder_new(G_VARIANT_TYPE("a{ss}")); - - for (int i = 0 ; i < num ; i = i + 2) { - key = va_arg(args, char *); - value = va_arg(args, char *); - _I("key(%s), value(%s)", key, value); - g_variant_builder_add(builder, "{ss}", key, value); - } - - var = g_variant_new("(a{ss})", builder); - g_variant_builder_unref(builder); - - reply = g_dbus_connection_call_sync(dh->conn, - dest, path, iface, method, - var, NULL, G_DBUS_CALL_FLAGS_NONE, DBUS_REPLY_TIMEOUT, NULL, &err); - if (!reply || err) { - _E("failed to g_dbus_connection_call_sync"); - return -1; - } - - if (g_strcmp0("(i)", g_variant_get_type_string(reply)) == 0) - g_variant_get(reply, "(i)", &ret); - else - ret = -ENOMSG; - - g_variant_unref(reply); - - return ret; -} - -int dbus_handle_method_async_pairs(const char *dest, - const char *path, - const char *iface, - const char *method, - int num, - va_list args) -{ - char *key, *value; - GVariant *var; - GVariantBuilder *builder; - dbus_handle_s *dh = NULL; - - if (!dest || !path || !iface || !method) { - _E("wrong parameters dest(%s) path(%s) iface(%s) method(%s)", dest, path, iface, method); - return -1; - } - - dh = _dbus_handle_get_default_connection(); - if (!dh) { - _E("failed to get default connection, bustype:%d", (int)dbus_handle_get_default_bus_type()); - return -1; - } - - // dict - builder = g_variant_builder_new(G_VARIANT_TYPE("a{ss}")); - - for (int i = 0 ; i < num ; i = i + 2) { - key = va_arg(args, char *); - value = va_arg(args, char *); - _I("key(%s), value(%s)", key, value); - g_variant_builder_add(builder, "{ss}", key, value); - } - - var = g_variant_new("(a{ss})", builder); - g_variant_builder_unref(builder); - - g_dbus_connection_call(dh->conn, - dest, path, iface, method, - var, NULL, - G_DBUS_CALL_FLAGS_NONE, - -1, - NULL, - NULL, - NULL); - - return 0; -} - int dbus_handle_method_async(const char *dest, const char *path, const char *iface, @@ -2443,78 +2339,6 @@ out: free(data); } -int dbus_handle_method_async_pairs_with_reply(const char *dest, - const char *path, - const char *iface, - const char *method, - int num, - va_list args, - dbus_pending_cb cb, - int timeout_msec, - void *data) -{ - dbus_handle_s *dh = NULL; - pending_call_data *pdata = NULL; - GVariantBuilder *builder; - char *key, *value; - GVariant *param; - int ret = 0; - - if (!dest || !path || !iface || !method) { - _E("wrong parameters dest(%s) path(%s) iface(%s) method(%s)", dest, path, iface, method); - return -1; - } - - if (timeout_msec < -1) { - _E("wrong timeout %d", timeout_msec); - return -1; - } - - dh = _dbus_handle_get_default_connection(); - if (!dh) { - _E("failed to get default connection, bustype:%d", (int)dbus_handle_get_default_bus_type()); - return -EPERM; - } - - // dict - builder = g_variant_builder_new(G_VARIANT_TYPE("a{ss}")); - - for (int i = 0 ; i < num ; i = i + 2) { - key = va_arg(args, char *); - value = va_arg(args, char *); - _I("key(%s), value(%s)", key, value); - g_variant_builder_add(builder, "{ss}", key, value); - } - - param = g_variant_new("(a{ss})", builder); - g_variant_builder_unref(builder); - - if (cb) { - pdata = (pending_call_data*)malloc(sizeof(pending_call_data)); - if (!pdata) { - ret = -ENOMEM; - goto err; - } - - pdata->func = cb; - pdata->data = data; - } - g_dbus_connection_call(dh->conn, - dest, path, iface, method, - param, NULL, - G_DBUS_CALL_FLAGS_NONE, - timeout_msec, - NULL, - (GAsyncReadyCallback)_cb_pending, - pdata); - - return ret; -err: - if (param) - g_variant_unref(param); - return ret; -} - int dbus_handle_method_async_with_reply(const char *dest, const char *path, const char *iface, diff --git a/src/libgdbus/dbus-system.h b/src/libgdbus/dbus-system.h index cbcc9be..29fa58f 100644 --- a/src/libgdbus/dbus-system.h +++ b/src/libgdbus/dbus-system.h @@ -122,20 +122,6 @@ int dbus_handle_method_sync_timeout (const char *dest, const char *param[], int timeout); -int dbus_handle_method_sync_pairs (const char *dest, - const char *path, - const char *interface, - const char *method, - int num, - va_list args); - -int dbus_handle_method_async_pairs (const char *dest, - const char *path, - const char *interface, - const char *method, - int num, - va_list args); - int dbus_handle_method_async (const char *dest, const char *path, const char *interface, @@ -168,16 +154,6 @@ int dbus_handle_method_async_with_reply_var (const char *dest, int timeout_msec, void *data); -int dbus_handle_method_async_pairs_with_reply (const char *dest, - const char *path, - const char *iface, - const char *method, - int num, - va_list args, - dbus_pending_cb cb, - int timeout_msec, - void *data); - GVariant *dbus_handle_method_sync_with_reply_var (const char *dest, const char *path, const char *iface, @@ -303,4 +279,4 @@ GVariant *dbus_handle_make_simple_array (const char *sig, int *param); -#endif \ No newline at end of file +#endif -- 2.7.4 From f79b0093383b1b693294ca912a9a0a52bacd6def Mon Sep 17 00:00:00 2001 From: Hyotaek Shim Date: Thu, 4 Mar 2021 11:17:58 +0900 Subject: [PATCH 06/16] Remove unused gdbus APIs based on char string Change-Id: I6ddb7dd5948c5268f7da0b3977d25059b7898110 Signed-off-by: Hyotaek Shim --- src/libgdbus/dbus-system.c | 366 --------------------------------------------- src/libgdbus/dbus-system.h | 44 ------ 2 files changed, 410 deletions(-) diff --git a/src/libgdbus/dbus-system.c b/src/libgdbus/dbus-system.c index 5df1959..6ef7c6d 100644 --- a/src/libgdbus/dbus-system.c +++ b/src/libgdbus/dbus-system.c @@ -115,7 +115,6 @@ dbus_handle_s * _dbus_handle_get_default_connection(void) dbus_object_handle_s * _dbus_handle_lookup_object(GList *list_obj, const char *obj_path); dbus_interface_s * _dbus_handle_lookup_interface(GList *list_iface, const char *iface_name); dbus_method_s * _dbus_handle_lookup_method(GList *list_methods, const char *method_name); -static GVariant* _append_variant(const char *signature, const char *param[]); dbus_interface_s *_iface_u_to_s(const dbus_interface_u *iface_u) { @@ -1670,83 +1669,6 @@ int _check_type_string_is_container(const char *signature) return TRUE; } -/* todo: looks like garbage... */ -static GVariant* _append_variant(const char *signature, const char *param[]) -{ - char *ch; - int i; - int pi; - int int_type; - gboolean bool_type; - unsigned long long int64_type; - GVariant *ret; - int len; - char container[255];// The maximum length of a signature is 255. - const char *sig = signature; - GVariantBuilder *builder = NULL; - - if (!signature || !param) - return 0; - - /* workaround for user fault "(i) != i" but we treat this as same signature */ - /* G_VARIANT_TYPE("si") return NULL */ - /* todo: actually user have to use correct signature */ - if (!_check_type_string_is_container(signature)) { - snprintf(container, sizeof(container) - 1, "(%s)", signature); - sig = container; - } - if (!g_variant_type_is_container(G_VARIANT_TYPE(sig))) - _E("signature (%s) is not container type", signature); - - builder = g_variant_builder_new(G_VARIANT_TYPE(sig)); - len = strlen(sig); - pi = 0; - for (ch = (char *)sig, i = 0; i < len; ++i, ++ch) { - switch (*ch) { - case '(': - case ')': - continue; - case 'b': - bool_type = (atoi(param[pi++]) == 0 ? FALSE : TRUE); - g_variant_builder_add(builder, "b", bool_type); - break; - case 'i': - int_type = atoi(param[pi++]); - g_variant_builder_add(builder, "i", int_type); - break; - case 'u': - int_type = strtoul(param[pi++], NULL, 10); - g_variant_builder_add(builder, "u", int_type); - break; - case 't': - int64_type = atoll(param[pi++]); - g_variant_builder_add(builder, "t", int64_type); - break; - case 's': - g_variant_builder_add(builder, "s", param[pi++]); - break; - case 'a': - ++ch; - switch (*ch) { - case 'y': - g_variant_builder_add(builder, "^ay", param[pi++]); - ++i; - break; - default: - break; - } - break; - default: - break; - } - } - ret = g_variant_builder_end(builder); - g_variant_builder_clear(builder); - g_variant_builder_unref(builder); - - return ret; -} - int dbus_handle_emit_dbus_signal(const char *dest, const char *path, const char *iface, @@ -1941,91 +1863,6 @@ gint* dbus_handle_get_unix_fd_list(GDBusMethodInvocation *invocation, int *size) return g_unix_fd_list_steal_fds(fd_list, NULL); } -GVariant *dbus_handle_method_with_unix_fd_list_sync_with_reply(const char *dest, - const char *path, - const char *iface, - const char *method, - const char *signature, - const char *param[], - int *in_fdlist, - int in_size, - int **out_fdlist, - int *out_size) -{ - GError *err = NULL; - GVariant * var = NULL; - GVariant * ret = NULL; - dbus_handle_s *dh = NULL; - GUnixFDList *g_infdlist = NULL; - GUnixFDList *g_outfdlist = NULL; - - if (!dest || !path || !iface || !method) { - _E("wrong parameters dest(%s) path(%s) iface(%s) method(%s)", dest, path, iface, method); - return NULL; - } - if (in_fdlist && in_size == 0) { - _E("wrong in_fdlist is not null but in_size is 0"); - return NULL; - } - - dh = _dbus_handle_get_default_connection(); - if (!dh) { - _E("failed to get default connection, bustype:%d", (int)dbus_handle_get_default_bus_type()); - return NULL; - } - - if (signature && param) - var = _append_variant(signature, param); - - /* append fd */ - if (in_fdlist) { - g_infdlist = g_unix_fd_list_new_from_array(in_fdlist, in_size); - if (!g_infdlist) { - _E("failed to g_unix_fd_list_new_from_array\n"); - goto out; - } - //g_infdlist = g_unix_fd_list_new(); - //if (g_unix_fd_list_append(g_infdlist, in_fdlist[0], &err) < 0) { - } - - ret = g_dbus_connection_call_with_unix_fd_list_sync(dh->conn, - dest, path, iface, method, - var, NULL, - G_DBUS_CALL_FLAGS_NONE, - -1, - g_infdlist, &g_outfdlist, - NULL, - &err); - if (!ret || err) { - if (err) { - _E("failed to g_dbus_connection_call_with_unix_fd_list_sync:%s", err->message); - g_error_free(err); - } else { - _E("failed to g_dbus_connection_call_with_unix_fd_list_sync:"); - if (var) - g_variant_unref(var); - if (g_infdlist) - g_object_unref(g_infdlist); - } - goto out; - } - - /* fds to out array */ - if (g_outfdlist) { - *out_size = g_unix_fd_list_get_length(g_outfdlist); - if (*out_size == 0) - goto out; - - *out_fdlist = g_unix_fd_list_steal_fds(g_outfdlist, NULL); - } - -out: - if (g_outfdlist) - g_object_unref(g_outfdlist); - - return ret; -} - GVariant *dbus_handle_method_with_unix_fd_list_sync_with_reply_var(const char *dest, const char *path, const char *iface, @@ -2103,62 +1940,6 @@ out: return ret; } -int dbus_handle_method_sync(const char *dest, - const char *path, - const char *iface, - const char *method, - const char *signature, - const char *param[]) -{ - int result; - gboolean result_bool; - GVariant *reply = NULL; - GVariant * var = NULL; - GError *err = NULL; - dbus_handle_s *dh = NULL; - - if (!dest || !path || !iface || !method) { - _E("wrong parameters dest(%s) path(%s) iface(%s) method(%s)", dest, path, iface, method); - return -1; - } - - dh = _dbus_handle_get_default_connection(); - if (!dh) { - _E("failed to get default connection, bustype:%d", (int)dbus_handle_get_default_bus_type()); - return -ECOMM; - } - - if (signature && param) - var = _append_variant(signature, param); - - reply = g_dbus_connection_call_sync(dh->conn, - dest, path, iface, method, - var, NULL, G_DBUS_CALL_FLAGS_NONE, DBUS_REPLY_TIMEOUT, NULL, &err); - if (!reply || err) { - if (err) { - _E("failed to g_dbus_connection_call_sync:%s", err->message); - g_error_free(err); - } else { - _E("failed to g_dbus_connection_call_sync"); - g_variant_unref(var); - } - return -ECOMM; - } - - if (g_strcmp0("(i)", g_variant_get_type_string(reply)) == 0) { - g_variant_get(reply, "(i)", &result); - } else if (g_strcmp0("(b)", g_variant_get_type_string(reply)) == 0) { - g_variant_get(reply, "(b)", &result_bool); - result = (int)result_bool; - } else { - result = -ENOMSG; - } - - g_variant_unref(reply); - - return result; -} - int dbus_handle_method_sync_var(const char *dest, const char *path, const char *iface, @@ -2192,93 +1973,6 @@ int dbus_handle_method_sync_var(const char *dest, return result; } -int dbus_handle_method_sync_timeout(const char *dest, - const char *path, - const char *iface, - const char *method, - const char *signature, - const char *param[], - int timeout) -{ - dbus_handle_s *dh = NULL; - GError *err = NULL; - GVariant * var = NULL; - GVariant * reply = NULL; - int result = 0; - - if (!dest || !path || !iface || !method) { - _E("wrong parameters dest(%s) path(%s) iface(%s) method(%s)", dest, path, iface, method); - return -1; - } - - dh = _dbus_handle_get_default_connection(); - if (!dh) { - _E("failed to get default connection, bustype:%d", (int)dbus_handle_get_default_bus_type()); - return -EPERM; - } - - if (signature && param) - var = _append_variant(signature, param); - - reply = g_dbus_connection_call_sync(dh->conn, - dest, path, iface, method, - var, NULL, - G_DBUS_CALL_FLAGS_NONE, - timeout, - NULL, - &err); - if (!reply || err) { - _E("failed to g_dbus_connection_call_sync:%s", err->message); - g_error_free(err); - return -1; - } - - if (g_strcmp0("(i)", g_variant_get_type_string(reply)) == 0) - g_variant_get(reply, "(i)", &result); - else - result = -ENOMSG; - - g_variant_unref(reply); - - return result; -} - -int dbus_handle_method_async(const char *dest, - const char *path, - const char *iface, - const char *method, - const char *signature, - const char *param[]) -{ - GVariant * var = NULL; - dbus_handle_s *dh = NULL; - - if (!dest || !path || !iface || !method) { - _E("wrong parameters dest(%s) path(%s) iface(%s) method(%s)", dest, path, iface, method); - return -1; - } - - dh = _dbus_handle_get_default_connection(); - if (!dh) { - _E("failed to get default connection, bustype:%d", (int)dbus_handle_get_default_bus_type()); - return -1; - } - - if (signature && param) - var = _append_variant(signature, param); - - g_dbus_connection_call(dh->conn, - dest, path, iface, method, - var, NULL, - G_DBUS_CALL_FLAGS_NONE, - -1, - NULL, - NULL, - NULL); - - return 0; -} - int dbus_handle_method_async_var(const char *dest, const char *path, const char *iface, @@ -2339,66 +2033,6 @@ out: free(data); } -int dbus_handle_method_async_with_reply(const char *dest, - const char *path, - const char *iface, - const char *method, - const char *signature, - const char *param[], - dbus_pending_cb cb, - int timeout_msec, - void *data) -{ - dbus_handle_s *dh = NULL; - pending_call_data *pdata = NULL; - GVariant * var = NULL; - int ret = 0; - - if (!dest || !path || !iface || !method) { - _E("wrong parameters dest(%s) path(%s) iface(%s) method(%s)", dest, path, iface, method); - return -1; - } - - if (timeout_msec < -1) { - _E("wrong timeout %d", timeout_msec); - return -1; - } - - dh = _dbus_handle_get_default_connection(); - if (!dh) { - _E("failed to get default connection, bustype:%d", (int)dbus_handle_get_default_bus_type()); - return -EPERM; - } - - if (signature && param) - var = _append_variant(signature, param); - - if (cb) { - pdata = (pending_call_data*)malloc(sizeof(pending_call_data)); - if (!pdata) { - ret = -ENOMEM; - goto err; - } - - pdata->func = cb; - pdata->data = data; - } - g_dbus_connection_call(dh->conn, - dest, path, iface, method, - var, NULL, - G_DBUS_CALL_FLAGS_NONE, - timeout_msec, - NULL, - (GAsyncReadyCallback)_cb_pending, - pdata); - - return ret; -err: - if (var) - g_variant_unref(var); - return ret; -} - int dbus_handle_method_async_with_reply_var(const char *dest, const char *path, const char *iface, diff --git a/src/libgdbus/dbus-system.h b/src/libgdbus/dbus-system.h index 29fa58f..df591b2 100644 --- a/src/libgdbus/dbus-system.h +++ b/src/libgdbus/dbus-system.h @@ -100,51 +100,18 @@ int dbus_handle_add_dbus_object (dbus_handle_h handle, int dbus_handle_register_dbus_object_all (dbus_handle_h handle); - -int dbus_handle_method_sync (const char *dest, - const char *path, - const char *interface, - const char *method, - const char *sig, - const char *param[]); - int dbus_handle_method_sync_var (const char *dest, const char *path, const char *iface, const char *method, GVariant *param); -int dbus_handle_method_sync_timeout (const char *dest, - const char *path, - const char *interface, - const char *method, - const char *sig, - const char *param[], - int timeout); - -int dbus_handle_method_async (const char *dest, - const char *path, - const char *interface, - const char *method, - const char *sig, - const char *param[]); - int dbus_handle_method_async_var (const char *dest, const char *path, const char *iface, const char *method, GVariant *param); -int dbus_handle_method_async_with_reply (const char *dest, - const char *path, - const char *iface, - const char *method, - const char *signature, - const char *param[], - dbus_pending_cb cb, - int timeout_msec, - void *data); - int dbus_handle_method_async_with_reply_var (const char *dest, const char *path, const char *iface, @@ -170,17 +137,6 @@ GVariant *dbus_handle_method_sync_with_reply_var_timeout (const char *dest, gint* dbus_handle_get_unix_fd_list (GDBusMethodInvocation *invocation, int *size); -GVariant *dbus_handle_method_with_unix_fd_list_sync_with_reply (const char *dest, - const char *path, - const char *iface, - const char *method, - const char *signature, - const char *param[], - int *in_fdlist, - int in_size, - int **out_fdlist, - int *out_size); - GVariant *dbus_handle_method_with_unix_fd_list_sync_with_reply_var(const char *dest, const char *path, const char *iface, -- 2.7.4 From f70189da9900d8418529c249d556025dc964f8ad Mon Sep 17 00:00:00 2001 From: "taemin.yeom" Date: Wed, 3 Mar 2021 16:54:50 +0900 Subject: [PATCH 07/16] Change dbus_handle_method_sync_with_reply_var to add a return value indicating error results. Change-Id: I557c3fe79168076aaa9516f0c36eafd471e19c56 Signed-off-by: taemin.yeom --- src/libgdbus/dbus-system.c | 71 +++++++++++++++++++++++++-------------------- src/libgdbus/dbus-system.h | 10 ++++--- src/libgdbus/dbus-systemd.c | 39 ++++++++++++++++--------- 3 files changed, 71 insertions(+), 49 deletions(-) diff --git a/src/libgdbus/dbus-system.c b/src/libgdbus/dbus-system.c index 6ef7c6d..8c7197c 100644 --- a/src/libgdbus/dbus-system.c +++ b/src/libgdbus/dbus-system.c @@ -1748,96 +1748,96 @@ int dbus_handle_flush_sync(dbus_handle_h handle) return ret; } -GVariant *dbus_handle_method_sync_with_reply_var(const char *dest, +int dbus_handle_method_sync_with_reply_var(const char *dest, const char *path, const char *iface, const char *method, - GVariant *var) + GVariant *param, + GVariant **reply) { GError *err = NULL; - GVariant * ret = NULL; + int ret = 0; dbus_handle_s *dh = NULL; if (!dest || !path || !iface || !method) { _E("wrong parameters dest(%s) path(%s) iface(%s) method(%s)", dest, path, iface, method); - if (var) - g_variant_unref(var); - return NULL; + if (param) + g_variant_unref(param); + return -EINVAL; } dh = _dbus_handle_get_default_connection(); if (!dh) { _E("failed to get default connection, bustype:%d", (int)dbus_handle_get_default_bus_type()); - if (var) - g_variant_unref(var); - return NULL; + if (param) + g_variant_unref(param); + return -ECOMM; } - ret = g_dbus_connection_call_sync(dh->conn, + *reply = g_dbus_connection_call_sync(dh->conn, dest, path, iface, method, - var, NULL, + param, NULL, G_DBUS_CALL_FLAGS_NONE, DBUS_REPLY_TIMEOUT, NULL, &err); - if (!ret || err) { + if (!(*reply) || err) { if (err) { _E("failed to g_dbus_connection_call_sync:%s", err->message); if (g_error_matches(err, G_DBUS_ERROR, G_DBUS_ERROR_ACCESS_DENIED)) - ret = g_variant_new("(i)", -EPERM); + ret = -EPERM; else - ret = NULL; + ret = -ECOMM; g_error_free(err); return ret; } else { _E("failed to g_dbus_connection_call_sync"); } - return NULL; + return -ECOMM; } return ret; } -GVariant *dbus_handle_method_sync_with_reply_var_timeout(const char *dest, const char *path, - const char *iface, const char *method, GVariant *var, int timeout) +int dbus_handle_method_sync_with_reply_var_timeout(const char *dest, const char *path, + const char *iface, const char *method, GVariant *param, GVariant **reply, int timeout) { GError *err = NULL; - GVariant * ret = NULL; dbus_handle_s *dh = NULL; if (!dest || !path || !iface || !method) { _E("wrong parameters dest(%s) path(%s) iface(%s) method(%s)", dest, path, iface, method); - if (var) - g_variant_unref(var); - return NULL; + if (param) + g_variant_unref(param); + return -EINVAL; } dh = _dbus_handle_get_default_connection(); if (!dh) { _E("failed to get default connection, bustype:%d", (int)dbus_handle_get_default_bus_type()); - if (var) - g_variant_unref(var); - return NULL; + if (param) + g_variant_unref(param); + return -ECOMM; } - ret = g_dbus_connection_call_sync(dh->conn, + *reply = g_dbus_connection_call_sync(dh->conn, dest, path, iface, method, - var, NULL, + param, NULL, G_DBUS_CALL_FLAGS_NONE, timeout, NULL, &err); - if (!ret || err) { + if (!(*reply) || err) { if (err) { _E("failed to g_dbus_connection_call_sync:%s", err->message); g_error_free(err); } else { _E("failed to g_dbus_connection_call_sync"); } - return NULL; + return -ECOMM; } - return ret; + return 0; } gint* dbus_handle_get_unix_fd_list(GDBusMethodInvocation *invocation, int *size) @@ -1947,6 +1947,7 @@ int dbus_handle_method_sync_var(const char *dest, GVariant *param) { int result; + int ret = 0; gboolean result_bool; GVariant *reply = NULL; @@ -1955,7 +1956,10 @@ int dbus_handle_method_sync_var(const char *dest, return -1; } - reply = dbus_handle_method_sync_with_reply_var(dest, path, iface, method, param); + ret = dbus_handle_method_sync_with_reply_var(dest, path, iface, method, param, &reply); + if (ret < 0) + return ret; + if (!reply) return -ECOMM; @@ -2376,11 +2380,14 @@ int check_systemd_active(void) _I("%s %s", "org.freedesktop.systemd1.Unit", "ActiveState"); - msg = dbus_handle_method_sync_with_reply_var("org.freedesktop.systemd1", + ret = dbus_handle_method_sync_with_reply_var("org.freedesktop.systemd1", "/org/freedesktop/systemd1/unit/default_2etarget", "org.freedesktop.DBus.Properties", "Get", - g_variant_new("(ss)", "org.freedesktop.systemd1.Unit", "ActiveState")); + g_variant_new("(ss)", "org.freedesktop.systemd1.Unit", "ActiveState"), + &msg); + if (ret < 0) + return ret; if (!msg) return -EBADMSG; diff --git a/src/libgdbus/dbus-system.h b/src/libgdbus/dbus-system.h index df591b2..c367510 100644 --- a/src/libgdbus/dbus-system.h +++ b/src/libgdbus/dbus-system.h @@ -121,17 +121,19 @@ int dbus_handle_method_async_with_reply_var (const char *dest, int timeout_msec, void *data); -GVariant *dbus_handle_method_sync_with_reply_var (const char *dest, +int dbus_handle_method_sync_with_reply_var (const char *dest, const char *path, const char *iface, const char *method, - GVariant *var); + GVariant *param, + GVariant **reply); -GVariant *dbus_handle_method_sync_with_reply_var_timeout (const char *dest, +int dbus_handle_method_sync_with_reply_var_timeout (const char *dest, const char *path, const char *iface, const char *method, - GVariant *var, + GVariant *param, + GVariant **reply, int timeout); gint* dbus_handle_get_unix_fd_list (GDBusMethodInvocation *invocation, diff --git a/src/libgdbus/dbus-systemd.c b/src/libgdbus/dbus-systemd.c index 9667115..14c8a72 100644 --- a/src/libgdbus/dbus-systemd.c +++ b/src/libgdbus/dbus-systemd.c @@ -132,11 +132,15 @@ static int _systemd_control_unit_wait(const char *method, goto finish; } - reply = dbus_handle_method_sync_with_reply_var(SYSTEMD_DBUS_DEST, + ret = dbus_handle_method_sync_with_reply_var(SYSTEMD_DBUS_DEST, SYSTEMD_DBUS_PATH, SYSTEMD_DBUS_MANAGER_IFACE, method, - g_variant_new("(ss)", name, "replace")); + g_variant_new("(ss)", name, "replace"), + &reply); + if (ret < 0) + goto finish; + if (!reply || !g_variant_get_safe(reply, "(o)", &objpath)) { _E("fail (%s): no message", method); ret = -EBADMSG; @@ -182,11 +186,14 @@ static int _systemd_control_unit_async(const char *method, const char *name) _I("Starting: %s %s", method, name); - reply = dbus_handle_method_sync_with_reply_var(SYSTEMD_DBUS_DEST, + ret = dbus_handle_method_sync_with_reply_var(SYSTEMD_DBUS_DEST, SYSTEMD_DBUS_PATH, SYSTEMD_DBUS_MANAGER_IFACE, method, - g_variant_new("(ss)", name, "replace")); + g_variant_new("(ss)", name, "replace"), + &reply); + if (ret < 0) + goto finish; if (!reply || !g_variant_get_safe(reply, "(o)", &objpath)) { _E("fail (%s): no message", method); @@ -404,16 +411,18 @@ GVariant *systemd_get_manager_property(const char *property) { GVariant *reply = NULL; GVariant *val = NULL; + int ret = 0; if (!property) return NULL; - reply = dbus_handle_method_sync_with_reply_var(SYSTEMD_DBUS_DEST, + ret = dbus_handle_method_sync_with_reply_var(SYSTEMD_DBUS_DEST, SYSTEMD_DBUS_PATH, DBUS_IFACE_DBUS_PROPERTIES, "Get", - g_variant_new("(ss)", SYSTEMD_DBUS_MANAGER_IFACE, property)); - if (!reply || !g_variant_get_safe(reply, "(v)", &val)) + g_variant_new("(ss)", SYSTEMD_DBUS_MANAGER_IFACE, property), + &reply); + if (!reply || !g_variant_get_safe(reply, "(v)", &val) || ret < 0) _E("Failed to get variant"); if (reply) g_variant_unref(reply); @@ -426,19 +435,21 @@ GVariant *systemd_get_unit_property(const char *unit, const char *property) char *escaped; GVariant *reply = NULL; GVariant *val = NULL; + int ret = 0; if (!unit || !property) return NULL; escaped = systemd_get_unit_dbus_path(unit); - reply = dbus_handle_method_sync_with_reply_var(SYSTEMD_DBUS_DEST, + ret = dbus_handle_method_sync_with_reply_var(SYSTEMD_DBUS_DEST, escaped, DBUS_IFACE_DBUS_PROPERTIES, "Get", - g_variant_new("(ss)", SYSTEMD_DBUS_UNIT_IFACE, property)); + g_variant_new("(ss)", SYSTEMD_DBUS_UNIT_IFACE, property), + &reply); - if (!reply || !g_variant_get_safe(reply, "(v)", &val)) + if (!reply || !g_variant_get_safe(reply, "(v)", &val) || ret < 0) _E("Failed to get variant"); if (reply) g_variant_unref(reply); @@ -452,18 +463,20 @@ GVariant *systemd_get_service_property(const char *unit, const char *property) char *escaped; GVariant *reply = NULL; GVariant *val = NULL; + int ret = 0; if (!unit || !property) return NULL; escaped = systemd_get_unit_dbus_path(unit); - reply = dbus_handle_method_sync_with_reply_var(SYSTEMD_DBUS_DEST, + ret = dbus_handle_method_sync_with_reply_var(SYSTEMD_DBUS_DEST, escaped, DBUS_IFACE_DBUS_PROPERTIES, "Get", - g_variant_new("(ss)", SYSTEMD_DBUS_SERVICE_IFACE, property)); - if (!reply || !g_variant_get_safe(reply, "(v)", &val)) + g_variant_new("(ss)", SYSTEMD_DBUS_SERVICE_IFACE, property), + &reply); + if (!reply || !g_variant_get_safe(reply, "(v)", &val) || ret < 0) _E("Failed to get variant"); if (reply) g_variant_unref(reply); -- 2.7.4 From 99c433e6de1cc3d093fe2eebc16b706b5b2c3544 Mon Sep 17 00:00:00 2001 From: "taemin.yeom" Date: Thu, 4 Mar 2021 15:20:57 +0900 Subject: [PATCH 08/16] Change dbus handle method functions change "dbus_handle_method_sync_var" and "dbus_handle_method_with_unix_fd_list_sync_with_reply_var" to add a return value indicating error results Change-Id: Ib9063dc6811bb28e885f71e85b0253dfd6d303bc Signed-off-by: taemin.yeom --- src/libgdbus/dbus-system.c | 31 +++++++++++++++++-------------- src/libgdbus/dbus-system.h | 6 ++++-- 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/src/libgdbus/dbus-system.c b/src/libgdbus/dbus-system.c index 8c7197c..fdf1859 100644 --- a/src/libgdbus/dbus-system.c +++ b/src/libgdbus/dbus-system.c @@ -1863,35 +1863,36 @@ gint* dbus_handle_get_unix_fd_list(GDBusMethodInvocation *invocation, int *size) return g_unix_fd_list_steal_fds(fd_list, NULL); } -GVariant *dbus_handle_method_with_unix_fd_list_sync_with_reply_var(const char *dest, +int dbus_handle_method_with_unix_fd_list_sync_with_reply_var(const char *dest, const char *path, const char *iface, const char *method, GVariant *param, + GVariant **reply, int *in_fdlist, int in_size, int **out_fdlist, int *out_size) { + int ret = 0; GError *err = NULL; - GVariant * ret = NULL; dbus_handle_s *dh = NULL; GUnixFDList *g_infdlist = NULL; GUnixFDList *g_outfdlist = NULL; if (!dest || !path || !iface || !method) { _E("wrong parameters dest(%s) path(%s) iface(%s) method(%s)", dest, path, iface, method); - return NULL; + return -EINVAL; } if (in_fdlist && in_size == 0) { _E("wrong in_fdlist is not null but in_size is 0"); - return NULL; + return -EINVAL; } dh = _dbus_handle_get_default_connection(); if (!dh) { _E("failed to get default connection, bustype:%d", (int)dbus_handle_get_default_bus_type()); - return NULL; + return -EAGAIN; } /* append fd */ @@ -1899,6 +1900,7 @@ GVariant *dbus_handle_method_with_unix_fd_list_sync_with_reply_var(const char *d g_infdlist = g_unix_fd_list_new_from_array(in_fdlist, in_size); if (!g_infdlist) { _E("failed to g_unix_fd_list_new_from_array\n"); + ret = -EAGAIN; goto out; } //g_infdlist = g_unix_fd_list_new(); @@ -1906,14 +1908,14 @@ GVariant *dbus_handle_method_with_unix_fd_list_sync_with_reply_var(const char *d } /* send message */ - ret = g_dbus_connection_call_with_unix_fd_list_sync(dh->conn, + *reply = g_dbus_connection_call_with_unix_fd_list_sync(dh->conn, dest, path, iface, method, param, NULL, G_DBUS_CALL_FLAGS_NONE, -1, g_infdlist, &g_outfdlist, NULL, &err); - if (!ret || err) { + if (!(*reply) || err) { if (err) { _E("failed to g_dbus_connection_call_with_unix_fd_list_sync:%s", err->message); g_error_free(err); @@ -1924,6 +1926,7 @@ GVariant *dbus_handle_method_with_unix_fd_list_sync_with_reply_var(const char *d if (g_infdlist) g_object_unref(g_infdlist); } + ret = -EAGAIN; goto out; } @@ -1944,16 +1947,16 @@ int dbus_handle_method_sync_var(const char *dest, const char *path, const char *iface, const char *method, - GVariant *param) + GVariant *param, + int *output) { - int result; int ret = 0; gboolean result_bool; GVariant *reply = NULL; if (!dest || !path || !iface || !method) { _E("wrong parameters dest(%s) path(%s) iface(%s) method(%s)", dest, path, iface, method); - return -1; + return -EINVAL; } ret = dbus_handle_method_sync_with_reply_var(dest, path, iface, method, param, &reply); @@ -1964,17 +1967,17 @@ int dbus_handle_method_sync_var(const char *dest, return -ECOMM; if (g_strcmp0("(i)", g_variant_get_type_string(reply)) == 0) { - g_variant_get(reply, "(i)", &result); + g_variant_get(reply, "(i)", output); } else if (g_strcmp0("(b)", g_variant_get_type_string(reply)) == 0) { g_variant_get(reply, "(b)", &result_bool); - result = (int)result_bool; + *output = (int)result_bool; } else { - result = -ENOMSG; + ret = -ENOMSG; } g_variant_unref(reply); - return result; + return ret; } int dbus_handle_method_async_var(const char *dest, diff --git a/src/libgdbus/dbus-system.h b/src/libgdbus/dbus-system.h index c367510..0b831da 100644 --- a/src/libgdbus/dbus-system.h +++ b/src/libgdbus/dbus-system.h @@ -104,7 +104,8 @@ int dbus_handle_method_sync_var (const char *dest, const char *path, const char *iface, const char *method, - GVariant *param); + GVariant *param, + int *output); int dbus_handle_method_async_var (const char *dest, const char *path, @@ -139,11 +140,12 @@ int dbus_handle_method_sync_with_reply_var_timeout (const char *dest, gint* dbus_handle_get_unix_fd_list (GDBusMethodInvocation *invocation, int *size); -GVariant *dbus_handle_method_with_unix_fd_list_sync_with_reply_var(const char *dest, +int dbus_handle_method_with_unix_fd_list_sync_with_reply_var(const char *dest, const char *path, const char *iface, const char *method, GVariant *param, + GVariant **reply, int *in_fdlist, int in_size, int **out_fdlist, -- 2.7.4 From 1b0113f5303c03b34176fc60024c0827da348141 Mon Sep 17 00:00:00 2001 From: "taemin.yeom" Date: Fri, 5 Mar 2021 14:38:18 +0900 Subject: [PATCH 09/16] Improve error handling Change-Id: I2db312e210c37a457eb874d41f1adcfb5700885a Signed-off-by: taemin.yeom --- src/libgdbus/dbus-system.c | 56 ++++++++++++++++++++++++++++++++-------------- 1 file changed, 39 insertions(+), 17 deletions(-) diff --git a/src/libgdbus/dbus-system.c b/src/libgdbus/dbus-system.c index fdf1859..2b3fbb5 100644 --- a/src/libgdbus/dbus-system.c +++ b/src/libgdbus/dbus-system.c @@ -1756,7 +1756,8 @@ int dbus_handle_method_sync_with_reply_var(const char *dest, GVariant **reply) { GError *err = NULL; - int ret = 0; + GVariant *ret = NULL; + int err_val = 0; dbus_handle_s *dh = NULL; if (!dest || !path || !iface || !method) { @@ -1774,35 +1775,41 @@ int dbus_handle_method_sync_with_reply_var(const char *dest, return -ECOMM; } - *reply = g_dbus_connection_call_sync(dh->conn, + ret = g_dbus_connection_call_sync(dh->conn, dest, path, iface, method, param, NULL, G_DBUS_CALL_FLAGS_NONE, DBUS_REPLY_TIMEOUT, NULL, &err); - if (!(*reply) || err) { + if (!ret || err) { if (err) { _E("failed to g_dbus_connection_call_sync:%s", err->message); if (g_error_matches(err, G_DBUS_ERROR, G_DBUS_ERROR_ACCESS_DENIED)) - ret = -EPERM; + err_val = -EPERM; else - ret = -ECOMM; + err_val = -ECOMM; g_error_free(err); - return ret; + return err_val; } else { _E("failed to g_dbus_connection_call_sync"); } return -ECOMM; } - return ret; + if(reply) + *reply = ret; + else + g_variant_unref(ret); + + return err_val; } int dbus_handle_method_sync_with_reply_var_timeout(const char *dest, const char *path, const char *iface, const char *method, GVariant *param, GVariant **reply, int timeout) { GError *err = NULL; + GVariant *ret; dbus_handle_s *dh = NULL; if (!dest || !path || !iface || !method) { @@ -1820,14 +1827,14 @@ int dbus_handle_method_sync_with_reply_var_timeout(const char *dest, const char return -ECOMM; } - *reply = g_dbus_connection_call_sync(dh->conn, + ret = g_dbus_connection_call_sync(dh->conn, dest, path, iface, method, param, NULL, G_DBUS_CALL_FLAGS_NONE, timeout, NULL, &err); - if (!(*reply) || err) { + if (!ret || err) { if (err) { _E("failed to g_dbus_connection_call_sync:%s", err->message); g_error_free(err); @@ -1837,6 +1844,11 @@ int dbus_handle_method_sync_with_reply_var_timeout(const char *dest, const char return -ECOMM; } + if(reply) + *reply = ret; + else + g_variant_unref(ret); + return 0; } @@ -1874,7 +1886,8 @@ int dbus_handle_method_with_unix_fd_list_sync_with_reply_var(const char *dest, int **out_fdlist, int *out_size) { - int ret = 0; + int err_val = 0; + GVariant *ret = NULL; GError *err = NULL; dbus_handle_s *dh = NULL; GUnixFDList *g_infdlist = NULL; @@ -1900,7 +1913,7 @@ int dbus_handle_method_with_unix_fd_list_sync_with_reply_var(const char *dest, g_infdlist = g_unix_fd_list_new_from_array(in_fdlist, in_size); if (!g_infdlist) { _E("failed to g_unix_fd_list_new_from_array\n"); - ret = -EAGAIN; + err_val = -EAGAIN; goto out; } //g_infdlist = g_unix_fd_list_new(); @@ -1908,14 +1921,14 @@ int dbus_handle_method_with_unix_fd_list_sync_with_reply_var(const char *dest, } /* send message */ - *reply = g_dbus_connection_call_with_unix_fd_list_sync(dh->conn, + ret = g_dbus_connection_call_with_unix_fd_list_sync(dh->conn, dest, path, iface, method, param, NULL, G_DBUS_CALL_FLAGS_NONE, -1, g_infdlist, &g_outfdlist, NULL, &err); - if (!(*reply) || err) { + if (!ret || err) { if (err) { _E("failed to g_dbus_connection_call_with_unix_fd_list_sync:%s", err->message); g_error_free(err); @@ -1926,10 +1939,15 @@ int dbus_handle_method_with_unix_fd_list_sync_with_reply_var(const char *dest, if (g_infdlist) g_object_unref(g_infdlist); } - ret = -EAGAIN; + err_val = -EAGAIN; goto out; } + if(reply) + *reply = ret; + else + g_variant_unref(ret); + /* copy fds to out array */ if (g_outfdlist) { *out_size = g_unix_fd_list_get_length(g_outfdlist); @@ -1940,7 +1958,7 @@ int dbus_handle_method_with_unix_fd_list_sync_with_reply_var(const char *dest, out: if (g_outfdlist) g_object_unref(g_outfdlist); - return ret; + return err_val; } int dbus_handle_method_sync_var(const char *dest, @@ -1951,6 +1969,7 @@ int dbus_handle_method_sync_var(const char *dest, int *output) { int ret = 0; + int result; gboolean result_bool; GVariant *reply = NULL; @@ -1967,10 +1986,13 @@ int dbus_handle_method_sync_var(const char *dest, return -ECOMM; if (g_strcmp0("(i)", g_variant_get_type_string(reply)) == 0) { - g_variant_get(reply, "(i)", output); + g_variant_get(reply, "(i)", &result); + if(output) + *output = result; } else if (g_strcmp0("(b)", g_variant_get_type_string(reply)) == 0) { g_variant_get(reply, "(b)", &result_bool); - *output = (int)result_bool; + if(output) + *output = (int)result_bool; } else { ret = -ENOMSG; } -- 2.7.4 From f2162bc7cb174f59357b416701f84123289f1a4a Mon Sep 17 00:00:00 2001 From: "taemin.yeom" Date: Mon, 8 Mar 2021 17:23:27 +0900 Subject: [PATCH 10/16] Restore gdbus APIs based on va_list Change-Id: I9c275d6c652ac4253d3058fa3c022340ca55c6cd Signed-off-by: taemin.yeom --- src/libgdbus/dbus-system.c | 176 +++++++++++++++++++++++++++++++++++++++++++++ src/libgdbus/dbus-system.h | 24 +++++++ 2 files changed, 200 insertions(+) diff --git a/src/libgdbus/dbus-system.c b/src/libgdbus/dbus-system.c index 2b3fbb5..45b0874 100644 --- a/src/libgdbus/dbus-system.c +++ b/src/libgdbus/dbus-system.c @@ -1852,6 +1852,110 @@ int dbus_handle_method_sync_with_reply_var_timeout(const char *dest, const char return 0; } +int dbus_handle_method_sync_pairs(const char *dest, + const char *path, + const char *iface, + const char *method, + int num, + va_list args) +{ + GError *err = NULL; + GVariant * reply = NULL; + char *key, *value; + int ret = 0; + GVariant *var; + GVariantBuilder *builder; + dbus_handle_s *dh = NULL; + + if (!dest || !path || !iface || !method) { + _E("wrong parameters dest(%s) path(%s) iface(%s) method(%s)", dest, path, iface, method); + return -1; + } + + dh = _dbus_handle_get_default_connection(); + if (!dh) { + _E("failed to get default connection, bustype:%d", (int)dbus_handle_get_default_bus_type()); + return -1; + } + + builder = g_variant_builder_new(G_VARIANT_TYPE("a{ss}")); + + for (int i = 0 ; i < num ; i = i + 2) { + key = va_arg(args, char *); + value = va_arg(args, char *); + _I("key(%s), value(%s)", key, value); + g_variant_builder_add(builder, "{ss}", key, value); + } + + var = g_variant_new("(a{ss})", builder); + g_variant_builder_unref(builder); + + reply = g_dbus_connection_call_sync(dh->conn, + dest, path, iface, method, + var, NULL, G_DBUS_CALL_FLAGS_NONE, DBUS_REPLY_TIMEOUT, NULL, &err); + if (!reply || err) { + _E("failed to g_dbus_connection_call_sync"); + return -1; + } + + if (g_strcmp0("(i)", g_variant_get_type_string(reply)) == 0) + g_variant_get(reply, "(i)", &ret); + else + ret = -ENOMSG; + + g_variant_unref(reply); + + return ret; +} + +int dbus_handle_method_async_pairs(const char *dest, + const char *path, + const char *iface, + const char *method, + int num, + va_list args) +{ + char *key, *value; + GVariant *var; + GVariantBuilder *builder; + dbus_handle_s *dh = NULL; + + if (!dest || !path || !iface || !method) { + _E("wrong parameters dest(%s) path(%s) iface(%s) method(%s)", dest, path, iface, method); + return -1; + } + + dh = _dbus_handle_get_default_connection(); + if (!dh) { + _E("failed to get default connection, bustype:%d", (int)dbus_handle_get_default_bus_type()); + return -1; + } + + // dict + builder = g_variant_builder_new(G_VARIANT_TYPE("a{ss}")); + + for (int i = 0 ; i < num ; i = i + 2) { + key = va_arg(args, char *); + value = va_arg(args, char *); + _I("key(%s), value(%s)", key, value); + g_variant_builder_add(builder, "{ss}", key, value); + } + + var = g_variant_new("(a{ss})", builder); + g_variant_builder_unref(builder); + + g_dbus_connection_call(dh->conn, + dest, path, iface, method, + var, NULL, + G_DBUS_CALL_FLAGS_NONE, + -1, + NULL, + NULL, + NULL); + + return 0; +} + gint* dbus_handle_get_unix_fd_list(GDBusMethodInvocation *invocation, int *size) { GUnixFDList *fd_list = NULL; @@ -2117,6 +2221,78 @@ err: return ret; } +int dbus_handle_method_async_pairs_with_reply(const char *dest, + const char *path, + const char *iface, + const char *method, + int num, + va_list args, + dbus_pending_cb cb, + int timeout_msec, + void *data) +{ + dbus_handle_s *dh = NULL; + pending_call_data *pdata = NULL; + GVariantBuilder *builder; + char *key, *value; + GVariant *param; + int ret = 0; + + if (!dest || !path || !iface || !method) { + _E("wrong parameters dest(%s) path(%s) iface(%s) method(%s)", dest, path, iface, method); + return -1; + } + + if (timeout_msec < -1) { + _E("wrong timeout %d", timeout_msec); + return -1; + } + + dh = _dbus_handle_get_default_connection(); + if (!dh) { + _E("failed to get default connection, bustype:%d", (int)dbus_handle_get_default_bus_type()); + return -EPERM; + } + + // dict + builder = g_variant_builder_new(G_VARIANT_TYPE("a{ss}")); + + for (int i = 0 ; i < num ; i = i + 2) { + key = va_arg(args, char *); + value = va_arg(args, char *); + _I("key(%s), value(%s)", key, value); + g_variant_builder_add(builder, "{ss}", key, value); + } + + param = g_variant_new("(a{ss})", builder); + g_variant_builder_unref(builder); + + if (cb) { + pdata = (pending_call_data*)malloc(sizeof(pending_call_data)); + if (!pdata) { + ret = -ENOMEM; + goto err; + } + + pdata->func = cb; + pdata->data = data; + } + g_dbus_connection_call(dh->conn, + dest, path, iface, method, + param, NULL, + G_DBUS_CALL_FLAGS_NONE, + timeout_msec, + NULL, + (GAsyncReadyCallback)_cb_pending, + pdata); + + return ret; +err: + if (param) + g_variant_unref(param); + return ret; +} + int dbus_connection_get_sender_pid(GDBusConnection *conn, const char * sender) { GError *err = NULL; diff --git a/src/libgdbus/dbus-system.h b/src/libgdbus/dbus-system.h index 0b831da..c707d19 100644 --- a/src/libgdbus/dbus-system.h +++ b/src/libgdbus/dbus-system.h @@ -137,6 +137,30 @@ int dbus_handle_method_sync_with_reply_var_timeout (const char *dest, GVariant **reply, int timeout); +int dbus_handle_method_sync_pairs (const char *dest, + const char *path, + const char *interface, + const char *method, + int num, + va_list args); + +int dbus_handle_method_async_pairs (const char *dest, + const char *path, + const char *interface, + const char *method, + int num, + va_list args); + +int dbus_handle_method_async_pairs_with_reply (const char *dest, + const char *path, + const char *iface, + const char *method, + int num, + va_list args, + dbus_pending_cb cb, + int timeout_msec, + void *data); + gint* dbus_handle_get_unix_fd_list (GDBusMethodInvocation *invocation, int *size); -- 2.7.4 From 41bb90025fbe75dbc13f6bfc926109e1a337f591 Mon Sep 17 00:00:00 2001 From: Hyotaek Shim Date: Tue, 9 Mar 2021 13:24:11 +0900 Subject: [PATCH 11/16] Rearrange header and source files Change-Id: I7cb9725a5be1ac4ead7cac73d50203f413f669cf Signed-off-by: Hyotaek Shim --- CMakeLists.txt | 12 ++--- .../{dbus-system-iface.h => dbus-iface-system.h} | 0 src/libgdbus/{dbus-system.c => libgdbus.c} | 2 +- src/libgdbus/{dbus-system.h => libgdbus.h} | 2 +- .../dbus-systemd.c => libsystemd/libsystemd.c} | 40 +++++++++++++- .../dbus-systemd.h => libsystemd/libsystemd.h} | 3 +- src/libsystemd/systemd-state.c | 61 ---------------------- src/libsystemd/systemd-state.h | 35 ------------- 8 files changed, 48 insertions(+), 107 deletions(-) rename src/libgdbus/{dbus-system-iface.h => dbus-iface-system.h} (100%) rename src/libgdbus/{dbus-system.c => libgdbus.c} (99%) rename src/libgdbus/{dbus-system.h => libgdbus.h} (99%) rename src/{libgdbus/dbus-systemd.c => libsystemd/libsystemd.c} (93%) rename src/{libgdbus/dbus-systemd.h => libsystemd/libsystemd.h} (95%) delete mode 100644 src/libsystemd/systemd-state.c delete mode 100644 src/libsystemd/systemd-state.h diff --git a/CMakeLists.txt b/CMakeLists.txt index d314ee5..e16516d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,16 +12,14 @@ SET(INCLUDEDIR "${PREFIX}/include") SET(VERSION 4.1) SET(libsyscommon_SRCS - src/libgdbus/dbus-system.c - src/libgdbus/dbus-systemd.c - src/libsystemd/systemd-state.c + src/libgdbus/libgdbus.c + src/libsystemd/libsystemd.c src/libcommon/ini-parser.c ) SET(HEADERS - src/libgdbus/dbus-system.h - src/libgdbus/dbus-system-iface.h - src/libgdbus/dbus-systemd.h - src/libsystemd/systemd-state.h + src/libgdbus/libgdbus.h + src/libgdbus/dbus-iface-system.h + src/libsystemd/libsystemd.h src/libcommon/list.h src/libcommon/ini-parser.h src/libcommon/file.h diff --git a/src/libgdbus/dbus-system-iface.h b/src/libgdbus/dbus-iface-system.h similarity index 100% rename from src/libgdbus/dbus-system-iface.h rename to src/libgdbus/dbus-iface-system.h diff --git a/src/libgdbus/dbus-system.c b/src/libgdbus/libgdbus.c similarity index 99% rename from src/libgdbus/dbus-system.c rename to src/libgdbus/libgdbus.c index 45b0874..499a449 100644 --- a/src/libgdbus/dbus-system.c +++ b/src/libgdbus/libgdbus.c @@ -24,7 +24,7 @@ #include #include "shared/log.h" -#include "dbus-system.h" +#include "libgdbus.h" /* 10 seconds */ #define DBUS_REPLY_TIMEOUT (10000) diff --git a/src/libgdbus/dbus-system.h b/src/libgdbus/libgdbus.h similarity index 99% rename from src/libgdbus/dbus-system.h rename to src/libgdbus/libgdbus.h index c707d19..99fdc3e 100644 --- a/src/libgdbus/dbus-system.h +++ b/src/libgdbus/libgdbus.h @@ -26,7 +26,7 @@ #include #include -#include "dbus-system-iface.h" +#include "dbus-iface-system.h" typedef struct { const unsigned char *data; diff --git a/src/libgdbus/dbus-systemd.c b/src/libsystemd/libsystemd.c similarity index 93% rename from src/libgdbus/dbus-systemd.c rename to src/libsystemd/libsystemd.c index 14c8a72..a463118 100644 --- a/src/libgdbus/dbus-systemd.c +++ b/src/libsystemd/libsystemd.c @@ -21,7 +21,7 @@ #include #include #include -#include +#include #include "shared/log.h" @@ -483,3 +483,41 @@ GVariant *systemd_get_service_property(const char *unit, const char *property) free(escaped); return val; } + +#define SYSTEMD_DBUS_METHOD_SYSTEM_STATE "SystemState" +#define SYSTEMD_STATE_RUNNING "running" +#define SYSTEMD_STATE_DEGRADED "degraded" + +int check_system_boot_finished(void) +{ + char *state = NULL; + int ret = 0; + size_t len; + GVariant *reply = NULL; + + reply = systemd_get_manager_property(SYSTEMD_DBUS_METHOD_SYSTEM_STATE); + if (!reply) { + _E("Failed to get system state: No reply"); + goto err; + } + if (!g_variant_get_safe(reply, "s", &state)) { + _E("Failed to get system state(%s)", g_variant_get_type_string(reply)); + goto err; + } + + _I("System state=%s", state); + + len = strlen(state) + 1; + if (!strncmp(state, SYSTEMD_STATE_RUNNING, len) || + !strncmp(state, SYSTEMD_STATE_DEGRADED, len)) + ret = 1; + else + ret = 0; + +err: + if (reply) + g_variant_unref(reply); + free(state); + + return ret; +} diff --git a/src/libgdbus/dbus-systemd.h b/src/libsystemd/libsystemd.h similarity index 95% rename from src/libgdbus/dbus-systemd.h rename to src/libsystemd/libsystemd.h index 4d15200..79c9f9b 100644 --- a/src/libgdbus/dbus-systemd.h +++ b/src/libsystemd/libsystemd.h @@ -20,7 +20,7 @@ #ifndef __DBUS_SYSTEMD_H__ #define __DBUS_SYSTEMD_H__ -#include "dbus-system.h" +#include #ifdef __cplusplus extern "C" { @@ -49,6 +49,7 @@ GVariant *systemd_get_unit_property (const char *unit, GVariant *systemd_get_service_property (const char *unit, const char *property); +int check_system_boot_finished(void); #ifdef __cplusplus } diff --git a/src/libsystemd/systemd-state.c b/src/libsystemd/systemd-state.c deleted file mode 100644 index 1c25575..0000000 --- a/src/libsystemd/systemd-state.c +++ /dev/null @@ -1,61 +0,0 @@ -/* - * libsyscommon - * - * Copyright (c) 2019 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include - -#include "shared/log.h" - -#define SYSTEMD_DBUS_METHOD_SYSTEM_STATE "SystemState" -#define SYSTEMD_STATE_RUNNING "running" -#define SYSTEMD_STATE_DEGRADED "degraded" - -int check_system_boot_finished(void) -{ - char *state = NULL; - int ret = 0; - size_t len; - GVariant *reply = NULL; - - reply = systemd_get_manager_property(SYSTEMD_DBUS_METHOD_SYSTEM_STATE); - if (!reply) { - _E("Failed to get system state: No reply"); - goto err; - } - if (!g_variant_get_safe(reply, "s", &state)) { - _E("Failed to get system state(%s)", g_variant_get_type_string(reply)); - goto err; - } - - _I("System state=%s", state); - - len = strlen(state) + 1; - if (!strncmp(state, SYSTEMD_STATE_RUNNING, len) || - !strncmp(state, SYSTEMD_STATE_DEGRADED, len)) - ret = 1; - else - ret = 0; - -err: - if (reply) - g_variant_unref(reply); - free(state); - - return ret; -} diff --git a/src/libsystemd/systemd-state.h b/src/libsystemd/systemd-state.h deleted file mode 100644 index 54b4217..0000000 --- a/src/libsystemd/systemd-state.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - * libsyscommon - * - * Copyright (c) 2019 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#ifndef __SYSTEMD_STATE_H__ -#define __SYSTEMD_STATE_H__ - -#include "dbus-systemd.h" - -#ifdef __cplusplus -extern "C" { -#endif - -int check_system_boot_finished(void); - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#endif __SYSTEMD_STATE_H__ -- 2.7.4 From dfd0397af377e125ef1dd7bcf27a99b4f981ed4d Mon Sep 17 00:00:00 2001 From: "taemin.yeom" Date: Fri, 12 Mar 2021 11:02:08 +0900 Subject: [PATCH 12/16] Add GVariant NULL check Change-Id: I7278251402d76f4785b15b8fdc6724d80e59f642 Signed-off-by: taemin.yeom --- src/libgdbus/libgdbus.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libgdbus/libgdbus.h b/src/libgdbus/libgdbus.h index 99fdc3e..91fb1f3 100644 --- a/src/libgdbus/libgdbus.h +++ b/src/libgdbus/libgdbus.h @@ -66,7 +66,7 @@ typedef struct { gchar *sec_label; } GDBusCredentials; -#define g_variant_get_safe(gvar, signature, ...) ((g_strcmp0(signature, g_variant_get_type_string(gvar)) == 0) ? g_variant_get(gvar, signature, __VA_ARGS__), TRUE : FALSE) +#define g_variant_get_safe(gvar, signature, ...) ((gvar && (g_strcmp0(signature, g_variant_get_type_string(gvar)) == 0)) ? g_variant_get(gvar, signature, __VA_ARGS__), TRUE : FALSE) #define dbus_handle_new_g_variant_tuple() g_variant_new_tuple(NULL, 0) -- 2.7.4 From 5e55b268d818cd9ec315630b4bc8f4b2e4936301 Mon Sep 17 00:00:00 2001 From: "taemin.yeom" Date: Thu, 11 Mar 2021 18:17:04 +0900 Subject: [PATCH 13/16] Improve variable naming style Change-Id: I5236467f2efbc7768f49028b09e0a758967fd979 Signed-off-by: taemin.yeom --- src/libgdbus/libgdbus.c | 128 ++++++++++++++++++++++---------------------- src/libgdbus/libgdbus.h | 6 +-- src/libsystemd/libsystemd.c | 18 +++---- 3 files changed, 76 insertions(+), 76 deletions(-) diff --git a/src/libgdbus/libgdbus.c b/src/libgdbus/libgdbus.c index 499a449..3679337 100644 --- a/src/libgdbus/libgdbus.c +++ b/src/libgdbus/libgdbus.c @@ -998,21 +998,21 @@ static void _method_call_handler(GDBusConnection *conn, { dbus_interface_s *iface_s = (dbus_interface_s *)user_data; const dbus_method_s *methods; - GVariant *result = NULL; + GVariant *reply = NULL; /* todo: ghash ? */ methods = _dbus_handle_lookup_method(iface_s->list_methods, name); if (methods) { - result = methods->func(conn, sender, path, iface, name, param, invocation, get_dh_from_oh(iface_s->oh)); + reply = methods->func(conn, sender, path, iface, name, param, invocation, get_dh_from_oh(iface_s->oh)); /* async, maybe they will reply...maybe.. */ - if (!result) + if (!reply) return; } else { _E("no methods"); } - g_dbus_method_invocation_return_value(invocation, result); + g_dbus_method_invocation_return_value(invocation, reply); } static GDBusInterfaceVTable path_vtable = {_method_call_handler}; @@ -1356,7 +1356,7 @@ int dbus_handle_register_dbus_object_all(dbus_handle_h handle) dcl_dbus_handle(); dbus_object_handle_s *oh = NULL; dbus_interface_s *ih = NULL; - int ret = 0; + int ret_dbus = 0; if (!dh) { dh = _dbus_handle_get_default_connection(); @@ -1405,9 +1405,9 @@ int dbus_handle_register_dbus_object_all(dbus_handle_h handle) if (ih && ih->list_methods) _D("method list len %d", g_list_length(ih->list_methods));*/ - ret = _dbus_handle_register_dbus_object(dh, oh->path, ih); - if (ret <= 0) - _E("failed to register dbus object%d", ret); + ret_dbus = _dbus_handle_register_dbus_object(dh, oh->path, ih); + if (ret_dbus <= 0) + _E("failed to register dbus object%d", ret_dbus); } } @@ -1753,11 +1753,11 @@ int dbus_handle_method_sync_with_reply_var(const char *dest, const char *iface, const char *method, GVariant *param, - GVariant **reply) + GVariant **out_reply) { GError *err = NULL; - GVariant *ret = NULL; - int err_val = 0; + GVariant *reply = NULL; + int ret = 0; dbus_handle_s *dh = NULL; if (!dest || !path || !iface || !method) { @@ -1775,41 +1775,41 @@ int dbus_handle_method_sync_with_reply_var(const char *dest, return -ECOMM; } - ret = g_dbus_connection_call_sync(dh->conn, + reply = g_dbus_connection_call_sync(dh->conn, dest, path, iface, method, param, NULL, G_DBUS_CALL_FLAGS_NONE, DBUS_REPLY_TIMEOUT, NULL, &err); - if (!ret || err) { + if (!reply || err) { if (err) { _E("failed to g_dbus_connection_call_sync:%s", err->message); if (g_error_matches(err, G_DBUS_ERROR, G_DBUS_ERROR_ACCESS_DENIED)) - err_val = -EPERM; + ret = -EPERM; else - err_val = -ECOMM; + ret = -ECOMM; g_error_free(err); - return err_val; + return ret; } else { _E("failed to g_dbus_connection_call_sync"); } return -ECOMM; } - if(reply) - *reply = ret; + if(out_reply) + *out_reply = reply; else - g_variant_unref(ret); + g_variant_unref(reply); - return err_val; + return ret; } int dbus_handle_method_sync_with_reply_var_timeout(const char *dest, const char *path, - const char *iface, const char *method, GVariant *param, GVariant **reply, int timeout) + const char *iface, const char *method, GVariant *param, GVariant **out_reply, int timeout) { GError *err = NULL; - GVariant *ret; + GVariant *reply; dbus_handle_s *dh = NULL; if (!dest || !path || !iface || !method) { @@ -1827,14 +1827,14 @@ int dbus_handle_method_sync_with_reply_var_timeout(const char *dest, const char return -ECOMM; } - ret = g_dbus_connection_call_sync(dh->conn, + reply = g_dbus_connection_call_sync(dh->conn, dest, path, iface, method, param, NULL, G_DBUS_CALL_FLAGS_NONE, timeout, NULL, &err); - if (!ret || err) { + if (!reply || err) { if (err) { _E("failed to g_dbus_connection_call_sync:%s", err->message); g_error_free(err); @@ -1844,10 +1844,10 @@ int dbus_handle_method_sync_with_reply_var_timeout(const char *dest, const char return -ECOMM; } - if(reply) - *reply = ret; + if(out_reply) + *out_reply = reply; else - g_variant_unref(ret); + g_variant_unref(reply); return 0; } @@ -1860,7 +1860,7 @@ int dbus_handle_method_sync_pairs(const char *dest, va_list args) { GError *err = NULL; - GVariant * reply = NULL; + GVariant *reply = NULL; char *key, *value; int ret = 0; GVariant *var; @@ -1984,14 +1984,14 @@ int dbus_handle_method_with_unix_fd_list_sync_with_reply_var(const char *dest, const char *iface, const char *method, GVariant *param, - GVariant **reply, + GVariant **out_reply, int *in_fdlist, int in_size, int **out_fdlist, int *out_size) { - int err_val = 0; - GVariant *ret = NULL; + int ret = 0; + GVariant *reply = NULL; GError *err = NULL; dbus_handle_s *dh = NULL; GUnixFDList *g_infdlist = NULL; @@ -2017,7 +2017,7 @@ int dbus_handle_method_with_unix_fd_list_sync_with_reply_var(const char *dest, g_infdlist = g_unix_fd_list_new_from_array(in_fdlist, in_size); if (!g_infdlist) { _E("failed to g_unix_fd_list_new_from_array\n"); - err_val = -EAGAIN; + ret = -EAGAIN; goto out; } //g_infdlist = g_unix_fd_list_new(); @@ -2025,14 +2025,14 @@ int dbus_handle_method_with_unix_fd_list_sync_with_reply_var(const char *dest, } /* send message */ - ret = g_dbus_connection_call_with_unix_fd_list_sync(dh->conn, + reply = g_dbus_connection_call_with_unix_fd_list_sync(dh->conn, dest, path, iface, method, param, NULL, G_DBUS_CALL_FLAGS_NONE, -1, g_infdlist, &g_outfdlist, NULL, &err); - if (!ret || err) { + if (!reply || err) { if (err) { _E("failed to g_dbus_connection_call_with_unix_fd_list_sync:%s", err->message); g_error_free(err); @@ -2043,14 +2043,14 @@ int dbus_handle_method_with_unix_fd_list_sync_with_reply_var(const char *dest, if (g_infdlist) g_object_unref(g_infdlist); } - err_val = -EAGAIN; + ret = -EAGAIN; goto out; } - if(reply) - *reply = ret; + if(out_reply) + *out_reply = reply; else - g_variant_unref(ret); + g_variant_unref(reply); /* copy fds to out array */ if (g_outfdlist) { @@ -2062,7 +2062,7 @@ int dbus_handle_method_with_unix_fd_list_sync_with_reply_var(const char *dest, out: if (g_outfdlist) g_object_unref(g_outfdlist); - return err_val; + return ret; } int dbus_handle_method_sync_var(const char *dest, @@ -2296,7 +2296,7 @@ err: int dbus_connection_get_sender_pid(GDBusConnection *conn, const char * sender) { GError *err = NULL; - GVariant *vret = NULL; + GVariant *reply = NULL; pid_t pid = 0; if (!conn) { @@ -2308,21 +2308,21 @@ int dbus_connection_get_sender_pid(GDBusConnection *conn, const char * sender) return -1; } - vret = g_dbus_connection_call_sync(conn, + reply = g_dbus_connection_call_sync(conn, "org.freedesktop.DBus", "/", "org.freedesktop.DBus", "GetConnectionUnixProcessID", g_variant_new("(s)", sender), NULL, G_DBUS_CALL_FLAGS_NONE, DBUS_REPLY_TIMEOUT, NULL, &err); - if (!vret || err) { + if (!reply || err) { _E("failed to g_dbus_connection_call_sync:%s", err->message); g_error_free(err); return -1; } - g_variant_get(vret, "(u)", &pid); - g_variant_unref(vret); + g_variant_get(reply, "(u)", &pid); + g_variant_unref(reply); return pid; } @@ -2350,7 +2350,7 @@ int dbus_handle_get_sender_pid(dbus_handle_h handle, const char * sender) int dbus_handle_get_sender_credentials(dbus_handle_h handle, const char *name, GDBusCredentials *creds) { dcl_dbus_handle(); - GVariant *vret = NULL; + GVariant *reply = NULL; GError *err = NULL; GVariantIter *iter = NULL; char * item; @@ -2363,7 +2363,7 @@ int dbus_handle_get_sender_credentials(dbus_handle_h handle, const char *name, G return -1; } } - vret = g_dbus_connection_call_sync(dh->conn, + reply = g_dbus_connection_call_sync(dh->conn, DBUS_BUS_NAME, DBUS_OBJECT_PATH, DBUS_INTERFACE_NAME, @@ -2374,12 +2374,12 @@ int dbus_handle_get_sender_credentials(dbus_handle_h handle, const char *name, G DBUS_REPLY_TIMEOUT, NULL, &err); - if (!vret || err) { + if (!reply || err) { _E("failed to g_dbus_connection_call_sync:%s", err->message); return -1; } - g_variant_get(vret, "(a{sv})", &iter); + g_variant_get(reply, "(a{sv})", &iter); while (g_variant_iter_loop(iter, "{sv}", &item, &sub)) { if (!g_strcmp0(item, "UnixUserID")) { @@ -2396,8 +2396,8 @@ int dbus_handle_get_sender_credentials(dbus_handle_h handle, const char *name, G if (iter) g_variant_iter_free(iter); - if (vret) - g_variant_unref(vret); + if (reply) + g_variant_unref(reply); return 0; } @@ -2451,7 +2451,7 @@ void dbus_handle_unwatch_name(guint id) int _get_cmdline_name(pid_t pid, char *cmdline, size_t cmdline_size) { - int fd, ret; + int fd, ret_file; char buf[PATH_MAX + 1]; char *filename; @@ -2462,9 +2462,9 @@ int _get_cmdline_name(pid_t pid, char *cmdline, size_t cmdline_size) return -1; } - ret = read(fd, buf, PATH_MAX); + ret_file = read(fd, buf, PATH_MAX); close(fd); - if (ret < 0) + if (ret_file < 0) return -1; buf[PATH_MAX] = '\0'; @@ -2490,7 +2490,7 @@ char **dbus_handle_get_owner_list(dbus_handle_h handle, const char *bus_name) { dcl_dbus_handle(); GError *err = NULL; - GVariant *vret = NULL; + GVariant *reply = NULL; GVariantIter *iter = NULL; gchar **strv = NULL; gchar *str = NULL; @@ -2509,7 +2509,7 @@ char **dbus_handle_get_owner_list(dbus_handle_h handle, const char *bus_name) } } - vret = g_dbus_connection_call_sync(dh->conn, + reply = g_dbus_connection_call_sync(dh->conn, "org.freedesktop.DBus", "/", "org.freedesktop.DBus", @@ -2520,13 +2520,13 @@ char **dbus_handle_get_owner_list(dbus_handle_h handle, const char *bus_name) DBUS_REPLY_TIMEOUT, NULL, &err); - if (!vret || err) { + if (!reply || err) { _E("failed to g_dbus_connection_call_sync:%s", err->message); g_error_free(err); return NULL; } - g_variant_get(vret, "(as)", &iter); + g_variant_get(reply, "(as)", &iter); strv = g_new(gchar *, g_variant_iter_n_children(iter) + 1); i = 0; @@ -2535,7 +2535,7 @@ char **dbus_handle_get_owner_list(dbus_handle_h handle, const char *bus_name) strv[i] = NULL; g_variant_iter_free(iter); - g_variant_unref(vret); + g_variant_unref(reply); return strv; } @@ -2575,7 +2575,7 @@ void dbus_handle_check_owner_name(dbus_handle_h handle, const char *owner_name) int check_systemd_active(void) { int ret = FALSE; - GVariant *msg = NULL; + GVariant *reply = NULL; GVariant *var = NULL; char *state; @@ -2586,13 +2586,13 @@ int check_systemd_active(void) "org.freedesktop.DBus.Properties", "Get", g_variant_new("(ss)", "org.freedesktop.systemd1.Unit", "ActiveState"), - &msg); + &reply); if (ret < 0) return ret; - if (!msg) + if (!reply) return -EBADMSG; - if (!g_variant_get_safe(msg, "(v)", &var)) { + if (!g_variant_get_safe(reply, "(v)", &var)) { _E("reply is not variant type"); ret = -EBADMSG; goto out; @@ -2610,8 +2610,8 @@ int check_systemd_active(void) out: if (var) g_variant_unref(var); - if (msg) - g_variant_unref(msg); + if (reply) + g_variant_unref(reply); return ret; } diff --git a/src/libgdbus/libgdbus.h b/src/libgdbus/libgdbus.h index 91fb1f3..0e26bb8 100644 --- a/src/libgdbus/libgdbus.h +++ b/src/libgdbus/libgdbus.h @@ -127,14 +127,14 @@ int dbus_handle_method_sync_with_reply_var (const char *dest, const char *iface, const char *method, GVariant *param, - GVariant **reply); + GVariant **out_reply); int dbus_handle_method_sync_with_reply_var_timeout (const char *dest, const char *path, const char *iface, const char *method, GVariant *param, - GVariant **reply, + GVariant **out_reply, int timeout); int dbus_handle_method_sync_pairs (const char *dest, @@ -169,7 +169,7 @@ int dbus_handle_method_with_unix_fd_list_sync_with_reply_var(const char *dest, const char *iface, const char *method, GVariant *param, - GVariant **reply, + GVariant **out_reply, int *in_fdlist, int in_size, int **out_fdlist, diff --git a/src/libsystemd/libsystemd.c b/src/libsystemd/libsystemd.c index a463118..a045616 100644 --- a/src/libsystemd/libsystemd.c +++ b/src/libsystemd/libsystemd.c @@ -411,18 +411,18 @@ GVariant *systemd_get_manager_property(const char *property) { GVariant *reply = NULL; GVariant *val = NULL; - int ret = 0; + int ret_dbus = 0; if (!property) return NULL; - ret = dbus_handle_method_sync_with_reply_var(SYSTEMD_DBUS_DEST, + ret_dbus = dbus_handle_method_sync_with_reply_var(SYSTEMD_DBUS_DEST, SYSTEMD_DBUS_PATH, DBUS_IFACE_DBUS_PROPERTIES, "Get", g_variant_new("(ss)", SYSTEMD_DBUS_MANAGER_IFACE, property), &reply); - if (!reply || !g_variant_get_safe(reply, "(v)", &val) || ret < 0) + if (ret_dbus < 0 || !g_variant_get_safe(reply, "(v)", &val)) _E("Failed to get variant"); if (reply) g_variant_unref(reply); @@ -435,21 +435,21 @@ GVariant *systemd_get_unit_property(const char *unit, const char *property) char *escaped; GVariant *reply = NULL; GVariant *val = NULL; - int ret = 0; + int ret_dbus = 0; if (!unit || !property) return NULL; escaped = systemd_get_unit_dbus_path(unit); - ret = dbus_handle_method_sync_with_reply_var(SYSTEMD_DBUS_DEST, + ret_dbus = dbus_handle_method_sync_with_reply_var(SYSTEMD_DBUS_DEST, escaped, DBUS_IFACE_DBUS_PROPERTIES, "Get", g_variant_new("(ss)", SYSTEMD_DBUS_UNIT_IFACE, property), &reply); - if (!reply || !g_variant_get_safe(reply, "(v)", &val) || ret < 0) + if (ret_dbus < 0 || !g_variant_get_safe(reply, "(v)", &val)) _E("Failed to get variant"); if (reply) g_variant_unref(reply); @@ -463,20 +463,20 @@ GVariant *systemd_get_service_property(const char *unit, const char *property) char *escaped; GVariant *reply = NULL; GVariant *val = NULL; - int ret = 0; + int ret_dbus = 0; if (!unit || !property) return NULL; escaped = systemd_get_unit_dbus_path(unit); - ret = dbus_handle_method_sync_with_reply_var(SYSTEMD_DBUS_DEST, + ret_dbus = dbus_handle_method_sync_with_reply_var(SYSTEMD_DBUS_DEST, escaped, DBUS_IFACE_DBUS_PROPERTIES, "Get", g_variant_new("(ss)", SYSTEMD_DBUS_SERVICE_IFACE, property), &reply); - if (!reply || !g_variant_get_safe(reply, "(v)", &val) || ret < 0) + if (ret_dbus < 0 || !g_variant_get_safe(reply, "(v)", &val)) _E("Failed to get variant"); if (reply) g_variant_unref(reply); -- 2.7.4 From e2a628e2e58cd35758846667e4d8ae4379c5dcd3 Mon Sep 17 00:00:00 2001 From: "taemin.yeom" Date: Fri, 19 Mar 2021 14:14:10 +0900 Subject: [PATCH 14/16] Change dbus function name Change-Id: I67b2b5d555db01ecbd32078380662e90f1dc3b6f Signed-off-by: taemin.yeom --- src/libgdbus/libgdbus.c | 692 +++++++++++++++++++++++++++++--------------- src/libgdbus/libgdbus.h | 155 +++++----- src/libsystemd/libsystemd.c | 20 +- 3 files changed, 553 insertions(+), 314 deletions(-) diff --git a/src/libgdbus/libgdbus.c b/src/libgdbus/libgdbus.c index 3679337..9295582 100644 --- a/src/libgdbus/libgdbus.c +++ b/src/libgdbus/libgdbus.c @@ -32,7 +32,7 @@ static GBusType g_default_bus_type = G_BUS_TYPE_SYSTEM; pthread_mutex_t g_mutex = PTHREAD_MUTEX_INITIALIZER; -void dbus_handle_set_default_bus_type(GBusType bus_type) +void gdbus_set_default_bus_type(GBusType bus_type) { if (bus_type != G_BUS_TYPE_SYSTEM && bus_type != G_BUS_TYPE_SESSION) return ; @@ -42,7 +42,7 @@ void dbus_handle_set_default_bus_type(GBusType bus_type) pthread_mutex_unlock(&g_mutex); } -GBusType dbus_handle_get_default_bus_type(void) +GBusType gdbus_get_default_bus_type(void) { GBusType type; @@ -88,33 +88,33 @@ typedef struct { /* global shared bus : system, session */ static dbus_handle_s g_dh[2]; -static dbus_handle_s *_dbus_handle_get_connection(GBusType bus_type); +static dbus_handle_s *_gdbus_get_connection(GBusType bus_type); -dbus_handle_s * _dbus_handle_get_default_connection(void) +dbus_handle_s * _gdbus_get_default_connection(void) { - return _dbus_handle_get_connection(dbus_handle_get_default_bus_type()); + return _gdbus_get_connection(gdbus_get_default_bus_type()); } -#define dbus_handle_lock(handle) do {\ +#define gdbus_lock(handle) do {\ assert(handle);\ pthread_mutex_lock(&((handle)->mutex));\ } while (0); -#define dbus_handle_unlock(handle) do {\ +#define gdbus_unlock(handle) do {\ assert(handle);\ pthread_mutex_unlock(&(handle)->mutex);\ } while (0); -#define dcl_dbus_handle() dbus_handle_s *dh = (dbus_handle_s *)handle; -#define dcl_dbus_handle_null_check() dbus_handle_s *dh = (dbus_handle_s *)handle;\ +#define dcl_gdbus() dbus_handle_s *dh = (dbus_handle_s *)handle; +#define dcl_gdbus_null_check() dbus_handle_s *dh = (dbus_handle_s *)handle;\ if (!dh) {\ _E("dbus handle is null\n");\ return 0;\ } -dbus_object_handle_s * _dbus_handle_lookup_object(GList *list_obj, const char *obj_path); -dbus_interface_s * _dbus_handle_lookup_interface(GList *list_iface, const char *iface_name); -dbus_method_s * _dbus_handle_lookup_method(GList *list_methods, const char *method_name); +dbus_object_handle_s * _gdbus_lookup_object(GList *list_obj, const char *obj_path); +dbus_interface_s * _gdbus_lookup_interface(GList *list_iface, const char *iface_name); +dbus_method_s * _gdbus_lookup_method(GList *list_methods, const char *method_name); dbus_interface_s *_iface_u_to_s(const dbus_interface_u *iface_u) { @@ -196,7 +196,7 @@ static GDBusConnection * _get_bus_private(GBusType bus_type) } /* ref cout is 1 */ -static dbus_handle_s *_dbus_handle_get_connection(GBusType bus_type) +static dbus_handle_s *_gdbus_get_connection(GBusType bus_type) { int ibus = bus_type - 1; dbus_handle_s *dh = NULL; @@ -207,25 +207,25 @@ static dbus_handle_s *_dbus_handle_get_connection(GBusType bus_type) } dh = &g_dh[ibus]; - dbus_handle_lock(dh); + gdbus_lock(dh); if (!dh->conn) { dh->conn = _get_bus(bus_type); if (!dh->conn) { - dbus_handle_unlock(dh); + gdbus_unlock(dh); return NULL; } dh->priv = FALSE; dh->bus_type = bus_type; } - dbus_handle_unlock(dh); + gdbus_unlock(dh); return dh; } /* ref cout is 1 */ -static dbus_handle_s *_dbus_handle_get_connection_private(GBusType bus_type) +static dbus_handle_s *_gdbus_get_connection_private(GBusType bus_type) { dbus_handle_s * dh; @@ -240,7 +240,7 @@ static dbus_handle_s *_dbus_handle_get_connection_private(GBusType bus_type) return NULL; } - dbus_handle_lock(dh); + gdbus_lock(dh); if (!dh->conn) { dh->conn = _get_bus_private(bus_type); @@ -249,18 +249,18 @@ static dbus_handle_s *_dbus_handle_get_connection_private(GBusType bus_type) goto err; } - dbus_handle_unlock(dh); + gdbus_unlock(dh); return dh; err: if (dh) { - dbus_handle_unlock(dh); + gdbus_unlock(dh); free(dh); } return NULL; } -dbus_handle_h dbus_handle_get_connection(GBusType bus_type, gboolean priv) +dbus_handle_h gdbus_get_connection(GBusType bus_type, gboolean priv) { dbus_handle_s *dh = NULL; int i; @@ -273,10 +273,10 @@ dbus_handle_h dbus_handle_get_connection(GBusType bus_type, gboolean priv) for (i = 0 ; i < 3; ++i) { /* private */ if (priv) - dh = _dbus_handle_get_connection_private(bus_type); + dh = _gdbus_get_connection_private(bus_type); /* shared */ else - dh = _dbus_handle_get_connection(bus_type); + dh = _gdbus_get_connection(bus_type); if (dh) break; @@ -286,7 +286,7 @@ dbus_handle_h dbus_handle_get_connection(GBusType bus_type, gboolean priv) return dh; } -static void _dbus_handle_add_bus_name(dbus_handle_s *handle, const char *name, guint id) +static void _gdbus_add_bus_name(dbus_handle_s *handle, const char *name, guint id) { dbus_name *dn = NULL; int locked = 0; @@ -313,7 +313,7 @@ static void _dbus_handle_add_bus_name(dbus_handle_s *handle, const char *name, g // todo : delete lock ? if (locked != EBUSY) - dbus_handle_unlock(handle); + gdbus_unlock(handle); } static gint _compare_dbus_name(gconstpointer a, gconstpointer b) @@ -324,7 +324,7 @@ static gint _compare_dbus_name(gconstpointer a, gconstpointer b) return strcmp(bus_name, (const char *)b); } -dbus_name * _dbus_handle_lookup_dbus_name(GList *list_name, const char *bus_name) +dbus_name * _gdbus_lookup_dbus_name(GList *list_name, const char *bus_name) { if (!list_name || !bus_name) return NULL; @@ -339,9 +339,9 @@ dbus_name * _dbus_handle_lookup_dbus_name(GList *list_name, const char *bus_name #define dh_to_ds(x) ((dbus_handle_s*)x) /* remove dbus_name from dbus handle */ -static void _dbus_handle_remove_bus_name(dbus_handle_s *handle, const char *bus_name) +static void _gdbus_remove_bus_name(dbus_handle_s *handle, const char *bus_name) { - dcl_dbus_handle(); + dcl_gdbus(); dbus_name *dn = NULL; if (!bus_name) { @@ -349,15 +349,15 @@ static void _dbus_handle_remove_bus_name(dbus_handle_s *handle, const char *bus_ return ; } if (!dh) { - dh = _dbus_handle_get_default_connection(); + dh = _gdbus_get_default_connection(); if (!dh) { - _E("failed to get default connection, bustype:%d", (int)dbus_handle_get_default_bus_type()); + _E("failed to get default connection, bustype:%d", (int)gdbus_get_default_bus_type()); return ; } } - dbus_handle_lock(dh); - dn = _dbus_handle_lookup_dbus_name(dh->list_names, bus_name); + gdbus_lock(dh); + dn = _gdbus_lookup_dbus_name(dh->list_names, bus_name); if (!dn) { _E("failed to find dbus name %s", bus_name); goto out; @@ -365,7 +365,7 @@ static void _dbus_handle_remove_bus_name(dbus_handle_s *handle, const char *bus_ dh->list_names = g_list_remove(dh->list_names, dn); free(dn); out: - dbus_handle_unlock(dh); + gdbus_unlock(dh); } //extern void booting_done(void); @@ -395,15 +395,15 @@ static void _name_lost(GDBusConnection *connection, const gchar *name, gpointer _E("%s:%d:dbus handle is null\n", __func__, __LINE__); return ; } - _dbus_handle_remove_bus_name(dh, name); + _gdbus_remove_bus_name(dh, name); } -int dbus_handle_request_bus_name(dbus_handle_h handle, +int gdbus_request_name(dbus_handle_h handle, const char *bus_name, GBusNameAcquiredCallback acquired_handler, GBusNameLostCallback lost_handler) { - dcl_dbus_handle(); + dcl_gdbus(); int id = -1; GList *item = NULL; @@ -414,14 +414,14 @@ int dbus_handle_request_bus_name(dbus_handle_h handle, /* get shared connection */ if (!dh) { - dh = _dbus_handle_get_default_connection(); + dh = _gdbus_get_default_connection(); if (!dh) { - _E("failed to get default connection, bustype:%d", (int)dbus_handle_get_default_bus_type()); + _E("failed to get default connection, bustype:%d", (int)gdbus_get_default_bus_type()); return -1; } } - dbus_handle_lock(dh); + gdbus_lock(dh); if (!dh->conn) { _E("failed to register name: connection is null\n"); goto out; @@ -447,17 +447,17 @@ int dbus_handle_request_bus_name(dbus_handle_h handle, goto out; } - _dbus_handle_add_bus_name(dh, bus_name, id); + _gdbus_add_bus_name(dh, bus_name, id); out: - dbus_handle_unlock(dh); + gdbus_unlock(dh); return id; } /* !! _name_lost handler callback is disabled by g_bus_unown_name : ubuntu */ -int dbus_handle_release_bus_name(dbus_handle_h handle, const char *bus_name) +int gdbus_release_name(dbus_handle_h handle, const char *bus_name) { - dcl_dbus_handle(); + dcl_gdbus(); dbus_name *dn = NULL; if (!bus_name) { @@ -466,14 +466,14 @@ int dbus_handle_release_bus_name(dbus_handle_h handle, const char *bus_name) } if (!dh) { - dh = _dbus_handle_get_default_connection(); + dh = _gdbus_get_default_connection(); if (!dh) { - _E("failed to get default connection, bustype:%d", (int)dbus_handle_get_default_bus_type()); + _E("failed to get default connection, bustype:%d", (int)gdbus_get_default_bus_type()); return -1; } } - dn = _dbus_handle_lookup_dbus_name(dh->list_names, bus_name); + dn = _gdbus_lookup_dbus_name(dh->list_names, bus_name); if (!dn) { _E("failed to find bus_name %s on dbus handle", bus_name); return -1; @@ -483,25 +483,89 @@ int dbus_handle_release_bus_name(dbus_handle_h handle, const char *bus_name) /* _name_lost handler is disabled by g_bus_unown_name : ubuntu */ g_bus_unown_name(dn->id); - dbus_handle_lock(dh); + gdbus_lock(dh); dh->list_names = g_list_remove(dh->list_names, dn); free(dn); - dbus_handle_unlock(dh); + gdbus_unlock(dh); return 0; } -int dbus_handle_free_connection(dbus_handle_h handle) +void gdbus_unwatch_name(guint id) { - dcl_dbus_handle(); + if (id == 0) { + _E("wrong id %d", id); + return; + } + g_bus_unwatch_name(id); +} + +// g_strfreev(strv) +char **gdbus_get_owner_list(dbus_handle_h handle, const char *bus_name) +{ + dcl_gdbus(); + GError *err = NULL; + GVariant *reply = NULL; + GVariantIter *iter = NULL; + gchar **strv = NULL; + gchar *str = NULL; + int i = 0; + + if (!bus_name) { + _E("wrong parameter bus_name is null"); + return NULL; + } + + if (!dh) { + dh = _gdbus_get_default_connection(); + if (!dh) { + _E("failed to get default connection, bustype:%d", (int)gdbus_get_default_bus_type()); + return NULL; + } + } + + reply = g_dbus_connection_call_sync(dh->conn, + "org.freedesktop.DBus", + "/", + "org.freedesktop.DBus", + "ListQueuedOwners", + g_variant_new("(s)", bus_name), + NULL, + G_DBUS_CALL_FLAGS_NONE, + DBUS_REPLY_TIMEOUT, + NULL, + &err); + if (!reply || err) { + _E("failed to g_dbus_connection_call_sync:%s", err->message); + g_error_free(err); + return NULL; + } + + g_variant_get(reply, "(as)", &iter); + strv = g_new(gchar *, g_variant_iter_n_children(iter) + 1); + + i = 0; + while (g_variant_iter_loop(iter, "s", &str)) + strv[i++] = g_strdup(str); + strv[i] = NULL; + + g_variant_iter_free(iter); + g_variant_unref(reply); + + return strv; +} + +int gdbus_free_connection(dbus_handle_h handle) +{ + dcl_gdbus(); dbus_handle_s *pdh = NULL; GError *err = NULL; GList *item = NULL; if (!dh) { - dh = _dbus_handle_get_default_connection(); + dh = _gdbus_get_default_connection(); if (!dh) { - _E("failed to get default connection, bustype:%d", (int)dbus_handle_get_default_bus_type()); + _E("failed to get default connection, bustype:%d", (int)gdbus_get_default_bus_type()); return -1; } } @@ -514,7 +578,7 @@ int dbus_handle_free_connection(dbus_handle_h handle) pdh = dh; /* disable dbus handler */ - dbus_handle_lock(dh); + gdbus_lock(dh); if (!pdh->conn) { _E("conn is null"); free(pdh); @@ -591,7 +655,7 @@ int dbus_handle_free_connection(dbus_handle_h handle) g_object_unref(pdh->conn); - dbus_handle_unlock(dh); + gdbus_unlock(dh); if (dh->priv) free(dh); @@ -824,7 +888,7 @@ static gint _compare_dbus_method(gconstpointer a, gconstpointer b) return strcmp(pa->member, (const char*)b); } -dbus_object_handle_s * _dbus_handle_lookup_object(GList *list_obj, const char *obj_path) +dbus_object_handle_s * _gdbus_lookup_object(GList *list_obj, const char *obj_path) { if (!list_obj || !obj_path) return NULL; @@ -836,7 +900,7 @@ dbus_object_handle_s * _dbus_handle_lookup_object(GList *list_obj, const char *o return (dbus_object_handle_s *)item->data; } -dbus_interface_s * _dbus_handle_lookup_interface(GList *list_iface, const char *iface_name) +dbus_interface_s * _gdbus_lookup_interface(GList *list_iface, const char *iface_name) { if (!list_iface || !iface_name) return NULL; @@ -848,7 +912,7 @@ dbus_interface_s * _dbus_handle_lookup_interface(GList *list_iface, const char * return (dbus_interface_s *)item->data; } -dbus_interface_s * _dbus_handle_lookup_interface_by_id(GList *list_iface, guint id) +dbus_interface_s * _gdbus_lookup_interface_by_id(GList *list_iface, guint id) { if (!list_iface || !id) return NULL; @@ -860,7 +924,7 @@ dbus_interface_s * _dbus_handle_lookup_interface_by_id(GList *list_iface, guint return (dbus_interface_s *)item->data; } -dbus_method_s * _dbus_handle_lookup_method(GList *list_methods, const char *method_name) +dbus_method_s * _gdbus_lookup_method(GList *list_methods, const char *method_name) { if (!list_methods || !method_name) return NULL; @@ -908,7 +972,7 @@ static void _free_func_object(gpointer data) } } -static int _dbus_handle_attach_object(dbus_handle_s *dh, const char *obj_path, dbus_interface_s *iface) +static int _gdbus_attach_object(dbus_handle_s *dh, const char *obj_path, dbus_interface_s *iface) { dbus_object_handle_s *oh = NULL; @@ -919,7 +983,7 @@ static int _dbus_handle_attach_object(dbus_handle_s *dh, const char *obj_path, d /* find object handle */ if (dh->list_object) - oh = _dbus_handle_lookup_object(dh->list_object, obj_path); + oh = _gdbus_lookup_object(dh->list_object, obj_path); if (!oh) { oh = (dbus_object_handle_s*)calloc(1, sizeof(dbus_object_handle_s)); @@ -1001,7 +1065,7 @@ static void _method_call_handler(GDBusConnection *conn, GVariant *reply = NULL; /* todo: ghash ? */ - methods = _dbus_handle_lookup_method(iface_s->list_methods, name); + methods = _gdbus_lookup_method(iface_s->list_methods, name); if (methods) { reply = methods->func(conn, sender, path, iface, name, param, invocation, get_dh_from_oh(iface_s->oh)); @@ -1020,11 +1084,11 @@ static GDBusInterfaceVTable path_vtable = {_method_call_handler}; /* before register object, attach object into dbus handle -_dbus_handle_attach_object() +_gdbus_attach_object() */ -static int _dbus_handle_register_dbus_object(dbus_handle_h handle, const char *obj_path, dbus_interface_s *iface) +static int _gdbus_register_object(dbus_handle_h handle, const char *obj_path, dbus_interface_s *iface) { - dcl_dbus_handle(); + dcl_gdbus(); int ret = 0; char *buf = NULL; GError *err = NULL; @@ -1036,9 +1100,9 @@ static int _dbus_handle_register_dbus_object(dbus_handle_h handle, const char *o return -1; } if (!dh) { - dh = _dbus_handle_get_default_connection(); + dh = _gdbus_get_default_connection(); if (!dh) { - _E("failed to get default connection, bustype:%d", (int)dbus_handle_get_default_bus_type()); + _E("failed to get default connection, bustype:%d", (int)gdbus_get_default_bus_type()); return -1; } } @@ -1123,13 +1187,13 @@ register same interface at once if interface is constructed by multiple methods, also it is not possible to make methods struct at once, -use dbus_handle_add_dbus_object(), dbus_handle_register_dbus_object_all(). +use gdbus_add_object(), gdbus_register_object_all(). return reg_id */ -int dbus_handle_register_dbus_object(dbus_handle_h handle, const char *obj_path, const dbus_interface_u *iface_u) +int gdbus_register_object(dbus_handle_h handle, const char *obj_path, const dbus_interface_u *iface_u) { - dcl_dbus_handle(); + dcl_gdbus(); int ret = 0; dbus_interface_s *iface = NULL; @@ -1138,9 +1202,9 @@ int dbus_handle_register_dbus_object(dbus_handle_h handle, const char *obj_path, return -1; } if (!dh) { - dh = _dbus_handle_get_default_connection(); + dh = _gdbus_get_default_connection(); if (!dh) { - _E("failed to get default connection, bustype:%d", (int)dbus_handle_get_default_bus_type()); + _E("failed to get default connection, bustype:%d", (int)gdbus_get_default_bus_type()); return -1; } } @@ -1151,9 +1215,9 @@ int dbus_handle_register_dbus_object(dbus_handle_h handle, const char *obj_path, /* check registered interface */ if (dh->list_object) { - dbus_object_handle_s *oh = _dbus_handle_lookup_object(dh->list_object, obj_path); + dbus_object_handle_s *oh = _gdbus_lookup_object(dh->list_object, obj_path); if (oh) { - dbus_interface_s *ih = _dbus_handle_lookup_interface(oh->list_ifaces, iface_u->name); + dbus_interface_s *ih = _gdbus_lookup_interface(oh->list_ifaces, iface_u->name); if (ih) { _E("path %s, interface %s already registered", obj_path, iface_u->name); return -1; @@ -1168,13 +1232,13 @@ int dbus_handle_register_dbus_object(dbus_handle_h handle, const char *obj_path, } /* attach interface before register object */ - ret = _dbus_handle_attach_object(dh, obj_path, iface); + ret = _gdbus_attach_object(dh, obj_path, iface); if (ret < 0) { _E("failed to attach object"); goto err; } - ret = _dbus_handle_register_dbus_object(dh, obj_path, iface); + ret = _gdbus_register_object(dh, obj_path, iface); if (ret <= 0) { _E("failed to register dbus object%d", ret); goto err; @@ -1183,9 +1247,68 @@ err: return ret; } +int gdbus_unregister_object(dbus_handle_h handle, const char *obj_path) +{ + dcl_gdbus(); + dbus_object_handle_s *oh = NULL; + int ret = 0; + + if (!obj_path) + return -1; + + if (!dh) { + dh = _gdbus_get_default_connection(); + if (!dh) { + _E("failed to get default connection, bustype:%d", (int)gdbus_get_default_bus_type()); + return -1; + } + } + if (!dh->list_object) { + _E("list_object is empty"); + return 0; + } + + oh = _gdbus_lookup_object(dh->list_object, obj_path); + if (!oh) { + _E("no object with name %s", obj_path); + return -1; + } + + /* unregister every interface of object*/ + for (GList *item = g_list_first(oh->list_ifaces); item != NULL; item = g_list_next(item)) { + dbus_interface_s *ih = item->data; + if (!ih) { + _E("this is error"); + assert(0); + } + + /* remove ih from list_ifaces */ + if (!ih->reg_id) { + item = g_list_previous(item); + + /* remove and free link */ + oh->list_ifaces = g_list_remove(oh->list_ifaces, ih); + + /* free list_methods */ + g_list_free(ih->list_methods); + + /* free data */ + free(ih); + continue; + } + + /* unregister object by id */ + ret = g_dbus_connection_unregister_object(dh->conn, ih->reg_id); + if (!ret) + _E("failed to unregister object %s, interface %s, regid %d", oh->path, ih->name, ih->reg_id); + } + + return 0; +} + int dbus_handle_unregister_dbus_object(dbus_handle_h handle, const char *obj_path) { - dcl_dbus_handle(); + dcl_gdbus(); dbus_object_handle_s *oh = NULL; int ret = 0; @@ -1193,9 +1316,9 @@ int dbus_handle_unregister_dbus_object(dbus_handle_h handle, const char *obj_pat return -1; if (!dh) { - dh = _dbus_handle_get_default_connection(); + dh = _gdbus_get_default_connection(); if (!dh) { - _E("failed to get default connection, bustype:%d", (int)dbus_handle_get_default_bus_type()); + _E("failed to get default connection, bustype:%d", (int)gdbus_get_default_bus_type()); return -1; } } @@ -1204,7 +1327,7 @@ int dbus_handle_unregister_dbus_object(dbus_handle_h handle, const char *obj_pat return 0; } - oh = _dbus_handle_lookup_object(dh->list_object, obj_path); + oh = _gdbus_lookup_object(dh->list_object, obj_path); if (!oh) { _E("no object with name %s", obj_path); return -1; @@ -1244,13 +1367,116 @@ int dbus_handle_unregister_dbus_object(dbus_handle_h handle, const char *obj_pat /* add object temporarily. -dbus_handle_register_dbus_object_all register every objects on connection. +gdbus_register_object_all register every objects on connection. return registered method count */ +int gdbus_add_object(dbus_handle_h handle, const char *obj_path, const dbus_interface_u *iface_u) +{ + dcl_gdbus(); + dbus_object_handle_s *oh = NULL; + dbus_interface_s *ih = NULL; + int cnt; + + if (!obj_path || !iface_u) { + _E("wrong parameter path %s, iface_u %p\n", obj_path, iface_u); + return -1; + } + if (iface_u && (!iface_u->name || !iface_u->methods)) { + _E("wrong parameter path %s, iface_u %p\n", obj_path, iface_u); + return -1; + } + + cnt = iface_u->nr_methods; + + if (!dh) { + dh = _gdbus_get_default_connection(); + if (!dh) { + _E("failed to get default connection, bustype:%d", (int)gdbus_get_default_bus_type()); + return -1; + } + } + + if (!dh->conn) { + _E("failed to register method. connection is null\n"); + return -1; + } + + /* if there are no object list, just add */ + if (!dh->list_object) { + if (_gdbus_attach_object(dh, obj_path, _iface_u_to_s(iface_u))) { + _E("failed to attach object"); + return -1; + } + goto out; + } + + oh = _gdbus_lookup_object(dh->list_object, obj_path); + /* if there are no matched object, just add */ + if (!oh) { + if (_gdbus_attach_object(dh, obj_path, _iface_u_to_s(iface_u))) { + _E("failed to attach object"); + return -1; + } + goto out; + } + + /* this is an error, interface must have one or more item ? */ + if (!oh->list_ifaces) { + _E("error. list_ifaces is null\n"); + assert(0); + goto out; + } + + ih = _gdbus_lookup_interface(oh->list_ifaces, iface_u->name); + /* if there are no matched interface, just add */ + if (!ih) { + if (_gdbus_attach_object(dh, obj_path, _iface_u_to_s(iface_u))) { + _E("failed to attach object"); + return -1; + } + goto out; + } + + /* todo: + 1. unregister interface + 2. update interface and methods + 3. register interface + */ + if (ih->reg_id) { + _E("interface already registered, ignore new interface"); + return -1; + } + + /* attach new methods */ + cnt = 0; + for (int i = 0; i < iface_u->nr_methods; ++i) { + GList *item = g_list_find_custom(g_list_first(ih->list_methods), iface_u->methods[i].member, _compare_dbus_method); + if (!item) { + //_D("attached %s", iface_u->methods[i].member); + ih->list_methods = g_list_prepend(ih->list_methods, (void*)(iface_u->methods + i)); + ++cnt; + } + } + + if (cnt) + ih->modified = TRUE; + +out: + /*todo: delete debugging log */ + //if (dh && dh->list_object) + // _D("obj list len %d", g_list_length(dh->list_object)); + //if (oh && oh->list_ifaces) + // _D("iface list len %d", g_list_length(oh->list_ifaces)); + //if (ih && ih->list_methods) + // _D("method list len %d", g_list_length(ih->list_methods)); + + return cnt; +} + int dbus_handle_add_dbus_object(dbus_handle_h handle, const char *obj_path, const dbus_interface_u *iface_u) { - dcl_dbus_handle(); + dcl_gdbus(); dbus_object_handle_s *oh = NULL; dbus_interface_s *ih = NULL; int cnt; @@ -1267,9 +1493,9 @@ int dbus_handle_add_dbus_object(dbus_handle_h handle, const char *obj_path, cons cnt = iface_u->nr_methods; if (!dh) { - dh = _dbus_handle_get_default_connection(); + dh = _gdbus_get_default_connection(); if (!dh) { - _E("failed to get default connection, bustype:%d", (int)dbus_handle_get_default_bus_type()); + _E("failed to get default connection, bustype:%d", (int)gdbus_get_default_bus_type()); return -1; } } @@ -1281,17 +1507,17 @@ int dbus_handle_add_dbus_object(dbus_handle_h handle, const char *obj_path, cons /* if there are no object list, just add */ if (!dh->list_object) { - if (_dbus_handle_attach_object(dh, obj_path, _iface_u_to_s(iface_u))) { + if (_gdbus_attach_object(dh, obj_path, _iface_u_to_s(iface_u))) { _E("failed to attach object"); return -1; } goto out; } - oh = _dbus_handle_lookup_object(dh->list_object, obj_path); + oh = _gdbus_lookup_object(dh->list_object, obj_path); /* if there are no matched object, just add */ if (!oh) { - if (_dbus_handle_attach_object(dh, obj_path, _iface_u_to_s(iface_u))) { + if (_gdbus_attach_object(dh, obj_path, _iface_u_to_s(iface_u))) { _E("failed to attach object"); return -1; } @@ -1305,10 +1531,10 @@ int dbus_handle_add_dbus_object(dbus_handle_h handle, const char *obj_path, cons goto out; } - ih = _dbus_handle_lookup_interface(oh->list_ifaces, iface_u->name); + ih = _gdbus_lookup_interface(oh->list_ifaces, iface_u->name); /* if there are no matched interface, just add */ if (!ih) { - if (_dbus_handle_attach_object(dh, obj_path, _iface_u_to_s(iface_u))) { + if (_gdbus_attach_object(dh, obj_path, _iface_u_to_s(iface_u))) { _E("failed to attach object"); return -1; } @@ -1351,17 +1577,85 @@ out: return cnt; } +int gdbus_register_object_all(dbus_handle_h handle) +{ + dcl_gdbus(); + dbus_object_handle_s *oh = NULL; + dbus_interface_s *ih = NULL; + int ret_dbus = 0; + + if (!dh) { + dh = _gdbus_get_default_connection(); + if (!dh) { + _E("failed to get default connection, bustype:%d", (int)gdbus_get_default_bus_type()); + return -1; + } + } + if (!dh->conn) { + _E("connection is null\n"); + return -1; + } + + if (!dh->list_object) { + _E("obj list is empty"); + return -1; + } + + /*if (dh && dh->list_object) + _D("obj list len %d", g_list_length(dh->list_object));*/ + + for (GList *item = g_list_first(dh->list_object); item != NULL; item = g_list_next(item)) { + oh = (dbus_object_handle_s *)item->data; + + if (!oh) { + _E("something wrong"); + assert(0); + } + if (!oh->list_ifaces) { + _E("path %s: list_ifaces are null", oh->path); + goto err; + } + + //_D("iface list len %d", g_list_length(oh->list_ifaces)); + + for (GList *li = g_list_first(oh->list_ifaces); li != NULL; li = g_list_next(li)) { + ih = (dbus_interface_s *)li->data; + + /* if there are no modification, goto next */ + if (!ih->modified) + continue; + + /* todo: if already registered interface, unregister first */ + + /*_E("interface %s:", ih->name); + if (ih && ih->list_methods) + _D("method list len %d", g_list_length(ih->list_methods));*/ + + ret_dbus = _gdbus_register_object(dh, oh->path, ih); + if (ret_dbus <= 0) + _E("failed to register dbus object%d", ret_dbus); + + } + } + return 0; +err: + + // todo: delete all updates + + return -1; +} + int dbus_handle_register_dbus_object_all(dbus_handle_h handle) { - dcl_dbus_handle(); + dcl_gdbus(); dbus_object_handle_s *oh = NULL; dbus_interface_s *ih = NULL; int ret_dbus = 0; if (!dh) { - dh = _dbus_handle_get_default_connection(); + dh = _gdbus_get_default_connection(); if (!dh) { - _E("failed to get default connection, bustype:%d", (int)dbus_handle_get_default_bus_type()); + _E("failed to get default connection, bustype:%d", (int)gdbus_get_default_bus_type()); return -1; } } @@ -1405,7 +1699,7 @@ int dbus_handle_register_dbus_object_all(dbus_handle_h handle) if (ih && ih->list_methods) _D("method list len %d", g_list_length(ih->list_methods));*/ - ret_dbus = _dbus_handle_register_dbus_object(dh, oh->path, ih); + ret_dbus = _gdbus_register_object(dh, oh->path, ih); if (ret_dbus <= 0) _E("failed to register dbus object%d", ret_dbus); @@ -1419,17 +1713,17 @@ err: return -1; } -guint subscribe_dbus_signal(dbus_handle_h handle, const char *path, +guint gdbus_signal_subscribe(dbus_handle_h handle, const char *path, const char *iface, const char *name, GDBusSignalCallback cb, void *data, destroy_notified free_func) { - dcl_dbus_handle(); + dcl_gdbus(); if (!dh) { - dh = _dbus_handle_get_default_connection(); + dh = _gdbus_get_default_connection(); if (!dh) { - _E("failed to get default connection, bustype:%d", (int)dbus_handle_get_default_bus_type()); + _E("failed to get default connection, bustype:%d", (int)gdbus_get_default_bus_type()); return 0; } } @@ -1441,13 +1735,13 @@ guint subscribe_dbus_signal(dbus_handle_h handle, const char *path, return g_dbus_connection_signal_subscribe(dh->conn, NULL, iface, name, path, NULL, G_DBUS_SIGNAL_FLAGS_NONE, cb, data, free_func); } -void unsubscribe_dbus_signal(dbus_handle_h handle, guint id) +void gdbus_signal_unsubscribe(dbus_handle_h handle, guint id) { - dcl_dbus_handle(); + dcl_gdbus(); if (!dh) { - dh = _dbus_handle_get_default_connection(); + dh = _gdbus_get_default_connection(); if (!dh) { - _E("failed to get default connection, bustype:%d", (int)dbus_handle_get_default_bus_type()); + _E("failed to get default connection, bustype:%d", (int)gdbus_get_default_bus_type()); return; } } @@ -1484,7 +1778,7 @@ static void _signal_reply_sync_cb(GDBusConnection *conn, g_main_loop_quit(ctx->loop); } -sig_ctx *dbus_handle_new_signal_ctx(void) +sig_ctx *gdbus_signal_ctx_new(void) { sig_ctx *ctx; @@ -1517,7 +1811,7 @@ sig_ctx *dbus_handle_new_signal_ctx(void) return ctx; } -void dbus_handle_free_signal_ctx(sig_ctx *ctx) +void gdbus_signal_ctx_free(sig_ctx *ctx) { if (!ctx) return ; @@ -1527,7 +1821,7 @@ void dbus_handle_free_signal_ctx(sig_ctx *ctx) ctx->param = NULL; } if (ctx->sig_id) { - unsubscribe_dbus_signal(NULL, ctx->sig_id); + gdbus_signal_unsubscribe(NULL, ctx->sig_id); ctx->sig_id = 0; } if (ctx->timeout_src) { @@ -1559,7 +1853,7 @@ static gboolean _cb_ctx_timeout(gpointer user_data) /* if cb return FALSE, source will be destroyed */ ctx->timeout_src = NULL; - unsubscribe_dbus_signal(NULL, ctx->sig_id); + gdbus_signal_unsubscribe(NULL, ctx->sig_id); ctx->sig_id = 0; g_main_loop_quit(ctx->loop); @@ -1569,7 +1863,7 @@ static gboolean _cb_ctx_timeout(gpointer user_data) #define CTX_MAX_TIMEOUT 25000 -int dbus_handle_signal_ctx_add_timeout(sig_ctx *ctx, int timeout_msec) +int gdbus_signal_ctx_add_timeout(sig_ctx *ctx, int timeout_msec) { GSource *src = NULL; @@ -1594,12 +1888,12 @@ int dbus_handle_signal_ctx_add_timeout(sig_ctx *ctx, int timeout_msec) return 0; } -guint subscribe_dbus_signal_ctx(dbus_handle_h handle, sig_ctx *ctx, +guint gdbus_signal_ctx_subscribe(dbus_handle_h handle, sig_ctx *ctx, const char *sender, const char *path, const char *iface, const char *name, GDBusSignalCallback _cb) { - dcl_dbus_handle(); + dcl_gdbus(); if (!ctx) { _E("wrong param ctx is null"); @@ -1607,10 +1901,10 @@ guint subscribe_dbus_signal_ctx(dbus_handle_h handle, sig_ctx *ctx, } if (!dh) { - dh = _dbus_handle_get_default_connection(); + dh = _gdbus_get_default_connection(); if (!dh) { _E("failed to get default connection, bustype:%d", - (int)dbus_handle_get_default_bus_type()); + (int)gdbus_get_default_bus_type()); return 0; } } @@ -1637,7 +1931,7 @@ guint subscribe_dbus_signal_ctx(dbus_handle_h handle, sig_ctx *ctx, return ctx->sig_id; } -int dbus_handle_signal_ctx_wait(sig_ctx *ctx) +int gdbus_signal_ctx_wait(sig_ctx *ctx) { if (!ctx || !ctx->loop) return -EINVAL; @@ -1669,7 +1963,7 @@ int _check_type_string_is_container(const char *signature) return TRUE; } -int dbus_handle_emit_dbus_signal(const char *dest, +int gdbus_signal_emit(const char *dest, const char *path, const char *iface, const char *name, @@ -1679,9 +1973,9 @@ int dbus_handle_emit_dbus_signal(const char *dest, GError *err = NULL; gboolean ret = 0; - dh = _dbus_handle_get_default_connection(); + dh = _gdbus_get_default_connection(); if (!dh) { - _E("failed to get default connection, bustype:%d", (int)dbus_handle_get_default_bus_type()); + _E("failed to get default connection, bustype:%d", (int)gdbus_get_default_bus_type()); return -1; } @@ -1694,7 +1988,7 @@ int dbus_handle_emit_dbus_signal(const char *dest, return ret; } -int dbus_handle_emit_dbus_signal_sync(const char *dest, +int gdbus_signal_emit_sync(const char *dest, const char *path, const char *iface, const char *name, @@ -1704,9 +1998,9 @@ int dbus_handle_emit_dbus_signal_sync(const char *dest, GError *err = NULL; gboolean ret = 0; - dh = _dbus_handle_get_default_connection(); + dh = _gdbus_get_default_connection(); if (!dh) { - _E("failed to get default connection, bustype:%d", (int)dbus_handle_get_default_bus_type()); + _E("failed to get default connection, bustype:%d", (int)gdbus_get_default_bus_type()); return -1; } @@ -1725,16 +2019,16 @@ int dbus_handle_emit_dbus_signal_sync(const char *dest, return ret; } -int dbus_handle_flush_sync(dbus_handle_h handle) +int gdbus_flush_sync(dbus_handle_h handle) { - dcl_dbus_handle(); + dcl_gdbus(); GError *err = NULL; gboolean ret = 0; if (!dh) { - dh = _dbus_handle_get_default_connection(); + dh = _gdbus_get_default_connection(); if (!dh) { - _E("failed to get default connection, bustype:%d", (int)dbus_handle_get_default_bus_type()); + _E("failed to get default connection, bustype:%d", (int)gdbus_get_default_bus_type()); return 0; } } @@ -1748,7 +2042,7 @@ int dbus_handle_flush_sync(dbus_handle_h handle) return ret; } -int dbus_handle_method_sync_with_reply_var(const char *dest, +int gdbus_call_sync_with_reply(const char *dest, const char *path, const char *iface, const char *method, @@ -1767,9 +2061,9 @@ int dbus_handle_method_sync_with_reply_var(const char *dest, return -EINVAL; } - dh = _dbus_handle_get_default_connection(); + dh = _gdbus_get_default_connection(); if (!dh) { - _E("failed to get default connection, bustype:%d", (int)dbus_handle_get_default_bus_type()); + _E("failed to get default connection, bustype:%d", (int)gdbus_get_default_bus_type()); if (param) g_variant_unref(param); return -ECOMM; @@ -1805,7 +2099,7 @@ int dbus_handle_method_sync_with_reply_var(const char *dest, return ret; } -int dbus_handle_method_sync_with_reply_var_timeout(const char *dest, const char *path, +int gdbus_call_sync_with_reply_timeout(const char *dest, const char *path, const char *iface, const char *method, GVariant *param, GVariant **out_reply, int timeout) { GError *err = NULL; @@ -1819,9 +2113,9 @@ int dbus_handle_method_sync_with_reply_var_timeout(const char *dest, const char return -EINVAL; } - dh = _dbus_handle_get_default_connection(); + dh = _gdbus_get_default_connection(); if (!dh) { - _E("failed to get default connection, bustype:%d", (int)dbus_handle_get_default_bus_type()); + _E("failed to get default connection, bustype:%d", (int)gdbus_get_default_bus_type()); if (param) g_variant_unref(param); return -ECOMM; @@ -1852,7 +2146,7 @@ int dbus_handle_method_sync_with_reply_var_timeout(const char *dest, const char return 0; } -int dbus_handle_method_sync_pairs(const char *dest, +int gdbus_call_pairs_sync_with_reply_int(const char *dest, const char *path, const char *iface, const char *method, @@ -1872,9 +2166,9 @@ int dbus_handle_method_sync_pairs(const char *dest, return -1; } - dh = _dbus_handle_get_default_connection(); + dh = _gdbus_get_default_connection(); if (!dh) { - _E("failed to get default connection, bustype:%d", (int)dbus_handle_get_default_bus_type()); + _E("failed to get default connection, bustype:%d", (int)gdbus_get_default_bus_type()); return -1; } @@ -1908,7 +2202,7 @@ int dbus_handle_method_sync_pairs(const char *dest, return ret; } -int dbus_handle_method_async_pairs(const char *dest, +int gdbus_call_pairs_async(const char *dest, const char *path, const char *iface, const char *method, @@ -1925,9 +2219,9 @@ int dbus_handle_method_async_pairs(const char *dest, return -1; } - dh = _dbus_handle_get_default_connection(); + dh = _gdbus_get_default_connection(); if (!dh) { - _E("failed to get default connection, bustype:%d", (int)dbus_handle_get_default_bus_type()); + _E("failed to get default connection, bustype:%d", (int)gdbus_get_default_bus_type()); return -1; } @@ -1956,7 +2250,7 @@ int dbus_handle_method_async_pairs(const char *dest, return 0; } -gint* dbus_handle_get_unix_fd_list(GDBusMethodInvocation *invocation, int *size) +gint* gdbus_get_unix_fd_list(GDBusMethodInvocation *invocation, int *size) { GUnixFDList *fd_list = NULL; int length = 0; @@ -1979,7 +2273,7 @@ gint* dbus_handle_get_unix_fd_list(GDBusMethodInvocation *invocation, int *size) return g_unix_fd_list_steal_fds(fd_list, NULL); } -int dbus_handle_method_with_unix_fd_list_sync_with_reply_var(const char *dest, +int gdbus_call_unix_fd_list_sync_with_reply(const char *dest, const char *path, const char *iface, const char *method, @@ -2006,9 +2300,9 @@ int dbus_handle_method_with_unix_fd_list_sync_with_reply_var(const char *dest, return -EINVAL; } - dh = _dbus_handle_get_default_connection(); + dh = _gdbus_get_default_connection(); if (!dh) { - _E("failed to get default connection, bustype:%d", (int)dbus_handle_get_default_bus_type()); + _E("failed to get default connection, bustype:%d", (int)gdbus_get_default_bus_type()); return -EAGAIN; } @@ -2065,7 +2359,7 @@ out: return ret; } -int dbus_handle_method_sync_var(const char *dest, +int gdbus_call_sync_with_reply_int(const char *dest, const char *path, const char *iface, const char *method, @@ -2082,7 +2376,7 @@ int dbus_handle_method_sync_var(const char *dest, return -EINVAL; } - ret = dbus_handle_method_sync_with_reply_var(dest, path, iface, method, param, &reply); + ret = gdbus_call_sync_with_reply(dest, path, iface, method, param, &reply); if (ret < 0) return ret; @@ -2106,7 +2400,7 @@ int dbus_handle_method_sync_var(const char *dest, return ret; } -int dbus_handle_method_async_var(const char *dest, +int gdbus_call_async(const char *dest, const char *path, const char *iface, const char *method, @@ -2119,9 +2413,9 @@ int dbus_handle_method_async_var(const char *dest, return -1; } - dh = _dbus_handle_get_default_connection(); + dh = _gdbus_get_default_connection(); if (!dh) { - _E("failed to get default connection, bustype:%d", (int)dbus_handle_get_default_bus_type()); + _E("failed to get default connection, bustype:%d", (int)gdbus_get_default_bus_type()); return -1; } @@ -2166,7 +2460,7 @@ out: free(data); } -int dbus_handle_method_async_with_reply_var(const char *dest, +int gdbus_call_async_with_reply(const char *dest, const char *path, const char *iface, const char *method, @@ -2189,9 +2483,9 @@ int dbus_handle_method_async_with_reply_var(const char *dest, return -1; } - dh = _dbus_handle_get_default_connection(); + dh = _gdbus_get_default_connection(); if (!dh) { - _E("failed to get default connection, bustype:%d", (int)dbus_handle_get_default_bus_type()); + _E("failed to get default connection, bustype:%d", (int)gdbus_get_default_bus_type()); return -EPERM; } @@ -2221,7 +2515,7 @@ err: return ret; } -int dbus_handle_method_async_pairs_with_reply(const char *dest, +int gdbus_call_pairs_async_with_reply(const char *dest, const char *path, const char *iface, const char *method, @@ -2248,9 +2542,9 @@ int dbus_handle_method_async_pairs_with_reply(const char *dest, return -1; } - dh = _dbus_handle_get_default_connection(); + dh = _gdbus_get_default_connection(); if (!dh) { - _E("failed to get default connection, bustype:%d", (int)dbus_handle_get_default_bus_type()); + _E("failed to get default connection, bustype:%d", (int)gdbus_get_default_bus_type()); return -EPERM; } @@ -2293,7 +2587,7 @@ err: return ret; } -int dbus_connection_get_sender_pid(GDBusConnection *conn, const char * sender) +int gdbus_connection_get_sender_pid(GDBusConnection *conn, const char * sender) { GError *err = NULL; GVariant *reply = NULL; @@ -2327,14 +2621,14 @@ int dbus_connection_get_sender_pid(GDBusConnection *conn, const char * sender) return pid; } -int dbus_handle_get_sender_pid(dbus_handle_h handle, const char * sender) +int gdbus_get_sender_pid(dbus_handle_h handle, const char * sender) { - dcl_dbus_handle(); + dcl_gdbus(); if (!dh) { - dh = _dbus_handle_get_default_connection(); + dh = _gdbus_get_default_connection(); if (!dh) { - _E("failed to get default connection, bustype:%d", (int)dbus_handle_get_default_bus_type()); + _E("failed to get default connection, bustype:%d", (int)gdbus_get_default_bus_type()); return -1; } } @@ -2344,12 +2638,12 @@ int dbus_handle_get_sender_pid(dbus_handle_h handle, const char * sender) return -1; } - return dbus_connection_get_sender_pid(dh->conn, sender); + return gdbus_connection_get_sender_pid(dh->conn, sender); } -int dbus_handle_get_sender_credentials(dbus_handle_h handle, const char *name, GDBusCredentials *creds) +int gdbus_get_sender_credentials(dbus_handle_h handle, const char *name, GDBusCredentials *creds) { - dcl_dbus_handle(); + dcl_gdbus(); GVariant *reply = NULL; GError *err = NULL; GVariantIter *iter = NULL; @@ -2357,9 +2651,9 @@ int dbus_handle_get_sender_credentials(dbus_handle_h handle, const char *name, G GVariant *sub; if (!dh) { - dh = _dbus_handle_get_default_connection(); + dh = _gdbus_get_default_connection(); if (!dh) { - _E("failed to get default connection, bustype:%d", (int)dbus_handle_get_default_bus_type()); + _E("failed to get default connection, bustype:%d", (int)gdbus_get_default_bus_type()); return -1; } } @@ -2408,7 +2702,7 @@ void _destroy_notify_watch_name(gpointer data) // free(data); } -int dbus_handle_watch_name(const char *name, +int gdbus_watch_name(const char *name, GBusNameAppearedCallback name_appeared_handler, GBusNameVanishedCallback name_vanished_handler, void *user_data, @@ -2425,7 +2719,7 @@ int dbus_handle_watch_name(const char *name, return -1; } - id = g_bus_watch_name(dbus_handle_get_default_bus_type(), + id = g_bus_watch_name(gdbus_get_default_bus_type(), name, G_BUS_NAME_WATCHER_FLAGS_NONE, name_appeared_handler, @@ -2440,15 +2734,6 @@ int dbus_handle_watch_name(const char *name, return id; } -void dbus_handle_unwatch_name(guint id) -{ - if (id == 0) { - _E("wrong id %d", id); - return; - } - g_bus_unwatch_name(id); -} - int _get_cmdline_name(pid_t pid, char *cmdline, size_t cmdline_size) { int fd, ret_file; @@ -2485,85 +2770,30 @@ int _get_cmdline_name(pid_t pid, char *cmdline, size_t cmdline_size) return 0; } -// g_strfreev(strv) -char **dbus_handle_get_owner_list(dbus_handle_h handle, const char *bus_name) -{ - dcl_dbus_handle(); - GError *err = NULL; - GVariant *reply = NULL; - GVariantIter *iter = NULL; - gchar **strv = NULL; - gchar *str = NULL; - int i = 0; - - if (!bus_name) { - _E("wrong parameter bus_name is null"); - return NULL; - } - - if (!dh) { - dh = _dbus_handle_get_default_connection(); - if (!dh) { - _E("failed to get default connection, bustype:%d", (int)dbus_handle_get_default_bus_type()); - return NULL; - } - } - - reply = g_dbus_connection_call_sync(dh->conn, - "org.freedesktop.DBus", - "/", - "org.freedesktop.DBus", - "ListQueuedOwners", - g_variant_new("(s)", bus_name), - NULL, - G_DBUS_CALL_FLAGS_NONE, - DBUS_REPLY_TIMEOUT, - NULL, - &err); - if (!reply || err) { - _E("failed to g_dbus_connection_call_sync:%s", err->message); - g_error_free(err); - return NULL; - } - - g_variant_get(reply, "(as)", &iter); - strv = g_new(gchar *, g_variant_iter_n_children(iter) + 1); - - i = 0; - while (g_variant_iter_loop(iter, "s", &str)) - strv[i++] = g_strdup(str); - strv[i] = NULL; - - g_variant_iter_free(iter); - g_variant_unref(reply); - - return strv; -} - -void dbus_handle_check_owner_name(dbus_handle_h handle, const char *owner_name) +void gdbus_check_name_owner(dbus_handle_h handle, const char *owner_name) { - dcl_dbus_handle(); + dcl_gdbus(); char exe_name[PATH_MAX]; int pid; char **strv = NULL; int i; if (!dh) { - dh = _dbus_handle_get_default_connection(); + dh = _gdbus_get_default_connection(); if (!dh) { - _E("failed to get default connection, bustype:%d", (int)dbus_handle_get_default_bus_type()); + _E("failed to get default connection, bustype:%d", (int)gdbus_get_default_bus_type()); return ; } } - strv = dbus_handle_get_owner_list(dh, owner_name); + strv = gdbus_get_owner_list(dh, owner_name); if (!strv) { _E("failed to get owner list of %s", owner_name); return ; } for (i = 0; strv[i] != NULL; ++i) { - pid = dbus_handle_get_sender_pid(dh, strv[i]); + pid = gdbus_get_sender_pid(dh, strv[i]); if (_get_cmdline_name(pid, exe_name, PATH_MAX) != 0) break; _I("%s(%d)", exe_name, pid); @@ -2581,7 +2811,7 @@ int check_systemd_active(void) _I("%s %s", "org.freedesktop.systemd1.Unit", "ActiveState"); - ret = dbus_handle_method_sync_with_reply_var("org.freedesktop.systemd1", + ret = gdbus_call_sync_with_reply("org.freedesktop.systemd1", "/org/freedesktop/systemd1/unit/default_2etarget", "org.freedesktop.DBus.Properties", "Get", @@ -2616,7 +2846,7 @@ out: return ret; } -GVariant *dbus_handle_make_simple_array(const char *sig, int *param) +GVariant *gdbus_make_simple_array(const char *sig, int *param) { GVariantBuilder *builder = NULL; GVariant *var = NULL; diff --git a/src/libgdbus/libgdbus.h b/src/libgdbus/libgdbus.h index 0e26bb8..6828b76 100644 --- a/src/libgdbus/libgdbus.h +++ b/src/libgdbus/libgdbus.h @@ -68,7 +68,7 @@ typedef struct { #define g_variant_get_safe(gvar, signature, ...) ((gvar && (g_strcmp0(signature, g_variant_get_type_string(gvar)) == 0)) ? g_variant_get(gvar, signature, __VA_ARGS__), TRUE : FALSE) -#define dbus_handle_new_g_variant_tuple() g_variant_new_tuple(NULL, 0) +#define gdbus_new_g_variant_tuple() g_variant_new_tuple(NULL, 0) typedef void (*destroy_notified)(void *data); @@ -79,18 +79,44 @@ typedef struct { void *data; } pending_call_data; -dbus_handle_h dbus_handle_get_connection (GBusType bus_type, +dbus_handle_h gdbus_get_connection (GBusType bus_type, gboolean priv); -int dbus_handle_request_bus_name (dbus_handle_h handle, +int gdbus_request_name (dbus_handle_h handle, const char *bus_name, GBusNameAcquiredCallback acquired_handler, GBusNameLostCallback lost_handler); -int dbus_handle_register_dbus_object (dbus_handle_h handle, +int gdbus_release_name (dbus_handle_h handle, + const char *bus_name); + +int gdbus_watch_name (const char *name, + GBusNameAppearedCallback name_appeared_handler, + GBusNameVanishedCallback name_vanished_handler, + void *user_data, + GDestroyNotify user_data_free_func); + +void gdbus_unwatch_name (guint id); + +char** gdbus_get_owner_list (dbus_handle_h handle, + const char *bus_name); + +void gdbus_check_name_owner (dbus_handle_h handle, + const char *owner_name); + +int gdbus_register_object (dbus_handle_h handle, const char *obj_path, const dbus_interface_u *iface); +int gdbus_unregister_object (dbus_handle_h handle, + const char *obj_path); + +int gdbus_add_object (dbus_handle_h handle, + const char *obj_path, + const dbus_interface_u *iface_u); + +int gdbus_register_object_all (dbus_handle_h handle); + int dbus_handle_unregister_dbus_object (dbus_handle_h handle, const char *obj_path); @@ -100,20 +126,35 @@ int dbus_handle_add_dbus_object (dbus_handle_h handle, int dbus_handle_register_dbus_object_all (dbus_handle_h handle); -int dbus_handle_method_sync_var (const char *dest, +int gdbus_call_sync_with_reply_int (const char *dest, const char *path, const char *iface, const char *method, GVariant *param, int *output); -int dbus_handle_method_async_var (const char *dest, +int gdbus_call_sync_with_reply (const char *dest, + const char *path, + const char *iface, + const char *method, + GVariant *param, + GVariant **out_reply); + +int gdbus_call_sync_with_reply_timeout (const char *dest, + const char *path, + const char *iface, + const char *method, + GVariant *param, + GVariant **out_reply, + int timeout); + +int gdbus_call_async (const char *dest, const char *path, const char *iface, const char *method, GVariant *param); -int dbus_handle_method_async_with_reply_var (const char *dest, +int gdbus_call_async_with_reply (const char *dest, const char *path, const char *iface, const char *method, @@ -122,36 +163,32 @@ int dbus_handle_method_async_with_reply_var (const char *dest, int timeout_msec, void *data); -int dbus_handle_method_sync_with_reply_var (const char *dest, - const char *path, - const char *iface, - const char *method, - GVariant *param, - GVariant **out_reply); - -int dbus_handle_method_sync_with_reply_var_timeout (const char *dest, +int gdbus_call_unix_fd_list_sync_with_reply (const char *dest, const char *path, const char *iface, const char *method, GVariant *param, GVariant **out_reply, - int timeout); + int *in_fdlist, + int in_size, + int **out_fdlist, + int *out_size); -int dbus_handle_method_sync_pairs (const char *dest, +int gdbus_call_pairs_sync_with_reply_int (const char *dest, const char *path, const char *interface, const char *method, int num, va_list args); -int dbus_handle_method_async_pairs (const char *dest, +int gdbus_call_pairs_async (const char *dest, const char *path, const char *interface, const char *method, int num, va_list args); -int dbus_handle_method_async_pairs_with_reply (const char *dest, +int gdbus_call_pairs_async_with_reply (const char *dest, const char *path, const char *iface, const char *method, @@ -161,45 +198,28 @@ int dbus_handle_method_async_pairs_with_reply (const char *dest, int timeout_msec, void *data); -gint* dbus_handle_get_unix_fd_list (GDBusMethodInvocation *invocation, - int *size); - -int dbus_handle_method_with_unix_fd_list_sync_with_reply_var(const char *dest, - const char *path, - const char *iface, - const char *method, - GVariant *param, - GVariant **out_reply, - int *in_fdlist, - int in_size, - int **out_fdlist, - int *out_size); - - -guint subscribe_dbus_signal (dbus_handle_h handle, - const char *path, - const char *iface, - const char *name, - GDBusSignalCallback cb, - void *data, - destroy_notified free_func); - -void unsubscribe_dbus_signal (dbus_handle_h handle, - guint id); - -int dbus_handle_emit_dbus_signal (const char *dest, +int gdbus_signal_emit (const char *dest, const char *path, const char *iface, const char *name, GVariant *param); -int dbus_handle_emit_dbus_signal_sync(const char *dest, +int gdbus_signal_emit_sync(const char *dest, const char *path, const char *iface, const char *name, GVariant *param); -int dbus_handle_flush_sync(dbus_handle_h handle); +guint gdbus_signal_subscribe (dbus_handle_h handle, + const char *path, + const char *iface, + const char *name, + GDBusSignalCallback cb, + void *data, + destroy_notified free_func); + +void gdbus_signal_unsubscribe (dbus_handle_h handle, + guint id); enum ctx_quit_reason {CTX_QUIT_UNKNOWN, CTX_QUIT_NORMAL, CTX_QUIT_TIMEOUT}; @@ -213,11 +233,7 @@ typedef struct { void *user_data; } sig_ctx; -sig_ctx *dbus_handle_new_signal_ctx (void); - -void dbus_handle_free_signal_ctx (sig_ctx *ctx); - -guint subscribe_dbus_signal_ctx (dbus_handle_h handle, +guint gdbus_signal_ctx_subscribe (dbus_handle_h handle, sig_ctx *ctx, const char *sender, const char *path, @@ -225,42 +241,35 @@ guint subscribe_dbus_signal_ctx (dbus_handle_h handle, const char *name, GDBusSignalCallback cb); -int dbus_handle_signal_ctx_wait (sig_ctx *ctx); +sig_ctx *gdbus_signal_ctx_new (void); -int dbus_handle_signal_ctx_add_timeout (sig_ctx *ctx, - int timeout); +void gdbus_signal_ctx_free (sig_ctx *ctx); +int gdbus_signal_ctx_wait (sig_ctx *ctx); +int gdbus_signal_ctx_add_timeout (sig_ctx *ctx, + int timeout); +int gdbus_flush_sync(dbus_handle_h handle); -int dbus_connection_get_sender_pid (GDBusConnection *conn, +int gdbus_connection_get_sender_pid (GDBusConnection *conn, const char * sender); -int dbus_handle_get_sender_pid (dbus_handle_h handle, +int gdbus_get_sender_pid (dbus_handle_h handle, const char * sender); -int dbus_handle_get_sender_credentials (dbus_handle_h handle, +int gdbus_get_sender_credentials (dbus_handle_h handle, const char *name, GDBusCredentials *creds); -int dbus_handle_watch_name (const char *name, - GBusNameAppearedCallback name_appeared_handler, - GBusNameVanishedCallback name_vanished_handler, - void *user_data, - GDestroyNotify user_data_free_func); - -void dbus_handle_unwatch_name (guint id); - -char** dbus_handle_get_owner_list (dbus_handle_h handle, - const char *bus_name); +gint* gdbus_get_unix_fd_list (GDBusMethodInvocation *invocation, + int *size); -void dbus_handle_check_owner_name (dbus_handle_h handle, - const char *owner_name); +GVariant *gdbus_make_simple_array (const char *sig, + int *param); int check_systemd_active (void); -GVariant *dbus_handle_make_simple_array (const char *sig, - int *param); #endif diff --git a/src/libsystemd/libsystemd.c b/src/libsystemd/libsystemd.c index a045616..8b8295c 100644 --- a/src/libsystemd/libsystemd.c +++ b/src/libsystemd/libsystemd.c @@ -113,14 +113,14 @@ static int _systemd_control_unit_wait(const char *method, unitinfo uinfo; int quit_reason; - ctx = dbus_handle_new_signal_ctx(); + ctx = gdbus_signal_ctx_new(); if (!ctx) return -ENOMEM; _I("Starting: %s %s", method, name); /* synchronous signal subscription */ - ret = subscribe_dbus_signal_ctx(NULL, + ret = gdbus_signal_ctx_subscribe(NULL, ctx, SYSTEMD_DBUS_SERVICE, SYSTEMD_DBUS_PATH, @@ -132,7 +132,7 @@ static int _systemd_control_unit_wait(const char *method, goto finish; } - ret = dbus_handle_method_sync_with_reply_var(SYSTEMD_DBUS_DEST, + ret = gdbus_call_sync_with_reply(SYSTEMD_DBUS_DEST, SYSTEMD_DBUS_PATH, SYSTEMD_DBUS_MANAGER_IFACE, method, @@ -152,14 +152,14 @@ static int _systemd_control_unit_wait(const char *method, ctx->user_data = &uinfo; /* set timeout */ - ret = dbus_handle_signal_ctx_add_timeout(ctx, timeout_msec); + ret = gdbus_signal_ctx_add_timeout(ctx, timeout_msec); if (ret < 0) { _E("Failed to set timeout, %d", ret); goto finish; } /* run loop and wait signal callback */ - quit_reason = dbus_handle_signal_ctx_wait(ctx); + quit_reason = gdbus_signal_ctx_wait(ctx); if (quit_reason != CTX_QUIT_NORMAL) { ret = -1; _E("Failed to receive JobRemoved signal %d", quit_reason); @@ -173,7 +173,7 @@ finish: g_variant_unref(reply); g_free(objpath); - dbus_handle_free_signal_ctx(ctx); + gdbus_signal_ctx_free(ctx); return ret; } @@ -186,7 +186,7 @@ static int _systemd_control_unit_async(const char *method, const char *name) _I("Starting: %s %s", method, name); - ret = dbus_handle_method_sync_with_reply_var(SYSTEMD_DBUS_DEST, + ret = gdbus_call_sync_with_reply(SYSTEMD_DBUS_DEST, SYSTEMD_DBUS_PATH, SYSTEMD_DBUS_MANAGER_IFACE, method, @@ -416,7 +416,7 @@ GVariant *systemd_get_manager_property(const char *property) if (!property) return NULL; - ret_dbus = dbus_handle_method_sync_with_reply_var(SYSTEMD_DBUS_DEST, + ret_dbus = gdbus_call_sync_with_reply(SYSTEMD_DBUS_DEST, SYSTEMD_DBUS_PATH, DBUS_IFACE_DBUS_PROPERTIES, "Get", @@ -442,7 +442,7 @@ GVariant *systemd_get_unit_property(const char *unit, const char *property) escaped = systemd_get_unit_dbus_path(unit); - ret_dbus = dbus_handle_method_sync_with_reply_var(SYSTEMD_DBUS_DEST, + ret_dbus = gdbus_call_sync_with_reply(SYSTEMD_DBUS_DEST, escaped, DBUS_IFACE_DBUS_PROPERTIES, "Get", @@ -470,7 +470,7 @@ GVariant *systemd_get_service_property(const char *unit, const char *property) escaped = systemd_get_unit_dbus_path(unit); - ret_dbus = dbus_handle_method_sync_with_reply_var(SYSTEMD_DBUS_DEST, + ret_dbus = gdbus_call_sync_with_reply(SYSTEMD_DBUS_DEST, escaped, DBUS_IFACE_DBUS_PROPERTIES, "Get", -- 2.7.4 From e67938efffc0ed9a0732c26fa25dd185eb3ff21e Mon Sep 17 00:00:00 2001 From: Hyotaek Shim Date: Fri, 19 Mar 2021 17:40:06 +0900 Subject: [PATCH 15/16] Fix including libgdbus header libsystemd Change-Id: I427757673726c8829a777d8667dcd096eb481a49 Signed-off-by: Hyotaek Shim --- src/libsystemd/libsystemd.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libsystemd/libsystemd.h b/src/libsystemd/libsystemd.h index 79c9f9b..1f807d3 100644 --- a/src/libsystemd/libsystemd.h +++ b/src/libsystemd/libsystemd.h @@ -20,7 +20,7 @@ #ifndef __DBUS_SYSTEMD_H__ #define __DBUS_SYSTEMD_H__ -#include +#include #ifdef __cplusplus extern "C" { -- 2.7.4 From e2af1e6325af742bd3ed90af862734958b6622e1 Mon Sep 17 00:00:00 2001 From: Hyotaek Shim Date: Thu, 22 Apr 2021 10:01:48 +0900 Subject: [PATCH 16/16] Remove with_tizen build macro Change-Id: I565075d4b1dbc99f73fd3bcc7afe5eb944bce854 Signed-off-by: Hyotaek Shim --- packaging/libsyscommon.spec | 8 -------- 1 file changed, 8 deletions(-) diff --git a/packaging/libsyscommon.spec b/packaging/libsyscommon.spec index 3b6869f..80e7db4 100644 --- a/packaging/libsyscommon.spec +++ b/packaging/libsyscommon.spec @@ -5,9 +5,7 @@ Release: 0%{?release_flags} License: Apache-2.0 Group: System/Libraries Source: %{name}-%{version}.tar.gz -%if 0%{?_with_tizen} Source1001: %{name}.manifest -%endif BuildRequires: pkgconfig(glib-2.0) >= 2.44 BuildRequires: pkgconfig(gio-2.0) >= 2.44 @@ -36,9 +34,7 @@ Development header files for system common library. %prep %setup -q -%if 0%{?_with_tizen} cp %{SOURCE1001} . -%endif %build %cmake . @@ -58,17 +54,13 @@ touch debugsources.list %files %defattr(-,root,root,-) -%if 0%{?_with_tizen} %manifest %{name}.manifest -%endif %license LICENSE.Apache-2.0 %{_libdir}/libsyscommon.so.* %files -n libsyscommon-devel %defattr(-,root,root,-) -%if 0%{?_with_tizen} %manifest %{name}.manifest -%endif %license LICENSE.Apache-2.0 %{_libdir}/libsyscommon.so %{_includedir}/libsyscommon/*.h -- 2.7.4