Break out error codes, cleanup header files and HISTORY

This commit is contained in:
Greg Smith
2011-02-15 00:43:36 -05:00
parent f6618a01c7
commit 45022debc6
6 changed files with 81 additions and 33 deletions

View File

@@ -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)

37
errcode.h Normal file
View File

@@ -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 <http://www.gnu.org/licenses/>.
*
*/
#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_ */

View File

@@ -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.

View File

@@ -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
{

View File

@@ -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 <http://www.gnu.org/licenses/>.
*
*/
#include <stdarg.h>
@@ -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;

View File

@@ -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 <http://www.gnu.org/licenses/>.
*
*/
#ifndef _STRUTIL_H_
#define _STRUTIL_H_
#include <stdlib.h>
#include <errcode.h>
#define QUERY_STR_LEN 8192
#define MAXLEN 1024