Index: include/common.h
===================================================================
--- include/common.h	(revision 45170)
+++ include/common.h	(working copy)
@@ -1026,4 +1026,7 @@
 #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	(revision 45170)
+++ include/daemon.h	(working copy)
@@ -28,7 +28,7 @@
 
 #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();
 
 int	zbx_sigusr_send(zbx_task_t task);
@@ -36,6 +36,6 @@
 #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/libs/zbxnix/daemon.c
===================================================================
--- src/libs/zbxnix/daemon.c	(revision 45170)
+++ src/libs/zbxnix/daemon.c	(working copy)
@@ -135,6 +135,7 @@
  *                                                                            *
  * 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                                                   *
  *                                                                            *
@@ -141,7 +142,7 @@
  * 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;
@@ -196,16 +197,23 @@
 #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_agent/zabbix_agentd.c
===================================================================
--- src/zabbix_agent/zabbix_agentd.c	(revision 45170)
+++ src/zabbix_agent/zabbix_agentd.c	(working copy)
@@ -58,6 +58,8 @@
 	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 @@
 
 /* application USAGE message */
 const char	usage_message[] =
-	"[-Vhp]"
+	"[-Vhfp]"
 #ifdef _WINDOWS
 	" [-idsx] [-m]"
 #endif
@@ -88,6 +90,7 @@
 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 @@
 /* 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 char	shortopts[] =
-	"c:hVpt:"
+	"c:hfVpt:"
 #ifdef _WINDOWS
 	"idsxm"
 #endif
@@ -164,6 +168,9 @@
 	{
 		switch (ch)
 		{
+			case 'f':
+				CONFIG_FOREGROUND = ZBX_RUN_FOREGROUND;
+				break;
 			case 'c':
 				CONFIG_FILE = strdup(zbx_optarg);
 				break;
@@ -851,7 +858,7 @@
 			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/zabbix_proxy/proxy.c
===================================================================
--- src/zabbix_proxy/proxy.c	(revision 45170)
+++ src/zabbix_proxy/proxy.c	(working copy)
@@ -65,6 +65,7 @@
 
 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 @@
 /* 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 @@
 };
 
 /* short options */
-static char	shortopts[] = "c:n:hVR:";
+static char	shortopts[] = "c:n:fhVR:";
 
 /* end of COMMAND LINE OPTIONS */
 
@@ -194,6 +196,7 @@
 char	**CONFIG_LOAD_MODULE		= NULL;
 
 char	*CONFIG_USER			= NULL;
+int	CONFIG_FOREGROUND		= ZBX_RUN_BACKGROUND;
 
 /******************************************************************************
  *                                                                            *
@@ -531,6 +534,9 @@
 	{
 		switch (ch)
 		{
+			case 'f':
+				CONFIG_FOREGROUND = ZBX_RUN_FOREGROUND;
+				break;
 			case 'c':
 				CONFIG_FILE = zbx_strdup(CONFIG_FILE, zbx_optarg);
 				break;
@@ -573,7 +579,7 @@
 	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_server/server.c
===================================================================
--- src/zabbix_server/server.c	(revision 45170)
+++ src/zabbix_server/server.c	(working copy)
@@ -69,6 +69,7 @@
 
 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",
 	"",
@@ -86,6 +87,7 @@
 /* long options */
 static struct zbx_option	longopts[] =
 {
+	{"foreground",		0,	NULL,	'f'},
 	{"config",		1,	NULL,	'c'},
 	{"runtime-control",	1,	NULL,	'R'},
 	{"help",		0,	NULL,	'h'},
@@ -94,7 +96,7 @@
 };
 
 /* short options */
-static char	shortopts[] = "c:n:hVR:";
+static char	shortopts[] = "c:n:fhVR:";
 
 /* end of COMMAND LINE OPTIONS */
 
@@ -190,6 +192,7 @@
 char	**CONFIG_LOAD_MODULE		= NULL;
 
 char	*CONFIG_USER			= NULL;
+int	CONFIG_FOREGROUND		= ZBX_RUN_BACKGROUND;
 
 /******************************************************************************
  *                                                                            *
@@ -485,6 +488,9 @@
 	{
 		switch (ch)
 		{
+			case 'f':
+				CONFIG_FOREGROUND = ZBX_RUN_FOREGROUND;
+				break;
 			case 'c':
 				CONFIG_FILE = zbx_strdup(CONFIG_FILE, zbx_optarg);
 				break;
@@ -527,7 +533,7 @@
 	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()
