Compare commits
	
		
			12 Commits
		
	
	
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
|   | 4a3454966a | ||
|   | 63e40f31bf | ||
|   | e43ee29eb4 | ||
|   | a3555b1442 | ||
|   | eb863156fb | ||
|   | ac76b24b85 | ||
|   | b8e57c693a | ||
|   | 5df12e2414 | ||
|   | 461df0c78b | ||
|   | cefae65392 | ||
|   | 69fbd12993 | ||
|   | 4aa5686d90 | 
							
								
								
									
										232
									
								
								ChangeLog
									
									
									
									
									
								
							
							
						
						
									
										232
									
								
								ChangeLog
									
									
									
									
									
								
							| @@ -1,3 +1,97 @@ | |||||||
|  | commit 63e40f31bfc7d8908fee8059ea383038832dd84f | ||||||
|  | Author: William Hubbs <w.d.hubbs@gmail.com> | ||||||
|  | Commit: William Hubbs <w.d.hubbs@gmail.com> | ||||||
|  |  | ||||||
|  |     fix compiler warnings | ||||||
|  |  | ||||||
|  | commit e43ee29eb4310ff23c438d1877ef79c56539b002 | ||||||
|  | Author: William Hubbs <w.d.hubbs@gmail.com> | ||||||
|  | Commit: William Hubbs <w.d.hubbs@gmail.com> | ||||||
|  |  | ||||||
|  |     supervise-daemon: do not use the exec_service() function | ||||||
|  |      | ||||||
|  |     In order to run healthcheck() and the unhealthy() function, add an | ||||||
|  |     exec_command call to the supervisor. | ||||||
|  |     Another difference is This function also logs errors instead of | ||||||
|  |     attempting to display them. | ||||||
|  |      | ||||||
|  |     This is for #271. | ||||||
|  |  | ||||||
|  | commit a3555b144291b7d32f7c14fd9bd0dbe3ee6e33f9 | ||||||
|  | Author: William Hubbs <w.d.hubbs@gmail.com> | ||||||
|  | Commit: William Hubbs <w.d.hubbs@gmail.com> | ||||||
|  |  | ||||||
|  |     Add debug logging to start-stop-daemon and rc-supervisor | ||||||
|  |      | ||||||
|  |     This will make it easier to track down why the supervisor intermittently | ||||||
|  |     hangs after it runs for a long time. | ||||||
|  |  | ||||||
|  | commit eb863156fbcbce236c60dec0e90338edbd9de686 | ||||||
|  | Author: William Hubbs <w.d.hubbs@gmail.com> | ||||||
|  | Commit: William Hubbs <w.d.hubbs@gmail.com> | ||||||
|  |  | ||||||
|  |     version 0.40.3 | ||||||
|  |  | ||||||
|  | commit ac76b24b85d3767a9561b76ac0fee5569383a63a | ||||||
|  | Author: William Hubbs <w.d.hubbs@gmail.com> | ||||||
|  | Commit: William Hubbs <w.d.hubbs@gmail.com> | ||||||
|  |  | ||||||
|  |     Update ChangeLog | ||||||
|  |  | ||||||
|  | commit b8e57c693a973528799c9a5fdf86135b658dcce2 | ||||||
|  | Author: William Hubbs <w.d.hubbs@gmail.com> | ||||||
|  | Commit: William Hubbs <w.d.hubbs@gmail.com> | ||||||
|  |  | ||||||
|  |     init.d/agetty: set default respawn period to 60 seconds | ||||||
|  |      | ||||||
|  |     Without a respawn period setting, the supervisor will give up on | ||||||
|  |     respawning agetty after it is respawned respawn_max times. For most | ||||||
|  |     daemons giving up like this is reasonable, but not for agettys. Agettys | ||||||
|  |     should always be respawned unless they are respawning too fafst,. | ||||||
|  |      | ||||||
|  |     If an agetty is respawning faster than 10 times in 60 seconds, this | ||||||
|  |     seems to be too fast. | ||||||
|  |  | ||||||
|  | commit 5df12e24146cd091de71c77737c07eed5a14101f | ||||||
|  | Author: William Hubbs <w.d.hubbs@gmail.com> | ||||||
|  | Commit: William Hubbs <w.d.hubbs@gmail.com> | ||||||
|  |  | ||||||
|  |     supervise-daemon: fix busy loop | ||||||
|  |      | ||||||
|  |     This fixes #264. | ||||||
|  |  | ||||||
|  | commit 461df0c78b1b8a58bb272958dce4af39fc2549c0 | ||||||
|  | Author: William Hubbs <w.d.hubbs@gmail.com> | ||||||
|  | Commit: William Hubbs <w.d.hubbs@gmail.com> | ||||||
|  |  | ||||||
|  |     version 0.40.2 | ||||||
|  |  | ||||||
|  | commit cefae65392568afac83f64773b6ad33462791c38 | ||||||
|  | Author: William Hubbs <w.d.hubbs@gmail.com> | ||||||
|  | Commit: William Hubbs <w.d.hubbs@gmail.com> | ||||||
|  |  | ||||||
|  |     Update ChangeLog | ||||||
|  |  | ||||||
|  | commit 69fbd129938522cdd9b82fea2b83c857796a32af | ||||||
|  | Author: Alexander Zubkov <green@msu.ru> | ||||||
|  | Commit: William Hubbs <w.d.hubbs@gmail.com> | ||||||
|  |  | ||||||
|  |     supervise-daemon: redirect std{in,out,err} to /dev/null after demonizing | ||||||
|  |      | ||||||
|  |     This fixes #239. | ||||||
|  |  | ||||||
|  | commit 4aa5686d9037132b27d7554436738fa98e8e9057 | ||||||
|  | Author: William Hubbs <w.d.hubbs@gmail.com> | ||||||
|  | Commit: William Hubbs <w.d.hubbs@gmail.com> | ||||||
|  |  | ||||||
|  |     version 0.40.1 | ||||||
|  |  | ||||||
|  | commit ab6c8d56f155564f56d61553c4b1af9e7f63a9d2 | ||||||
|  | Author: William Hubbs <w.d.hubbs@gmail.com> | ||||||
|  | Commit: William Hubbs <w.d.hubbs@gmail.com> | ||||||
|  |  | ||||||
|  |     Update ChangeLog | ||||||
|  |  | ||||||
| commit fb4dd351c7ef2614076309d630e163ff963ac8bf | commit fb4dd351c7ef2614076309d630e163ff963ac8bf | ||||||
| Author: Austin English <austinenglish@gmail.com> | Author: Austin English <austinenglish@gmail.com> | ||||||
| Commit: William Hubbs <w.d.hubbs@gmail.com> | Commit: William Hubbs <w.d.hubbs@gmail.com> | ||||||
| @@ -1270,141 +1364,3 @@ Commit: William Hubbs <w.d.hubbs@gmail.com> | |||||||
|     This fixes #196. |     This fixes #196. | ||||||
|      |      | ||||||
|     [1] https://elkano.org/blog/manage-interface-bondings-sysfs-interface/ |     [1] https://elkano.org/blog/manage-interface-bondings-sysfs-interface/ | ||||||
|  |  | ||||||
| commit 7affff568a0aa83d732757c4699d4b94b7e3a9aa |  | ||||||
| Author: William Hubbs <w.d.hubbs@gmail.com> |  | ||||||
| Commit: William Hubbs <w.d.hubbs@gmail.com> |  | ||||||
|  |  | ||||||
|     init.d.examples: pid files always go in /var |  | ||||||
|      |  | ||||||
|     This removes the @VARBASE@ substitution since it is always translated to |  | ||||||
|     /var. |  | ||||||
|  |  | ||||||
| commit 4f750933fd8ef944be58bfeef071a8e35fc0c606 |  | ||||||
| Author: William Hubbs <w.d.hubbs@gmail.com> |  | ||||||
| Commit: William Hubbs <w.d.hubbs@gmail.com> |  | ||||||
|  |  | ||||||
|     procfs: remove the @sysconfdir@ reference |  | ||||||
|  |  | ||||||
| commit 50b69d564a8f89b8137bb6d9d53aac1e44f6c23c |  | ||||||
| Author: William Hubbs <w.d.hubbs@gmail.com> |  | ||||||
| Commit: William Hubbs <w.d.hubbs@gmail.com> |  | ||||||
|  |  | ||||||
|     hostname: replace @SYSCONFDIR@ references with /etc |  | ||||||
|      |  | ||||||
|     I do not know of any situation where /etc/hostname is at any other |  | ||||||
|     location. Also, this does not run on prefix. |  | ||||||
|  |  | ||||||
| commit eb18f4f3483b99705f944c7274b4a6b451716df7 |  | ||||||
| Author: William Hubbs <w.d.hubbs@gmail.com> |  | ||||||
| Commit: William Hubbs <w.d.hubbs@gmail.com> |  | ||||||
|  |  | ||||||
|     hwclock: use shell variables for configuration file path |  | ||||||
|      |  | ||||||
|     This removes a reference to @SYSCONFDIR@. |  | ||||||
|  |  | ||||||
| commit d5f3fe52c87928095bd2659823b985d231f0718c |  | ||||||
| Author: William Hubbs <w.d.hubbs@gmail.com> |  | ||||||
| Commit: William Hubbs <w.d.hubbs@gmail.com> |  | ||||||
|  |  | ||||||
|     sysctl: hard code paths for sysctl files on *bsd |  | ||||||
|      |  | ||||||
|     For *BSD,the sysctl*.conf files are always in /etc. |  | ||||||
|  |  | ||||||
| commit bb1bc6eeb73b3483a1ebdfc142a11240b58588cf |  | ||||||
| Author: William Hubbs <w.d.hubbs@gmail.com> |  | ||||||
| Commit: William Hubbs <w.d.hubbs@gmail.com> |  | ||||||
|  |  | ||||||
|     local: misc cleanups |  | ||||||
|      |  | ||||||
|     Remove references to @SYSCONFDIR@ since these can be calculated at |  | ||||||
|     runtime. |  | ||||||
|     Also style fixes. |  | ||||||
|  |  | ||||||
| commit 53844fd0dcd9741b5f19dee7c00787be7e904c3c |  | ||||||
| Author: William Hubbs <w.d.hubbs@gmail.com> |  | ||||||
| Commit: William Hubbs <w.d.hubbs@gmail.com> |  | ||||||
|  |  | ||||||
|     devfs: cleanup |  | ||||||
|      |  | ||||||
|     clean up local definitions. Also remove @SYSCONFDIR@ substitutions since |  | ||||||
|     they can be calculated at runtime. |  | ||||||
|  |  | ||||||
| commit 14938c29cefe869872b987f8e606da72024fa8bb |  | ||||||
| Author: bell07 <web.alexander@web.de> |  | ||||||
| Commit: William Hubbs <w.d.hubbs@gmail.com> |  | ||||||
|  |  | ||||||
|     net-online: wait for ping_test_host |  | ||||||
|      |  | ||||||
|     The script should wait till the ping host is available or timeout reached |  | ||||||
|     Closes : #179 |  | ||||||
|     Closes : #191 |  | ||||||
|  |  | ||||||
| commit 8bf501aaf2cb60b8ddf1b2fa2d1ba0ef970fb790 |  | ||||||
| Author: William Hubbs <w.d.hubbs@gmail.com> |  | ||||||
| Commit: William Hubbs <w.d.hubbs@gmail.com> |  | ||||||
|  |  | ||||||
|     network: use 'command -v ip' to test for the ip executable |  | ||||||
|      |  | ||||||
|     This is an improved test because it doesn't require the ip executable to be |  | ||||||
|     in a specific path. |  | ||||||
|  |  | ||||||
| commit 9d05f68b51d7b31634cde30a482ec0e3da3b1c21 |  | ||||||
| Author: William Hubbs <w.d.hubbs@gmail.com> |  | ||||||
| Commit: William Hubbs <w.d.hubbs@gmail.com> |  | ||||||
|  |  | ||||||
|     Do not use file tests in net-online |  | ||||||
|      |  | ||||||
|     https://unix.stackexchange.com/questions/252002/help-testing-special-file-in-sys-class-net |  | ||||||
|      |  | ||||||
|     This is for #189 |  | ||||||
|  |  | ||||||
| commit ee2524cd1d0305e207f7dfac52742a1d5e77ea4a |  | ||||||
| Author: William Hubbs <w.d.hubbs@gmail.com> |  | ||||||
| Commit: William Hubbs <w.d.hubbs@gmail.com> |  | ||||||
|  |  | ||||||
|     net-online: clean up quoting and test for existence |  | ||||||
|      |  | ||||||
|     This is for #178. |  | ||||||
|  |  | ||||||
| commit 5c81661d4758dea039860ae2481476a70e78ac47 |  | ||||||
| Author: Marcel Greter <marcel.greter@ocbnet.ch> |  | ||||||
| Commit: William Hubbs <w.d.hubbs@gmail.com> |  | ||||||
|  |  | ||||||
|     Gracefully handle unreadable /sys/class/net/dev/ nodes |  | ||||||
|      |  | ||||||
|     Fixes https://bugs.gentoo.org/629228 |  | ||||||
|     Fixes #189 |  | ||||||
|     Fixes #185 |  | ||||||
|     Fixes #178 |  | ||||||
|  |  | ||||||
| commit fb96c9c127dcfa932460b0e8a977ba5f7d26a418 |  | ||||||
| Author: William Hubbs <w.d.hubbs@gmail.com> |  | ||||||
| Commit: William Hubbs <w.d.hubbs@gmail.com> |  | ||||||
|  |  | ||||||
|     Make bash-completion and zsh-completion optional |  | ||||||
|  |  | ||||||
| commit 6c456f9383ab0000527b4363bc82fc17850aba18 |  | ||||||
| Author: William Hubbs <w.d.hubbs@gmail.com> |  | ||||||
| Commit: William Hubbs <w.d.hubbs@gmail.com> |  | ||||||
|  |  | ||||||
|     Add zsh-completion support |  | ||||||
|  |  | ||||||
| commit d220fc272337b216bff6ac781a7b6be4e6f3caee |  | ||||||
| Author: William Hubbs <w.d.hubbs@gmail.com> |  | ||||||
| Commit: William Hubbs <w.d.hubbs@gmail.com> |  | ||||||
|  |  | ||||||
|     add bash completion support |  | ||||||
|      |  | ||||||
|     This fixes #188. |  | ||||||
|  |  | ||||||
| commit a2447dfb420cbd97a65cc085404c031d42cb3dfb |  | ||||||
| Author: William Hubbs <w.d.hubbs@gmail.com> |  | ||||||
| Commit: William Hubbs <w.d.hubbs@gmail.com> |  | ||||||
|  |  | ||||||
|     rc-service: add --ifcrashed option |  | ||||||
|      |  | ||||||
|     This works like the other --if options. If the service is crashed, run |  | ||||||
|     the command. |  | ||||||
|      |  | ||||||
|     This fixes #154. |  | ||||||
|   | |||||||
| @@ -1,3 +1,3 @@ | |||||||
| NAME=		openrc | NAME=		openrc | ||||||
| VERSION=	0.40 | VERSION=	0.40.3 | ||||||
| PKG=		${NAME}-${VERSION} | PKG=		${NAME}-${VERSION} | ||||||
|   | |||||||
| @@ -12,6 +12,7 @@ | |||||||
| description="start agetty on a terminal line" | description="start agetty on a terminal line" | ||||||
| supervisor=supervise-daemon | supervisor=supervise-daemon | ||||||
| port="${RC_SVCNAME#*.}" | port="${RC_SVCNAME#*.}" | ||||||
|  | respawn_period="${respawn_period:-60}" | ||||||
| term_type="${term_type:-linux}" | term_type="${term_type:-linux}" | ||||||
| command=/sbin/agetty | command=/sbin/agetty | ||||||
| command_args_foreground="${agetty_options} ${port} ${baud} ${term_type}" | command_args_foreground="${agetty_options} ${port} ${baud} ${term_type}" | ||||||
|   | |||||||
| @@ -277,7 +277,6 @@ static RC_STRINGLIST *rc_config_kcl(RC_STRINGLIST *config) | |||||||
| 	char *tmp = NULL; | 	char *tmp = NULL; | ||||||
| 	char *value = NULL; | 	char *value = NULL; | ||||||
| 	size_t varlen = 0; | 	size_t varlen = 0; | ||||||
| 	size_t len = 0; |  | ||||||
|  |  | ||||||
| 	overrides = rc_stringlist_new(); | 	overrides = rc_stringlist_new(); | ||||||
|  |  | ||||||
| @@ -295,7 +294,6 @@ static RC_STRINGLIST *rc_config_kcl(RC_STRINGLIST *config) | |||||||
| 		} | 		} | ||||||
|  |  | ||||||
| 		if (value != NULL) { | 		if (value != NULL) { | ||||||
| 			len = varlen + strlen(value) + 2; |  | ||||||
| 			xasprintf(&tmp, "%s=%s", override->value, value); | 			xasprintf(&tmp, "%s=%s", override->value, value); | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
|   | |||||||
| @@ -133,7 +133,7 @@ void broadcast(char *text) | |||||||
| 	char *p; | 	char *p; | ||||||
| 	char *line = NULL; | 	char *line = NULL; | ||||||
| 	struct sigaction sa; | 	struct sigaction sa; | ||||||
| 	int fd; | 	volatile int fd; | ||||||
| 	FILE *tp; | 	FILE *tp; | ||||||
| 	int	flags; | 	int	flags; | ||||||
| 	char *term = NULL; | 	char *term = NULL; | ||||||
|   | |||||||
| @@ -160,9 +160,7 @@ static void sleep_no_interrupt(int seconds) | |||||||
|  |  | ||||||
| static void stop_shutdown(int sig) | static void stop_shutdown(int sig) | ||||||
| { | { | ||||||
| 	/* use the sig parameter so the compiler will not complain */ | 	(void) sig; | ||||||
| 	if (sig == SIGINT) |  | ||||||
| 		; |  | ||||||
| 	unlink(nologin_file); | 	unlink(nologin_file); | ||||||
| 	unlink(shutdown_pid); | 	unlink(shutdown_pid); | ||||||
| einfo("Shutdown canceled"); | einfo("Shutdown canceled"); | ||||||
|   | |||||||
| @@ -28,6 +28,7 @@ | |||||||
| #include <stdio.h> | #include <stdio.h> | ||||||
| #include <stdlib.h> | #include <stdlib.h> | ||||||
| #include <string.h> | #include <string.h> | ||||||
|  | #include <syslog.h> | ||||||
| #include <time.h> | #include <time.h> | ||||||
| #include <unistd.h> | #include <unistd.h> | ||||||
| #include <sys/stat.h> | #include <sys/stat.h> | ||||||
| @@ -270,8 +271,11 @@ int do_stop(const char *applet, const char *exec, const char *const *argv, | |||||||
| 			einfo("Would send signal %d to PID %d", sig, pi->pid); | 			einfo("Would send signal %d to PID %d", sig, pi->pid); | ||||||
| 			nkilled++; | 			nkilled++; | ||||||
| 		} else { | 		} else { | ||||||
| 			if (!quiet) | 			if (sig) { | ||||||
| 				ebeginv("Sending signal %d to PID %d", sig, pi->pid); | 				syslog(LOG_DEBUG, "Sending signal %d to PID %d", sig, pi->pid); | ||||||
|  | 				if (!quiet) | ||||||
|  | 					ebeginv("Sending signal %d to PID %d", sig, pi->pid); | ||||||
|  | 			} | ||||||
| 			errno = 0; | 			errno = 0; | ||||||
| 			killed = (kill(pi->pid, sig) == 0 || | 			killed = (kill(pi->pid, sig) == 0 || | ||||||
| 			    errno == ESRCH ? true : false); | 			    errno == ESRCH ? true : false); | ||||||
| @@ -279,6 +283,9 @@ int do_stop(const char *applet, const char *exec, const char *const *argv, | |||||||
| 				eendv(killed ? 0 : 1, | 				eendv(killed ? 0 : 1, | ||||||
| 				"%s: failed to send signal %d to PID %d: %s", | 				"%s: failed to send signal %d to PID %d: %s", | ||||||
| 				applet, sig, pi->pid, strerror(errno)); | 				applet, sig, pi->pid, strerror(errno)); | ||||||
|  | 			else if (!killed) | ||||||
|  | 				syslog(LOG_ERR, "Failed to send signal %d to PID %d: %s", | ||||||
|  | 						sig, pi->pid, strerror(errno)); | ||||||
| 			if (!killed) { | 			if (!killed) { | ||||||
| 				nkilled = -1; | 				nkilled = -1; | ||||||
| 			} else { | 			} else { | ||||||
| @@ -310,12 +317,18 @@ int run_stop_schedule(const char *applet, | |||||||
| 	if (!(pid > 0 || exec || uid || (argv && *argv))) | 	if (!(pid > 0 || exec || uid || (argv && *argv))) | ||||||
| 		return 0; | 		return 0; | ||||||
|  |  | ||||||
| 	if (exec) | 	if (exec) { | ||||||
| 		einfov("Will stop %s", exec); | 		einfov("Will stop %s", exec); | ||||||
| 	if (pid > 0) | 		syslog(LOG_DEBUG, "Will stop %s", exec); | ||||||
|  | 	} | ||||||
|  | 	if (pid > 0) { | ||||||
| 		einfov("Will stop PID %d", pid); | 		einfov("Will stop PID %d", pid); | ||||||
| 	if (uid) | 		syslog(LOG_DEBUG, "Will stop PID %d", pid); | ||||||
|  | 	} | ||||||
|  | 	if (uid) { | ||||||
| 		einfov("Will stop processes owned by UID %d", uid); | 		einfov("Will stop processes owned by UID %d", uid); | ||||||
|  | 		syslog(LOG_DEBUG, "Will stop processes owned by UID %d", uid); | ||||||
|  | 	} | ||||||
| 	if (argv && *argv) { | 	if (argv && *argv) { | ||||||
| 		einfovn("Will stop processes of `"); | 		einfovn("Will stop processes of `"); | ||||||
| 		if (rc_yesno(getenv("EINFO_VERBOSE"))) { | 		if (rc_yesno(getenv("EINFO_VERBOSE"))) { | ||||||
|   | |||||||
| @@ -184,13 +184,22 @@ static void re_exec_supervisor(void) | |||||||
| static void handle_signal(int sig) | static void handle_signal(int sig) | ||||||
| { | { | ||||||
| 	int serrno = errno; | 	int serrno = errno; | ||||||
|  | 	pid_t pid; | ||||||
|  |  | ||||||
| 	switch (sig) { | 	switch (sig) { | ||||||
| 	case SIGALRM: | 	case SIGALRM: | ||||||
| 		do_healthcheck = 1; | 		do_healthcheck = 1; | ||||||
| 		break; | 		break; | ||||||
| 	case SIGCHLD: | 	case SIGCHLD: | ||||||
| 		while (waitpid((pid_t)(-1), NULL, WNOHANG) > 0) {} | 		if (exiting) | ||||||
|  | 			while (waitpid((pid_t)(-1), NULL, WNOHANG) > 0) {} | ||||||
|  | 		else { | ||||||
|  | 			while ((pid = waitpid((pid_t)(-1), NULL, WNOHANG|WNOWAIT)) > 0) { | ||||||
|  | 				if (pid == child_pid) | ||||||
|  | 					break; | ||||||
|  | 				pid = waitpid(pid, NULL, WNOHANG); | ||||||
|  | 			} | ||||||
|  | 		} | ||||||
| 		break; | 		break; | ||||||
| 	case SIGTERM: | 	case SIGTERM: | ||||||
| 		exiting = 1; | 		exiting = 1; | ||||||
| @@ -258,6 +267,56 @@ static char *make_cmdline(char **argv) | |||||||
| 	return cmdline; | 	return cmdline; | ||||||
| } | } | ||||||
|  |  | ||||||
|  | static pid_t exec_command(const char *cmd) | ||||||
|  | { | ||||||
|  | 	char *file; | ||||||
|  | 	pid_t pid = -1; | ||||||
|  | 	sigset_t full; | ||||||
|  | 	sigset_t old; | ||||||
|  | 	struct sigaction sa; | ||||||
|  |  | ||||||
|  | 	file = rc_service_resolve(svcname); | ||||||
|  | 	if (!exists(file)) { | ||||||
|  | 		free(file); | ||||||
|  | 		return 0; | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	/* We need to block signals until we have forked */ | ||||||
|  | 	memset(&sa, 0, sizeof (sa)); | ||||||
|  | 	sa.sa_handler = SIG_DFL; | ||||||
|  | 	sigemptyset(&sa.sa_mask); | ||||||
|  | 	sigfillset(&full); | ||||||
|  | 	sigprocmask(SIG_SETMASK, &full, &old); | ||||||
|  |  | ||||||
|  | 	pid = fork(); | ||||||
|  | 	if (pid == 0) { | ||||||
|  | 		/* Restore default handlers */ | ||||||
|  | 		sigaction(SIGCHLD, &sa, NULL); | ||||||
|  | 		sigaction(SIGHUP, &sa, NULL); | ||||||
|  | 		sigaction(SIGINT, &sa, NULL); | ||||||
|  | 		sigaction(SIGQUIT, &sa, NULL); | ||||||
|  | 		sigaction(SIGTERM, &sa, NULL); | ||||||
|  | 		sigaction(SIGUSR1, &sa, NULL); | ||||||
|  | 		sigaction(SIGWINCH, &sa, NULL); | ||||||
|  |  | ||||||
|  | 		/* Unmask signals */ | ||||||
|  | 		sigprocmask(SIG_SETMASK, &old, NULL); | ||||||
|  |  | ||||||
|  | 		/* Safe to run now */ | ||||||
|  | 		execl(file, file, cmd, (char *) NULL); | ||||||
|  | 		syslog(LOG_ERR, "unable to exec `%s': %s\n", | ||||||
|  | 		    file, strerror(errno)); | ||||||
|  | 		_exit(EXIT_FAILURE); | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	if (pid == -1) | ||||||
|  | 		syslog(LOG_ERR, "fork: %s\n",strerror (errno)); | ||||||
|  |  | ||||||
|  | 	sigprocmask(SIG_SETMASK, &old, NULL); | ||||||
|  | 	free(file); | ||||||
|  | 	return pid; | ||||||
|  | } | ||||||
|  |  | ||||||
| static void child_process(char *exec, char **argv) | static void child_process(char *exec, char **argv) | ||||||
| { | { | ||||||
| 	RC_STRINGLIST *env_list; | 	RC_STRINGLIST *env_list; | ||||||
| @@ -498,18 +557,18 @@ static void supervisor(char *exec, char **argv) | |||||||
| 		alarm(healthcheckdelay); | 		alarm(healthcheckdelay); | ||||||
| 	else if (healthchecktimer) | 	else if (healthchecktimer) | ||||||
| 		alarm(healthchecktimer); | 		alarm(healthchecktimer); | ||||||
|  fifo_fd = open(fifopath, O_RDONLY |O_NONBLOCK); |  | ||||||
|  failing = 0; |  failing = 0; | ||||||
| 	while (!exiting) { | 	while (!exiting) { | ||||||
| 		healthcheck_respawn = 0; | 		healthcheck_respawn = 0; | ||||||
| 		wait_pid = waitpid(child_pid, &i, WNOHANG); |  	fifo_fd = open(fifopath, O_RDONLY); | ||||||
| 		memset(buf, 0, sizeof(buf)); | 		if (fifo_fd > 0) { | ||||||
| 		if (fifo_fd >= 0) { | 			memset(buf, 0, sizeof(buf)); | ||||||
| 			count = read(fifo_fd, buf, sizeof(buf) - 1); | 			count = read(fifo_fd, buf, sizeof(buf) - 1); | ||||||
|  | 			close(fifo_fd); | ||||||
| 			if (count != -1) | 			if (count != -1) | ||||||
| 				buf[count] = 0; | 				buf[count] = 0; | ||||||
| 		} | 			if (count == 0) | ||||||
| 		if (strlen(buf) > 0) { | 				continue; | ||||||
| 			syslog(LOG_DEBUG, "Received %s from fifo", buf); | 			syslog(LOG_DEBUG, "Received %s from fifo", buf); | ||||||
| 			if (strncasecmp(buf, "sig", 3) == 0) { | 			if (strncasecmp(buf, "sig", 3) == 0) { | ||||||
| 				if ((sscanf(buf, "%s %d", cmd, &sig_send) == 2) | 				if ((sscanf(buf, "%s %d", cmd, &sig_send) == 2) | ||||||
| @@ -521,18 +580,19 @@ static void supervisor(char *exec, char **argv) | |||||||
| 								sig_send, child_pid); | 								sig_send, child_pid); | ||||||
| 				} | 				} | ||||||
| 			} | 			} | ||||||
|  | 			continue; | ||||||
| 		} | 		} | ||||||
| 		if (do_healthcheck) { | 		if (do_healthcheck) { | ||||||
| 			do_healthcheck = 0; | 			do_healthcheck = 0; | ||||||
| 			alarm(0); | 			alarm(0); | ||||||
| 			syslog(LOG_DEBUG, "running health check for %s", svcname); | 			syslog(LOG_DEBUG, "running health check for %s", svcname); | ||||||
| 			health_pid = exec_service(svcname, "healthcheck"); | 			health_pid = exec_command("healthcheck"); | ||||||
| 			health_status = rc_waitpid(health_pid); | 			health_status = rc_waitpid(health_pid); | ||||||
| 			if (WIFEXITED(health_status) && WEXITSTATUS(health_status) == 0) | 			if (WIFEXITED(health_status) && WEXITSTATUS(health_status) == 0) | ||||||
| 				alarm(healthchecktimer); | 				alarm(healthchecktimer); | ||||||
| 			else { | 			else { | ||||||
| 				syslog(LOG_WARNING, "health check for %s failed", svcname); | 				syslog(LOG_WARNING, "health check for %s failed", svcname); | ||||||
| 				health_pid = exec_service(svcname, "unhealthy"); | 				health_pid = exec_command("unhealthy"); | ||||||
| 				rc_waitpid(health_pid); | 				rc_waitpid(health_pid); | ||||||
| 				syslog(LOG_INFO, "stopping %s, pid %d", exec, child_pid); | 				syslog(LOG_INFO, "stopping %s, pid %d", exec, child_pid); | ||||||
| 				nkilled = run_stop_schedule(applet, NULL, NULL, child_pid, 0, | 				nkilled = run_stop_schedule(applet, NULL, NULL, child_pid, 0, | ||||||
| @@ -553,6 +613,7 @@ static void supervisor(char *exec, char **argv) | |||||||
| 				syslog(LOG_INFO, "killed %d processes", nkilled); | 				syslog(LOG_INFO, "killed %d processes", nkilled); | ||||||
| 			continue; | 			continue; | ||||||
| 		} | 		} | ||||||
|  | 		wait_pid = waitpid(child_pid, &i, WNOHANG); | ||||||
| 		if (wait_pid == child_pid) { | 		if (wait_pid == child_pid) { | ||||||
| 			if (WIFEXITED(i)) | 			if (WIFEXITED(i)) | ||||||
| 				syslog(LOG_WARNING, "%s, pid %d, exited with return code %d", | 				syslog(LOG_WARNING, "%s, pid %d, exited with return code %d", | ||||||
| @@ -982,6 +1043,9 @@ int main(int argc, char **argv) | |||||||
| 		tty_fd = open("/dev/tty", O_RDWR); | 		tty_fd = open("/dev/tty", O_RDWR); | ||||||
| #endif | #endif | ||||||
| 		devnull_fd = open("/dev/null", O_RDWR); | 		devnull_fd = open("/dev/null", O_RDWR); | ||||||
|  | 		dup2(devnull_fd, STDIN_FILENO); | ||||||
|  | 		dup2(devnull_fd, STDOUT_FILENO); | ||||||
|  | 		dup2(devnull_fd, STDERR_FILENO); | ||||||
| 		child_pid = fork(); | 		child_pid = fork(); | ||||||
| 		if (child_pid == -1) | 		if (child_pid == -1) | ||||||
| 			eerrorx("%s: fork: %s", applet, strerror(errno)); | 			eerrorx("%s: fork: %s", applet, strerror(errno)); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user