From: Felix Fietkau Date: Sat, 5 Mar 2016 11:16:13 +0000 (+0100) Subject: add a build-time option to disable init related code X-Git-Url: http://git.archive.openwrt.org/?a=commitdiff_plain;h=1d5dd0c269a58e0592897ff5b9261301a483777e;p=project%2Fprocd.git add a build-time option to disable init related code Signed-off-by: Felix Fietkau --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 7299d9c..74959e0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/plug/hotplug.h b/plug/hotplug.h index 2a44442..9e469d1 100644 --- a/plug/hotplug.h +++ b/plug/hotplug.h @@ -17,9 +17,33 @@ #include +#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 66d183c..e87c87a 100644 --- 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); diff --git a/service/trigger.c b/service/trigger.c index fb249b6..216e1f2 100644 --- a/service/trigger.c +++ b/service/trigger.c @@ -16,9 +16,6 @@ #include #include -#include -#include - #include #include #include diff --git a/signal.c b/signal.c index 16824f7..07dda9a 100644 --- 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 1ed70f5..d51970e 100644 --- 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: diff --git a/watchdog.h b/watchdog.h index 015fa93..e5c696a 100644 --- a/watchdog.h +++ b/watchdog.h @@ -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