From 18c2cfda0b420309488f76e10dd9fd39a05d390f Mon Sep 17 00:00:00 2001 From: Ian Barwick Date: Sat, 22 Apr 2017 09:06:42 +0900 Subject: [PATCH] Fix tabulation --- dbutils.c | 34 ++++----- dbutils.h | 10 +-- errcode.h | 2 +- log.c | 2 +- log.h | 2 +- repmgr-client.c | 187 ++++++++++++++++++++++++------------------------ repmgr-client.h | 48 ++++++------- repmgr.h | 8 +-- strutil.h | 2 +- 9 files changed, 148 insertions(+), 147 deletions(-) diff --git a/dbutils.c b/dbutils.c index 60b0f1ef..6636fe05 100644 --- a/dbutils.c +++ b/dbutils.c @@ -29,7 +29,7 @@ static bool _set_config(PGconn *conn, const char *config_param, const char *sqlq * Connect to a database using a conninfo string. * * NOTE: *do not* use this for replication connections; instead use: - * establish_db_connection_by_params() + * establish_db_connection_by_params() */ static PGconn * @@ -112,7 +112,7 @@ establish_db_connection_as_user(const char *conninfo, { PGconn *conn = NULL; t_conninfo_param_list conninfo_params; - bool parse_success; + bool parse_success; char *errmsg = NULL; initialize_conninfo_params(&conninfo_params, false); @@ -121,7 +121,7 @@ establish_db_connection_as_user(const char *conninfo, if (parse_success == false) { - log_error(_("unable to pass provided conninfo string:\n %s"), errmsg); + log_error(_("unable to pass provided conninfo string:\n %s"), errmsg); return NULL; } @@ -140,8 +140,8 @@ establish_db_connection_by_params(const char *keywords[], const char *values[], const bool exit_on_error) { PGconn *conn; - bool replication_connection = false; - int i; + bool replication_connection = false; + int i; /* Connect to the database using the provided parameters */ conn = PQconnectdbParams(keywords, values, true); @@ -149,7 +149,7 @@ establish_db_connection_by_params(const char *keywords[], const char *values[], /* Check to see that the backend connection was successfully made */ if ((PQstatus(conn) != CONNECTION_OK)) { - log_error(_("connection to database failed:\n %s"), + log_error(_("connection to database failed:\n %s"), PQerrorMessage(conn)); if (exit_on_error) { @@ -295,8 +295,8 @@ param_get(t_conninfo_param_list *param_list, const char *param) { if (param_list->values[c] != NULL && param_list->values[c][0] != '\0') return param_list->values[c]; - else - return NULL; + else + return NULL; } } @@ -376,7 +376,7 @@ begin_transaction(PGconn *conn) if (PQresultStatus(res) != PGRES_COMMAND_OK) { - log_error(_("Unable to begin transaction:\n %s"), + log_error(_("Unable to begin transaction:\n %s"), PQerrorMessage(conn)); PQclear(res); @@ -424,7 +424,7 @@ rollback_transaction(PGconn *conn) if (PQresultStatus(res) != PGRES_COMMAND_OK) { - log_error(_("Unable to rollback transaction:\n %s"), + log_error(_("Unable to rollback transaction:\n %s"), PQerrorMessage(conn)); PQclear(res); @@ -461,7 +461,7 @@ _set_config(PGconn *conn, const char *config_param, const char *sqlquery) } bool -set_config(PGconn *conn, const char *config_param, const char *config_value) +set_config(PGconn *conn, const char *config_param, const char *config_value) { char sqlquery[MAX_QUERY_LEN]; @@ -589,8 +589,8 @@ get_master_connection(PGconn *conn, initPQExpBuffer(&query); appendPQExpBuffer(&query, " SELECT node_id, conninfo, " - " CASE WHEN type = 'master' THEN 1 ELSE 2 END AS type_priority" - " FROM repmgr.nodes " + " CASE WHEN type = 'master' THEN 1 ELSE 2 END AS type_priority" + " FROM repmgr.nodes " " WHERE type != 'witness' " "ORDER BY active DESC, type_priority, priority, node_id"); @@ -599,7 +599,7 @@ get_master_connection(PGconn *conn, res = PQexec(conn, query.data); if (PQresultStatus(res) != PGRES_TUPLES_OK) { - log_error(_("unable to retrieve node records:\n %s"), + log_error(_("unable to retrieve node records:\n %s"), PQerrorMessage(conn)); PQclear(res); return NULL; @@ -626,7 +626,7 @@ get_master_connection(PGconn *conn, if (is_node_standby == -1) { - log_error(_("unable to retrieve recovery state from node %i:\n %s"), + log_error(_("unable to retrieve recovery state from node %i:\n %s"), node_id, PQerrorMessage(remote_conn)); PQfinish(remote_conn); @@ -672,8 +672,8 @@ get_master_node_id(PGconn *conn) initPQExpBuffer(&query); appendPQExpBuffer(&query, - "SELECT node_id " - " FROM repmgr.nodes " + "SELECT node_id " + " FROM repmgr.nodes " " WHERE type = 'master' " " AND active IS TRUE "); diff --git a/dbutils.h b/dbutils.h index 9784322f..a9dde811 100644 --- a/dbutils.h +++ b/dbutils.h @@ -75,7 +75,7 @@ typedef struct s_event_info { char *node_name; char *conninfo_str; -} t_event_info; +} t_event_info; #define T_EVENT_INFO_INITIALIZER { \ NULL, \ @@ -88,7 +88,7 @@ typedef struct s_event_info */ typedef struct { - int size; + int size; char **keywords; char **values; } t_conninfo_param_list; @@ -100,9 +100,9 @@ typedef struct typedef struct s_replication_slot { char slot_name[MAXLEN]; - char slot_type[MAXLEN]; + char slot_type[MAXLEN]; bool active; -} t_replication_slot; +} t_replication_slot; /* connection functions */ @@ -133,7 +133,7 @@ bool rollback_transaction(PGconn *conn); bool check_cluster_schema(PGconn *conn); /* GUC manipulation functions */ -bool set_config(PGconn *conn, const char *config_param, const char *config_value); +bool set_config(PGconn *conn, const char *config_param, const char *config_value); bool set_config_bool(PGconn *conn, const char *config_param, bool state); /* Server information functions */ diff --git a/errcode.h b/errcode.h index dad6069e..43ae981d 100644 --- a/errcode.h +++ b/errcode.h @@ -27,5 +27,5 @@ #define ERR_BARMAN 19 #define ERR_REGISTRATION_SYNC 20 -#endif /* _ERRCODE_H_ */ +#endif /* _ERRCODE_H_ */ diff --git a/log.c b/log.c index 44c85f5c..68bb0b04 100644 --- a/log.c +++ b/log.c @@ -78,7 +78,7 @@ _stderr_log_with_level(const char *level_name, int level, const char *fmt, va_li } vfprintf(stderr, fmt, ap); - fprintf(stderr, "\n"); + fprintf(stderr, "\n"); fflush(stderr); } } diff --git a/log.h b/log.h index 02f95cb9..5694abb0 100644 --- a/log.h +++ b/log.h @@ -12,7 +12,7 @@ #define REPMGR_STDERR 2 #define OM_COMMAND_LINE 1 -#define OM_DAEMON 2 +#define OM_DAEMON 2 extern void stderr_log_with_level(const char *level_name, int level, const char *fmt,...) diff --git a/repmgr-client.c b/repmgr-client.c index c41e0760..a5e85e74 100644 --- a/repmgr-client.c +++ b/repmgr-client.c @@ -27,9 +27,9 @@ ItemList cli_errors = { NULL, NULL }; ItemList cli_warnings = { NULL, NULL }; static bool config_file_required = true; -static char pg_bindir[MAXLEN] = ""; +static char pg_bindir[MAXLEN] = ""; -static char repmgr_slot_name[MAXLEN] = ""; +static char repmgr_slot_name[MAXLEN] = ""; static char *repmgr_slot_name_ptr = NULL; int @@ -38,13 +38,13 @@ main(int argc, char **argv) int optindex; int c; - char *repmgr_node_type = NULL; - char *repmgr_action = NULL; - bool valid_repmgr_node_type_found = true; + char *repmgr_node_type = NULL; + char *repmgr_action = NULL; + bool valid_repmgr_node_type_found = true; int action = NO_ACTION; - char *dummy_action = ""; + char *dummy_action = ""; - bool config_file_parsed = false; + bool config_file_parsed = false; set_progname(argv[0]); @@ -68,10 +68,10 @@ main(int argc, char **argv) */ switch (c) { - /* - * Options which cause repmgr to exit in this block; - * these are the only ones which can be executed as root user - */ + /* + * Options which cause repmgr to exit in this block; + * these are the only ones which can be executed as root user + */ case OPT_HELP: /* --help */ do_help(); exit(SUCCESS); @@ -88,7 +88,7 @@ main(int argc, char **argv) exit(SUCCESS); /* general configuration options - * ----------------------------- */ + * ----------------------------- */ /* -f/--config-file */ case 'f': @@ -112,7 +112,7 @@ main(int argc, char **argv) break; /* logging options - * --------------- */ + * --------------- */ /* -L/--log-level */ case 'L': @@ -143,7 +143,7 @@ main(int argc, char **argv) runtime_options.terse = true; break; /* --verbose */ - case 'v': + case 'v': runtime_options.verbose = true; break; @@ -152,10 +152,10 @@ main(int argc, char **argv) } /* - * Disallow further running as root to prevent directory ownership problems. - * We check this here to give the root user a chance to execute --help/--version - * options. - */ + * Disallow further running as root to prevent directory ownership problems. + * We check this here to give the root user a chance to execute --help/--version + * options. + */ if (geteuid() == 0) { fprintf(stderr, @@ -176,73 +176,73 @@ main(int argc, char **argv) /* * Determine the node type and action; following are valid: - * - * { MASTER | PRIMARY } REGISTER | - * STANDBY {REGISTER | UNREGISTER | CLONE [node] | PROMOTE | FOLLOW [node] | SWITCHOVER | REWIND} | - * WITNESS { CREATE | REGISTER | UNREGISTER } | - * BDR { REGISTER | UNREGISTER } | - * CLUSTER { CROSSCHECK | MATRIX | SHOW | CLEANUP } + * + * { MASTER | PRIMARY } REGISTER | + * STANDBY {REGISTER | UNREGISTER | CLONE [node] | PROMOTE | FOLLOW [node] | SWITCHOVER | REWIND} | + * WITNESS { CREATE | REGISTER | UNREGISTER } | + * BDR { REGISTER | UNREGISTER } | + * CLUSTER { CROSSCHECK | MATRIX | SHOW | CLEANUP } * * [node] is an optional hostname, provided instead of the -h/--host optipn */ if (optind < argc) { repmgr_node_type = argv[optind++]; - } + } - if (optind < argc) - { - repmgr_action = argv[optind++]; - } - else - { - repmgr_action = dummy_action; - } + if (optind < argc) + { + repmgr_action = argv[optind++]; + } + else + { + repmgr_action = dummy_action; + } - if (repmgr_node_type != NULL) - { - if (strcasecmp(repmgr_node_type, "MASTER") == 0 || strcasecmp(repmgr_node_type, "PRIMARY") == 0 ) + if (repmgr_node_type != NULL) + { + if (strcasecmp(repmgr_node_type, "MASTER") == 0 || strcasecmp(repmgr_node_type, "PRIMARY") == 0 ) { if (strcasecmp(repmgr_action, "REGISTER") == 0) action = MASTER_REGISTER; } - else - { - valid_repmgr_node_type_found = false; - } - } + else + { + valid_repmgr_node_type_found = false; + } + } if (action == NO_ACTION) - { - PQExpBufferData command_error; - initPQExpBuffer(&command_error); + { + PQExpBufferData command_error; + initPQExpBuffer(&command_error); - if (repmgr_node_type == NULL) - { - appendPQExpBuffer(&command_error, - _("no repmgr command provided")); - } - else if (valid_repmgr_node_type_found == false && repmgr_action[0] == '\0') - { - appendPQExpBuffer(&command_error, - _("unknown repmgr node type '%s'"), - repmgr_node_type); - } + if (repmgr_node_type == NULL) + { + appendPQExpBuffer(&command_error, + _("no repmgr command provided")); + } + else if (valid_repmgr_node_type_found == false && repmgr_action[0] == '\0') + { + appendPQExpBuffer(&command_error, + _("unknown repmgr node type '%s'"), + repmgr_node_type); + } else if (repmgr_action[0] == '\0') { - appendPQExpBuffer(&command_error, - _("no action provided for node type '%s'"), - repmgr_node_type); + appendPQExpBuffer(&command_error, + _("no action provided for node type '%s'"), + repmgr_node_type); } else { appendPQExpBuffer(&command_error, - _("unknown repmgr action '%s %s'"), - repmgr_node_type, - repmgr_action); + _("unknown repmgr action '%s %s'"), + repmgr_node_type, + repmgr_action); } - item_list_append(&cli_errors, command_error.data); + item_list_append(&cli_errors, command_error.data); } /* @@ -297,11 +297,11 @@ main(int argc, char **argv) /* * Initialize the logger. We've previously requested STDERR logging only - * to ensure the repmgr command doesn't have its output diverted to a logging - * facility (which usually doesn't make sense for a command line program). - * - * If required (e.g. when calling repmgr from repmgrd), this behaviour can be - * overridden with "--log-to-file". + * to ensure the repmgr command doesn't have its output diverted to a logging + * facility (which usually doesn't make sense for a command line program). + * + * If required (e.g. when calling repmgr from repmgrd), this behaviour can be + * overridden with "--log-to-file". */ logger_init(&config_file_options, progname()); @@ -380,11 +380,11 @@ print_error_list(ItemList *error_list, int log_level) for (cell = error_list->head; cell; cell = cell->next) { - fprintf(stderr, " "); + fprintf(stderr, " "); switch(log_level) { /* Currently we only need errors and warnings */ - case LOG_ERROR: + case LOG_ERROR: log_error("%s", cell->string); break; case LOG_WARNING: @@ -399,36 +399,36 @@ static void do_help(void) { printf(_("%s: replication management tool for PostgreSQL\n"), progname()); - puts(""); + puts(""); - /* add a big friendly warning if root is executing "repmgr --help" */ + /* add a big friendly warning if root is executing "repmgr --help" */ if (geteuid() == 0) { - printf(_(" **************************************************\n")); - printf(_(" *** repmgr must be executed by a non-superuser ***\n")); - printf(_(" **************************************************\n")); - puts(""); - } + printf(_(" **************************************************\n")); + printf(_(" *** repmgr must be executed by a non-superuser ***\n")); + printf(_(" **************************************************\n")); + puts(""); + } printf(_("Usage:\n")); - printf(_(" %s [OPTIONS] master register\n"), progname()); - puts(""); + printf(_(" %s [OPTIONS] master register\n"), progname()); + puts(""); printf(_("General options:\n")); printf(_(" -?, --help show this help, then exit\n")); printf(_(" -V, --version output version information, then exit\n")); - puts(""); + puts(""); printf(_("General configuration options:\n")); printf(_(" -b, --pg_bindir=PATH path to PostgreSQL binaries (optional)\n")); printf(_(" -f, --config-file=PATH path to the configuration file\n")); printf(_(" -F, --force force potentially dangerous operations to happen\n")); - puts(""); + puts(""); printf(_("Logging options:\n")); printf(_(" -L, --log-level set log level (overrides configuration file; default: NOTICE)\n")); printf(_(" --log-to-file log to file (or logging facility) defined in repmgr.conf\n")); printf(_(" -t, --terse don't display hints and other non-critical output\n")); printf(_(" -v, --verbose display additional log output (useful for debugging)\n")); - puts(""); + puts(""); } @@ -506,6 +506,7 @@ do_master_register(void) exit(ERR_BAD_CONFIG); } + } @@ -519,22 +520,22 @@ bool create_repmgr_extension(PGconn *conn) char *current_user; const char *superuser_status; bool is_superuser; - PGconn *superuser_conn = NULL; - PGconn *schema_create_conn = NULL; + PGconn *superuser_conn = NULL; + PGconn *schema_create_conn = NULL; initPQExpBuffer(&query); appendPQExpBuffer(&query, - " SELECT ae.name, e.extname " + " SELECT ae.name, e.extname " " FROM pg_catalog.pg_available_extensions ae " "LEFT JOIN pg_catalog.pg_extension e " " ON e.extname=ae.name " - " WHERE ae.name='repmgr' "); + " WHERE ae.name='repmgr' "); res = PQexec(conn, query.data); if (PQresultStatus(res) != PGRES_TUPLES_OK) { - log_error(_("unable to execute extension query:\n %s"), + log_error(_("unable to execute extension query:\n %s"), PQerrorMessage(conn)); PQclear(res); @@ -639,7 +640,7 @@ bool create_repmgr_extension(PGconn *conn) if (PQresultStatus(res) != PGRES_COMMAND_OK) { - log_error(_("unable to grant usage on \"repmgr\" extension to %s:\n %s"), + log_error(_("unable to grant usage on \"repmgr\" extension to %s:\n %s"), current_user, PQerrorMessage(schema_create_conn)); PQclear(res); @@ -666,18 +667,18 @@ bool create_repmgr_extension(PGconn *conn) * Verify that the server is MIN_SUPPORTED_VERSION_NUM or later * * PGconn *conn: - * the connection to check + * the connection to check * * char *server_type: - * either "master" or "standby"; used to format error message + * either "master" or "standby"; used to format error message * * bool exit_on_error: - * exit if reported server version is too low; optional to enable some callers - * to perform additional cleanup + * exit if reported server version is too low; optional to enable some callers + * to perform additional cleanup * * char *server_version_string - * passed to get_server_version(), which will place the human-readable - * server version string there (e.g. "9.4.0") + * passed to get_server_version(), which will place the human-readable + * server version string there (e.g. "9.4.0") */ static int check_server_version(PGconn *conn, char *server_type, bool exit_on_error, char *server_version_string) diff --git a/repmgr-client.h b/repmgr-client.h index 359f7168..729a906d 100644 --- a/repmgr-client.h +++ b/repmgr-client.h @@ -27,37 +27,37 @@ #define STANDBY_CLONE 4 #define STANDBY_PROMOTE 5 #define STANDBY_FOLLOW 6 -#define STANDBY_SWITCHOVER 7 +#define STANDBY_SWITCHOVER 7 #define STANDBY_ARCHIVE_CONFIG 8 #define STANDBY_RESTORE_CONFIG 9 #define WITNESS_CREATE 10 -#define WITNESS_REGISTER 11 -#define WITNESS_UNREGISTER 12 +#define WITNESS_REGISTER 11 +#define WITNESS_UNREGISTER 12 #define CLUSTER_SHOW 13 #define CLUSTER_CLEANUP 14 #define CLUSTER_MATRIX 15 #define CLUSTER_CROSSCHECK 16 -#define BDR_REGISTER 17 -#define BDR_UNREGISTER 18 +#define BDR_REGISTER 17 +#define BDR_UNREGISTER 18 /* command line options without short versions */ -#define OPT_HELP 1 -#define OPT_CHECK_UPSTREAM_CONFIG 2 -#define OPT_RECOVERY_MIN_APPLY_DELAY 3 -#define OPT_COPY_EXTERNAL_CONFIG_FILES 4 -#define OPT_CONFIG_ARCHIVE_DIR 5 -#define OPT_PG_REWIND 6 -#define OPT_PWPROMPT 7 -#define OPT_CSV 8 -#define OPT_NODE 9 -#define OPT_WITHOUT_BARMAN 10 -#define OPT_NO_UPSTREAM_CONNECTION 11 -#define OPT_REGISTER_WAIT 12 -#define OPT_CLUSTER 13 -#define OPT_LOG_TO_FILE 14 -#define OPT_UPSTREAM_CONNINFO 15 -#define OPT_NO_CONNINFO_PASSWORD 16 -#define OPT_REPLICATION_USER 17 +#define OPT_HELP 1 +#define OPT_CHECK_UPSTREAM_CONFIG 2 +#define OPT_RECOVERY_MIN_APPLY_DELAY 3 +#define OPT_COPY_EXTERNAL_CONFIG_FILES 4 +#define OPT_CONFIG_ARCHIVE_DIR 5 +#define OPT_PG_REWIND 6 +#define OPT_PWPROMPT 7 +#define OPT_CSV 8 +#define OPT_NODE 9 +#define OPT_WITHOUT_BARMAN 10 +#define OPT_NO_UPSTREAM_CONNECTION 11 +#define OPT_REGISTER_WAIT 12 +#define OPT_CLUSTER 13 +#define OPT_LOG_TO_FILE 14 +#define OPT_UPSTREAM_CONNINFO 15 +#define OPT_NO_CONNINFO_PASSWORD 16 +#define OPT_REPLICATION_USER 17 static struct option long_options[] = { @@ -120,7 +120,7 @@ typedef struct bool force; char pg_bindir[MAXLEN]; /* overrides setting in repmgr.conf */ - /* logging options */ + /* logging options */ char loglevel[MAXLEN]; /* overrides setting in repmgr.conf */ bool log_to_file; bool terse; @@ -130,7 +130,7 @@ typedef struct char superuser[MAXLEN]; -} t_runtime_options; +} t_runtime_options; #define T_RUNTIME_OPTIONS_INITIALIZER { \ /* general configuration options */ \ diff --git a/repmgr.h b/repmgr.h index b99cd1c8..6cd697fc 100644 --- a/repmgr.h +++ b/repmgr.h @@ -22,14 +22,14 @@ #define MIN_SUPPORTED_VERSION "9.3" #define MIN_SUPPORTED_VERSION_NUM 90300 -#define NODE_NOT_FOUND -1 +#define NODE_NOT_FOUND -1 #define NO_UPSTREAM_NODE -1 -#define UNKNOWN_NODE_ID -1 +#define UNKNOWN_NODE_ID -1 #define REPLICATION_TYPE_PHYSICAL 1 -#define REPLICATION_TYPE_BDR 2 +#define REPLICATION_TYPE_BDR 2 -#define BDR_MONITORING_LOCAL 1 +#define BDR_MONITORING_LOCAL 1 #define BDR_MONITORING_PRIORITY 2 #define MANUAL_FAILOVER 0 diff --git a/strutil.h b/strutil.h index 172325dc..5ff149a8 100644 --- a/strutil.h +++ b/strutil.h @@ -28,4 +28,4 @@ __attribute__((format(PG_PRINTF_ATTRIBUTE, 2, 3))); extern char * escape_recovery_conf_value(const char *src); -#endif /* _STRUTIL_H_ */ +#endif /* _STRUTIL_H_ */