Skip to content

Commit 449c73f

Browse files
committed
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
1 parent f826f8f commit 449c73f

File tree

1 file changed

+15
-17
lines changed

1 file changed

+15
-17
lines changed

contrib/pg_archivecleanup/pg_archivecleanup.c

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* $PostgreSQL: pgsql/contrib/pg_archivecleanup/pg_archivecleanup.c,v 1.1 2010/06/14 16:19:24 sriggs Exp $
2+
* $PostgreSQL: pgsql/contrib/pg_archivecleanup/pg_archivecleanup.c,v 1.2 2010/06/17 17:31:27 tgl Exp $
33
*
44
* pg_archivecleanup.c
55
*
@@ -43,7 +43,6 @@ char WALFilePath[MAXPGPATH]; /* the file path including archive */
4343
char exclusiveCleanupFileName[MAXPGPATH]; /* the oldest file we want to
4444
* remain in archive */
4545

46-
struct stat stat_buf;
4746

4847
/* =====================================================================
4948
*
@@ -78,10 +77,13 @@ Initialize(void)
7877
* This code assumes that archiveLocation is a directory, so we use
7978
* stat to test if it's accessible.
8079
*/
81-
if (stat(archiveLocation, &stat_buf) != 0)
80+
struct stat stat_buf;
81+
82+
if (stat(archiveLocation, &stat_buf) != 0 ||
83+
!S_ISDIR(stat_buf.st_mode))
8284
{
83-
fprintf(stderr, "%s: archiveLocation \"%s\" does not exist\n", progname, archiveLocation);
84-
fflush(stderr);
85+
fprintf(stderr, "%s: archiveLocation \"%s\" does not exist\n",
86+
progname, archiveLocation);
8587
exit(2);
8688
}
8789
}
@@ -122,25 +124,23 @@ CleanupPriorWALFiles(void)
122124
#endif
123125

124126
if (debug)
125-
fprintf(stderr, "\n%s: removing \"%s\"", progname, WALFilePath);
127+
fprintf(stderr, "%s: removing file \"%s\"\n",
128+
progname, WALFilePath);
126129

127130
rc = unlink(WALFilePath);
128131
if (rc != 0)
129132
{
130-
fprintf(stderr, "\n%s: ERROR failed to remove \"%s\": %s",
133+
fprintf(stderr, "%s: ERROR: could not remove file \"%s\": %s\n",
131134
progname, WALFilePath, strerror(errno));
132135
break;
133136
}
134137
}
135138
}
136-
if (debug)
137-
fprintf(stderr, "\n");
139+
closedir(xldir);
138140
}
139141
else
140-
fprintf(stderr, "%s: archiveLocation \"%s\" open error\n", progname, archiveLocation);
141-
142-
closedir(xldir);
143-
fflush(stderr);
142+
fprintf(stderr, "%s: could not open archiveLocation \"%s\": %s\n",
143+
progname, archiveLocation, strerror(errno));
144144
}
145145

146146
/*
@@ -304,10 +304,8 @@ main(int argc, char **argv)
304304
SetWALFileNameForCleanup();
305305

306306
if (debug)
307-
{
308-
fprintf(stderr, "%s: keep WAL file %s and later", progname, exclusiveCleanupFileName);
309-
fflush(stderr);
310-
}
307+
fprintf(stderr, "%s: keep WAL file \"%s\" and later\n",
308+
progname, exclusiveCleanupFileName);
311309

312310
/*
313311
* Remove WAL files older than cut-off

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy