Skip to content

Commit

Permalink
Break out error codes, cleanup header files and HISTORY
Browse files Browse the repository at this point in the history
  • Loading branch information
Greg Smith authored and Greg Smith committed Feb 15, 2011
1 parent f6618a0 commit 45022de
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 33 deletions.
7 changes: 6 additions & 1 deletion HISTORY
Original file line number Diff line number Diff line change
Expand Up @@ -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 changes: 37 additions & 0 deletions errcode.h
Original file line number Diff line number Diff line change
@@ -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_ */
23 changes: 8 additions & 15 deletions repmgr.c
Original file line number Diff line number Diff line change
Expand Up @@ -1025,19 +1025,15 @@ do_standby_clone(void)
}
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);
Expand All @@ -1046,9 +1042,6 @@ do_standby_clone(void)
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.
Expand Down
15 changes: 1 addition & 14 deletions repmgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
{
Expand Down
15 changes: 14 additions & 1 deletion strutil.c
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -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;
Expand Down
17 changes: 15 additions & 2 deletions strutil.h
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 45022de

Please sign in to comment.