| 429 | } |
| 430 | |
| 431 | static void |
| 432 | check_exec(const char *dir, const char *program, bool check_version) |
| 433 | { |
| 434 | char path[MAXPGPATH]; |
| 435 | char line[MAXPGPATH]; |
| 436 | char cmd[MAXPGPATH]; |
| 437 | char versionstr[128]; |
| 438 | char gp_versionstr[128]; |
| 439 | int ret; |
| 440 | |
| 441 | snprintf(path, sizeof(path), "%s/%s", dir, program); |
| 442 | |
| 443 | ret = validate_exec(path); |
| 444 | |
| 445 | if (ret == -1) |
| 446 | pg_fatal("check for \"%s\" failed: not a regular file\n", |
| 447 | path); |
| 448 | else if (ret == -2) |
| 449 | pg_fatal("check for \"%s\" failed: cannot execute (permission denied)\n", |
| 450 | path); |
| 451 | |
| 452 | snprintf(cmd, sizeof(cmd), "\"%s\" -V", path); |
| 453 | |
| 454 | if (!pipe_read_line(cmd, line, sizeof(line))) |
| 455 | pg_fatal("check for \"%s\" failed: cannot execute\n", |
| 456 | path); |
| 457 | |
| 458 | if (check_version) |
| 459 | { |
| 460 | pg_strip_crlf(line); |
| 461 | |
| 462 | snprintf(versionstr, sizeof(versionstr), "%s (PostgreSQL) " PG_VERSION, program); |
| 463 | snprintf(gp_versionstr, sizeof(versionstr), "%s (Apache Cloudberry) " PG_VERSION, program); |
| 464 | |
| 465 | if (strcmp(line, versionstr) != 0 && strcmp(line, gp_versionstr) != 0) |
| 466 | pg_fatal("check for \"%s\" failed: incorrect version: found \"%s\", expected \"%s\" or \"%s\"\n", |
| 467 | path, line, versionstr, gp_versionstr); |
| 468 | } |
| 469 | } |
no test coverage detected