diff --git a/HISTORY b/HISTORY index 6a79dce9..731b3deb 100644 --- a/HISTORY +++ b/HISTORY @@ -15,4 +15,9 @@ Add information about progress during "standby clone" (Gabriele) Fix double free error in repmgrd (Charles Duffy) Make repmgr exit with an error code when encountering an error (Charles) - Standardize on error return codes, use in repmgrd too (Greg) + Standardize on error return codes, use in repmgrd too (Greg) + Add [un]install actions/SQL like most contrib modules (Daniel Farina) + Wrap all string construction and produce error on overflow (Daniel) + Correct freeing of memory from first_wal_segment (Daniel) + Allow creating recovery.conf file with a password (Daniel) + Inform when STANDBY CLONE sees an unused config file (Daniel) diff --git a/errcode.h b/errcode.h new file mode 100644 index 00000000..49433dae --- /dev/null +++ b/errcode.h @@ -0,0 +1,37 @@ +/* + * errcode.h + * Copyright (C) 2ndQuadrant, 2011 + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +#ifndef _ERRCODE_H_ +#define _ERRCODE_H_ + +/* Exit return code */ + +#define SUCCESS 0 +#define ERR_BAD_CONFIG 1 +#define ERR_BAD_RSYNC 2 +#define ERR_STOP_BACKUP 3 +#define ERR_NO_RESTART 4 +#define ERR_NEEDS_XLOG 5 +#define ERR_DB_CON 6 +#define ERR_DB_QUERY 7 +#define ERR_PROMOTED 8 +#define ERR_BAD_PASSWORD 9 +#define ERR_STR_OVERFLOW 10 + +#endif /* _ERRCODE_H_ */ diff --git a/repmgr.c b/repmgr.c index e921a7cf..4802b8f8 100644 --- a/repmgr.c +++ b/repmgr.c @@ -1025,19 +1025,15 @@ stop_backup: } last_wal_segment = PQgetvalue(res, 0, 0); - if (runtime_options.verbose) - { - printf( - _("%s requires primary to keep WAL files %s until at least %s\n"), - progname, first_wal_segment, last_wal_segment); + log_info(_("%s requires primary to keep WAL files %s until at least %s\n"), + progname, first_wal_segment, last_wal_segment); - /* - * Only free the first_wal_segment since it was copied out of the - * pqresult. - */ - free(first_wal_segment); - first_wal_segment = NULL; - } + /* + * Only free the first_wal_segment since it was copied out of the + * pqresult. + */ + free(first_wal_segment); + first_wal_segment = NULL; PQclear(res); PQfinish(conn); @@ -1046,9 +1042,6 @@ stop_backup: if (r != 0) exit(ERR_BAD_RSYNC); - log_info(_("%s requires primary to keep WAL files %s until at least %s\n"), - progname, first_wal_segment, last_wal_segment); - /* * We need to create the pg_xlog sub directory too, I'm reusing a variable * here. diff --git a/repmgr.h b/repmgr.h index 484ea10b..c2c96fab 100644 --- a/repmgr.h +++ b/repmgr.h @@ -26,13 +26,13 @@ #include "strutil.h" #include "dbutils.h" +#include "errcode.h" #define PRIMARY_MODE 0 #define STANDBY_MODE 1 #include "config.h" #define MAXFILENAME 1024 -#define MAXLINELENGTH 4096 #define ERRBUFF_SIZE 512 #define DEFAULT_CONFIG_FILE "./repmgr.conf" @@ -42,19 +42,6 @@ #define DEFAULT_DBNAME "postgres" #define DEFAULT_REPMGR_SCHEMA_PREFIX "repmgr_" -/* Exit return code */ - -#define SUCCESS 0 -#define ERR_BAD_CONFIG 1 -#define ERR_BAD_RSYNC 2 -#define ERR_STOP_BACKUP 3 -#define ERR_NO_RESTART 4 -#define ERR_NEEDS_XLOG 5 -#define ERR_DB_CON 6 -#define ERR_DB_QUERY 7 -#define ERR_PROMOTED 8 -#define ERR_BAD_PASSWORD 9 - /* Run time options type */ typedef struct { diff --git a/strutil.c b/strutil.c index 0969597d..641b234f 100644 --- a/strutil.c +++ b/strutil.c @@ -3,6 +3,19 @@ * * Copyright (C) 2ndQuadrant, 2011 * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * */ #include @@ -24,7 +37,7 @@ xvsnprintf(char *str, size_t size, const char *format, va_list ap) if (retval >= size) { fprintf(stderr, "Buffer not large enough to format entire string\n"); - exit(255); + exit(ERR_STR_OVERFLOW); } return retval; diff --git a/strutil.h b/strutil.h index 959448fe..ec39cbf4 100644 --- a/strutil.h +++ b/strutil.h @@ -1,15 +1,28 @@ /* * strutil.h - * * Copyright (C) 2ndQuadrant, 2010-2011 * + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * */ #ifndef _STRUTIL_H_ #define _STRUTIL_H_ #include - +#include #define QUERY_STR_LEN 8192 #define MAXLEN 1024