1
0
mirror of https://github.com/postgrespro/pg_probackup.git synced 2024-11-24 08:52:38 +02:00

Sync the latest pgut and update copyrights.

git-svn-id: http://pg-rman.googlecode.com/svn/trunk@28 182aca00-e38e-11de-a668-6fd11605f5ce
This commit is contained in:
itagaki.takahiro 2010-01-06 02:25:21 +00:00
parent e3b9fd4e16
commit 4df4b1644f
20 changed files with 117 additions and 94 deletions

View File

@ -1,5 +1,7 @@
Copyright (c) 2008-2009, NIPPON TELEGRAPH AND TELEPHONE CORPORATION
All rights reserved.
Copyright (c) 2009-2010, NIPPON TELEGRAPH AND TELEPHONE CORPORATION
Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
Portions Copyright (c) 1994, The Regents of the University of California
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

View File

@ -2,7 +2,7 @@
*
* backup.c: backup DB cluster, archived WAL, serverlog.
*
* Copyright (c) 2009, NIPPON TELEGRAPH AND TELEPHONE CORPORATION
* Copyright (c) 2009-2010, NIPPON TELEGRAPH AND TELEPHONE CORPORATION
*
*-------------------------------------------------------------------------
*/

View File

@ -2,7 +2,7 @@
*
* catalog.c: backup catalog opration
*
* Copyright (c) 2009, NIPPON TELEGRAPH AND TELEPHONE CORPORATION
* Copyright (c) 2009-2010, NIPPON TELEGRAPH AND TELEPHONE CORPORATION
*
*-------------------------------------------------------------------------
*/
@ -430,7 +430,7 @@ catalog_read_ini(const char *path)
{ 0 }
};
backup = (pgBackup *) pgut_malloc(sizeof(*backup));
backup = pgut_new(pgBackup);
catalog_init_config(backup);
i = 0;

2
data.c
View File

@ -2,7 +2,7 @@
*
* data.c: compress / uncompress data pages
*
* Copyright (c) 2009, NIPPON TELEGRAPH AND TELEPHONE CORPORATION
* Copyright (c) 2009-2010, NIPPON TELEGRAPH AND TELEPHONE CORPORATION
*
*-------------------------------------------------------------------------
*/

View File

@ -2,7 +2,7 @@
*
* delete.c: delete backup files.
*
* Copyright (c) 2009, NIPPON TELEGRAPH AND TELEPHONE CORPORATION
* Copyright (c) 2009-2010, NIPPON TELEGRAPH AND TELEPHONE CORPORATION
*
*-------------------------------------------------------------------------
*/

2
dir.c
View File

@ -2,7 +2,7 @@
*
* dir.c: directory operation utility.
*
* Copyright (c) 2009, NIPPON TELEGRAPH AND TELEPHONE CORPORATION
* Copyright (c) 2009-2010, NIPPON TELEGRAPH AND TELEPHONE CORPORATION
*
*-------------------------------------------------------------------------
*/

2
init.c
View File

@ -2,7 +2,7 @@
*
* init.c: manage backup catalog.
*
* Copyright (c) 2009, NIPPON TELEGRAPH AND TELEPHONE CORPORATION
* Copyright (c) 2009-2010, NIPPON TELEGRAPH AND TELEPHONE CORPORATION
*
*-------------------------------------------------------------------------
*/

View File

@ -2,7 +2,7 @@
*
* parray.c: pointer array collection.
*
* Copyright (c) 2009, NIPPON TELEGRAPH AND TELEPHONE CORPORATION
* Copyright (c) 2009-2010, NIPPON TELEGRAPH AND TELEPHONE CORPORATION
*
*-------------------------------------------------------------------------
*/
@ -24,7 +24,7 @@ struct parray
parray *
parray_new(void)
{
parray *a = pgut_malloc(sizeof(parray));
parray *a = pgut_new(parray);
a->data = NULL;
a->used = 0;

View File

@ -2,7 +2,7 @@
*
* parray.h: pointer array collection.
*
* Copyright (c) 2009, NIPPON TELEGRAPH AND TELEPHONE CORPORATION
* Copyright (c) 2009-2010, NIPPON TELEGRAPH AND TELEPHONE CORPORATION
*
*-------------------------------------------------------------------------
*/

View File

@ -2,7 +2,7 @@
*
* pg_rman.c: Backup/Recovery manager for PostgreSQL.
*
* Copyright (c) 2009, NIPPON TELEGRAPH AND TELEPHONE CORPORATION
* Copyright (c) 2009-2010, NIPPON TELEGRAPH AND TELEPHONE CORPORATION
*
*-------------------------------------------------------------------------
*/

View File

@ -2,7 +2,7 @@
*
* pg_rman.h: Backup/Recovery manager for PostgreSQL.
*
* Copyright (c) 2009, NIPPON TELEGRAPH AND TELEPHONE CORPORATION
* Copyright (c) 2009-2010, NIPPON TELEGRAPH AND TELEPHONE CORPORATION
*
*-------------------------------------------------------------------------
*/

View File

@ -2,7 +2,7 @@
*
* pgut-port.c
*
* Copyright (c) 2009, NIPPON TELEGRAPH AND TELEPHONE CORPORATION
* Copyright (c) 2009-2010, NIPPON TELEGRAPH AND TELEPHONE CORPORATION
*
*-------------------------------------------------------------------------
*/

View File

@ -2,7 +2,7 @@
*
* pgut-port.h
*
* Copyright (c) 2009, NIPPON TELEGRAPH AND TELEPHONE CORPORATION
* Copyright (c) 2009-2010, NIPPON TELEGRAPH AND TELEPHONE CORPORATION
*
*-------------------------------------------------------------------------
*/

View File

@ -2,7 +2,7 @@
*
* pgut.c
*
* Copyright (c) 2009, NIPPON TELEGRAPH AND TELEPHONE CORPORATION
* Copyright (c) 2009-2010, NIPPON TELEGRAPH AND TELEPHONE CORPORATION
*
*-------------------------------------------------------------------------
*/
@ -18,6 +18,15 @@
#include "pgut.h"
/* old gcc doesn't have LLONG_MAX. */
#ifndef LLONG_MAX
#if defined(HAVE_LONG_INT_64) || !defined(HAVE_LONG_LONG_INT_64)
#define LLONG_MAX LONG_MAX
#else
#define LLONG_MAX INT64CONST(0x7FFFFFFFFFFFFFFF)
#endif
#endif
const char *PROGRAM_NAME = NULL;
const char *dbname = NULL;
@ -111,7 +120,7 @@ option_merge(const pgut_option opts1[], const pgut_option opts2[])
size_t len2 = option_length(opts2);
size_t n = len1 + len2;
result = pgut_malloc(sizeof(struct option) * (n + 1));
result = pgut_newarray(struct option, n + 1);
option_copy(result, opts1, len1);
option_copy(result + len1, opts2, len2);
memset(&result[n], 0, sizeof(pgut_option));
@ -404,13 +413,7 @@ parse_int64(const char *value, int64 *result)
if (strcmp(value, INFINITE_STR) == 0)
{
#if defined(HAVE_LONG_INT_64)
*result = LONG_MAX;
#elif defined(HAVE_LONG_LONG_INT_64)
*result = LLONG_MAX;
#else
*result = LONG_MAX;
#endif
return true;
}
@ -474,56 +477,50 @@ parse_uint64(const char *value, uint64 *result)
return true;
}
#ifdef WIN32 /* == not defined(HAVE_STRPTIME) */
static char *
strptime(const char *s, const char *format, struct tm *tm)
{
int n;
char c;
/* only support single format for now */
if (strcmp(format, "%Y-%m-%d %H:%M:%S") != 0)
{
errno = EINVAL;
return NULL;
}
n = sscanf(s, "%d-%d-%d %d:%d:%d%c",
&tm->tm_year, &tm->tm_mon, &tm->tm_mday,
&tm->tm_hour, &tm->tm_min, &tm->tm_sec, &c);
if (tm->tm_year >= 1900)
tm->tm_year -= 1900; /* years since 1900 */
if (tm->tm_mon > 0)
tm->tm_mon -= 1; /* tm_mon is [0,11] */
if (n == 6)
return (char *) (s + strlen(s));
else
return strchr(s, c);
}
#endif
/*
* Convert ISO-8601 format string to time_t value.
*/
bool
parse_time(const char *value, time_t *time)
{
char *endp;
struct tm tm = { 0 };
size_t len;
char *tmp;
int i;
struct tm tm;
char junk[2];
/* special case for invalid time */
if (strcmp(value, "****-**-** **:**:**") == 0)
{
*time = (time_t) 0;
return true;
}
/* tmp = replace( value, !isalnum, ' ' ) */
tmp = pgut_malloc(strlen(value) + + 1);
len = 0;
for (i = 0; value[i]; i++)
tmp[len++] = (IsAlnum(value[i]) ? value[i] : ' ');
tmp[len] = '\0';
endp = strptime(value, "%Y-%m-%d %H:%M:%S", &tm);
if (endp == NULL || *endp)
/* parse for "YYYY-MM-DD HH:MI:SS" */
tm.tm_year = 0; /* tm_year is year - 1900 */
tm.tm_mon = 0; /* tm_mon is 0 - 11 */
tm.tm_mday = 1; /* tm_mday is 1 - 31 */
tm.tm_hour = 0;
tm.tm_min = 0;
tm.tm_sec = 0;
i = sscanf(tmp, "%04d %02d %02d %02d %02d %02d%1s",
&tm.tm_year, &tm.tm_mon, &tm.tm_mday,
&tm.tm_hour, &tm.tm_min, &tm.tm_sec, junk);
free(tmp);
if (i < 1 || 6 < i)
return false;
/* adjust year */
if (tm.tm_year < 100)
tm.tm_year += 2000 - 1900;
else if (tm.tm_year >= 1900)
tm.tm_year -= 1900;
/* adjust month */
if (i > 1)
tm.tm_mon -= 1;
*time = mktime(&tm);
return true;
@ -670,14 +667,8 @@ pgut_readopt(const char *path, pgut_option options[], int elevel)
if (!options)
return;
fp = fopen(path, "rt");
if (fp == NULL)
{
if (errno != ENOENT)
elog(WARNING, _("can't open config file \"%s\": %s"), path,
strerror(errno));
if ((fp = pgut_fopen(path, "rt", true)) == NULL)
return;
}
while (fgets(buf, lengthof(buf), fp))
{
@ -823,7 +814,7 @@ parse_pair(const char buffer[], char key[], char value[])
if (end - start <= 0)
{
if (*start == '=')
elog(WARNING, _("syntax error in \"%s\"."), buffer);
elog(WARNING, "syntax error in \"%s\"", buffer);
return false;
}
@ -837,7 +828,7 @@ parse_pair(const char buffer[], char key[], char value[])
if (*start != '=')
{
elog(WARNING, _("syntax error in \"%s\"."), buffer);
elog(WARNING, "syntax error in \"%s\"", buffer);
return false;
}
@ -854,7 +845,7 @@ parse_pair(const char buffer[], char key[], char value[])
if (*start != '\0' && *start != '#')
{
elog(WARNING, _("syntax error in \"%s\"."), buffer);
elog(WARNING, "syntax error in \"%s\"", buffer);
return false;
}
@ -1297,7 +1288,7 @@ pgut_atexit_push(pgut_atexit_callback callback, void *userdata)
AssertArg(callback != NULL);
item = pgut_malloc(sizeof(pgut_atexit_item));
item = pgut_new(pgut_atexit_item);
item->callback = callback;
item->userdata = userdata;
item->next = pgut_atexit_stack;
@ -1383,11 +1374,16 @@ help(bool details)
printf(" --debug debug mode\n");
}
printf(" --help show this help, then exit\n");
printf(" --version output version information, then exit\n\n");
if (PROGRAM_URL)
printf("Read the website for details. <%s>\n", PROGRAM_URL);
if (PROGRAM_EMAIL)
printf("Report bugs to <%s>.\n", PROGRAM_EMAIL);
printf(" --version output version information, then exit\n");
if (details && (PROGRAM_URL || PROGRAM_EMAIL))
{
printf("\n");
if (PROGRAM_URL)
printf("Read the website for details. <%s>\n", PROGRAM_URL);
if (PROGRAM_EMAIL)
printf("Report bugs to <%s>.\n", PROGRAM_EMAIL);
}
}
/*
@ -1482,7 +1478,7 @@ pgut_malloc(size_t size)
char *ret;
if ((ret = malloc(size)) == NULL)
elog(ERROR_NOMEM, "can't allocate memory (%lu bytes): %s",
elog(ERROR_NOMEM, "could not allocate memory (%lu bytes): %s",
(unsigned long) size, strerror(errno));
return ret;
}
@ -1493,7 +1489,7 @@ pgut_realloc(void *p, size_t size)
char *ret;
if ((ret = realloc(p, size)) == NULL)
elog(ERROR_NOMEM, "can't re-allocate memory (%lu bytes): %s",
elog(ERROR_NOMEM, "could not re-allocate memory (%lu bytes): %s",
(unsigned long) size, strerror(errno));
return ret;
}
@ -1507,7 +1503,7 @@ pgut_strdup(const char *str)
return NULL;
if ((ret = strdup(str)) == NULL)
elog(ERROR_NOMEM, "can't duplicate string \"%s\": %s",
elog(ERROR_NOMEM, "could not duplicate string \"%s\": %s",
str, strerror(errno));
return ret;
}
@ -1542,6 +1538,23 @@ strdup_trim(const char *str)
return strdup_with_len(str, len);
}
FILE *
pgut_fopen(const char *path, const char *mode, bool missing_ok)
{
FILE *fp;
if ((fp = fopen(path, mode)) == NULL)
{
if (missing_ok && errno == ENOENT)
return NULL;
elog(ERROR_SYSTEM, "could not open file \"%s\": %s",
path, strerror(errno));
}
return fp;
}
#ifdef WIN32
static int select_win32(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, const struct timeval * timeout);
#define select select_win32

View File

@ -2,7 +2,7 @@
*
* pgut.h
*
* Copyright (c) 2009, NIPPON TELEGRAPH AND TELEPHONE CORPORATION
* Copyright (c) 2009-2010, NIPPON TELEGRAPH AND TELEPHONE CORPORATION
*
*-------------------------------------------------------------------------
*/
@ -51,9 +51,9 @@ typedef enum pgut_optsrc
* b: bool (true)
* B: bool (false)
* f: pgut_optfn
* i: 32bit singed integer
* i: 32bit signed integer
* u: 32bit unsigned integer
* I: 64bit singed integer
* I: 64bit signed integer
* U: 64bit unsigned integer
* s: string
* t: time_t
@ -133,6 +133,14 @@ extern char *pgut_strdup(const char *str);
extern char *strdup_with_len(const char *str, size_t len);
extern char *strdup_trim(const char *str);
#define pgut_new(type) ((type *) pgut_malloc(sizeof(type)))
#define pgut_newarray(type, n) ((type *) pgut_malloc(sizeof(type) * (n)))
/*
* file operations
*/
extern FILE *pgut_fopen(const char *path, const char *mode, bool missing_ok);
/*
* elog
*/

View File

@ -2,7 +2,7 @@
*
* restore.c: restore DB cluster and archived WAL.
*
* Copyright (c) 2009, NIPPON TELEGRAPH AND TELEPHONE CORPORATION
* Copyright (c) 2009-2010, NIPPON TELEGRAPH AND TELEPHONE CORPORATION
*
*-------------------------------------------------------------------------
*/
@ -741,7 +741,7 @@ readTimeLineHistory(TimeLineID targetTLI)
if (*ptr == '\0' || *ptr == '#')
continue;
timeline = pgut_malloc(sizeof(*timeline));
timeline = pgut_new(pgTimeLine);
timeline->tli = 0;
timeline->end.xlogid = 0;
timeline->end.xrecoff = 0;
@ -785,7 +785,7 @@ readTimeLineHistory(TimeLineID targetTLI)
_("Timeline IDs must be less than child timeline's ID."));
/* append target timeline */
timeline = pgut_malloc(sizeof(*timeline));
timeline = pgut_new(pgTimeLine);
timeline->tli = targetTLI;
timeline->end.xlogid = (uint32) -1; /* lsn in target timelie is valid */
timeline->end.xrecoff = (uint32) -1; /* lsn target timelie is valid */

2
show.c
View File

@ -2,7 +2,7 @@
*
* show.c: show backup catalog.
*
* Copyright (c) 2009, NIPPON TELEGRAPH AND TELEPHONE CORPORATION
* Copyright (c) 2009-2010, NIPPON TELEGRAPH AND TELEPHONE CORPORATION
*
*-------------------------------------------------------------------------
*/

2
util.c
View File

@ -2,7 +2,7 @@
*
* util.c: log messages to log file or stderr, and misc code.
*
* Copyright (c) 2009, NIPPON TELEGRAPH AND TELEPHONE CORPORATION
* Copyright (c) 2009-2010, NIPPON TELEGRAPH AND TELEPHONE CORPORATION
*
*-------------------------------------------------------------------------
*/

View File

@ -2,7 +2,7 @@
*
* validate.c: validate backup files.
*
* Copyright (c) 2009, NIPPON TELEGRAPH AND TELEPHONE CORPORATION
* Copyright (c) 2009-2010, NIPPON TELEGRAPH AND TELEPHONE CORPORATION
*
*-------------------------------------------------------------------------
*/

2
xlog.c
View File

@ -2,7 +2,7 @@
*
* xlog.c: Parse WAL files.
*
* Copyright (c) 2009, NIPPON TELEGRAPH AND TELEPHONE CORPORATION
* Copyright (c) 2009-2010, NIPPON TELEGRAPH AND TELEPHONE CORPORATION
*
*-------------------------------------------------------------------------
*/