reasonbuf must be at least BUFSZ, supplied by caller */
| 391 | #ifndef SFCTOOL |
| 392 | /* reasonbuf must be at least BUFSZ, supplied by caller */ |
| 393 | int |
| 394 | validate_prefix_locations(char *reasonbuf) |
| 395 | { |
| 396 | #if defined(NOCWD_ASSUMPTIONS) |
| 397 | FILE *fp; |
| 398 | const char *filename; |
| 399 | int prefcnt, failcount = 0; |
| 400 | char panicbuf1[BUFSZ], panicbuf2[BUFSZ]; |
| 401 | const char *details; |
| 402 | #endif |
| 403 | |
| 404 | if (reasonbuf) |
| 405 | reasonbuf[0] = '\0'; |
| 406 | #if defined(NOCWD_ASSUMPTIONS) |
| 407 | for (prefcnt = 1; prefcnt < PREFIX_COUNT; prefcnt++) { |
| 408 | /* don't test writing to configdir or datadir; they're readonly */ |
| 409 | if (prefcnt == SYSCONFPREFIX || prefcnt == CONFIGPREFIX |
| 410 | || prefcnt == DATAPREFIX) |
| 411 | continue; |
| 412 | filename = fqname("validate", prefcnt, 3); |
| 413 | if ((fp = fopen(filename, "w"))) { |
| 414 | fclose(fp); |
| 415 | (void) unlink(filename); |
| 416 | } else { |
| 417 | if (reasonbuf) { |
| 418 | if (failcount) |
| 419 | Strcat(reasonbuf, ", "); |
| 420 | Strcat(reasonbuf, fqn_prefix_names[prefcnt]); |
| 421 | } |
| 422 | /* the paniclog entry gets the value of errno as well */ |
| 423 | Sprintf(panicbuf1, "Invalid %s", fqn_prefix_names[prefcnt]); |
| 424 | #if defined(NHSTDC) && !defined(NOTSTDC) |
| 425 | if (!(details = strerror(errno))) |
| 426 | #endif |
| 427 | details = ""; |
| 428 | Sprintf(panicbuf2, "\"%s\", (%d) %s", |
| 429 | gf.fqn_prefix[prefcnt], errno, details); |
| 430 | paniclog(panicbuf1, panicbuf2); |
| 431 | failcount++; |
| 432 | } |
| 433 | } |
| 434 | if (failcount) |
| 435 | return 0; |
| 436 | else |
| 437 | #endif |
| 438 | return 1; |
| 439 | } |
| 440 | |
| 441 | /* fopen a file, with OS-dependent bells and whistles */ |
| 442 | /* NOTE: a simpler version of this routine also exists in util/dlb_main.c */ |