| 382 | } |
| 383 | |
| 384 | static int |
| 385 | proc_info_preparse_args(int argc, char **argv) |
| 386 | { |
| 387 | char *prgname = argv[0]; |
| 388 | int i; |
| 389 | |
| 390 | for (i = 0; i < argc; i++) { |
| 391 | /* Print stats or xstats to STDOUT in collectd format */ |
| 392 | if (!strncmp(argv[i], "--collectd-format", MAX_LONG_OPT_SZ)) { |
| 393 | enable_collectd_format = 1; |
| 394 | stdout_fd = dup(STDOUT_FILENO); |
| 395 | close(STDOUT_FILENO); |
| 396 | } |
| 397 | if (!strncmp(argv[i], "--host-id", MAX_LONG_OPT_SZ)) { |
| 398 | if ((i + 1) == argc) { |
| 399 | printf("Invalid host id or not specified\n"); |
| 400 | proc_info_usage(prgname); |
| 401 | return -1; |
| 402 | } |
| 403 | strlcpy(host_id, argv[i + 1], sizeof(host_id)); |
| 404 | } |
| 405 | } |
| 406 | |
| 407 | if (!strlen(host_id)) { |
| 408 | int err = gethostname(host_id, MAX_LONG_OPT_SZ-1); |
| 409 | |
| 410 | if (err) |
| 411 | strlcpy(host_id, "unknown", sizeof(host_id)); |
| 412 | } |
| 413 | |
| 414 | return 0; |
| 415 | } |
| 416 | |
| 417 | /* Parse the argument given in the command line of the application */ |
| 418 | static int |
no test coverage detected