File zabbix-2.2.3-run_foreground-v3.patch of Package zabbix

Index: include/common.h
===================================================================
--- include/common.h.orig	2014-10-24 13:54:43.000000000 +0200
+++ include/common.h	2014-11-18 23:48:31.772528466 +0100
@@ -1067,4 +1067,7 @@ int	parse_serveractive_element(char *str
 #define ZBX_SESSION_ACTIVE	0
 #define ZBX_SESSION_PASSIVE	1
 
+#define ZBX_RUN_BACKGROUND      0
+#define ZBX_RUN_FOREGROUND      1
+
 #endif
Index: include/daemon.h
===================================================================
--- include/daemon.h.orig	2014-10-24 13:54:43.000000000 +0200
+++ include/daemon.h	2014-11-18 23:48:31.775528804 +0100
@@ -30,7 +30,7 @@ extern char	*CONFIG_PID_FILE;
 
 #include "threads.h"
 
-int	daemon_start(int allow_root);
+int	daemon_start(int allow_root, int run_foreground);
 void	daemon_stop();
 
 int	zbx_sigusr_send(zbx_task_t task);
@@ -38,6 +38,6 @@ int	zbx_sigusr_send(zbx_task_t task);
 #define ZBX_IS_RUNNING()	1
 #define ZBX_DO_EXIT()
 
-#define START_MAIN_ZABBIX_ENTRY(a)	daemon_start(a)
+#define START_MAIN_ZABBIX_ENTRY(a, f)	daemon_start(a, f)
 
 #endif	/* ZABBIX_DAEMON_H */
Index: src/libs/zbxnix/daemon.c
===================================================================
--- src/libs/zbxnix/daemon.c.orig	2014-10-24 13:54:43.000000000 +0200
+++ src/libs/zbxnix/daemon.c	2014-11-18 23:48:31.776528916 +0100
@@ -134,13 +134,14 @@ static void	set_daemon_signal_handlers()
  * Purpose: init process as daemon                                            *
  *                                                                            *
  * Parameters: allow_root - allow root permission for application             *
+ *             run_foreground - should it close its controling tty            *
  *                                                                            *
  * Author: Alexei Vladishev                                                   *
  *                                                                            *
  * Comments: it doesn't allow running under 'root' if allow_root is zero      *
  *                                                                            *
  ******************************************************************************/
-int	daemon_start(int allow_root)
+int	daemon_start(int allow_root, int run_foreground)
 {
 	pid_t			pid;
 	struct passwd		*pwd;
@@ -186,15 +187,20 @@ int	daemon_start(int allow_root)
 #endif
 	}
 
-	if (0 != (pid = zbx_fork()))
-		exit(0);
+	if ( ZBX_RUN_FOREGROUND != run_foreground)
+		if (0 != (pid = zbx_fork()))
+			exit(0);
 
 	setsid();
 
 	signal(SIGHUP, SIG_IGN);
 
-	if (0 != (pid = zbx_fork()))
-		exit(0);
+	if ( ZBX_RUN_FOREGROUND == run_foreground) {
+		zabbix_log(LOG_LEVEL_INFORMATION, "Running in foreground...");
+	} else {
+		if (0 != (pid = zbx_fork()))
+			exit(0);
+	}
 
 	if (-1 == chdir("/"))	/* this is to eliminate warning: ignoring return value of chdir */
 		assert(0);
Index: src/zabbix_agent/zabbix_agentd.c
===================================================================
--- src/zabbix_agent/zabbix_agentd.c.orig	2014-10-24 13:54:43.000000000 +0200
+++ src/zabbix_agent/zabbix_agentd.c	2014-11-18 23:48:31.778529142 +0100
@@ -58,6 +58,8 @@ const char	*progname = NULL;
 	static char	DEFAULT_CONFIG_FILE[]	= SYSCONFDIR "/zabbix_agentd.conf";
 #endif
 
+int CONFIG_FOREGROUND = ZBX_RUN_BACKGROUND;
+
 /* application TITLE */
 const char	title_message[] = APPLICATION_NAME
 #if defined(_WIN64)
@@ -77,7 +79,7 @@ const char	syslog_app_name[] = "zabbix_a
 
 /* application USAGE message */
 const char	usage_message[] =
-	"[-Vhp]"
+	"[-Vhfp]"
 #ifdef _WINDOWS
 	" [-idsx] [-m]"
 #endif
@@ -88,6 +90,7 @@ const char	usage_message[] =
 const char	*help_message[] = {
 	"Options:",
 	"",
+	"  -f --foreground            Run in foreground don't fork",
 	"  -c --config <config-file>  Absolute path to the configuration file",
 	"  -p --print                 Print known items and exit",
 	"  -t --test <item key>       Test specified item and exit",
@@ -112,6 +115,7 @@ const char	*help_message[] = {
 /* COMMAND LINE OPTIONS */
 static struct zbx_option	longopts[] =
 {
+	{"foreground",		0,	NULL,	'f'},
 	{"config",		1,	NULL,	'c'},
 	{"help",		0,	NULL,	'h'},
 	{"version",		0,	NULL,	'V'},
@@ -130,7 +134,7 @@ static struct zbx_option	longopts[] =
 };
 
 static char	shortopts[] =
-	"c:hVpt:"
+	"c:hfVpt:"
 #ifdef _WINDOWS
 	"idsxm"
 #endif
@@ -164,6 +168,9 @@ static void	parse_commandline(int argc,
 	{
 		switch (ch)
 		{
+			case 'f':
+				CONFIG_FOREGROUND = ZBX_RUN_FOREGROUND;
+				break;
 			case 'c':
 				CONFIG_FILE = strdup(zbx_optarg);
 				break;
@@ -839,7 +846,7 @@ int	main(int argc, char **argv)
 			break;
 	}
 
-	START_MAIN_ZABBIX_ENTRY(CONFIG_ALLOW_ROOT);
+	START_MAIN_ZABBIX_ENTRY(CONFIG_ALLOW_ROOT, CONFIG_FOREGROUND);
 
 	exit(SUCCEED);
 }
Index: src/zabbix_proxy/proxy.c
===================================================================
--- src/zabbix_proxy/proxy.c.orig	2014-10-24 13:54:43.000000000 +0200
+++ src/zabbix_proxy/proxy.c	2014-11-18 23:48:31.781529480 +0100
@@ -65,6 +65,7 @@ const char	usage_message[] = "[-hV] [-c
 
 const char	*help_message[] = {
 	"Options:",
+	"  -f --foreground                 Run in foreground don't fork",
 	"  -c --config <file>              Absolute path to the configuration file",
 	"  -R --runtime-control <option>   Perform administrative functions",
 	"",
@@ -82,6 +83,7 @@ const char	*help_message[] = {
 /* long options */
 static struct zbx_option	longopts[] =
 {
+	{"foreground",		0,	NULL,	'f'},
 	{"config",		1,	NULL,	'c'},
 	{"runtime-control",	1,	NULL,	'R'},
 	{"help",		0,	NULL,	'h'},
@@ -90,7 +92,7 @@ static struct zbx_option	longopts[] =
 };
 
 /* short options */
-static char	shortopts[] = "c:n:hVR:";
+static char	shortopts[] = "c:n:fhVR:";
 
 /* end of COMMAND LINE OPTIONS */
 
@@ -195,6 +197,8 @@ int	CONFIG_LOG_SLOW_QUERIES		= 0;	/* ms;
 /* zabbix server startup time */
 int	CONFIG_SERVER_STARTUP_TIME	= 0;
 
+int	CONFIG_FOREGROUND		= ZBX_RUN_BACKGROUND;
+
 char	*CONFIG_LOAD_MODULE_PATH	= NULL;
 char	**CONFIG_LOAD_MODULE		= NULL;
 
@@ -539,6 +543,9 @@ int	main(int argc, char **argv)
 	{
 		switch (ch)
 		{
+			case 'f':
+				CONFIG_FOREGROUND = ZBX_RUN_FOREGROUND;
+				break;
 			case 'c':
 				CONFIG_FILE = zbx_strdup(CONFIG_FILE, zbx_optarg);
 				break;
@@ -581,7 +588,7 @@ int	main(int argc, char **argv)
 	init_ipmi_handler();
 #endif
 
-	return daemon_start(CONFIG_ALLOW_ROOT);
+	return daemon_start(CONFIG_ALLOW_ROOT, CONFIG_FOREGROUND);
 }
 
 int	MAIN_ZABBIX_ENTRY()
Index: src/zabbix_server/server.c
===================================================================
--- src/zabbix_server/server.c.orig	2014-10-24 13:54:43.000000000 +0200
+++ src/zabbix_server/server.c	2014-11-18 23:48:31.782529592 +0100
@@ -71,6 +71,7 @@ const char	usage_message[] = "[-hV] [-c
 
 const char	*help_message[] = {
 	"Options:",
+	"  -f --foreground                 Run in foreground don't fork",
 	"  -c --config <file>              Absolute path to the configuration file",
 	"  -n --new-nodeid <nodeid>        Convert database data to new nodeid",
 	"  -R --runtime-control <option>   Perform administrative functions",
@@ -89,6 +90,7 @@ const char	*help_message[] = {
 /* long options */
 static struct zbx_option	longopts[] =
 {
+	{"foreground",		0,	NULL,	'f'},
 	{"config",		1,	NULL,	'c'},
 	{"new-nodeid",		1,	NULL,	'n'},
 	{"runtime-control",	1,	NULL,	'R'},
@@ -98,7 +100,7 @@ static struct zbx_option	longopts[] =
 };
 
 /* short options */
-static char	shortopts[] = "c:n:hVR:";
+static char	shortopts[] = "c:n:fhVR:";
 
 /* end of COMMAND LINE OPTIONS */
 
@@ -201,6 +203,8 @@ char	**CONFIG_LOAD_MODULE		= NULL;
 
 int	CONFIG_SNMP_BULK_REQUESTS	= 1;
 
+int	CONFIG_FOREGROUND		= ZBX_RUN_BACKGROUND;
+
 /* mutex for node syncs */
 ZBX_MUTEX	node_sync_access;
 
@@ -508,6 +512,9 @@ int	main(int argc, char **argv)
 	{
 		switch (ch)
 		{
+			case 'f':
+				CONFIG_FOREGROUND = ZBX_RUN_FOREGROUND;
+				break;
 			case 'c':
 				CONFIG_FILE = zbx_strdup(CONFIG_FILE, zbx_optarg);
 				break;
@@ -563,7 +570,7 @@ int	main(int argc, char **argv)
 			break;
 	}
 
-	return daemon_start(CONFIG_ALLOW_ROOT);
+	return daemon_start(CONFIG_ALLOW_ROOT, CONFIG_FOREGROUND);
 }
 
 int	MAIN_ZABBIX_ENTRY()
openSUSE Build Service is sponsored by