@cryptotaxi247 / netdata-1 / commits / 0f8aabc2d

minor fix

Costa Tsaousis (ktsaou) committed May 3, 2014 at 15:27 UTC 0f8aabc2d443db1454ca76669035de65a6f3c3ff
1 file changed +66 -63
netdata.c
+66 -63
@@ -88,6 +88,7 @@
88 #define D_DEFLATE 0x00000200
89 #define D_CONFIG 0x00000400
90 #define D_CHARTSD 0x00000800
91 +#define D_CHILDS 0x00001000
92
93 #define CT_APPLICATION_JSON 1
94 #define CT_TEXT_PLAIN 2
@@ -140,69 +141,6 @@ int update_every = UPDATE_EVERY;
141 int listen_port = LISTEN_PORT;
142
143
143 -// ----------------------------------------------------------------------------
144 -// helpers
145 -
146 -unsigned long long usecdiff(struct timeval *now, struct timeval *last) {
147 - return ((((now->tv_sec * 1000000ULL) + now->tv_usec) - ((last->tv_sec * 1000000ULL) + last->tv_usec)));
148 -}
149 -
150 -unsigned long simple_hash(const char *name)
151 -{
152 - int i, len = strlen(name);
153 - unsigned long hash = 0;
154 -
155 - for(i = 0; i < len ;i++) hash += (i * name[i]) + i + name[i];
156 -
157 - return hash;
158 -}
159 -
160 -#define PIPE_READ 0
161 -#define PIPE_WRITE 1
162 -
163 -FILE *mypopen(const char *command, pid_t *pidptr)
164 -{
165 - int pipefd[2];
166 -
167 - if(pipe(pipefd) == -1) return NULL;
168 -
169 - int pid = fork();
170 - if(pid == -1) {
171 - close(pipefd[PIPE_READ]);
172 - close(pipefd[PIPE_WRITE]);
173 - return NULL;
174 - }
175 - if(pid != 0) {
176 - // the parent
177 - *pidptr = pid;
178 - close(pipefd[PIPE_WRITE]);
179 - FILE *fp = fdopen(pipefd[PIPE_READ], "r");
180 - return(fp);
181 - }
182 - // the child
183 -
184 - // close all files
185 - int i;
186 - for(i = sysconf(_SC_OPEN_MAX); i > 0; i--)
187 - if(i != STDIN_FILENO && i != STDERR_FILENO && i != pipefd[PIPE_WRITE]) close(i);
188 -
189 - // move the pipe to stdout
190 - if(pipefd[PIPE_WRITE] != STDOUT_FILENO) {
191 - dup2(pipefd[PIPE_WRITE], STDOUT_FILENO);
192 - close(pipefd[PIPE_WRITE]);
193 - }
194 -
195 - fprintf(stderr, "Running command: '%s'\n", command);
196 - execl("/bin/sh", "sh", "-c", command, NULL);
197 - exit(1);
198 -}
199 -
200 -void mypclose(FILE *fp)
201 -{
202 - fclose(fp);
203 -}
204 -
205 -
144 // ----------------------------------------------------------------------------
145 // LOG
146
@@ -329,6 +267,69 @@ void log_access( const char *fmt, ... )
267 }
268
269
270 +// ----------------------------------------------------------------------------
271 +// helpers
272 +
273 +unsigned long long usecdiff(struct timeval *now, struct timeval *last) {
274 + return ((((now->tv_sec * 1000000ULL) + now->tv_usec) - ((last->tv_sec * 1000000ULL) + last->tv_usec)));
275 +}
276 +
277 +unsigned long simple_hash(const char *name)
278 +{
279 + int i, len = strlen(name);
280 + unsigned long hash = 0;
281 +
282 + for(i = 0; i < len ;i++) hash += (i * name[i]) + i + name[i];
283 +
284 + return hash;
285 +}
286 +
287 +#define PIPE_READ 0
288 +#define PIPE_WRITE 1
289 +
290 +FILE *mypopen(const char *command, pid_t *pidptr)
291 +{
292 + int pipefd[2];
293 +
294 + if(pipe(pipefd) == -1) return NULL;
295 +
296 + int pid = fork();
297 + if(pid == -1) {
298 + close(pipefd[PIPE_READ]);
299 + close(pipefd[PIPE_WRITE]);
300 + return NULL;
301 + }
302 + if(pid != 0) {
303 + // the parent
304 + *pidptr = pid;
305 + close(pipefd[PIPE_WRITE]);
306 + FILE *fp = fdopen(pipefd[PIPE_READ], "r");
307 + return(fp);
308 + }
309 + // the child
310 +
311 + // close all files
312 + int i;
313 + for(i = sysconf(_SC_OPEN_MAX); i > 0; i--)
314 + if(i != STDIN_FILENO && i != STDERR_FILENO && i != pipefd[PIPE_WRITE]) close(i);
315 +
316 + // move the pipe to stdout
317 + if(pipefd[PIPE_WRITE] != STDOUT_FILENO) {
318 + dup2(pipefd[PIPE_WRITE], STDOUT_FILENO);
319 + close(pipefd[PIPE_WRITE]);
320 + }
321 +
322 + debug(D_CHILDS, "Running command: '%s'\n", command);
323 + execl("/bin/sh", "sh", "-c", command, NULL);
324 + exit(1);
325 +}
326 +
327 +void mypclose(FILE *fp)
328 +{
329 + fclose(fp);
330 +}
331 +
332 +
333 // ----------------------------------------------------------------------------
334 // URL encode / decode
335 // code from: http://www.geekhideout.com/urlcode.shtml
@@ -6256,6 +6257,7 @@ int main(int argc, char **argv)
6257
6258 // --------------------------------------------------------------------
6259
6260 + silent = 0;
6261 error_log_file = config_get("global", "error log", "syslog");
6262 if(strcmp(error_log_file, "syslog") == 0) {
6263 error_log_syslog = 1;
@@ -6264,6 +6266,7 @@ int main(int argc, char **argv)
6266 else if(strcmp(error_log_file, "none") == 0) {
6267 error_log_syslog = 0;
6268 error_log_file = NULL;
6269 + silent = 1; // optimization - do not even generate debug log entries
6270 }
6271 else error_log_syslog = 0;
6272