diff --git a/ChangeLog b/ChangeLog index 362fe061..464649f1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,11 @@ # ChangeLog for Gentoo System Intialization ("rc") scripts # Copyright 1999-2007 Gentoo Foundation; Distributed under the GPLv2 + 31 Jul 2007; Roy Marples : + + All our binaries are now mulicalls into rc, which makes our on disk size + a lot smaller. + 23 Jul 2007; Roy Marples : appending noinitd=xdm will skip the xdm service when first booting, #181858. diff --git a/src/Makefile b/src/Makefile index bc7968b6..a4a1283f 100644 --- a/src/Makefile +++ b/src/Makefile @@ -30,12 +30,12 @@ LIBEINFOOBJS= libeinfo.o LIBRCSOVER = 0 LIBRCSO = librc.so.$(LIBRCSOVER) -LIBRCOBJS= librc.o librc-depend.o librc-daemon.o librc-misc.o librc-strlist.o +LIBRCOBJS= librc.o librc-depend.o librc-daemon.o librc-misc.o librc-strlist.o \ + env-update.o fstabinfo.o mountinfo.o \ + rc-depend.o rc-status.o runscript.o start-stop-daemon.o LIB_TARGETS = $(LIBEINFOSO) $(LIBRCSO) -BIN_TARGETS = rc-status -SBIN_TARGETS = env-update rc rc-update runscript start-stop-daemon -PRIV_BIN_TARGETS = fstabinfo mountinfo rc-depend +SBIN_TARGETS = rc SYS_WHITELIST = env_whitelist TARGET = $(LIB_TARGETS) $(BIN_TARGETS) $(SBIN_TARGETS) $(PRIV_BIN_TARGETS) @@ -51,8 +51,11 @@ RCLINKS = einfon einfo ewarnn ewarn eerrorn eerror ebegin eend ewend \ mark_service_stopping mark_service_stopped \ mark_service_inactive mark_service_wasinactive \ mark_service_coldplugged \ - get_options save_options rc-abort \ - is_runlevel_start is_runlevel_stop service_started_daemon + get_options save_options rc-abort rc-depend \ + is_runlevel_start is_runlevel_stop service_started_daemon \ + fstabinfo mountinfo +BINLINKS = rc-status +SBINLINKS = env-update rc-update runscript start-stop-daemon # Quick hack to make my life easier on BSD and Linux ifeq ($(OS),) @@ -129,7 +132,7 @@ start-stop-daemon: LDLIBS += $(LDLIBS_SSD) start-stop-daemon: $(LIBEINFOSO) $(LIBRCSO) start-stop-daemon.o links: rc - for x in $(RCLINKS) $(RCPRIVLINKS); do ln -sf rc $$x; done + for x in $(BINLINKS) $(SBINLINKS) $(RCLINKS) $(RCPRIVLINKS); do ln -sf rc $$x; done install: $(TARGET) install -m 0755 -d $(DESTDIR)/$(LIB) @@ -139,14 +142,14 @@ install: $(TARGET) install -m 0755 -d $(DESTDIR)/usr/include install -m 0644 einfo.h rc.h $(DESTDIR)/usr/include install -m 0755 -d $(DESTDIR)/bin - install -m 0755 $(BIN_TARGETS) $(DESTDIR)/bin install -m 0755 -d $(DESTDIR)/sbin install -m 0755 $(SBIN_TARGETS) $(DESTDIR)/sbin ln -sf rc-update $(DESTDIR)/sbin/update-rc install -m 0755 -d $(DESTDIR)/$(LIB)/rcscripts/conf.d install -m 0644 $(SYS_WHITELIST) $(DESTDIR)/$(LIB)/rcscripts/conf.d install -m 0755 -d $(DESTDIR)/$(LIB)/rcscripts/bin - install -m 0755 $(PRIV_BIN_TARGETS) $(DESTDIR)/$(LIB)/rcscripts/bin + for x in $(BINLINKS); do ln -sf $(DESTDIR)/sbin/rc $(DESTDIR)/bin/$$x; done + for x in $(SBINLINKS); do ln -sf $(DESTDIR)/sbin/rc $(DESTDIR)/sbin/$$x; done for x in $(RCLINKS); do ln -sf $(DESTDIR)/sbin/rc $(DESTDIR)/$(LIB)/rcscripts/bin/$$x; done if test "$(HAVE_PAM)" != "" ; then \ install -m 0755 -d $(DESTDIR)/etc/pam.d ; \ @@ -154,7 +157,7 @@ install: $(TARGET) fi clean: - rm -f $(TARGET) $(RCLINKS) $(RCPRIVLINKS) + rm -f $(TARGET) $(BINLINKS) $(SBINLINKS) $(RCLINKS) $(RCPRIVLINKS) rm -f *.o *~ *.core *.so .depend -include .depend diff --git a/src/env-update.c b/src/env-update.c index 5527070d..b20dce59 100644 --- a/src/env-update.c +++ b/src/env-update.c @@ -22,6 +22,7 @@ #include #include +#include "builtins.h" #include "einfo.h" #include "rc.h" #include "rc-misc.h" @@ -82,7 +83,7 @@ static struct option longopts[] = { }; #include "_usage.c" -int main (int argc, char **argv) +int env_update (int argc, char **argv) { char **files = rc_ls_dir (NULL, ENVDIR, 0); char *file; diff --git a/src/fstabinfo.c b/src/fstabinfo.c index 4601c57e..eecaf8a0 100644 --- a/src/fstabinfo.c +++ b/src/fstabinfo.c @@ -41,6 +41,7 @@ #define ENT_PASS(_ent) ent->fs_passno #endif +#include "builtins.h" #include "einfo.h" #ifdef HAVE_GETMNTENT @@ -68,7 +69,7 @@ static struct option longopts[] = { }; #include "_usage.c" -int main (int argc, char **argv) +int fstabinfo (int argc, char **argv) { #ifdef HAVE_GETMNTENT FILE *fp; diff --git a/src/mountinfo.c b/src/mountinfo.c index 77fe9111..76fec3bf 100644 --- a/src/mountinfo.c +++ b/src/mountinfo.c @@ -27,6 +27,7 @@ #include #include +#include "builtins.h" #include "einfo.h" #include "rc.h" #include "rc-misc.h" @@ -175,7 +176,7 @@ static struct option longopts[] = { }; #include "_usage.c" -int main (int argc, char **argv) +int mountinfo (int argc, char **argv) { int i; regex_t *fstype_regex = NULL; diff --git a/src/rc-depend.c b/src/rc-depend.c index 4c030fee..9d45e9c1 100644 --- a/src/rc-depend.c +++ b/src/rc-depend.c @@ -13,12 +13,13 @@ #include #include +#include "builtins.h" #include "einfo.h" #include "rc.h" #include "rc-misc.h" #include "strlist.h" -int main (int argc, char **argv) +int rc_depend (int argc, char **argv) { char **types = NULL; char **services = NULL; diff --git a/src/rc-misc.h b/src/rc-misc.h index 20dc74f7..e08f880c 100644 --- a/src/rc-misc.h +++ b/src/rc-misc.h @@ -31,4 +31,48 @@ /* Good defaults just incase user has none set */ #define RC_NET_FS_LIST_DEFAULT "afs cifs coda davfs fuse gfs ncpfs nfs nfs4 ocfs2 shfs smbfs" +/* RC utility functions. + Although not directly related to RC in general, they are used by RC + itself and the supporting applications. */ +void *rc_xcalloc (size_t n, size_t size); +void *rc_xmalloc (size_t size); +void *rc_xrealloc (void *ptr, size_t size); +char *rc_xstrdup (const char *str); + +/* Concat paths adding '/' if needed. */ +char *rc_strcatpaths (const char *path1, const char *paths, ...) SENTINEL; + +bool rc_is_env (const char *variable, const char *value); +bool rc_exists (const char *pathname); +bool rc_is_file (const char *pathname); +bool rc_is_link (const char *pathname); +bool rc_is_dir (const char *pathname); +bool rc_is_exec (const char *pathname); + +#define RC_LS_INITD 0x01 +char **rc_ls_dir (char **list, const char *dir, int options); + +bool rc_rm_dir (const char *pathname, bool top); + +/* Config file functions */ +char **rc_get_list (char **list, const char *file); +char **rc_get_config (char **list, const char *file); +char *rc_get_config_entry (char **list, const char *entry); + +/* Make an environment list which filters out all unwanted values + and loads it up with our RC config */ +char **rc_filter_env (void); +char **rc_config_env (char **env); + +/* Handy functions for dealing with string arrays of char ** */ +char **rc_strlist_add (char **list, const char *item); +char **rc_strlist_addu (char **list, const char *item); +char **rc_strlist_addsort (char **list, const char *item); +char **rc_strlist_addsortc (char **list, const char *item); +char **rc_strlist_addsortu (char **list, const char *item); +char **rc_strlist_delete (char **list, const char *item); +char **rc_strlist_join (char **list1, char **list2); +void rc_strlist_reverse (char **list); +void rc_strlist_free (char **list); + #endif diff --git a/src/rc-status.c b/src/rc-status.c index 7c99df7e..999026e7 100644 --- a/src/rc-status.c +++ b/src/rc-status.c @@ -5,19 +5,20 @@ Released under the GPLv2 */ -#define APPLET "rc-status" - #include #include #include #include #include +#include "builtins.h" #include "einfo.h" #include "rc.h" #include "rc-misc.h" #include "strlist.h" +#define APPLET "rc-status" + static void print_level (char *level) { printf ("Runlevel: %s%s%s\n", @@ -55,7 +56,7 @@ static void print_service (char *service) #include "_usage.h" #define getoptstring "alsu" getoptstring_COMMON -const struct option longopts[] = { +static const struct option longopts[] = { {"all", 0, NULL, 'a'}, {"list", 0, NULL, 'l'}, {"servicelist", 0, NULL, 's'}, @@ -65,7 +66,7 @@ const struct option longopts[] = { }; #include "_usage.c" -int main (int argc, char **argv) +int rc_status (int argc, char **argv) { char **levels = NULL; char **services = NULL; diff --git a/src/rc.c b/src/rc.c index 9c9423cc..c226f805 100644 --- a/src/rc.c +++ b/src/rc.c @@ -30,6 +30,7 @@ #include #include +#include "builtins.h" #include "einfo.h" #include "rc.h" #include "rc-misc.h" @@ -82,35 +83,37 @@ static pidlist_t *service_pids = NULL; static void cleanup (void) { - pidlist_t *pl = service_pids; + if (applet && strcmp (applet, "rc") == 0) { + pidlist_t *pl = service_pids; - rc_plugin_unload (); + rc_plugin_unload (); - if (! rc_in_plugin && termios_orig) { - tcsetattr (fileno (stdin), TCSANOW, termios_orig); - free (termios_orig); - } + if (! rc_in_plugin && termios_orig) { + tcsetattr (fileno (stdin), TCSANOW, termios_orig); + free (termios_orig); + } - while (pl) { - pidlist_t *p = pl->next; - free (pl); - pl = p; - } + while (pl) { + pidlist_t *p = pl->next; + free (pl); + pl = p; + } - rc_strlist_free (env); - rc_strlist_free (newenv); - rc_strlist_free (coldplugged_services); - rc_strlist_free (stop_services); - rc_strlist_free (start_services); - rc_free_deptree (deptree); - rc_strlist_free (types); + rc_strlist_free (env); + rc_strlist_free (newenv); + rc_strlist_free (coldplugged_services); + rc_strlist_free (stop_services); + rc_strlist_free (start_services); + rc_free_deptree (deptree); + rc_strlist_free (types); - /* Clean runlevel start, stop markers */ - if (! rc_in_plugin) { - if (rc_is_dir (RC_SVCDIR "softscripts.new")) - rc_rm_dir (RC_SVCDIR "softscripts.new", true); - if (rc_is_dir (RC_SVCDIR "softscripts.old")) - rc_rm_dir (RC_SVCDIR "softscripts.old", true); + /* Clean runlevel start, stop markers */ + if (! rc_in_plugin) { + if (rc_is_dir (RC_SVCDIR "softscripts.new")) + rc_rm_dir (RC_SVCDIR "softscripts.new", true); + if (rc_is_dir (RC_SVCDIR "softscripts.old")) + rc_rm_dir (RC_SVCDIR "softscripts.old", true); + } } free (applet); @@ -695,12 +698,30 @@ int main (int argc, char **argv) char pidstr[6]; int opt; + atexit (cleanup); if (argv[0]) applet = rc_xstrdup (basename (argv[0])); if (! applet) eerrorx ("arguments required"); + /* These used to be programs in their own right, so we shouldn't + * touch argc or argv for them */ + if (strcmp (applet, "env-update") == 0) + exit (env_update (argc, argv)); + else if (strcmp (applet, "fstabinfo") == 0) + exit (fstabinfo (argc, argv)); + else if (strcmp (applet, "mountinfo") == 0) + exit (mountinfo (argc, argv)); + else if (strcmp (applet, "rc-depend") == 0) + exit (rc_depend (argc, argv)); + else if (strcmp (applet, "rc-status") == 0) + exit (rc_status (argc, argv)); + else if (strcmp (applet, "runscript") == 0) + exit (runscript (argc, argv)); + else if (strcmp (applet, "start-stop-daemon") == 0) + exit (start_stop_daemon (argc, argv)); + argc--; argv++; @@ -739,8 +760,6 @@ int main (int argc, char **argv) if (strcmp (applet, "rc" ) != 0) eerrorx ("%s: unknown applet", applet); - atexit (cleanup); - /* Change dir to / to ensure all scripts don't use stuff in pwd */ chdir ("/"); diff --git a/src/rc.h b/src/rc.h index 9920901c..a22353e1 100644 --- a/src/rc.h +++ b/src/rc.h @@ -164,48 +164,5 @@ typedef enum * they wish. At this time we only support the setting of one env var. */ extern FILE *rc_environ_fd; -/* RC utility functions. - Although not directly related to RC in general, they are used by RC - itself and the supporting applications. */ -void *rc_xcalloc (size_t n, size_t size); -void *rc_xmalloc (size_t size); -void *rc_xrealloc (void *ptr, size_t size); -char *rc_xstrdup (const char *str); - -/* Concat paths adding '/' if needed. */ -char *rc_strcatpaths (const char *path1, const char *paths, ...) SENTINEL; - -bool rc_is_env (const char *variable, const char *value); -bool rc_exists (const char *pathname); -bool rc_is_file (const char *pathname); -bool rc_is_link (const char *pathname); -bool rc_is_dir (const char *pathname); -bool rc_is_exec (const char *pathname); - -#define RC_LS_INITD 0x01 -char **rc_ls_dir (char **list, const char *dir, int options); - -bool rc_rm_dir (const char *pathname, bool top); - -/* Config file functions */ -char **rc_get_list (char **list, const char *file); -char **rc_get_config (char **list, const char *file); -char *rc_get_config_entry (char **list, const char *entry); - -/* Make an environment list which filters out all unwanted values - and loads it up with our RC config */ -char **rc_filter_env (void); -char **rc_config_env (char **env); - -/* Handy functions for dealing with string arrays of char ** */ -char **rc_strlist_add (char **list, const char *item); -char **rc_strlist_addu (char **list, const char *item); -char **rc_strlist_addsort (char **list, const char *item); -char **rc_strlist_addsortc (char **list, const char *item); -char **rc_strlist_addsortu (char **list, const char *item); -char **rc_strlist_delete (char **list, const char *item); -char **rc_strlist_join (char **list1, char **list2); -void rc_strlist_reverse (char **list); -void rc_strlist_free (char **list); #endif diff --git a/src/runscript.c b/src/runscript.c index 876cddc7..ae7bbe7a 100644 --- a/src/runscript.c +++ b/src/runscript.c @@ -24,6 +24,7 @@ #include #include +#include "builtins.h" #include "einfo.h" #include "rc.h" #include "rc-misc.h" @@ -977,7 +978,7 @@ static struct option longopts[] = { }; // #include "_usage.c" -int main (int argc, char **argv) +int runscript (int argc, char **argv) { int i; bool deps = true; diff --git a/src/start-stop-daemon.c b/src/start-stop-daemon.c index 5d56ba4d..05325dfb 100644 --- a/src/start-stop-daemon.c +++ b/src/start-stop-daemon.c @@ -40,6 +40,7 @@ static struct pam_conv conv = { NULL, NULL} ; #endif +#include "builtins.h" #include "einfo.h" #include "rc.h" #include "rc-misc.h" @@ -475,7 +476,7 @@ static void handle_signal (int sig) errno = serrno; } -int main (int argc, char **argv) +int start_stop_daemon (int argc, char **argv) { int devnull_fd = -1;