From 369fcf2100a4a7b3f719d8459e1e656ed9c6acfe Mon Sep 17 00:00:00 2001 From: Joachim Nilsson Date: Mon, 26 Oct 2015 00:52:11 +0100 Subject: [PATCH] Issue #14: Improved support for static Finit builds - Upgrade libite (LITE) for new UNIX file parser API to improve static builds of Finit. - Re-enable bootmisc plugin for static builds by adding built-in support for reading GID from /etc/group. - Allow inetd support for static builds by adding built-in support for reading service and protocol from /etc/services and /etc/protocols. - Do not try to install/uninstall any plugins for static builds. Signed-off-by: Joachim Nilsson --- helpers.c | 10 ++++++++-- inetd.c | 29 ++++++++++++++++++++++++++++- libite | 2 +- plugin.c | 2 ++ plugins/Makefile | 7 +++++++ plugins/bootmisc.c | 5 ----- 6 files changed, 46 insertions(+), 9 deletions(-) diff --git a/helpers.c b/helpers.c index e22796ce..a8b7fdb1 100644 --- a/helpers.c +++ b/helpers.c @@ -174,27 +174,33 @@ int print_result(int fail) return fail; } -#ifndef ENABLE_STATIC int getuser(char *username) { +#ifdef ENABLE_STATIC + return fgetint("/etc/passwd", "x:\n", username); +#else struct passwd *usr; if (!username || (usr = getpwnam(username)) == NULL) return -1; return usr->pw_uid; +#endif } int getgroup(char *group) { +#ifdef ENABLE_STATIC + return fgetint("/etc/group", "x:\n", group); +#else struct group *grp; if ((grp = getgrnam(group)) == NULL) return -1; return grp->gr_gid; -} #endif +} /* Signal safe sleep ... we get a lot of SIGCHLD at reboot */ void do_sleep(unsigned int sec) diff --git a/inetd.c b/inetd.c index acf25fe7..3720c907 100644 --- a/inetd.c +++ b/inetd.c @@ -217,7 +217,22 @@ void inetd_stop(inetd_t *inetd) static int getent(char *service, char *proto, struct servent **sv, struct protoent **pv) { +#ifdef ENABLE_STATIC + int service_num; + static struct servent lfs; + + service_num = fgetint("/etc/services", " \n\t", service); + if (service_num > 0) { + lfs.s_name = service; + lfs.s_port = htons(service_num); + lfs.s_proto = NULL; + if (!strcmp("tcp", proto) || !strcmp("udp", proto)) + lfs.s_proto = proto; + *sv = &lfs; + } +#else *sv = getservbyname(service, proto); +#endif if (!*sv) { const char *errstr; static struct servent s; @@ -238,8 +253,20 @@ static int getent(char *service, char *proto, struct servent **sv, struct protoe *sv = &s; } - if (pv) { + if (pv && (*sv)->s_proto) { +#ifdef ENABLE_STATIC + int proto_num; + static struct protoent lfp; + + proto_num = fgetint("/etc/protocols", " \n\t", (*sv)->s_proto); + if (proto_num > 0) { + lfp.p_name = proto; + lfp.p_proto = proto_num; + } + *pv = &lfp; +#else *pv = getprotobyname((*sv)->s_proto); +#endif if (!*pv) { _e("Cannot find proto %s, skipping.", (*sv)->s_proto); return errno = EINVAL; diff --git a/libite b/libite index db08b20f..23badc99 160000 --- a/libite +++ b/libite @@ -1 +1 @@ -Subproject commit db08b20f239f2d17864b69822f85739a1e6eeae0 +Subproject commit 23badc990daf626dce537bcf3464d8bf0a593e93 diff --git a/plugin.c b/plugin.c index 30dc544e..f0f53b83 100644 --- a/plugin.c +++ b/plugin.c @@ -317,6 +317,8 @@ int plugin_load_all(uev_ctx_t *ctx, char *path) closedir(dp); #else _d("Finit built statically, not loading plugins from %s ...", path); + if (verbose) + print_desc("Initializing plugins", NULL); #endif /* ENABLE_STATIC */ /* Always initialize plugins */ diff --git a/plugins/Makefile b/plugins/Makefile index bc3a497f..f94dabf3 100644 --- a/plugins/Makefile +++ b/plugins/Makefile @@ -27,6 +27,7 @@ clean: distclean: -@$(RM) *.o *.so $(JUNK) $(DEPS) +ifneq ($(STATIC), 1) install: all @install -d $(DESTDIR)$(plugindir) @for plugin in $(PLUGINS); do \ @@ -40,6 +41,12 @@ uninstall: rm $(DESTDIR)$(plugindir)/$$plugin 2>/dev/null; \ done -@rmdir $(DESTDIR)$(plugindir) 2>/dev/null +else +install: + @true +uninstall: + @true +endif ifneq ($(MAKECMDGOALS),distclean) -include $(DEPS) diff --git a/plugins/bootmisc.c b/plugins/bootmisc.c index 4802304a..3e172732 100644 --- a/plugins/bootmisc.c +++ b/plugins/bootmisc.c @@ -29,9 +29,6 @@ #include "../plugin.h" #include "libite/lite.h" -/* This plugin uses getuser(), which relies on dynamically linked GLIBC. Cannot be built statically! */ -#ifndef ENABLE_STATIC - /* * Setup standard FHS 2.3 structure in /var, and * write runlevel to UTMP, needed by, e.g., printerdrake. @@ -104,8 +101,6 @@ PLUGIN_EXIT(plugin_exit) plugin_unregister(&plugin); } -#endif/* ENABLE_STATIC */ - /** * Local Variables: * version-control: t