rc_is_env is now rc_env_bool and just works with boolean values.
This commit is contained in:
		| @@ -1,6 +1,11 @@ | ||||
| # ChangeLog for Gentoo System Intialization ("rc") scripts | ||||
| # Copyright 1999-2007 Gentoo Foundation; Distributed under the GPLv2 | ||||
|  | ||||
|   26 Sep 2007; Roy Marples <uberlord@gentoo.org>: | ||||
|  | ||||
|     rc_is_env is now rc_env_bool and just works with boolean values. | ||||
|     errno is set when it's not a boolean or does not exist. | ||||
|  | ||||
|   25 Sep 2007; Mike Frysinger <vapier@gentoo.org>: | ||||
|  | ||||
|     Skip consolefont setup when RC_TTY_NUMBER is set to 0. | ||||
|   | ||||
| @@ -181,7 +181,7 @@ int fstabinfo (int argc, char **argv) | ||||
| 		} | ||||
|  | ||||
| 		/* No point in outputting if quiet */ | ||||
| 		if (rc_is_env ("RC_QUIET", "yes")) | ||||
| 		if (rc_env_bool ("RC_QUIET")) | ||||
| 			continue; | ||||
|  | ||||
| 		switch (output) { | ||||
|   | ||||
| @@ -57,20 +57,33 @@ char *rc_xstrdup (const char *str) | ||||
| } | ||||
| librc_hidden_def(rc_xstrdup) | ||||
|  | ||||
| bool rc_is_env (const char *var, const char *val) | ||||
| bool rc_env_bool (const char *var) | ||||
| { | ||||
| 	char *v; | ||||
|  | ||||
| 	if (! var) | ||||
| 		return (false); | ||||
|  | ||||
| 	v = getenv (var); | ||||
| 	if (! v) | ||||
| 		return (val == NULL ? true : false); | ||||
| 	if (! (v = getenv (var))) { | ||||
| 		errno = ENOENT; | ||||
| 		return (false); | ||||
| 	} | ||||
|  | ||||
| 	return (strcasecmp (v, val) == 0 ? true : false); | ||||
| 	if (strcasecmp (var, "true") == 0 || | ||||
| 		strcasecmp (var, "y") == 0 || | ||||
| 		strcasecmp (var, "yes") == 0 || | ||||
| 		strcasecmp (var, "1") == 0) | ||||
| 		return (true); | ||||
|  | ||||
| 	if (strcasecmp (var, "false") != 0 && | ||||
| 		strcasecmp (var, "n") != 0 && | ||||
| 		strcasecmp (var, "no") != 0 && | ||||
| 		strcasecmp (var, "0") != 0) | ||||
| 		errno = EINVAL; | ||||
|  | ||||
| 	return (false); | ||||
| } | ||||
| librc_hidden_def(rc_is_env) | ||||
| librc_hidden_def(rc_env_bool) | ||||
|  | ||||
| char *rc_strcatpaths (const char *path1, const char *paths, ...) | ||||
| { | ||||
|   | ||||
| @@ -50,6 +50,7 @@ | ||||
| #define librc_hidden_def(x) hidden_def(x) | ||||
|  | ||||
| librc_hidden_proto(rc_allow_plug) | ||||
| librc_hidden_proto(rc_env_bool) | ||||
| librc_hidden_proto(rc_exists) | ||||
| librc_hidden_proto(rc_filter_env) | ||||
| librc_hidden_proto(rc_find_pids) | ||||
| @@ -64,7 +65,6 @@ librc_hidden_proto(rc_get_runlevel) | ||||
| librc_hidden_proto(rc_get_runlevels) | ||||
| librc_hidden_proto(rc_get_service_option) | ||||
| librc_hidden_proto(rc_is_dir) | ||||
| librc_hidden_proto(rc_is_env) | ||||
| librc_hidden_proto(rc_is_exec) | ||||
| librc_hidden_proto(rc_is_file) | ||||
| librc_hidden_proto(rc_is_link) | ||||
|   | ||||
| @@ -364,7 +364,7 @@ int mountinfo (int argc, char **argv) | ||||
| 			continue; | ||||
| 		if (skip_point_regex && regexec (skip_point_regex, n, 0, NULL, 0) == 0) | ||||
| 			continue; | ||||
| 		if (! rc_is_env ("RC_QUIET", "yes")) | ||||
| 		if (rc_env_bool ("RC_QUIET")) | ||||
| 			printf ("%s\n", n); | ||||
| 		result = EXIT_SUCCESS; | ||||
| 	} | ||||
|   | ||||
							
								
								
									
										12
									
								
								src/rc.c
									
									
									
									
									
								
							
							
						
						
									
										12
									
								
								src/rc.c
									
									
									
									
									
								
							| @@ -457,7 +457,7 @@ static bool want_interactive (void) | ||||
| 		strcmp (PREVLEVEL, "1") != 0) | ||||
| 		return (false); | ||||
|  | ||||
| 	if (! rc_is_env ("RC_INTERACTIVE", "yes")) | ||||
| 	if (! rc_env_bool ("RC_INTERACTIVE")) | ||||
| 		return (false); | ||||
|  | ||||
| 	c = read_key (false); | ||||
| @@ -919,7 +919,7 @@ int main (int argc, char **argv) | ||||
| 					ecolor (ecolor_good), uts.sysname, ecolor (ecolor_bracket), | ||||
| 					ecolor (ecolor_normal)); | ||||
|  | ||||
| 			if (rc_is_env ("RC_INTERACTIVE", "yes")) | ||||
| 			if (rc_env_bool ("RC_INTERACTIVE")) | ||||
| 				printf ("Press %sI%s to enter interactive boot mode\n\n", | ||||
| 						ecolor (ecolor_good), ecolor (ecolor_normal)); | ||||
|  | ||||
| @@ -1056,7 +1056,7 @@ int main (int argc, char **argv) | ||||
| 	if (newlevel && strcmp (newlevel, bootlevel) == 0 && | ||||
| 		(strcmp (runlevel, RC_LEVEL_SINGLE) == 0 || | ||||
| 		 strcmp (runlevel, RC_LEVEL_SYSINIT) == 0) && | ||||
| 		rc_is_env ("RC_COLDPLUG", "yes")) | ||||
| 		rc_env_bool ("RC_COLDPLUG")) | ||||
| 	{ | ||||
| #if defined(__DragonFly__) || defined(__FreeBSD__) | ||||
| 		/* The net interfaces are easy - they're all in net /dev/net :) */ | ||||
| @@ -1186,7 +1186,7 @@ int main (int argc, char **argv) | ||||
| 		/* We always stop the service when in these runlevels */ | ||||
| 		if (going_down) { | ||||
| 			pid_t pid = rc_stop_service (service); | ||||
| 			if (pid > 0 && ! rc_is_env ("RC_PARALLEL", "yes")) | ||||
| 			if (pid > 0 && ! rc_env_bool ("RC_PARALLEL")) | ||||
| 				rc_waitpid (pid); | ||||
| 			continue; | ||||
| 		} | ||||
| @@ -1251,7 +1251,7 @@ int main (int argc, char **argv) | ||||
| 		/* After all that we can finally stop the blighter! */ | ||||
| 		if (! found) { | ||||
| 			pid_t pid = rc_stop_service (service); | ||||
| 			if (pid > 0 && ! rc_is_env ("RC_PARALLEL", "yes")) | ||||
| 			if (pid > 0 && ! rc_env_bool ("RC_PARALLEL")) | ||||
| 				rc_waitpid (pid); | ||||
| 		} | ||||
| 	} | ||||
| @@ -1352,7 +1352,7 @@ interactive_option: | ||||
| 			if ((pid = rc_start_service (service))) | ||||
| 				add_pid (pid); | ||||
|  | ||||
| 			if (! rc_is_env ("RC_PARALLEL", "yes")) { | ||||
| 			if (! rc_env_bool ("RC_PARALLEL")) { | ||||
| 				rc_waitpid (pid); | ||||
| 				remove_pid (pid); | ||||
| 			} | ||||
|   | ||||
							
								
								
									
										9
									
								
								src/rc.h
									
									
									
									
									
								
							
							
						
						
									
										9
									
								
								src/rc.h
									
									
									
									
									
								
							| @@ -367,11 +367,12 @@ char *rc_xstrdup (const char *str); | ||||
|  * @param paths NULL terminated list of paths to add | ||||
|  * @return pointer to the new path */ | ||||
| char *rc_strcatpaths (const char *path1, const char *paths, ...) SENTINEL; | ||||
| /*! Check if an environment variable matches the given value | ||||
| /*! Check if an environment variable is a boolean and return it's value. | ||||
|  * If variable is not a boolean then we set errno to be ENOENT when it does | ||||
|  * not exist or EINVAL if it's not a boolean. | ||||
|  * @param variable to check | ||||
|  * @param value it should be | ||||
|  * @return true if it matches */ | ||||
| bool rc_is_env (const char *variable, const char *value); | ||||
|  * @return true if it matches true, yes or 1, false if otherwise. */ | ||||
| bool rc_env_bool (const char *variable); | ||||
| /*! Check if the file exists or not | ||||
|  * @param pathname to check | ||||
|  * @return true if it exists, otherwise false */ | ||||
|   | ||||
| @@ -562,7 +562,7 @@ static void svc_start (bool deps) | ||||
| 	rc_plugin_run (rc_hook_service_start_in, applet); | ||||
| 	hook_out = rc_hook_service_start_out; | ||||
|  | ||||
| 	if (rc_is_env ("IN_HOTPLUG", "1") || in_background) { | ||||
| 	if (rc_env_bool ("IN_HOTPLUG") || in_background) { | ||||
| 		if (! rc_service_state (service, rc_service_inactive) && | ||||
| 			! rc_service_state (service, rc_service_stopped)) | ||||
| 			exit (EXIT_FAILURE); | ||||
| @@ -584,7 +584,7 @@ static void svc_start (bool deps) | ||||
|  | ||||
| 	make_exclusive (service); | ||||
|  | ||||
| 	if (rc_is_env ("RC_DEPEND_STRICT", "yes")) | ||||
| 	if (rc_env_bool ("RC_DEPEND_STRICT")) | ||||
| 		depoptions |= RC_DEP_STRICT; | ||||
|  | ||||
| 	if (rc_runlevel_starting ()) | ||||
| @@ -630,7 +630,7 @@ static void svc_start (bool deps) | ||||
| 			STRLIST_FOREACH (use_services, svc, i) | ||||
| 				if (rc_service_state (svc, rc_service_stopped)) { | ||||
| 					pid_t pid = rc_start_service (svc); | ||||
| 					if (! rc_is_env ("RC_PARALLEL", "yes")) | ||||
| 					if (! rc_env_bool ("RC_PARALLEL")) | ||||
| 						rc_waitpid (pid); | ||||
| 				} | ||||
| 		} | ||||
| @@ -802,7 +802,7 @@ static void svc_stop (bool deps) | ||||
| 		rc_service_state (service, rc_service_failed)) | ||||
| 		exit (EXIT_FAILURE); | ||||
|  | ||||
| 	if (rc_is_env ("IN_HOTPLUG", "1") || in_background) | ||||
| 	if (rc_env_bool ("IN_HOTPLUG") || in_background) | ||||
| 		if (! rc_service_state (service, rc_service_started) &&  | ||||
| 			! rc_service_state (service, rc_service_inactive)) | ||||
| 			exit (EXIT_FAILURE); | ||||
| @@ -827,7 +827,7 @@ static void svc_stop (bool deps) | ||||
| 		char *svc; | ||||
| 		int i; | ||||
|  | ||||
| 		if (rc_is_env ("RC_DEPEND_STRICT", "yes")) | ||||
| 		if (rc_env_bool ("RC_DEPEND_STRICT")) | ||||
| 			depoptions |= RC_DEP_STRICT; | ||||
|  | ||||
| 		if (rc_runlevel_stopping ()) | ||||
| @@ -857,7 +857,7 @@ static void svc_stop (bool deps) | ||||
| 					rc_service_state (svc, rc_service_inactive)) | ||||
| 				{ | ||||
| 					pid_t pid = rc_stop_service (svc); | ||||
| 					if (! rc_is_env ("RC_PARALLEL", "yes")) | ||||
| 					if (! rc_env_bool ("RC_PARALLEL")) | ||||
| 						rc_waitpid (pid); | ||||
| 					rc_strlist_add (&tmplist, svc); | ||||
| 				} | ||||
| @@ -1088,7 +1088,7 @@ int runscript (int argc, char **argv) | ||||
| 	setenv ("RC_RUNSCRIPT_PID", pid, 1); | ||||
|  | ||||
| 	/* eprefix is kinda klunky, but it works for our purposes */ | ||||
| 	if (rc_is_env ("RC_PARALLEL", "yes")) { | ||||
| 	if (rc_env_bool ("RC_PARALLEL")) { | ||||
| 		int l = 0; | ||||
| 		int ll; | ||||
|  | ||||
| @@ -1138,13 +1138,13 @@ int runscript (int argc, char **argv) | ||||
| 	/* Save the IN_BACKGROUND env flag so it's ONLY passed to the service | ||||
| 	   that is being called and not any dependents */ | ||||
| 	if (getenv ("IN_BACKGROUND")) { | ||||
| 		in_background = rc_is_env ("IN_BACKGROUND", "true"); | ||||
| 		in_background = rc_env_bool ("IN_BACKGROUND"); | ||||
| 		ibsave = rc_xstrdup (getenv ("IN_BACKGROUND")); | ||||
| 		unsetenv ("IN_BACKGROUND"); | ||||
| 	} | ||||
|  | ||||
| 	if (rc_is_env ("IN_HOTPLUG", "1")) { | ||||
| 		if (! rc_is_env ("RC_HOTPLUG", "yes") || ! rc_allow_plug (applet)) | ||||
| 	if (rc_env_bool ("IN_HOTPLUG")) { | ||||
| 		if (! rc_env_bool ("RC_HOTPLUG") || ! rc_allow_plug (applet)) | ||||
| 			eerrorx ("%s: not allowed to be hotplugged", applet); | ||||
| 	} | ||||
|  | ||||
| @@ -1196,7 +1196,7 @@ int runscript (int argc, char **argv) | ||||
| 				   strcmp (optarg, "iprovide") == 0) { | ||||
| 			int depoptions = RC_DEP_TRACE; | ||||
|  | ||||
| 			if (rc_is_env ("RC_DEPEND_STRICT", "yes")) | ||||
| 			if (rc_env_bool ("RC_DEPEND_STRICT")) | ||||
| 				depoptions |= RC_DEP_STRICT; | ||||
| 			 | ||||
| 			if (! deptree && ((deptree = rc_load_deptree ()) == NULL)) | ||||
|   | ||||
| @@ -684,7 +684,7 @@ int start_stop_daemon (int argc, char **argv) | ||||
| 			case_RC_COMMON_GETOPT | ||||
| 		} | ||||
|  | ||||
| 	quiet = rc_is_env ("RC_QUIET", "yes"); | ||||
| 	quiet = rc_env_bool ("RC_QUIET"); | ||||
| 	verbose = rc_is_env ("RC_VERBOSE", "yes"); | ||||
|  | ||||
| 	/* Allow start-stop-daemon --signal HUP --exec /usr/sbin/dnsmasq | ||||
|   | ||||
		Reference in New Issue
	
	Block a user