Browse Source

add a build-time option to disable init related code

Signed-off-by: Felix Fietkau <nbd@openwrt.org>
Felix Fietkau 8 years ago
parent
commit
1d5dd0c269
7 changed files with 80 additions and 10 deletions
  1. 9 5
      CMakeLists.txt
  2. 24 0
      plug/hotplug.h
  3. 0 1
      procd.h
  4. 0 3
      service/trigger.c
  5. 4 0
      signal.c
  6. 4 1
      state.c
  7. 39 0
      watchdog.h

+ 9 - 5
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)

+ 24 - 0
plug/hotplug.h

@@ -17,9 +17,33 @@
 
 #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

+ 0 - 1
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);

+ 0 - 3
service/trigger.c

@@ -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>

+ 4 - 0
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
 }

+ 4 - 1
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:

+ 39 - 0
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