aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosé Bollo <jose.bollo@iot.bzh>2017-10-12 10:58:40 +0200
committerJosé Bollo <jose.bollo@iot.bzh>2017-11-24 17:44:57 +0100
commit1a67d1b401cbf132687b5aaea52ca7875edaa1f9 (patch)
tree083ad7c8f235bfe255ca00ad47ccccef19f62f05
parentdd87fc32c026b4fba9b13ab52f032e3b403b04bf (diff)
Remove afm-system-daemon
Change-Id: I1e6c0488b7183724a65fcc06fd3cf6909e0efd53 Signed-off-by: José Bollo <jose.bollo@iot.bzh>
-rw-r--r--conf/CMakeLists.txt4
-rw-r--r--conf/afm-system-daemon.service.in3
-rw-r--r--conf/afm-system-daemon.socket.in13
-rw-r--r--src/CMakeLists.txt57
-rw-r--r--src/afm-system-daemon.c295
-rw-r--r--src/afm-system-daemon.xml16
6 files changed, 42 insertions, 346 deletions
diff --git a/conf/CMakeLists.txt b/conf/CMakeLists.txt
index 2188dc0..ad2090d 100644
--- a/conf/CMakeLists.txt
+++ b/conf/CMakeLists.txt
@@ -21,16 +21,16 @@ cmake_minimum_required(VERSION 2.8)
configure_file(afm-unit.conf.in afm-unit.conf)
configure_file(afm-unit-debug.conf.in afm-unit-debug.conf)
configure_file(afm-system-daemon.service.in afm-system-daemon.service)
+configure_file(afm-system-daemon.socket.in afm-system-daemon.socket)
configure_file(afm-user-daemon.service.in afm-user-daemon.service)
if(NOT USE_SDK)
- set(SYSCONFDIR_DBUS_SYSTEM ${CMAKE_INSTALL_SYSCONFDIR}/dbus-1/system.d CACHE STRING "Path to dbus system configuration files")
set(SYSCONFDIR_DBUS_USER ${CMAKE_INSTALL_SYSCONFDIR}/dbus-1/session.d CACHE STRING "Path to dbus session configuration files")
set(UNITDIR_SYSTEM ${CMAKE_INSTALL_LIBDIR}/systemd/system CACHE STRING "Path to systemd system unit files")
set(UNITDIR_USER ${CMAKE_INSTALL_LIBDIR}/systemd/user CACHE STRING "Path to systemd system unit files")
- install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/afm-system-daemon.conf DESTINATION ${SYSCONFDIR_DBUS_SYSTEM})
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/afm-system-daemon.service DESTINATION ${UNITDIR_SYSTEM})
+ install(FILES ${CMAKE_CURRENT_BINARY_DIR}/afm-system-daemon.socket DESTINATION ${UNITDIR_SYSTEM})
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/afm-user-daemon.conf DESTINATION ${SYSCONFDIR_DBUS_USER})
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/afm-user-daemon.service DESTINATION ${UNITDIR_USER})
install(DIRECTORY DESTINATION ${afm_confdir}/unit.env.d)
diff --git a/conf/afm-system-daemon.service.in b/conf/afm-system-daemon.service.in
index 77e1f1b..75a45f9 100644
--- a/conf/afm-system-daemon.service.in
+++ b/conf/afm-system-daemon.service.in
@@ -2,10 +2,9 @@
Description=Application Framework Master, system side
[Service]
-BusName=org.AGL.afm.system
User=afm
Group=afm
-ExecStart=/usr/bin/afm-system-daemon
+ExecStart=/usr/bin/afb-daemon --name=afm-system-daemon -no-httpd --no-ldpaths --binding=@CMAKE_INSTALL_LIBEXECDIR@/afm/afm-binding.so --ws-server=sd:afm-main
Restart=on-failure
RestartSec=5
CapabilityBoundingSet=CAP_DAC_OVERRIDE CAP_MAC_OVERRIDE
diff --git a/conf/afm-system-daemon.socket.in b/conf/afm-system-daemon.socket.in
new file mode 100644
index 0000000..d3f0285
--- /dev/null
+++ b/conf/afm-system-daemon.socket.in
@@ -0,0 +1,13 @@
+
+[Socket]
+SmackLabel=*
+ListenStream=/run/afm/apis/ws/afm-main
+FileDescriptorName=afm-main
+SocketUser=afm
+SocketGroup=afm
+
+Service=afm-system-daemon.service
+
+[Install]
+WantedBy=sockets.target
+
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 0214c12..e7b946b 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -56,12 +56,12 @@ else()
add_definitions(-DUSE_LIBZIP=0)
endif()
-pkg_check_modules(libsystemd REQUIRED libsystemd>=222)
-add_compile_options(${libsystemd_CFLAGS})
-include_directories(${libsystemd_INCLUDE_DIRS})
-link_libraries(${libsystemd_LIBRARIES})
+pkg_check_modules(libsystemd libsystemd>=222)
+if(NOT libsystemd_FOUND)
+ add_definitions(-DNO_LIBSYSTEMD)
+endif()
-pkg_check_modules(AFB REQUIRED afb-daemon>=4.99 libafbwsc>=4.99)
+pkg_check_modules(AFB afb-daemon>=4.99 libafbwsc>=4.99)
###########################################################################
@@ -129,7 +129,7 @@ add_library(afm STATIC
)
###########################################################################
-# packaging tools
+# off line tools tools
MESSAGE(STATUS "Creating packaging tools")
@@ -148,36 +148,31 @@ target_link_libraries(wgtpkg-installer wgtpkg wgt secwrp utils)
install(TARGETS wgtpkg-sign wgtpkg-pack wgtpkg-info wgtpkg-installer DESTINATION ${CMAKE_INSTALL_BINDIR})
###########################################################################
-# the daemons
+# dynamic tool daemons
-MESSAGE(STATUS "Creating daemons")
+if(libsystemd_FOUND AND AFB_FOUND)
+ MESSAGE(STATUS "Creating daemons")
-add_library(jbus STATIC utils-jbus.c)
+ add_compile_options(${libsystemd_CFLAGS} ${AFB_CFLAGS})
+ include_directories(${libsystemd_INCLUDE_DIRS} ${AFB_INCLUDE_DIRS})
+ link_libraries(${libsystemd_LIBRARIES} ${AFB_LIBRARIES})
-add_executable(afm-user-daemon afm-user-daemon.c)
-target_link_libraries(afm-user-daemon jbus utils afbwsc)
-install(TARGETS afm-user-daemon DESTINATION ${CMAKE_INSTALL_BINDIR})
+ add_library(jbus STATIC utils-jbus.c)
-add_executable(afm-system-daemon afm-system-daemon.c)
-target_link_libraries(afm-system-daemon wgtpkg afm secwrp wgt utils jbus)
-install(TARGETS afm-system-daemon DESTINATION ${CMAKE_INSTALL_BINDIR})
+ add_executable(afm-user-daemon afm-user-daemon.c)
+ target_link_libraries(afm-user-daemon jbus utils afbwsc)
+ install(TARGETS afm-user-daemon DESTINATION ${CMAKE_INSTALL_BINDIR})
-###########################################################################
-# the binding for afb
-
-message(STATUS "Creation afm-binding for AFB-DAEMON")
-###############################################################
-pkg_get_variable(afb_binding_install_dir afb-daemon binding_install_dir)
-###############################################################
-add_library(afm-binding MODULE afm-binding.c)
-target_compile_options(afm-binding PRIVATE ${AFB_CFLAGS})
-target_include_directories(afm-binding PRIVATE ${AFB_INCLUDE_DIRS})
-target_link_libraries(afm-binding wgtpkg wgt secwrp utils afm ${AFB_LIBRARIES})
-set_target_properties(afm-binding PROPERTIES
- PREFIX ""
- LINK_FLAGS "-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/afm-binding.export-map"
-)
-install(TARGETS afm-binding LIBRARY DESTINATION ${CMAKE_INSTALL_LIBEXECDIR}/afm)
+ add_library(afm-binding MODULE afm-binding.c)
+ target_link_libraries(afm-binding wgtpkg wgt secwrp utils afm)
+ set_target_properties(afm-binding PROPERTIES
+ PREFIX ""
+ LINK_FLAGS "-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/afm-binding.export-map"
+ )
+ install(TARGETS afm-binding LIBRARY DESTINATION ${CMAKE_INSTALL_LIBEXECDIR}/afm)
+else()
+ MESSAGE(STATUS "Not creating daemons")
+endif()
###########################################################################
# the tests
diff --git a/src/afm-system-daemon.c b/src/afm-system-daemon.c
deleted file mode 100644
index 501a61c..0000000
--- a/src/afm-system-daemon.c
+++ /dev/null
@@ -1,295 +0,0 @@
-/*
- Copyright 2015, 2016, 2017 IoT.bzh
-
- author: José Bollo <jose.bollo@iot.bzh>
-
- 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 <unistd.h>
-#include <stdio.h>
-#include <time.h>
-#include <getopt.h>
-#include <errno.h>
-
-#include <systemd/sd-bus.h>
-#include <systemd/sd-event.h>
-#include <json-c/json.h>
-
-#include "verbose.h"
-#include "utils-jbus.h"
-#include "utils-json.h"
-#include "utils-systemd.h"
-#include "afm.h"
-#include "wgt-info.h"
-#include "wgtpkg-install.h"
-#include "wgtpkg-uninstall.h"
-
-static const char appname[] = "afm-system-daemon";
-static const char *rootdir = NULL;
-
-static void version()
-{
- printf(
- "\n"
- " %s version="AFM_VERSION"\n"
- "\n"
- " Copyright (C) 2015, 2016, 2017 \"IoT.bzh\"\n"
- " AFB comes with ABSOLUTELY NO WARRANTY.\n"
- " Licence Apache 2\n"
- "\n",
- appname
- );
-}
-
-static void usage()
-{
- printf(
- "usage: %s [-q] [-v] [-r rootdir]\n"
- "\n"
- " -r rootdir set root directory of applications\n"
- " -d run as a daemon\n"
- " -q quiet\n"
- " -v verbose\n"
- " -V version\n"
- "\n",
- appname
- );
-}
-
-static struct option options[] = {
- { "root", required_argument, NULL, 'r' },
- { "daemon", no_argument, NULL, 'd' },
- { "quiet", no_argument, NULL, 'q' },
- { "verbose", no_argument, NULL, 'v' },
- { "help", no_argument, NULL, 'h' },
- { "version", no_argument, NULL, 'V' },
- { NULL, 0, NULL, 0 }
-};
-
-static struct jbus *jbus;
-
-const char error_nothing[] = "[]";
-const char error_bad_request[] = "\"bad request\"";
-const char error_not_found[] = "\"not found\"";
-const char error_cant_start[] = "\"can't start\"";
-
-static void do_reloads()
-{
- /* enforce daemon reload */
- systemd_daemon_reload(0);
- systemd_unit_restart_name(0, "sockets.target");
-}
-
-static void on_install(struct sd_bus_message *smsg, struct json_object *req, void *unused)
-{
- const char *wgtfile;
- const char *root;
- int force;
- int reload;
- struct wgt_info *ifo;
- struct json_object *resp;
-
- /* scan the request */
- switch (json_object_get_type(req)) {
- case json_type_string:
- wgtfile = json_object_get_string(req);
- root = rootdir;
- force = 0;
- reload = 1;
- break;
- case json_type_object:
- wgtfile = j_string_at(req, "wgt", NULL);
- if (wgtfile != NULL) {
- root = j_string_at(req, "root", rootdir);
- force = j_boolean_at(req, "force", 0);
- reload = j_boolean_at(req, "reload", 1);
- break;
- }
- /*@fallthrough@*/
- default:
- jbus_reply_error_s(smsg, error_bad_request);
- return;
- }
-
- /* install the widget */
- ifo = install_widget(wgtfile, root, force);
- if (ifo == NULL)
- jbus_reply_error_s(smsg, "\"installation failed\"");
- else {
- /* reload if needed */
- if (reload)
- do_reloads();
-
- /* build the response */
- resp = json_object_new_object();
- if(!resp || !j_add_string(resp, "added", wgt_info_desc(ifo)->idaver))
- jbus_reply_error_s(smsg, "\"out of memory but installed!\"");
- else {
- jbus_send_signal_s(jbus, "changed", "true");
- jbus_reply_j(smsg, resp);
- }
-
- /* clean-up */
- wgt_info_unref(ifo);
- json_object_put(resp);
- }
-}
-
-static void on_uninstall(struct sd_bus_message *smsg, struct json_object *req, void *unused)
-{
- const char *idaver;
- const char *root;
- int rc;
-
- /* scan the request */
- switch (json_object_get_type(req)) {
- case json_type_string:
- idaver = json_object_get_string(req);
- root = rootdir;
- break;
- case json_type_object:
- idaver = j_string_at(req, "id", NULL);
- if (idaver != NULL) {
- root = j_string_at(req, "root", rootdir);
- break;
- }
- /*@fallthrough@*/
- default:
- jbus_reply_error_s(smsg, error_bad_request);
- return;
- }
-
- /* install the widget */
- rc = uninstall_widget(idaver, root);
- if (rc)
- jbus_reply_error_s(smsg, "\"uninstallation had error\"");
- else {
- jbus_send_signal_s(jbus, "changed", "true");
- jbus_reply_s(smsg, "true");
- }
-}
-
-static int daemonize()
-{
- int rc = fork();
- if (rc < 0)
- return rc;
- if (rc)
- _exit(0);
- return 0;
-}
-
-int main(int ac, char **av)
-{
- int i, daemon = 0, rc;
- struct sd_event *evloop;
- struct sd_bus *sysbus;
-
- LOGAUTH(appname);
-
- /* interpretation of arguments */
- while ((i = getopt_long(ac, av, "hdqvVr:", options, NULL)) >= 0) {
- switch (i) {
- case 'h':
- usage();
- return 0;
- case 'V':
- version();
- return 0;
- case 'q':
- if (verbosity)
- verbosity--;
- break;
- case 'v':
- verbosity++;
- break;
- case 'd':
- daemon = 1;
- break;
- case 'r':
- if (rootdir == NULL)
- rootdir = optarg;
- else {
- ERROR("duplicate definition of rootdir");
- return 1;
- }
- break;
- case ':':
- ERROR("missing argument value");
- return 1;
- default:
- ERROR("unrecognized option");
- return 1;
- }
- }
-
- /* check the rootdir */
- if (rootdir == NULL)
- rootdir = FWK_APP_DIR;
- else {
- rootdir = realpath(rootdir, NULL);
- if (rootdir == NULL) {
- ERROR("out of memory");
- return 1;
- }
- }
- if (chdir(rootdir)) {
- ERROR("can't enter %s", rootdir);
- return 1;
- }
-
- /* daemonize */
- if (daemon && daemonize()) {
- ERROR("daemonization failed");
- return 1;
- }
-
- /* get systemd objects */
- rc = sd_event_new(&evloop);
- if (rc < 0) {
- ERROR("can't create event loop");
- return 1;
- }
- rc = sd_bus_open_system(&sysbus);
- if (rc < 0) {
- ERROR("can't create system bus");
- return 1;
- }
- rc = sd_bus_attach_event(sysbus, evloop, 0);
- if (rc < 0) {
- ERROR("can't attach system bus to event loop");
- return 1;
- }
-
- /* init service */
- jbus = create_jbus(sysbus, AFM_SYSTEM_DBUS_PATH);
- if (!jbus) {
- ERROR("create_jbus failed");
- return 1;
- }
- if(jbus_add_service_j(jbus, "install", on_install, NULL)
- || jbus_add_service_j(jbus, "uninstall", on_uninstall, NULL)) {
- ERROR("adding services failed");
- return 1;
- }
-
- /* start and run */
- if (jbus_start_serving(jbus) < 0) {
- ERROR("can't start server");
- return 1;
- }
- for(;;)
- sd_event_run(evloop, (uint64_t)-1);
- return 0;
-}
diff --git a/src/afm-system-daemon.xml b/src/afm-system-daemon.xml
deleted file mode 100644
index 482daf9..0000000
--- a/src/afm-system-daemon.xml
+++ /dev/null
@@ -1,16 +0,0 @@
-<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN" "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
-<node name="/org/AGL/afm/system">
- <interface name="org.AGL.afm.system">
- <method name="install">
- <arg name="in" type="s" direction="in"/>
- <arg name="out" type="s" direction="out"/>
- </method>
- <method name="uninstall">
- <arg name="in" type="s" direction="in"/>
- <arg name="out" type="s" direction="out"/>
- </method>
- <signal name="changed">
- <arg name="out" type="s" direction="out"/>
- </signal>
- </interface>
-</node>