OPTION(BUILD_LUA "build Lua plugin" ON)
OPTION(BUILD_EXAMPLES "build examples" ON)
-OPTION(ENABLE_SYSTEMD "systemd support" ON)
+OPTION(ENABLE_SYSTEMD "systemd support" OFF)
SET(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")
SET(UBUS_UNIX_SOCKET "/var/run/ubus.sock")
# do this after the installs so we have the proper paths
IF(ENABLE_SYSTEMD)
INCLUDE(FindPkgConfig)
- PKG_CHECK_MODULES(SYSTEMD systemd)
- IF(SYSTEMD_FOUND)
- ADD_SUBDIRECTORY(systemd)
- ENDIF()
+ PKG_CHECK_MODULES(SYSTEMD libsystemd REQUIRED)
+
+ SET_PROPERTY(TARGET ubusd APPEND PROPERTY COMPILE_FLAGS "${SYSTEMD_CFLAGS}")
+ SET_PROPERTY(TARGET ubusd APPEND PROPERTY LINK_FLAGS "${SYSTEMD_LDFLAGS}")
+ SET_PROPERTY(TARGET ubusd APPEND PROPERTY INCLUDE_DIRECTORIES ${SYSTEMD_INCLUDE_DIRS})
+ TARGET_LINK_LIBRARIES(ubusd ${SYSTEMD_LIBRARIES})
+ ADD_DEFINITIONS( -DENABLE_SYSTEMD)
+
+ ADD_SUBDIRECTORY(systemd)
ENDIF()
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
+#ifdef ENABLE_SYSTEMD
+#include <systemd/sd-daemon.h>
+#endif
#include <libubox/blob.h>
#include <libubox/uloop.h>
int main(int argc, char **argv)
{
const char *ubus_socket = UBUS_UNIX_SOCKET;
+ bool remove_socket = true;
int ret = 0;
int ch;
+#ifdef ENABLE_SYSTEMD
+ int n_fds;
+#endif
signal(SIGPIPE, SIG_IGN);
signal(SIGHUP, sighup_handler);
}
}
- unlink(ubus_socket);
- umask(0111);
- server_fd.fd = usock(USOCK_UNIX | USOCK_SERVER | USOCK_NONBLOCK, ubus_socket, NULL);
- if (server_fd.fd < 0) {
- perror("usock");
- ret = -1;
+#ifdef ENABLE_SYSTEMD
+ n_fds = sd_listen_fds(1);
+ if (n_fds > 1) {
+ fprintf(stderr, "Too many file descriptors received.\n");
+ ret = -1;
goto out;
+ } else if (n_fds == 1) {
+ server_fd.fd = SD_LISTEN_FDS_START + 0;
+ fcntl(server_fd.fd, F_SETFD, fcntl(server_fd.fd, F_GETFD) | FD_CLOEXEC);
+ fcntl(server_fd.fd, F_SETFL, fcntl(server_fd.fd, F_GETFL) | O_NONBLOCK);
+
+ remove_socket = false;
+ } else
+#endif
+ {
+ unlink(ubus_socket);
+ umask(0111);
+ server_fd.fd = usock(USOCK_UNIX | USOCK_SERVER | USOCK_NONBLOCK, ubus_socket, NULL);
+ if (server_fd.fd < 0) {
+ perror("usock");
+ ret = -1;
+ goto out;
+ }
}
uloop_fd_add(&server_fd, ULOOP_READ | ULOOP_EDGE_TRIGGER);
ubusd_acl_load();
uloop_run();
- unlink(ubus_socket);
+
+ if (remove_socket)
+ unlink(ubus_socket);
out:
uloop_done();