| 411 | } |
| 412 | |
| 413 | static int include_config(char *include, int manage_globals) |
| 414 | { |
| 415 | STRUCT_STAT sb; |
| 416 | char *match = manage_globals ? "*.conf" : "*.inc"; |
| 417 | int ret; |
| 418 | |
| 419 | if (do_stat(include, &sb) < 0) { |
| 420 | rsyserr(FLOG, errno, "unable to stat config file \"%s\"", include); |
| 421 | return 0; |
| 422 | } |
| 423 | |
| 424 | if (S_ISREG(sb.st_mode)) { |
| 425 | if (manage_globals && the_sfunc) |
| 426 | the_sfunc("]push"); |
| 427 | ret = pm_process(include, the_sfunc, the_pfunc); |
| 428 | if (manage_globals && the_sfunc) |
| 429 | the_sfunc("]pop"); |
| 430 | } else if (S_ISDIR(sb.st_mode)) { |
| 431 | char buf[MAXPATHLEN], **bpp; |
| 432 | item_list conf_list; |
| 433 | struct dirent *di; |
| 434 | size_t j; |
| 435 | DIR *d; |
| 436 | |
| 437 | if (!(d = opendir(include))) { |
| 438 | rsyserr(FLOG, errno, "unable to open config dir \"%s\"", include); |
| 439 | return 0; |
| 440 | } |
| 441 | |
| 442 | memset(&conf_list, 0, sizeof conf_list); |
| 443 | |
| 444 | while ((di = readdir(d)) != NULL) { |
| 445 | char *dname = d_name(di); |
| 446 | if (!wildmatch(match, dname)) |
| 447 | continue; |
| 448 | bpp = EXPAND_ITEM_LIST(&conf_list, char *, 32); |
| 449 | pathjoin(buf, sizeof buf, include, dname); |
| 450 | *bpp = strdup(buf); |
| 451 | } |
| 452 | closedir(d); |
| 453 | |
| 454 | if (!(bpp = conf_list.items)) |
| 455 | return 1; |
| 456 | |
| 457 | if (conf_list.count > 1) |
| 458 | qsort(bpp, conf_list.count, sizeof (char *), name_cmp); |
| 459 | |
| 460 | for (j = 0, ret = 1; j < conf_list.count; j++) { |
| 461 | if (manage_globals && the_sfunc) |
| 462 | the_sfunc(j == 0 ? "]push" : "]reset"); |
| 463 | if ((ret = pm_process(bpp[j], the_sfunc, the_pfunc)) != 1) |
| 464 | break; |
| 465 | } |
| 466 | |
| 467 | if (manage_globals && the_sfunc) |
| 468 | the_sfunc("]pop"); |
| 469 | |
| 470 | for (j = 0; j < conf_list.count; j++) |
no test coverage detected