forked from pgmoneta/pgmoneta
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli.c
946 lines (854 loc) · 22.4 KB
/
cli.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
/*
* Copyright (C) 2022 Red Hat
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list
* of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this
* list of conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may
* be used to endorse or promote products derived from this software without specific
* prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/* pgmoneta */
#include <pgmoneta.h>
#include <configuration.h>
#include <logging.h>
#include <management.h>
#include <network.h>
#include <security.h>
#include <shmem.h>
#include <utils.h>
/* system */
#include <getopt.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/mman.h>
#include <sys/types.h>
#include <openssl/ssl.h>
#define ACTION_UNKNOWN 0
#define ACTION_BACKUP 1
#define ACTION_LIST_BACKUP 2
#define ACTION_RESTORE 3
#define ACTION_ARCHIVE 4
#define ACTION_DELETE 5
#define ACTION_STOP 6
#define ACTION_STATUS 7
#define ACTION_DETAILS 8
#define ACTION_ISALIVE 9
#define ACTION_RESET 10
#define ACTION_RELOAD 11
#define ACTION_RETAIN 12
#define ACTION_EXPUNGE 13
#define ACTION_HELP 99
static int find_action(int argc, char** argv, int* place);
static void help_backup(void);
static void help_list_backup(void);
static void help_restore(void);
static void help_archive(void);
static void help_delete(void);
static void help_retain(void);
static void help_expunge(void);
static int backup(SSL* ssl, int socket, char* server);
static int list_backup(SSL* ssl, int socket, char* server);
static int restore(SSL* ssl, int socket, char* server, char* backup_id, char* position, char* directory);
static int archive(SSL* ssl, int socket, char* server, char* backup_id, char* position, char* directory);
static int delete(SSL* ssl, int socket, char* server, char* backup_id);
static int stop(SSL* ssl, int socket);
static int status(SSL* ssl, int socket);
static int details(SSL* ssl, int socket);
static int isalive(SSL* ssl, int socket);
static int reset(SSL* ssl, int socket);
static int reload(SSL* ssl, int socket);
static int retain(SSL* ssl, int socket, char* server, char* backup_id);
static int expunge(SSL* ssl, int socket, char* server, char* backup_id);
static void
version(void)
{
printf("pgmoneta-cli %s\n", VERSION);
exit(1);
}
static void
usage(void)
{
printf("pgmoneta-cli %s\n", VERSION);
printf(" Command line utility for pgmoneta\n");
printf("\n");
printf("Usage:\n");
printf(" pgmoneta-cli [ -c CONFIG_FILE ] [ COMMAND ] \n");
printf("\n");
printf("Options:\n");
printf(" -c, --config CONFIG_FILE Set the path to the pgmoneta.conf file\n");
printf(" -h, --host HOST Set the host name\n");
printf(" -p, --port PORT Set the port number\n");
printf(" -U, --user USERNAME Set the user name\n");
printf(" -P, --password PASSWORD Set the password\n");
printf(" -L, --logfile FILE Set the log file\n");
printf(" -v, --verbose Output text string of result\n");
printf(" -V, --version Display version information\n");
printf(" -?, --help Display help\n");
printf("\n");
printf("Commands:\n");
printf(" backup Backup a server\n");
printf(" list-backup List the backups for a server\n");
printf(" restore Restore a backup from a server\n");
printf(" archive Archive a backup from a server\n");
printf(" delete Delete a backup from a server\n");
printf(" retain Retain a backup from a server\n");
printf(" expunge Expunge a backup from a server\n");
printf(" is-alive Is pgmoneta alive\n");
printf(" stop Stop pgmoneta\n");
printf(" status Status of pgmoneta\n");
printf(" details Detailed status of pgmoneta\n");
printf(" reload Reload the configuration\n");
printf(" reset Reset the Prometheus statistics\n");
printf("\n");
printf("pgmoneta: %s\n", PGMONETA_HOMEPAGE);
printf("Report bugs: %s\n", PGMONETA_ISSUES);
}
int
main(int argc, char** argv)
{
int socket = -1;
SSL* s_ssl = NULL;
int ret;
int exit_code = 0;
char* configuration_path = NULL;
char* host = NULL;
char* port = NULL;
char* username = NULL;
char* password = NULL;
bool verbose = false;
char* logfile = NULL;
char* server = NULL;
char* id = NULL;
char* pos = NULL;
char* dir = NULL;
bool do_free = true;
int c;
int option_index = 0;
size_t size;
int position;
int32_t action = ACTION_UNKNOWN;
char un[MAX_USERNAME_LENGTH];
struct configuration* config = NULL;
while (1)
{
static struct option long_options[] =
{
{"config", required_argument, 0, 'c'},
{"host", required_argument, 0, 'h'},
{"port", required_argument, 0, 'p'},
{"user", required_argument, 0, 'U'},
{"password", required_argument, 0, 'P'},
{"logfile", required_argument, 0, 'L'},
{"verbose", no_argument, 0, 'v'},
{"version", no_argument, 0, 'V'},
{"help", no_argument, 0, '?'}
};
c = getopt_long(argc, argv, "vV?c:h:p:U:P:L:",
long_options, &option_index);
if (c == -1)
break;
switch (c)
{
case 'c':
configuration_path = optarg;
break;
case 'h':
host = optarg;
break;
case 'p':
port = optarg;
break;
case 'U':
username = optarg;
break;
case 'P':
password = optarg;
break;
case 'L':
logfile = optarg;
break;
case 'v':
verbose = true;
break;
case 'V':
version();
break;
case '?':
usage();
exit(1);
break;
default:
break;
}
}
if (getuid() == 0)
{
printf("pgmoneta-cli: Using the root account is not allowed\n");
exit(1);
}
if (configuration_path != NULL && (host != NULL || port != NULL))
{
printf("pgmoneta-cli: Use either -c or -h/-p to define endpoint\n");
exit(1);
}
if (argc <= 1)
{
usage();
exit(1);
}
size = sizeof(struct configuration);
if (pgmoneta_create_shared_memory(size, HUGEPAGE_OFF, &shmem))
{
printf("pgmoneta-cli: Error creating shared memory\n");
exit(1);
}
pgmoneta_init_configuration(shmem);
if (configuration_path != NULL)
{
ret = pgmoneta_read_configuration(shmem, configuration_path);
if (ret)
{
printf("pgmoneta-cli: Configuration not found: %s\n", configuration_path);
exit(1);
}
if (logfile)
{
config = (struct configuration*)shmem;
config->log_type = PGMONETA_LOGGING_TYPE_FILE;
memset(&config->log_path[0], 0, MISC_LENGTH);
memcpy(&config->log_path[0], logfile, MIN(MISC_LENGTH - 1, strlen(logfile)));
}
if (pgmoneta_start_logging())
{
exit(1);
}
config = (struct configuration*)shmem;
}
else
{
ret = pgmoneta_read_configuration(shmem, "/etc/pgmoneta/pgmoneta.conf");
if (ret)
{
if (host == NULL || port == NULL)
{
printf("pgmoneta-cli: Host and port must be specified\n");
exit(1);
}
}
else
{
configuration_path = "/etc/pgmoneta/pgmoneta.conf";
if (logfile)
{
config = (struct configuration*)shmem;
config->log_type = PGMONETA_LOGGING_TYPE_FILE;
memset(&config->log_path[0], 0, MISC_LENGTH);
memcpy(&config->log_path[0], logfile, MIN(MISC_LENGTH - 1, strlen(logfile)));
}
if (pgmoneta_start_logging())
{
exit(1);
}
config = (struct configuration*)shmem;
}
}
if (argc > 0)
{
action = find_action(argc, argv, &position);
if (action == ACTION_BACKUP)
{
if (argc == position + 2)
{
server = argv[argc - 1];
}
else
{
help_backup();
action = ACTION_HELP;
}
}
else if (action == ACTION_LIST_BACKUP)
{
if (argc == position + 2)
{
server = argv[argc - 1];
}
else
{
help_list_backup();
action = ACTION_HELP;
}
}
else if (action == ACTION_RESTORE)
{
if (argc == position + 5)
{
server = argv[argc - 4];
id = argv[argc - 3];
pos = argv[argc - 2];
dir = argv[argc - 1];
}
else if (argc == position + 4)
{
server = argv[argc - 3];
id = argv[argc - 2];
dir = argv[argc - 1];
}
else
{
help_restore();
action = ACTION_HELP;
}
}
else if (action == ACTION_ARCHIVE)
{
if (argc == position + 5)
{
server = argv[argc - 4];
id = argv[argc - 3];
pos = argv[argc - 2];
dir = argv[argc - 1];
}
else if (argc == position + 4)
{
server = argv[argc - 3];
id = argv[argc - 2];
dir = argv[argc - 1];
}
else
{
help_archive();
action = ACTION_HELP;
}
}
else if (action == ACTION_DELETE)
{
if (argc == position + 3)
{
server = argv[argc - 2];
id = argv[argc - 1];
}
else
{
help_delete();
action = ACTION_HELP;
}
}
else if (action == ACTION_STOP)
{
/* Ok */
}
else if (action == ACTION_STATUS)
{
/* Ok */
}
else if (action == ACTION_DETAILS)
{
/* Ok */
}
else if (action == ACTION_ISALIVE)
{
/* Ok */
}
else if (action == ACTION_RESET)
{
/* Ok */
}
else if (action == ACTION_RELOAD)
{
/* Local connection only */
if (configuration_path == NULL)
{
action = ACTION_UNKNOWN;
}
}
else if (action == ACTION_RETAIN)
{
if (argc == position + 3)
{
server = argv[argc - 2];
id = argv[argc - 1];
}
else
{
help_retain();
action = ACTION_HELP;
}
}
else if (action == ACTION_EXPUNGE)
{
if (argc == position + 3)
{
server = argv[argc - 2];
id = argv[argc - 1];
}
else
{
help_expunge();
action = ACTION_HELP;
}
}
if (action != ACTION_UNKNOWN)
{
if (configuration_path != NULL)
{
/* Local connection */
if (pgmoneta_connect_unix_socket(config->unix_socket_dir, MAIN_UDS, &socket))
{
exit_code = 1;
goto done;
}
}
else
{
/* Remote connection */
if (pgmoneta_connect(host, atoi(port), &socket))
{
printf("pgmoneta-cli: No route to host: %s:%s\n", host, port);
goto done;
}
/* User name */
if (username == NULL)
{
username:
printf("User name: ");
memset(&un, 0, sizeof(un));
fgets(&un[0], sizeof(un), stdin);
un[strlen(un) - 1] = 0;
username = &un[0];
}
if (username == NULL || strlen(username) == 0)
{
goto username;
}
/* Password */
if (password == NULL)
{
password:
if (password != NULL)
{
free(password);
password = NULL;
}
printf("Password : ");
password = pgmoneta_get_password();
printf("\n");
}
else
{
do_free = false;
}
for (int i = 0; i < strlen(password); i++)
{
if ((unsigned char)(*(password + i)) & 0x80)
{
goto password;
}
}
/* Authenticate */
if (pgmoneta_remote_management_scram_sha256(username, password, socket, &s_ssl) != AUTH_SUCCESS)
{
printf("pgmoneta-cli: Bad credentials for %s\n", username);
goto done;
}
}
}
if (action == ACTION_BACKUP)
{
exit_code = backup(s_ssl, socket, server);
}
else if (action == ACTION_LIST_BACKUP)
{
exit_code = list_backup(s_ssl, socket, server);
}
else if (action == ACTION_RESTORE)
{
exit_code = restore(s_ssl, socket, server, id, pos, dir);
}
else if (action == ACTION_ARCHIVE)
{
exit_code = archive(s_ssl, socket, server, id, pos, dir);
}
else if (action == ACTION_DELETE)
{
exit_code = delete(s_ssl, socket, server, id);
}
else if (action == ACTION_STOP)
{
exit_code = stop(s_ssl, socket);
}
else if (action == ACTION_STATUS)
{
exit_code = status(s_ssl, socket);
}
else if (action == ACTION_DETAILS)
{
exit_code = details(s_ssl, socket);
}
else if (action == ACTION_ISALIVE)
{
exit_code = isalive(s_ssl, socket);
}
else if (action == ACTION_RESET)
{
exit_code = reset(s_ssl, socket);
}
else if (action == ACTION_RELOAD)
{
exit_code = reload(s_ssl, socket);
}
else if (action == ACTION_RETAIN)
{
exit_code = retain(s_ssl, socket, server, id);
}
else if (action == ACTION_EXPUNGE)
{
exit_code = expunge(s_ssl, socket, server, id);
}
}
done:
if (s_ssl != NULL)
{
int res;
SSL_CTX* ctx = SSL_get_SSL_CTX(s_ssl);
res = SSL_shutdown(s_ssl);
if (res == 0)
{
SSL_shutdown(s_ssl);
}
SSL_free(s_ssl);
SSL_CTX_free(ctx);
}
pgmoneta_disconnect(socket);
if (action == ACTION_UNKNOWN)
{
usage();
exit_code = 1;
}
if (configuration_path != NULL)
{
if (action == ACTION_HELP)
{
/* Ok */
}
else if (action != ACTION_UNKNOWN && exit_code != 0)
{
printf("No connection to pgmoneta on %s\n", config->unix_socket_dir);
}
}
pgmoneta_stop_logging();
pgmoneta_destroy_shared_memory(shmem, size);
if (do_free)
{
free(password);
}
if (verbose)
{
if (exit_code == 0)
{
printf("Success (0)\n");
}
else
{
printf("Error (%d)\n", exit_code);
}
}
return exit_code;
}
static int
find_action(int argc, char** argv, int* place)
{
*place = -1;
for (int i = 1; i < argc; i++)
{
if (!strcmp("backup", argv[i]))
{
*place = i;
return ACTION_BACKUP;
}
else if (!strcmp("list-backup", argv[i]))
{
*place = i;
return ACTION_LIST_BACKUP;
}
else if (!strcmp("restore", argv[i]))
{
*place = i;
return ACTION_RESTORE;
}
else if (!strcmp("archive", argv[i]))
{
*place = i;
return ACTION_ARCHIVE;
}
else if (!strcmp("delete", argv[i]))
{
*place = i;
return ACTION_DELETE;
}
else if (!strcmp("stop", argv[i]))
{
*place = i;
return ACTION_STOP;
}
else if (!strcmp("status", argv[i]))
{
*place = i;
return ACTION_STATUS;
}
else if (!strcmp("details", argv[i]))
{
*place = i;
return ACTION_DETAILS;
}
else if (!strcmp("is-alive", argv[i]))
{
*place = i;
return ACTION_ISALIVE;
}
else if (!strcmp("reset", argv[i]))
{
*place = i;
return ACTION_RESET;
}
else if (!strcmp("reload", argv[i]))
{
*place = i;
return ACTION_RELOAD;
}
else if (!strcmp("retain", argv[i]))
{
*place = i;
return ACTION_RETAIN;
}
else if (!strcmp("expunge", argv[i]))
{
*place = i;
return ACTION_EXPUNGE;
}
}
return ACTION_UNKNOWN;
}
static void
help_backup(void)
{
printf("Backup a server\n");
printf(" pgmoneta-cli backup [<server>|all]\n");
}
static void
help_list_backup(void)
{
printf("List backups for a server\n");
printf(" pgmoneta-cli list-backup <server>\n");
}
static void
help_restore(void)
{
printf("Restore a backup for a server\n");
printf(" pgmoneta-cli restore <server> [<timestamp>|oldest|newest] [[current|name=X|xid=X|lsn=X|time=X|inclusive=X|timeline=X|action=X|primary|replica],*] <directory>\n");
}
static void
help_archive(void)
{
printf("Archive a backup for a server\n");
printf(" pgmoneta-cli archive [<server>|all] [<timestamp>|oldest|newest] [[current|name=X|xid=X|lsn=X|time=X|inclusive=X|timeline=X|action=X|primary|replica],*] <directory>\n");
}
static void
help_delete(void)
{
printf("Delete a backup for a server\n");
printf(" pgmoneta-cli delete <server> [<timestamp>|oldest|newest]\n");
}
static void
help_retain(void)
{
printf("Retain a backup for a server\n");
printf(" pgmoneta-cli retain <server> [<timestamp>|oldest|newest]\n");
}
static void
help_expunge(void)
{
printf("Expunge a backup for a server\n");
printf(" pgmoneta-cli expunge <server> [<timestamp>|oldest|newest]\n");
}
static int
backup(SSL* ssl, int socket, char* server)
{
int ret;
int number_of_returns = 0;
int code = 0;
ret = pgmoneta_management_backup(ssl, socket, server);
pgmoneta_management_read_int32(ssl, socket, &number_of_returns);
for (int i = 0; i < number_of_returns; i++)
{
pgmoneta_management_read_int32(ssl, socket, &code);
}
return ret;
}
static int
list_backup(SSL* ssl, int socket, char* server)
{
if (pgmoneta_management_list_backup(ssl, socket, server) == 0)
{
pgmoneta_management_read_list_backup(ssl, socket, server);
}
else
{
return 1;
}
return 0;
}
static int
restore(SSL* ssl, int socket, char* server, char* backup_id, char* position, char* directory)
{
int ret;
int number_of_returns = 0;
int code = 0;
ret = pgmoneta_management_restore(ssl, socket, server, backup_id, position, directory);
pgmoneta_management_read_int32(ssl, socket, &number_of_returns);
for (int i = 0; i < number_of_returns; i++)
{
pgmoneta_management_read_int32(ssl, socket, &code);
}
return ret;
}
static int
archive(SSL* ssl, int socket, char* server, char* backup_id, char* position, char* directory)
{
int ret;
int number_of_returns = 0;
int code = 0;
ret = pgmoneta_management_archive(ssl, socket, server, backup_id, position, directory);
pgmoneta_management_read_int32(ssl, socket, &number_of_returns);
for (int i = 0; i < number_of_returns; i++)
{
pgmoneta_management_read_int32(ssl, socket, &code);
}
return ret;
}
static int
delete(SSL* ssl, int socket, char* server, char* backup_id)
{
if (pgmoneta_management_delete(ssl, socket, server, backup_id) == 0)
{
pgmoneta_management_read_delete(ssl, socket, server, backup_id);
}
else
{
return 1;
}
return 0;
}
static int
stop(SSL* ssl, int socket)
{
if (pgmoneta_management_stop(ssl, socket))
{
return 1;
}
return 0;
}
static int
status(SSL* ssl, int socket)
{
if (pgmoneta_management_status(ssl, socket) == 0)
{
pgmoneta_management_read_status(ssl, socket);
}
else
{
return 1;
}
return 0;
}
static int
details(SSL* ssl, int socket)
{
if (pgmoneta_management_details(ssl, socket) == 0)
{
pgmoneta_management_read_details(ssl, socket);
}
else
{
return 1;
}
return 0;
}
static int
isalive(SSL* ssl, int socket)
{
int status = -1;
if (pgmoneta_management_isalive(ssl, socket) == 0)
{
if (pgmoneta_management_read_isalive(ssl, socket, &status))
{
return 1;
}
if (status != 1 && status != 2)
{
return 1;
}
}
else
{
return 1;
}
return 0;
}
static int
reset(SSL* ssl, int socket)
{
if (pgmoneta_management_reset(ssl, socket))
{
return 1;
}
return 0;
}
static int
reload(SSL* ssl, int socket)
{
if (pgmoneta_management_reload(ssl, socket))
{
return 1;
}
return 0;
}
static int
retain(SSL* ssl, int socket, char* server, char* backup_id)
{
if (pgmoneta_management_retain(ssl, socket, server, backup_id))
{
return 1;
}
return 0;
}
static int
expunge(SSL* ssl, int socket, char* server, char* backup_id)
{
if (pgmoneta_management_expunge(ssl, socket, server, backup_id))
{
return 1;
}
return 0;
}