[c5c522c] | 1 | diff -u -r zabbix-2.2.1/include/common.h zabbix-2.2.1.new/include/common.h |
---|
| 2 | --- zabbix-2.2.1/include/common.h 2013-12-09 09:15:13.000000000 +0000 |
---|
| 3 | +++ zabbix-2.2.1.new/include/common.h 2013-12-11 20:09:58.000000000 +0000 |
---|
| 4 | @@ -751,7 +751,8 @@ |
---|
| 5 | ZBX_TASK_START_SERVICE, |
---|
| 6 | ZBX_TASK_STOP_SERVICE, |
---|
| 7 | ZBX_TASK_CHANGE_NODEID, |
---|
| 8 | - ZBX_TASK_CONFIG_CACHE_RELOAD |
---|
| 9 | + ZBX_TASK_CONFIG_CACHE_RELOAD, |
---|
| 10 | + ZBX_TASK_START_FOREGROUND |
---|
| 11 | } |
---|
| 12 | zbx_task_t; |
---|
| 13 | |
---|
| 14 | diff -u -r zabbix-2.2.1/include/daemon.h zabbix-2.2.1.new/include/daemon.h |
---|
| 15 | --- zabbix-2.2.1/include/daemon.h 2013-12-09 09:15:13.000000000 +0000 |
---|
| 16 | +++ zabbix-2.2.1.new/include/daemon.h 2013-12-11 20:09:58.000000000 +0000 |
---|
| 17 | @@ -30,7 +30,7 @@ |
---|
| 18 | |
---|
| 19 | #include "threads.h" |
---|
| 20 | |
---|
| 21 | -int daemon_start(int allow_root); |
---|
| 22 | +int daemon_start(int allow_root, int foreground); |
---|
| 23 | void daemon_stop(); |
---|
| 24 | |
---|
| 25 | int zbx_sigusr_send(zbx_task_t task); |
---|
| 26 | @@ -38,6 +38,6 @@ |
---|
| 27 | #define ZBX_IS_RUNNING() 1 |
---|
| 28 | #define ZBX_DO_EXIT() |
---|
| 29 | |
---|
| 30 | -#define START_MAIN_ZABBIX_ENTRY(a) daemon_start(a) |
---|
| 31 | +#define START_MAIN_ZABBIX_ENTRY(a,b) daemon_start(a,b) |
---|
| 32 | |
---|
| 33 | #endif /* ZABBIX_DAEMON_H */ |
---|
| 34 | Only in zabbix-2.2.1/include: stamp-h1 |
---|
| 35 | diff -u -r zabbix-2.2.1/src/libs/zbxnix/daemon.c zabbix-2.2.1.new/src/libs/zbxnix/daemon.c |
---|
| 36 | --- zabbix-2.2.1/src/libs/zbxnix/daemon.c 2013-12-09 09:15:13.000000000 +0000 |
---|
| 37 | +++ zabbix-2.2.1.new/src/libs/zbxnix/daemon.c 2013-12-11 20:17:00.000000000 +0000 |
---|
| 38 | @@ -140,7 +140,7 @@ |
---|
| 39 | * Comments: it doesn't allow running under 'root' if allow_root is zero * |
---|
| 40 | * * |
---|
| 41 | ******************************************************************************/ |
---|
| 42 | -int daemon_start(int allow_root) |
---|
| 43 | +int daemon_start(int allow_root, int foreground) |
---|
| 44 | { |
---|
| 45 | pid_t pid; |
---|
| 46 | struct passwd *pwd; |
---|
| 47 | @@ -186,15 +186,19 @@ |
---|
| 48 | #endif |
---|
| 49 | } |
---|
| 50 | |
---|
| 51 | - if (0 != (pid = zbx_fork())) |
---|
| 52 | - exit(0); |
---|
| 53 | + /* 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 */ |
---|
| 54 | + if (!foreground) |
---|
| 55 | + { |
---|
| 56 | + if (0 != (pid = zbx_fork())) |
---|
| 57 | + exit(0); |
---|
| 58 | |
---|
| 59 | - setsid(); |
---|
| 60 | + setsid(); |
---|
| 61 | |
---|
| 62 | - signal(SIGHUP, SIG_IGN); |
---|
| 63 | + signal(SIGHUP, SIG_IGN); |
---|
| 64 | |
---|
| 65 | - if (0 != (pid = zbx_fork())) |
---|
| 66 | - exit(0); |
---|
| 67 | + if (0 != (pid = zbx_fork())) |
---|
| 68 | + exit(0); |
---|
| 69 | + } |
---|
| 70 | |
---|
| 71 | if (-1 == chdir("/")) /* this is to eliminate warning: ignoring return value of chdir */ |
---|
| 72 | assert(0); |
---|
| 73 | diff -u -r zabbix-2.2.1/src/zabbix_agent/zabbix_agentd.c zabbix-2.2.1.new/src/zabbix_agent/zabbix_agentd.c |
---|
| 74 | --- zabbix-2.2.1/src/zabbix_agent/zabbix_agentd.c 2013-12-09 09:15:14.000000000 +0000 |
---|
| 75 | +++ zabbix-2.2.1.new/src/zabbix_agent/zabbix_agentd.c 2013-12-11 20:09:58.000000000 +0000 |
---|
| 76 | @@ -89,6 +89,7 @@ |
---|
| 77 | " -c --config <config-file> Absolute path to the configuration file", |
---|
| 78 | " -p --print Print known items and exit", |
---|
| 79 | " -t --test <item key> Test specified item and exit", |
---|
| 80 | + " -f --foreground Start in the foreground. (for running a service supervisor)", |
---|
| 81 | " -h --help Give this help", |
---|
| 82 | " -V --version Display version number", |
---|
| 83 | #ifdef _WINDOWS |
---|
| 84 | @@ -112,6 +113,7 @@ |
---|
| 85 | { |
---|
| 86 | {"config", 1, NULL, 'c'}, |
---|
| 87 | {"help", 0, NULL, 'h'}, |
---|
| 88 | + {"foreground", 0, NULL, 'f'}, |
---|
| 89 | {"version", 0, NULL, 'V'}, |
---|
| 90 | {"print", 0, NULL, 'p'}, |
---|
| 91 | {"test", 1, NULL, 't'}, |
---|
| 92 | @@ -128,7 +130,7 @@ |
---|
| 93 | }; |
---|
| 94 | |
---|
| 95 | static char shortopts[] = |
---|
| 96 | - "c:hVpt:" |
---|
| 97 | + "c:hfVpt:" |
---|
| 98 | #ifdef _WINDOWS |
---|
| 99 | "idsxm" |
---|
| 100 | #endif |
---|
| 101 | @@ -187,13 +189,13 @@ |
---|
| 102 | TEST_METRIC = strdup(zbx_optarg); |
---|
| 103 | } |
---|
| 104 | break; |
---|
| 105 | + case 'f': |
---|
| 106 | + t->task = ZBX_TASK_START_FOREGROUND; |
---|
| 107 | + break; |
---|
| 108 | #ifdef _WINDOWS |
---|
| 109 | case 'i': |
---|
| 110 | t->task = ZBX_TASK_INSTALL_SERVICE; |
---|
| 111 | break; |
---|
| 112 | - case 'd': |
---|
| 113 | - t->task = ZBX_TASK_UNINSTALL_SERVICE; |
---|
| 114 | - break; |
---|
| 115 | case 's': |
---|
| 116 | t->task = ZBX_TASK_START_SERVICE; |
---|
| 117 | break; |
---|
| 118 | @@ -826,12 +828,16 @@ |
---|
| 119 | alias_list_free(); |
---|
| 120 | exit(SUCCEED); |
---|
| 121 | break; |
---|
| 122 | - default: |
---|
| 123 | + case ZBX_TASK_START: |
---|
| 124 | zbx_load_config(ZBX_CFG_FILE_REQUIRED); |
---|
| 125 | + START_MAIN_ZABBIX_ENTRY(CONFIG_ALLOW_ROOT, 0); |
---|
| 126 | break; |
---|
| 127 | + case ZBX_TASK_START_FOREGROUND: |
---|
| 128 | + zbx_load_config(ZBX_CFG_FILE_REQUIRED); |
---|
| 129 | + START_MAIN_ZABBIX_ENTRY(CONFIG_ALLOW_ROOT, 1); |
---|
| 130 | + break; |
---|
| 131 | + |
---|
| 132 | } |
---|
| 133 | |
---|
| 134 | - START_MAIN_ZABBIX_ENTRY(CONFIG_ALLOW_ROOT); |
---|
| 135 | - |
---|
| 136 | exit(SUCCEED); |
---|
| 137 | } |
---|
| 138 | diff -u -r zabbix-2.2.1/src/zabbix_proxy/proxy.c zabbix-2.2.1.new/src/zabbix_proxy/proxy.c |
---|
| 139 | --- zabbix-2.2.1/src/zabbix_proxy/proxy.c 2013-12-09 09:15:13.000000000 +0000 |
---|
| 140 | +++ zabbix-2.2.1.new/src/zabbix_proxy/proxy.c 2013-12-11 20:09:58.000000000 +0000 |
---|
| 141 | @@ -65,6 +65,7 @@ |
---|
| 142 | const char *help_message[] = { |
---|
| 143 | "Options:", |
---|
| 144 | " -c --config <file> Absolute path to the configuration file", |
---|
| 145 | + " -f --foreground Run in foreground (under a service supervisor)", |
---|
| 146 | " -R --runtime-control <option> Perform administrative functions", |
---|
| 147 | "", |
---|
| 148 | "Runtime control options:", |
---|
| 149 | @@ -84,12 +85,13 @@ |
---|
| 150 | {"config", 1, NULL, 'c'}, |
---|
| 151 | {"runtime-control", 1, NULL, 'R'}, |
---|
| 152 | {"help", 0, NULL, 'h'}, |
---|
| 153 | + {"foreground", 0, NULL, 'f'}, |
---|
| 154 | {"version", 0, NULL, 'V'}, |
---|
| 155 | {NULL} |
---|
| 156 | }; |
---|
| 157 | |
---|
| 158 | /* short options */ |
---|
| 159 | -static char shortopts[] = "c:n:hVR:"; |
---|
| 160 | +static char shortopts[] = "c:n:hfVR:"; |
---|
| 161 | |
---|
| 162 | /* end of COMMAND LINE OPTIONS */ |
---|
| 163 | |
---|
| 164 | @@ -548,6 +550,9 @@ |
---|
| 165 | version(); |
---|
| 166 | exit(-1); |
---|
| 167 | break; |
---|
| 168 | + case 'f': |
---|
| 169 | + task=ZBX_TASK_START_FOREGROUND; |
---|
| 170 | + break; |
---|
| 171 | default: |
---|
| 172 | usage(); |
---|
| 173 | exit(-1); |
---|
| 174 | @@ -570,7 +575,7 @@ |
---|
| 175 | init_ipmi_handler(); |
---|
| 176 | #endif |
---|
| 177 | |
---|
| 178 | - return daemon_start(CONFIG_ALLOW_ROOT); |
---|
| 179 | + return daemon_start(CONFIG_ALLOW_ROOT, task==ZBX_TASK_START_FOREGROUND); |
---|
| 180 | } |
---|
| 181 | |
---|
| 182 | int MAIN_ZABBIX_ENTRY() |
---|
| 183 | diff -u -r zabbix-2.2.1/src/zabbix_server/server.c zabbix-2.2.1.new/src/zabbix_server/server.c |
---|
| 184 | --- zabbix-2.2.1/src/zabbix_server/server.c 2013-12-09 09:15:13.000000000 +0000 |
---|
| 185 | +++ zabbix-2.2.1.new/src/zabbix_server/server.c 2013-12-11 20:09:58.000000000 +0000 |
---|
| 186 | @@ -72,6 +72,7 @@ |
---|
| 187 | "Options:", |
---|
| 188 | " -c --config <file> Absolute path to the configuration file", |
---|
| 189 | " -n --new-nodeid <nodeid> Convert database data to new nodeid", |
---|
| 190 | + " -f --foreground Run in foreground. (for use with service supervisors)", |
---|
| 191 | " -R --runtime-control <option> Perform administrative functions", |
---|
| 192 | "", |
---|
| 193 | "Runtime control options:", |
---|
| 194 | @@ -92,12 +93,13 @@ |
---|
| 195 | {"new-nodeid", 1, NULL, 'n'}, |
---|
| 196 | {"runtime-control", 1, NULL, 'R'}, |
---|
| 197 | {"help", 0, NULL, 'h'}, |
---|
| 198 | + {"foreground", 0, NULL, 'f'}, |
---|
| 199 | {"version", 0, NULL, 'V'}, |
---|
| 200 | {NULL} |
---|
| 201 | }; |
---|
| 202 | |
---|
| 203 | /* short options */ |
---|
| 204 | -static char shortopts[] = "c:n:hVR:"; |
---|
| 205 | +static char shortopts[] = "c:n:hfVR:"; |
---|
| 206 | |
---|
| 207 | /* end of COMMAND LINE OPTIONS */ |
---|
| 208 | |
---|
| 209 | @@ -512,6 +514,9 @@ |
---|
| 210 | help(); |
---|
| 211 | exit(-1); |
---|
| 212 | break; |
---|
| 213 | + case 'f': |
---|
| 214 | + task = ZBX_TASK_START_FOREGROUND; |
---|
| 215 | + break; |
---|
| 216 | case 'n': |
---|
| 217 | nodeid = (NULL == zbx_optarg ? 0 : atoi(zbx_optarg)); |
---|
| 218 | task = ZBX_TASK_CHANGE_NODEID; |
---|
| 219 | @@ -547,11 +552,14 @@ |
---|
| 220 | case ZBX_TASK_CHANGE_NODEID: |
---|
| 221 | exit(SUCCEED == change_nodeid(nodeid) ? EXIT_SUCCESS : EXIT_FAILURE); |
---|
| 222 | break; |
---|
| 223 | - default: |
---|
| 224 | + case ZBX_TASK_START: |
---|
| 225 | + return daemon_start(CONFIG_ALLOW_ROOT, 0); |
---|
| 226 | + break; |
---|
| 227 | + case ZBX_TASK_START_FOREGROUND: |
---|
| 228 | + return daemon_start(CONFIG_ALLOW_ROOT, 1); |
---|
| 229 | break; |
---|
| 230 | } |
---|
| 231 | |
---|
| 232 | - return daemon_start(CONFIG_ALLOW_ROOT); |
---|
| 233 | } |
---|
| 234 | |
---|
| 235 | int MAIN_ZABBIX_ENTRY() |
---|