Skip to content

Commit c64fd5a

Browse files
committed
Add -ssh-options option
1 parent 50cb6f7 commit c64fd5a

File tree

3 files changed

+52
-6
lines changed

3 files changed

+52
-6
lines changed

src/pg_probackup.c

+4-2
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ char *remote_host;
7878
char *remote_port;
7979
char *remote_proto = (char*)"ssh";
8080
char *ssh_config;
81+
char *ssh_options;
8182
bool is_remote_agent;
8283
bool is_remote_backup;
8384

@@ -178,8 +179,9 @@ static pgut_option options[] =
178179
{ 's', 20, "remote-port", &remote_port, SOURCE_CMDLINE, },
179180
{ 's', 21, "remote-proto", &remote_proto, SOURCE_CMDLINE, },
180181
{ 's', 22, "ssh-config", &ssh_config, SOURCE_CMDLINE, },
181-
{ 'b', 23, "agent", &is_remote_agent, SOURCE_CMDLINE, },
182-
{ 'b', 24, "remote", &is_remote_backup, SOURCE_CMDLINE, },
182+
{ 's', 23, "ssh-options", &ssh_options, SOURCE_CMDLINE, },
183+
{ 'b', 24, "agent", &is_remote_agent, SOURCE_CMDLINE, },
184+
{ 'b', 25, "remote", &is_remote_backup, SOURCE_CMDLINE, },
183185
/* restore options */
184186
{ 's', 30, "time", &target_time, SOURCE_CMDLINE },
185187
{ 's', 31, "xid", &target_xid, SOURCE_CMDLINE },

src/pg_probackup.h

+1
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,7 @@ extern char *remote_port;
357357
extern char *remote_host;
358358
extern char *remote_proto;
359359
extern char *ssh_config;
360+
extern char *ssh_options;
360361
extern const char *master_db;
361362
extern const char *master_host;
362363
extern const char *master_port;

src/utils/remote.c

+47-4
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
#include "pg_probackup.h"
88
#include "file.h"
99

10-
#define MAX_CMDLINE_LENGTH 4096
10+
#define MAX_CMDLINE_LENGTH 4096
11+
#define MAX_CMDLINE_OPTIONS 256
1112

1213
static int append_option(char* buf, size_t buf_size, size_t dst, char const* src)
1314
{
@@ -21,11 +22,50 @@ static int append_option(char* buf, size_t buf_size, size_t dst, char const* src
2122
return dst + len + 1;
2223
}
2324

25+
static int split_options(int argc, char* argv[], int max_options, char* options)
26+
{
27+
char* opt = options;
28+
char in_quote = '\0';
29+
while (true) {
30+
switch (*opt) {
31+
case '\'':
32+
case '\"':
33+
if (!in_quote) {
34+
in_quote = *opt++;
35+
continue;
36+
}
37+
if (*opt == in_quote && *++opt != in_quote) {
38+
in_quote = '\0';
39+
continue;
40+
}
41+
break;
42+
case '\0':
43+
if (opt != options) {
44+
argv[argc++] = options;
45+
if (argc >= max_options)
46+
elog(ERROR, "Too much options");
47+
}
48+
return argc;
49+
case ' ':
50+
argv[argc++] = options;
51+
if (argc >= max_options)
52+
elog(ERROR, "Too much options");
53+
*opt++ = '\0';
54+
options = opt;
55+
continue;
56+
default:
57+
break;
58+
}
59+
opt += 1;
60+
}
61+
return argc;
62+
}
63+
2464
int remote_execute(int argc, char* argv[], bool listen)
2565
{
2666
char cmd[MAX_CMDLINE_LENGTH];
2767
size_t dst = 0;
28-
char* ssh_argv[8];
68+
char* ssh_argv[MAX_CMDLINE_OPTIONS];
2969
int ssh_argc;
3070
int i;
3171
int outfd[2];
@@ -34,14 +74,17 @@ int remote_execute(int argc, char* argv[], bool listen)
3474

3575
ssh_argc = 0;
3676
ssh_argv[ssh_argc++] = remote_proto;
37-
if (remote_port != 0) {
77+
if (remote_port != NULL) {
3878
ssh_argv[ssh_argc++] = (char*)"-p";
3979
ssh_argv[ssh_argc++] = remote_port;
4080
}
41-
if (ssh_config != 0) {
81+
if (ssh_config != NULL) {
4282
ssh_argv[ssh_argc++] = (char*)"-F";
4383
ssh_argv[ssh_argc++] = ssh_config;
4484
}
85+
if (ssh_options != NULL) {
86+
ssh_argc = split_options(ssh_argc, ssh_argv, MAX_CMDLINE_OPTIONS, ssh_options);
87+
}
4588
ssh_argv[ssh_argc++] = remote_host;
4689
ssh_argv[ssh_argc++] = cmd+1;
4790
ssh_argv[ssh_argc] = NULL;

0 commit comments

Comments
 (0)