Add helpers and defines for action implementation 11/129511/3
authorKrzysztof Opasiak <k.opasiak@samsung.com>
Tue, 16 May 2017 11:07:17 +0000 (13:07 +0200)
committerKrzysztof Opasiak <k.opasiak@samsung.com>
Thu, 18 May 2017 17:20:26 +0000 (19:20 +0200)
Change-Id: Ie0fdc5a965ca9973acff67ac6c6db01604d88aa3
Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
Makefile.am
src/core/action.h
src/util/systemd_dbus.c [new file with mode: 0644]
src/util/systemd_dbus.h [new file with mode: 0644]

index c0ebf0bba86f8861bab4fdf691259966dda81002..7a2c45dcac8f40850bc9fcfa4a5e8415d8b0a089 100644 (file)
@@ -47,6 +47,7 @@ faultd_SOURCES = \
     src/listeners/audit.c \
     src/listeners/systemd.c \
     src/util/log.c \
-    src/util/notify_queue.c
+    src/util/notify_queue.c \
+    src/util/systemd_dbus.c
 faultd_LDADD = $(LIBSYSTEMD_LIBS) $(AUDIT_LIBS) $(LIBEJDB_LIBS)
 
index c5f0ed0291d454f1ee7d01d98279618b88b09bd9..caaeb4cbc4df0dd267229b46d45872a2f2a3d8aa 100644 (file)
@@ -24,4 +24,6 @@
 #define FAULTD_ACTION_REBOOT_ID "org.tizen.faultd.action.REBOOT"
 #define FAULTD_ACTION_RECOVERY_REBOOT_ID "org.tizen.faultd.action.RECOVERY_REBOOT"
 
+#define FAULTD_DEFAULT_ACTION_IMPL "default"
+
 #endif /* FAULTD_ACTION_H */
diff --git a/src/util/systemd_dbus.c b/src/util/systemd_dbus.c
new file mode 100644 (file)
index 0000000..771c365
--- /dev/null
@@ -0,0 +1,59 @@
+/*
+ * faultd
+ *
+ * Copyright © 2017 Samsung Electronics
+ *
+ * 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 <systemd/sd-bus.h>
+
+#include "common.h"
+#include "systemd_dbus.h"
+
+int faultd_dbus_call(char *service, char *obj, char *interface, char *method,
+                                        sd_bus_error *error, sd_bus_message **out_msg,
+                                        char *types, ...)
+{
+       _cleanup_(sd_bus_unrefp) sd_bus *bus = NULL;
+       _cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL;
+       _cleanup_(sd_bus_error_free) sd_bus_error error_buf = SD_BUS_ERROR_NULL;
+       int ret;
+
+       if (!error)
+               error = &error_buf;
+
+       ret = sd_bus_default_system(&bus);
+       if (ret < 0)
+               return ret;
+
+       ret = sd_bus_message_new_method_call(bus, &m, service,
+                                                                                obj, interface, method);
+       if (ret < 0)
+               goto fail;
+
+       if (types) {
+               va_list args;
+
+               va_start(args, types);
+               ret = sd_bus_message_appendv(m, types, args);
+               va_end(args);
+               if (ret < 0)
+                       goto fail;
+       }
+
+       return sd_bus_call(bus, m, 0, error, out_msg);
+
+fail:
+       return sd_bus_error_set_errno(error, ret);
+}
diff --git a/src/util/systemd_dbus.h b/src/util/systemd_dbus.h
new file mode 100644 (file)
index 0000000..88d31bf
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+ * faultd
+ *
+ * Copyright © 2017 Samsung Electronics
+ *
+ * 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 FAULTD_SYSTEMD_DBUS_H
+#define FAULTD_SYSTEMD_DBUS_H
+
+#include <systemd/sd-bus.h>
+
+#define SYSTEMD_SERVICE "org.freedesktop.systemd1"
+
+#define SYSTEMD_OBJ "/org/freedesktop/systemd1"
+
+#define SYSTEMD_MANAGER_INTERFACE "org.freedesktop.systemd1.Manager"
+#define SYSTEMD_UNIT_INTERFACE "org.freedesktop.systemd1.Unit"
+
+int faultd_dbus_call(char *service, char *obj, char *interface, char *method,
+                                        sd_bus_error *error, sd_bus_message **out_msg,
+                                        char *args, ...);
+
+#define faultd_dbus_call_simple(SRV, OBJ, INTF, METHOD, ARGS, ...)     \
+       faultd_dbus_call(SRV, OBJ, INTF, METHOD, NULL, NULL, ARGS, ##__VA_ARGS__)
+
+#define faultd_dbus_call_systemd_simple(OBJ, INTF, METHOD, ARGS, ...) \
+       faultd_dbus_call_simple(SYSTEMD_SERVICE, OBJ, INTF, METHOD,               \
+                                                       ARGS, ##__VA_ARGS__)
+
+#endif /* FAULTD_SYSTEMD_DBUS_H */