* pclose() plus useful error reporting */
| 397 | * pclose() plus useful error reporting |
| 398 | */ |
| 399 | int |
| 400 | pclose_check(FILE *stream) |
| 401 | { |
| 402 | int exitstatus; |
| 403 | char *reason; |
| 404 | |
| 405 | exitstatus = pclose(stream); |
| 406 | |
| 407 | if (exitstatus == 0) |
| 408 | return 0; /* all is well */ |
| 409 | |
| 410 | if (exitstatus == -1) |
| 411 | { |
| 412 | /* pclose() itself failed, and hopefully set errno */ |
| 413 | log_error(errcode(ERRCODE_SYSTEM_ERROR), |
| 414 | _("%s() failed: %m"), "pclose"); |
| 415 | } |
| 416 | else |
| 417 | { |
| 418 | reason = wait_result_to_str(exitstatus); |
| 419 | log_error(errcode(ERRCODE_SYSTEM_ERROR), |
| 420 | "%s", reason); |
| 421 | pfree(reason); |
| 422 | } |
| 423 | return exitstatus; |
| 424 | } |
| 425 | |
| 426 | /* |
| 427 | * set_pglocale_pgservice |
no test coverage detected