Index: include/common.h
===================================================================
--- include/common.h.orig	2015-10-15 17:57:03.000000000 +0200
+++ include/common.h	2015-11-02 17:59:04.779840013 +0100
@@ -1109,6 +1109,9 @@ int	zbx_strcmp_null(const char *s1, cons
 #define ZBX_SESSION_ACTIVE	0
 #define ZBX_SESSION_PASSIVE	1
 
+#define ZBX_RUN_BACKGROUND	0
+#define ZBX_RUN_FOREGROUND	1
+
 char	*zbx_dyn_escape_shell_single_quote(const char *text);
 
 #define ZBX_DO_NOT_SEND_RESPONSE	0
Index: include/daemon.h
===================================================================
--- include/daemon.h.orig	2015-10-15 17:57:03.000000000 +0200
+++ include/daemon.h	2015-11-02 17:59:04.779840013 +0100
@@ -28,7 +28,7 @@ extern char	*CONFIG_PID_FILE;
 
 #include "threads.h"
 
-int	daemon_start(int allow_root, const char *user);
+int	daemon_start(int allow_root, const char *user, int run_foreground);
 void	daemon_stop(void);
 
 int	zbx_sigusr_send(int flags);
@@ -36,6 +36,6 @@ int	zbx_sigusr_send(int flags);
 #define ZBX_IS_RUNNING()	1
 #define ZBX_DO_EXIT()
 
-#define START_MAIN_ZABBIX_ENTRY(a, u)	daemon_start(a, u)
+#define START_MAIN_ZABBIX_ENTRY(a, u, f)	daemon_start(a, u, f)
 
 #endif	/* ZABBIX_DAEMON_H */
Index: src/zabbix_server/server.c
===================================================================
--- src/zabbix_server/server.c.orig	2015-10-15 17:57:03.000000000 +0200
+++ src/zabbix_server/server.c	2015-11-02 17:59:04.779840013 +0100
@@ -66,6 +66,7 @@ const char	title_message[] = "zabbix_ser
 const char	syslog_app_name[] = "zabbix_server";
 const char	*usage_message[] = {
 	"[-c config-file]", NULL,
+	"[-c config-file]", "-f", NULL,
 	"[-c config-file]", "-R runtime-option", NULL,
 	"-h", NULL,
 	"-V", NULL,
@@ -78,6 +79,7 @@ const char	*help_message[] = {
 	"Options:",
 	"  -c --config config-file        Absolute path to the configuration file",
 	"                                 (default: \"" DEFAULT_CONFIG_FILE "\")",
+	"  -f --foreground                Run in foreground don't fork",
 	"  -R --runtime-control runtime-option   Perform administrative functions",
 	"",
 	"    Runtime control options:",
@@ -103,6 +105,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'},
@@ -111,7 +114,7 @@ static struct zbx_option	longopts[] =
 };
 
 /* short options */
-static char	shortopts[] = "c:hVR:";
+static char	shortopts[] = "c:fhVR:";
 
 /* end of COMMAND LINE OPTIONS */
 
@@ -210,6 +213,7 @@ char	*CONFIG_LOAD_MODULE_PATH	= NULL;
 char	**CONFIG_LOAD_MODULE		= NULL;
 
 char	*CONFIG_USER			= NULL;
+int	CONFIG_FOREGROUND		= ZBX_RUN_BACKGROUND;
 
 /* web monitoring */
 char	*CONFIG_SSL_CA_LOCATION		= NULL;
@@ -674,6 +678,9 @@ int	main(int argc, char **argv)
 	{
 		switch (ch)
 		{
+			case 'f':
+				CONFIG_FOREGROUND = ZBX_RUN_FOREGROUND;
+				break;
 			case 'c':
 				opt_c++;
 				if (NULL == CONFIG_FILE)
@@ -738,7 +745,7 @@ int	main(int argc, char **argv)
 #ifdef HAVE_OPENIPMI
 	init_ipmi_handler();
 #endif
-	return daemon_start(CONFIG_ALLOW_ROOT, CONFIG_USER);
+	return daemon_start(CONFIG_ALLOW_ROOT, CONFIG_USER, CONFIG_FOREGROUND);
 }
 
 int	MAIN_ZABBIX_ENTRY()
Index: src/zabbix_agent/zabbix_agentd.c
===================================================================
--- src/zabbix_agent/zabbix_agentd.c.orig	2015-10-15 17:57:04.000000000 +0200
+++ src/zabbix_agent/zabbix_agentd.c	2015-11-02 17:59:30.327164799 +0100
@@ -64,6 +64,8 @@ const char	*progname = NULL;
 #	define DEFAULT_CONFIG_FILE	SYSCONFDIR "/zabbix_agentd.conf"
 #endif
 
+int CONFIG_FOREGROUND = ZBX_RUN_BACKGROUND;
+
 /* application TITLE */
 const char	title_message[] = "zabbix_agentd"
 #if defined(_WIN64)
@@ -86,11 +88,13 @@ const char	*usage_message[] = {
 	"[-c config-file]", NULL,
 	"[-c config-file]", "-p", NULL,
 	"[-c config-file]", "-t item-key", NULL,
+	"[-c config-file]", "-f", NULL,
 #ifdef _WINDOWS
 	"[-c config-file]", "-i", "[-m]", NULL,
 	"[-c config-file]", "-d", "[-m]", NULL,
 	"[-c config-file]", "-s", "[-m]", NULL,
 	"[-c config-file]", "-x", "[-m]", NULL,
+	"[-c config-file]", "-f", "[-m]", NULL,
 #else
 	"[-c config-file]", "-R runtime-option", NULL,
 #endif
@@ -109,6 +113,7 @@ const char	*help_message[] = {
 	"                                 (default: \"" DEFAULT_CONFIG_FILE "\")",
 	"  -p --print                     Print known items and exit",
 	"  -t --test item-key             Test specified item and exit",
+	"  -f --foreground                Run in foreground don't fork",
 #ifdef _WINDOWS
 	"  -m --multiple-agents           For -i -d -s -x functions service name will",
 	"                                 include Hostname parameter specified in",
@@ -151,6 +156,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'},
@@ -171,7 +177,7 @@ static struct zbx_option	longopts[] =
 };
 
 static char	shortopts[] =
-	"c:hVpt:"
+	"c:hfVpt:"
 #ifndef _WINDOWS
 	"R:"
 #else
@@ -272,6 +278,9 @@ static int	parse_commandline(int argc, c
 
 		switch (ch)
 		{
+			case 'f':
+				CONFIG_FOREGROUND = ZBX_RUN_FOREGROUND;
+				break;
 			case 'c':
 				if (NULL == CONFIG_FILE)
 					CONFIG_FILE = strdup(zbx_optarg);
@@ -1144,7 +1153,7 @@ int	main(int argc, char **argv)
 			break;
 	}
 
-	START_MAIN_ZABBIX_ENTRY(CONFIG_ALLOW_ROOT, CONFIG_USER);
+	START_MAIN_ZABBIX_ENTRY(CONFIG_ALLOW_ROOT, CONFIG_USER, CONFIG_FOREGROUND);
 
 	exit(EXIT_SUCCESS);
 }
Index: src/libs/zbxnix/daemon.c
===================================================================
--- src/libs/zbxnix/daemon.c.orig	2015-10-15 17:57:03.000000000 +0200
+++ src/libs/zbxnix/daemon.c	2015-11-02 17:59:04.779840013 +0100
@@ -284,16 +284,17 @@ static void	set_daemon_signal_handlers(v
  *                                                                            *
  * Purpose: init process as daemon                                            *
  *                                                                            *
- * Parameters: allow_root - allow root permission for application             *
- *             user       - user on the system to which to drop the           *
- *                          privileges                                        *
+ * Parameters: allow_root     - allow root permission for application         *
+ *             user           - user on the system to which to drop the       *
+ *                              privileges                                    *
+ *             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, const char *user)
+int	daemon_start(int allow_root, const char *user, int run_foreground)
 {
 	pid_t		pid;
 	struct passwd	*pwd;
@@ -348,15 +349,22 @@ int	daemon_start(int allow_root, const c
 #endif
 	}
 
-	if (0 != (pid = zbx_fork()))
-		exit(EXIT_SUCCESS);
+	if ( ZBX_RUN_FOREGROUND != run_foreground)
+		if (0 != (pid = zbx_fork()))
+			exit(EXIT_SUCCESS);
 
 	setsid();
 
 	signal(SIGHUP, SIG_IGN);
 
-	if (0 != (pid = zbx_fork()))
-		exit(EXIT_SUCCESS);
+	if ( ZBX_RUN_FOREGROUND == run_foreground) {
+		zabbix_log(LOG_LEVEL_INFORMATION, "Running in foreground...");
+	} else {
+		if (0 != (pid = zbx_fork()))
+			exit(EXIT_SUCCESS);
+	}
+
+
 
 	if (-1 == chdir("/"))	/* this is to eliminate warning: ignoring return value of chdir */
 		assert(0);
Index: src/zabbix_proxy/proxy.c
===================================================================
--- src/zabbix_proxy/proxy.c.orig	2015-10-15 17:57:03.000000000 +0200
+++ src/zabbix_proxy/proxy.c	2015-11-02 17:59:04.779840013 +0100
@@ -62,6 +62,7 @@ const char	title_message[] = "zabbix_pro
 const char	syslog_app_name[] = "zabbix_proxy";
 const char	*usage_message[] = {
 	"[-c config-file]", NULL,
+	"[-c config-file]", "-f", NULL,
 	"[-c config-file]", "-R runtime-option", NULL,
 	"-h", NULL,
 	"-V", NULL,
@@ -75,6 +76,7 @@ const char	*help_message[] = {
 	"Options:",
 	"  -c --config config-file        Absolute path to the configuration file",
 	"                                 (default: \"" DEFAULT_CONFIG_FILE "\")",
+	"  -f --foreground Run in foreground don't fork",
 	"  -R --runtime-control runtime-option   Perform administrative functions",
 	"",
 	"    Runtime control options:",
@@ -100,6 +102,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'},
@@ -108,7 +111,7 @@ static struct zbx_option	longopts[] =
 };
 
 /* short options */
-static char	shortopts[] = "c:hVR:";
+static char	shortopts[] = "c:fhVR:";
 
 /* end of COMMAND LINE OPTIONS */
 
@@ -216,6 +219,7 @@ char	*CONFIG_LOAD_MODULE_PATH	= NULL;
 char	**CONFIG_LOAD_MODULE		= NULL;
 
 char	*CONFIG_USER			= NULL;
+int	CONFIG_FOREGROUND		= ZBX_RUN_BACKGROUND;
 
 /* web monitoring */
 char	*CONFIG_SSL_CA_LOCATION		= NULL;
@@ -721,6 +725,9 @@ int	main(int argc, char **argv)
 	{
 		switch (ch)
 		{
+			case 'f':
+				CONFIG_FOREGROUND = ZBX_RUN_FOREGROUND;
+				break;
 			case 'c':
 				opt_c++;
 				if (NULL == CONFIG_FILE)
@@ -785,7 +792,7 @@ int	main(int argc, char **argv)
 #ifdef HAVE_OPENIPMI
 	init_ipmi_handler();
 #endif
-	return daemon_start(CONFIG_ALLOW_ROOT, CONFIG_USER);
+	return daemon_start(CONFIG_ALLOW_ROOT, CONFIG_USER, CONFIG_FOREGROUND);
 }
 
 int	MAIN_ZABBIX_ENTRY()
