diff -u -r zabbix-2.2.1/include/common.h zabbix-2.2.1.new/include/common.h --- zabbix-2.2.1/include/common.h 2013-12-09 09:15:13.000000000 +0000 +++ zabbix-2.2.1.new/include/common.h 2013-12-11 20:09:58.000000000 +0000 @@ -751,7 +751,8 @@ ZBX_TASK_START_SERVICE, ZBX_TASK_STOP_SERVICE, ZBX_TASK_CHANGE_NODEID, - ZBX_TASK_CONFIG_CACHE_RELOAD + ZBX_TASK_CONFIG_CACHE_RELOAD, + ZBX_TASK_START_FOREGROUND } zbx_task_t; diff -u -r zabbix-2.2.1/include/daemon.h zabbix-2.2.1.new/include/daemon.h --- zabbix-2.2.1/include/daemon.h 2013-12-09 09:15:13.000000000 +0000 +++ zabbix-2.2.1.new/include/daemon.h 2013-12-11 20:09:58.000000000 +0000 @@ -30,7 +30,7 @@ #include "threads.h" -int daemon_start(int allow_root); +int daemon_start(int allow_root, int 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,b) daemon_start(a,b) #endif /* ZABBIX_DAEMON_H */ Only in zabbix-2.2.1/include: stamp-h1 diff -u -r zabbix-2.2.1/src/libs/zbxnix/daemon.c zabbix-2.2.1.new/src/libs/zbxnix/daemon.c --- zabbix-2.2.1/src/libs/zbxnix/daemon.c 2013-12-09 09:15:13.000000000 +0000 +++ zabbix-2.2.1.new/src/libs/zbxnix/daemon.c 2013-12-11 20:17:00.000000000 +0000 @@ -140,7 +140,7 @@ * 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 foreground) { pid_t pid; struct passwd *pwd; @@ -186,15 +186,19 @@ #endif } - if (0 != (pid = zbx_fork())) - exit(0); + /* The actual daemonizing is done here. Since nowadays deamons run as normal processes under service supervisors, we provide a foreground-option as well. edwin@datux.nl */ + if (!foreground) + { + if (0 != (pid = zbx_fork())) + exit(0); - setsid(); + setsid(); - signal(SIGHUP, SIG_IGN); + signal(SIGHUP, SIG_IGN); - if (0 != (pid = zbx_fork())) - exit(0); + if (0 != (pid = zbx_fork())) + exit(0); + } if (-1 == chdir("/")) /* this is to eliminate warning: ignoring return value of chdir */ assert(0); diff -u -r zabbix-2.2.1/src/zabbix_agent/zabbix_agentd.c zabbix-2.2.1.new/src/zabbix_agent/zabbix_agentd.c --- zabbix-2.2.1/src/zabbix_agent/zabbix_agentd.c 2013-12-09 09:15:14.000000000 +0000 +++ zabbix-2.2.1.new/src/zabbix_agent/zabbix_agentd.c 2013-12-11 20:09:58.000000000 +0000 @@ -89,6 +89,7 @@ " -c --config Absolute path to the configuration file", " -p --print Print known items and exit", " -t --test Test specified item and exit", + " -f --foreground Start in the foreground. (for running a service supervisor)", " -h --help Give this help", " -V --version Display version number", #ifdef _WINDOWS @@ -112,6 +113,7 @@ { {"config", 1, NULL, 'c'}, {"help", 0, NULL, 'h'}, + {"foreground", 0, NULL, 'f'}, {"version", 0, NULL, 'V'}, {"print", 0, NULL, 'p'}, {"test", 1, NULL, 't'}, @@ -128,7 +130,7 @@ }; static char shortopts[] = - "c:hVpt:" + "c:hfVpt:" #ifdef _WINDOWS "idsxm" #endif @@ -187,13 +189,13 @@ TEST_METRIC = strdup(zbx_optarg); } break; + case 'f': + t->task = ZBX_TASK_START_FOREGROUND; + break; #ifdef _WINDOWS case 'i': t->task = ZBX_TASK_INSTALL_SERVICE; break; - case 'd': - t->task = ZBX_TASK_UNINSTALL_SERVICE; - break; case 's': t->task = ZBX_TASK_START_SERVICE; break; @@ -826,12 +828,16 @@ alias_list_free(); exit(SUCCEED); break; - default: + case ZBX_TASK_START: zbx_load_config(ZBX_CFG_FILE_REQUIRED); + START_MAIN_ZABBIX_ENTRY(CONFIG_ALLOW_ROOT, 0); break; + case ZBX_TASK_START_FOREGROUND: + zbx_load_config(ZBX_CFG_FILE_REQUIRED); + START_MAIN_ZABBIX_ENTRY(CONFIG_ALLOW_ROOT, 1); + break; + } - START_MAIN_ZABBIX_ENTRY(CONFIG_ALLOW_ROOT); - exit(SUCCEED); } diff -u -r zabbix-2.2.1/src/zabbix_proxy/proxy.c zabbix-2.2.1.new/src/zabbix_proxy/proxy.c --- zabbix-2.2.1/src/zabbix_proxy/proxy.c 2013-12-09 09:15:13.000000000 +0000 +++ zabbix-2.2.1.new/src/zabbix_proxy/proxy.c 2013-12-11 20:09:58.000000000 +0000 @@ -65,6 +65,7 @@ const char *help_message[] = { "Options:", " -c --config Absolute path to the configuration file", + " -f --foreground Run in foreground (under a service supervisor)", " -R --runtime-control