diff -uNr zabbix-2.2.3-prepatched-orig/include/common.h zabbix-2.2.3-prepatched/include/common.h
--- zabbix-2.2.3-prepatched-orig/include/common.h	2014-04-07 11:03:40.000000000 +0200
+++ zabbix-2.2.3-prepatched/include/common.h	2014-05-08 17:01:33.000000000 +0200
@@ -1063,4 +1063,7 @@
 #define ZBX_SESSION_ACTIVE	0
 #define ZBX_SESSION_PASSIVE	1
 
+#define ZBX_RUN_BACKGROUND      0
+#define ZBX_RUN_FOREGROUND      1
+
 #endif
diff -uNr zabbix-2.2.3-prepatched-orig/include/daemon.h zabbix-2.2.3-prepatched/include/daemon.h
--- zabbix-2.2.3-prepatched-orig/include/daemon.h	2014-04-07 11:03:40.000000000 +0200
+++ zabbix-2.2.3-prepatched/include/daemon.h	2014-05-08 17:45:05.000000000 +0200
@@ -30,7 +30,7 @@
 
 #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 @@
 #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 */
diff -uNr zabbix-2.2.3-prepatched-orig/src/libs/zbxnix/daemon.c zabbix-2.2.3-prepatched/src/libs/zbxnix/daemon.c
--- zabbix-2.2.3-prepatched-orig/src/libs/zbxnix/daemon.c	2014-04-07 11:03:41.000000000 +0200
+++ zabbix-2.2.3-prepatched/src/libs/zbxnix/daemon.c	2014-05-08 17:37:56.000000000 +0200
@@ -134,13 +134,14 @@
  * 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 @@
 #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);
diff -uNr zabbix-2.2.3-prepatched-orig/src/zabbix_agent/zabbix_agentd.c zabbix-2.2.3-prepatched/src/zabbix_agent/zabbix_agentd.c
--- zabbix-2.2.3-prepatched-orig/src/zabbix_agent/zabbix_agentd.c	2014-04-07 11:03:41.000000000 +0200
+++ zabbix-2.2.3-prepatched/src/zabbix_agent/zabbix_agentd.c	2014-05-08 17:12:21.000000000 +0200
@@ -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;
@@ -839,7 +846,7 @@
 			break;
 	}
 
-	START_MAIN_ZABBIX_ENTRY(CONFIG_ALLOW_ROOT);
+	START_MAIN_ZABBIX_ENTRY(CONFIG_ALLOW_ROOT, CONFIG_FOREGROUND);
 
 	exit(SUCCEED);
 }
diff -uNr zabbix-2.2.3-prepatched-orig/src/zabbix_proxy/proxy.c zabbix-2.2.3-prepatched/src/zabbix_proxy/proxy.c
--- zabbix-2.2.3-prepatched-orig/src/zabbix_proxy/proxy.c	2014-04-07 11:03:40.000000000 +0200
+++ zabbix-2.2.3-prepatched/src/zabbix_proxy/proxy.c	2014-05-08 17:14:49.000000000 +0200
@@ -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 */
 
@@ -195,6 +197,8 @@
 /* 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;
 
@@ -577,7 +581,7 @@
 	init_ipmi_handler();
 #endif
 
-	return daemon_start(CONFIG_ALLOW_ROOT);
+	return daemon_start(CONFIG_ALLOW_ROOT, CONFIG_FOREGROUND);
 }
 
 int	MAIN_ZABBIX_ENTRY()
diff -uNr zabbix-2.2.3-prepatched-orig/src/zabbix_server/server.c zabbix-2.2.3-prepatched/src/zabbix_server/server.c
--- zabbix-2.2.3-prepatched-orig/src/zabbix_server/server.c	2014-04-07 11:03:41.000000000 +0200
+++ zabbix-2.2.3-prepatched/src/zabbix_server/server.c	2014-05-08 17:18:17.000000000 +0200
@@ -71,6 +71,7 @@
 
 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 @@
 /* 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 @@
 };
 
 /* short options */
-static char	shortopts[] = "c:n:hVR:";
+static char	shortopts[] = "c:n:fhVR:";
 
 /* end of COMMAND LINE OPTIONS */
 
@@ -199,6 +201,8 @@
 char	*CONFIG_LOAD_MODULE_PATH	= NULL;
 char	**CONFIG_LOAD_MODULE		= NULL;
 
+int	CONFIG_FOREGROUND		= ZBX_RUN_BACKGROUND;
+
 /* mutex for node syncs */
 ZBX_MUTEX	node_sync_access;
 
@@ -504,6 +508,9 @@
 	{
 		switch (ch)
 		{
+			case 'f':
+				CONFIG_FOREGROUND = ZBX_RUN_FOREGROUND;
+				break;
 			case 'c':
 				CONFIG_FILE = zbx_strdup(CONFIG_FILE, zbx_optarg);
 				break;
@@ -559,7 +566,7 @@
 			break;
 	}
 
-	return daemon_start(CONFIG_ALLOW_ROOT);
+	return daemon_start(CONFIG_ALLOW_ROOT, CONFIG_FOREGROUND);
 }
 
 int	MAIN_ZABBIX_ENTRY()
