forked from 2ndQuadrant/pglogical
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpglogical_fe.c
60 lines (49 loc) · 1.34 KB
/
pglogical_fe.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/*-------------------------------------------------------------------------
*
* pglogical.c
* pglogical utility functions shared between backend and frontend
*
* Copyright (c) 2015, PostgreSQL Global Development Group
*
* IDENTIFICATION
* pglogical.c
*
*-------------------------------------------------------------------------
*/
#include "postgres_fe.h"
#include "pglogical_fe.h"
/*
* Find another program in our binary's directory,
* and return its version.
*/
int
find_other_exec_version(const char *argv0, const char *target,
uint32 *version, char *retpath)
{
char cmd[MAXPGPATH];
char cmd_output[1024];
FILE *output;
int pre_dot = 0,
post_dot = 0;
if (find_my_exec(argv0, retpath) < 0)
return -1;
/* Trim off program name and keep just directory */
*last_dir_separator(retpath) = '\0';
canonicalize_path(retpath);
/* Now append the other program's name */
snprintf(retpath + strlen(retpath), MAXPGPATH - strlen(retpath),
"/%s%s", target, EXE);
snprintf(cmd, sizeof(cmd), "\"%s\" -V", retpath);
if ((output = popen(cmd, "r")) == NULL)
return -1;
if (fgets(cmd_output, sizeof(cmd_output), output) == NULL)
{
pclose(output);
return -1;
}
pclose(output);
if (sscanf(cmd_output, "%*s %*s %d.%d", &pre_dot, &post_dot) < 1)
return -2;
*version = (pre_dot * 100 + post_dot) * 100;
return 0;
}