add a build-time option to disable init related code
authorFelix Fietkau <nbd@openwrt.org>
Sat, 5 Mar 2016 11:16:13 +0000 (12:16 +0100)
committerFelix Fietkau <nbd@openwrt.org>
Sat, 5 Mar 2016 11:16:15 +0000 (12:16 +0100)
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
CMakeLists.txt
plug/hotplug.h
procd.h
service/trigger.c
signal.c
state.c
watchdog.h

index 7299d9ca628f6c479fca6007195b8d70e01134cb..74959e02951d286efda4c361eb1cbe7cba38e668 100644 (file)
@@ -18,9 +18,12 @@ INSTALL(TARGETS setlbf
 )
 
 
-SET(SOURCES procd.c signal.c watchdog.c state.c        inittab.c rcS.c ubus.c system.c
+SET(SOURCES procd.c signal.c state.c inittab.c rcS.c ubus.c system.c
        service/service.c service/instance.c service/validate.c service/trigger.c service/watch.c
-       plug/coldplug.c plug/hotplug.c utils/utils.c)
+       utils/utils.c)
+IF(NOT DISABLE_INIT)
+  SET(SOURCES ${SOURCES} watchdog.c plug/coldplug.c plug/hotplug.c)
+ENDIF()
 
 SET(LIBS ubox ubus json-c blobmsg_json json_script)
 
@@ -47,20 +50,21 @@ INSTALL(TARGETS procd
        RUNTIME DESTINATION ${CMAKE_INSTALL_SBINDIR}
 )
 
-IF(NOT DISABLE_INIT)
+IF(DISABLE_INIT)
+ADD_DEFINITIONS(-DDISABLE_INIT)
+ELSE()
 ADD_EXECUTABLE(init initd/init.c initd/early.c initd/preinit.c initd/mkdev.c watchdog.c
        utils/utils.c ${SOURCES_ZRAM})
 TARGET_LINK_LIBRARIES(init ${LIBS})
 INSTALL(TARGETS init
        RUNTIME DESTINATION ${CMAKE_INSTALL_SBINDIR}
 )
-ENDIF()
-
 
 ADD_EXECUTABLE(udevtrigger plug/udevtrigger.c)
 INSTALL(TARGETS udevtrigger
        RUNTIME DESTINATION ${CMAKE_INSTALL_SBINDIR}
 )
+ENDIF()
 
 
 ADD_EXECUTABLE(askfirst utils/askfirst.c)
index 2a444425936adc68974930cccae1d26cbe1d595b..9e469d18a6ce8e625977fabbcf453b82473b2ccb 100644 (file)
 
 #include <libubox/uloop.h>
 
+#ifndef DISABLE_INIT
 void hotplug(char *rules);
 int hotplug_run(char *rules);
 void hotplug_shutdown(void);
 void hotplug_last_event(uloop_timeout_handler handler);
+void procd_coldplug(void);
+#else
+static inline void hotplug(char *rules)
+{
+}
+
+static inline int hotplug_run(char *rules)
+{
+       return 0;
+}
+
+static inline void hotplug_shutdown(void)
+{
+}
+
+static inline void hotplug_last_event(uloop_timeout_handler handler)
+{
+}
+
+static inline void procd_coldplug(void)
+{
+}
+#endif
 
 #endif
diff --git a/procd.h b/procd.h
index 66d183c1bc11d623476a064da7e74631100b8539..e87c87a917016af7829c95d6ba4e6d11f50b0765 100644 (file)
--- a/procd.h
+++ b/procd.h
@@ -39,7 +39,6 @@ void procd_state_ubus_connect(void);
 void procd_shutdown(int event);
 void procd_early(void);
 void procd_preinit(void);
-void procd_coldplug(void);
 void procd_signal(void);
 void procd_signal_preinit(void);
 void procd_inittab(void);
index fb249b6605dccc7100566ed2a0d6bdf18d2ac8cc..216e1f2f00f7191e700f24c7612a3517e30b1f94 100644 (file)
@@ -16,9 +16,6 @@
 #include <sys/socket.h>
 #include <sys/types.h>
 
-#include <linux/types.h>
-#include <linux/netlink.h>
-
 #include <libubox/blobmsg_json.h>
 #include <libubox/json_script.h>
 #include <libubox/runqueue.h>
index 16824f7251b5c01344c4f1dd939ed0daef9ac022..07dda9a4c890e9106a56ec089c6f8bfcdefb22a0 100644 (file)
--- a/signal.c
+++ b/signal.c
@@ -35,6 +35,7 @@ static void signal_shutdown(int signal, siginfo_t *siginfo, void *data)
        int event = 0;
        char *msg = NULL;
 
+#ifndef DISABLE_INIT
        switch(signal) {
        case SIGINT:
        case SIGTERM:
@@ -47,6 +48,7 @@ static void signal_shutdown(int signal, siginfo_t *siginfo, void *data)
                msg = "poweroff";
                break;
        }
+#endif
 
        DEBUG(1, "Triggering %s\n", msg);
        if (event)
@@ -93,5 +95,7 @@ void procd_signal(void)
        sigaction(SIGHUP, &sa_dummy, NULL);
        sigaction(SIGKILL, &sa_dummy, NULL);
        sigaction(SIGSTOP, &sa_dummy, NULL);
+#ifndef DISABLE_INIT
        reboot(RB_DISABLE_CAD);
+#endif
 }
diff --git a/state.c b/state.c
index 1ed70f542f13d3ec7b8a3d3cf2fcf8e31cf42cd8..d51970e952d5a3326020aaf5745463d1e5f3cf5b 100644 (file)
--- a/state.c
+++ b/state.c
@@ -150,6 +150,7 @@ static void state_enter(void)
                kill(-1, SIGKILL);
                sync();
                sleep(1);
+#ifndef DISABLE_INIT
                if (reboot_event == RB_POWER_OFF)
                        LOG("- power down -\n");
                else
@@ -165,9 +166,11 @@ static void state_enter(void)
                        reboot(reboot_event);
                        _exit(EXIT_SUCCESS);
                }
-
                while (1)
                        sleep(1);
+#else
+               exit(0);
+#endif
                break;
 
        default:
index 015fa93b5865c81c6af445e434aed8bed88256ea..e5c696a37fa974d404ed5e530ec9108e52679c07 100644 (file)
@@ -15,6 +15,7 @@
 #ifndef __PROCD_WATCHDOG_H
 #define __PROCD_WATCHDOG_H
 
+#ifndef DISABLE_INIT
 void watchdog_init(int preinit);
 char* watchdog_fd(void);
 int watchdog_timeout(int timeout);
@@ -23,5 +24,43 @@ void watchdog_set_stopped(bool val);
 bool watchdog_get_stopped(void);
 void watchdog_no_cloexec(void);
 void watchdog_ping(void);
+#else
+static inline void watchdog_init(int preinit)
+{
+}
+
+static inline char* watchdog_fd(void)
+{
+       return "";
+}
+
+static inline int watchdog_timeout(int timeout)
+{
+       return 0;
+}
+
+static inline int watchdog_frequency(int frequency)
+{
+       return 0;
+}
+
+static inline void watchdog_set_stopped(bool val)
+{
+}
+
+static inline bool watchdog_get_stopped(void)
+{
+       return true;
+}
+
+static inline void watchdog_no_cloexec(void)
+{
+}
+
+static inline void watchdog_ping(void)
+{
+}
+
+#endif
 
 #endif