Skip to content
Snippets Groups Projects
Commit 449c73f4 authored by Tom Lane's avatar Tom Lane
Browse files

Clean up pg_archivecleanup's error and logging output: put newlines in

sane places, make messages follow project's message style guidelines.

Also, avoid closedir(NULL).

Fujii Masao and Tom Lane
parent f826f8fc
No related branches found
No related tags found
No related merge requests found
/* /*
* $PostgreSQL: pgsql/contrib/pg_archivecleanup/pg_archivecleanup.c,v 1.1 2010/06/14 16:19:24 sriggs Exp $ * $PostgreSQL: pgsql/contrib/pg_archivecleanup/pg_archivecleanup.c,v 1.2 2010/06/17 17:31:27 tgl Exp $
* *
* pg_archivecleanup.c * pg_archivecleanup.c
* *
...@@ -43,7 +43,6 @@ char WALFilePath[MAXPGPATH]; /* the file path including archive */ ...@@ -43,7 +43,6 @@ char WALFilePath[MAXPGPATH]; /* the file path including archive */
char exclusiveCleanupFileName[MAXPGPATH]; /* the oldest file we want to char exclusiveCleanupFileName[MAXPGPATH]; /* the oldest file we want to
* remain in archive */ * remain in archive */
struct stat stat_buf;
/* ===================================================================== /* =====================================================================
* *
...@@ -78,10 +77,13 @@ Initialize(void) ...@@ -78,10 +77,13 @@ Initialize(void)
* This code assumes that archiveLocation is a directory, so we use * This code assumes that archiveLocation is a directory, so we use
* stat to test if it's accessible. * stat to test if it's accessible.
*/ */
if (stat(archiveLocation, &stat_buf) != 0) struct stat stat_buf;
if (stat(archiveLocation, &stat_buf) != 0 ||
!S_ISDIR(stat_buf.st_mode))
{ {
fprintf(stderr, "%s: archiveLocation \"%s\" does not exist\n", progname, archiveLocation); fprintf(stderr, "%s: archiveLocation \"%s\" does not exist\n",
fflush(stderr); progname, archiveLocation);
exit(2); exit(2);
} }
} }
...@@ -122,25 +124,23 @@ CleanupPriorWALFiles(void) ...@@ -122,25 +124,23 @@ CleanupPriorWALFiles(void)
#endif #endif
if (debug) if (debug)
fprintf(stderr, "\n%s: removing \"%s\"", progname, WALFilePath); fprintf(stderr, "%s: removing file \"%s\"\n",
progname, WALFilePath);
rc = unlink(WALFilePath); rc = unlink(WALFilePath);
if (rc != 0) if (rc != 0)
{ {
fprintf(stderr, "\n%s: ERROR failed to remove \"%s\": %s", fprintf(stderr, "%s: ERROR: could not remove file \"%s\": %s\n",
progname, WALFilePath, strerror(errno)); progname, WALFilePath, strerror(errno));
break; break;
} }
} }
} }
if (debug) closedir(xldir);
fprintf(stderr, "\n");
} }
else else
fprintf(stderr, "%s: archiveLocation \"%s\" open error\n", progname, archiveLocation); fprintf(stderr, "%s: could not open archiveLocation \"%s\": %s\n",
progname, archiveLocation, strerror(errno));
closedir(xldir);
fflush(stderr);
} }
/* /*
...@@ -304,10 +304,8 @@ main(int argc, char **argv) ...@@ -304,10 +304,8 @@ main(int argc, char **argv)
SetWALFileNameForCleanup(); SetWALFileNameForCleanup();
if (debug) if (debug)
{ fprintf(stderr, "%s: keep WAL file \"%s\" and later\n",
fprintf(stderr, "%s: keep WAL file %s and later", progname, exclusiveCleanupFileName); progname, exclusiveCleanupFileName);
fflush(stderr);
}
/* /*
* Remove WAL files older than cut-off * Remove WAL files older than cut-off
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment