summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMagnus Hagander2011-12-07 11:09:05 +0000
committerMagnus Hagander2011-12-07 11:09:05 +0000
commit1f422db663aa291be4af4b079e7d1b0ef0d78af2 (patch)
treee68c1cb3acb616293ac1942ed3a5a9e00a23a4a3
parent16d8e594acd96661267cb7897834f9cba51a2ffd (diff)
Avoid using readlink() on platforms that don't support it
We don't have any such platforms now, but might in the future. Also, detect cases when a tablespace symlink points to a path that is longer than we can handle, and give a warning.
-rw-r--r--src/backend/replication/basebackup.c25
1 files changed, 22 insertions, 3 deletions
diff --git a/src/backend/replication/basebackup.c b/src/backend/replication/basebackup.c
index ba52ea8e98..2f4ae3b53d 100644
--- a/src/backend/replication/basebackup.c
+++ b/src/backend/replication/basebackup.c
@@ -109,6 +109,7 @@ perform_base_backup(basebackup_options *opt, DIR *tblspcdir)
{
char fullpath[MAXPGPATH];
char linkpath[MAXPGPATH];
+ int rllen;
/* Skip special stuff */
if (strcmp(de->d_name, ".") == 0 || strcmp(de->d_name, "..") == 0)
@@ -116,19 +117,37 @@ perform_base_backup(basebackup_options *opt, DIR *tblspcdir)
snprintf(fullpath, sizeof(fullpath), "pg_tblspc/%s", de->d_name);
- MemSet(linkpath, 0, sizeof(linkpath));
- if (readlink(fullpath, linkpath, sizeof(linkpath) - 1) == -1)
+#if defined(HAVE_READLINK) || defined(WIN32)
+ rllen = readlink(fullpath, linkpath, sizeof(linkpath) - 1);
+ if (rllen < 0)
+ {
+ ereport(WARNING,
+ (errmsg("could not read symbolic link \"%s\": %m", fullpath)));
+ continue;
+ }
+ else if (rllen >= sizeof(linkpath))
{
ereport(WARNING,
- (errmsg("could not read symbolic link \"%s\": %m", fullpath)));
+ (errmsg("symbolic link \"%s\" target is too long", fullpath)));
continue;
}
+ linkpath[rllen] = '\0';
ti = palloc(sizeof(tablespaceinfo));
ti->oid = pstrdup(de->d_name);
ti->path = pstrdup(linkpath);
ti->size = opt->progress ? sendDir(linkpath, strlen(linkpath), true) : -1;
tablespaces = lappend(tablespaces, ti);
+#else
+ /*
+ * If the platform does not have symbolic links, it should not be possible
+ * to have tablespaces - clearly somebody else created them. Warn about it
+ * and ignore.
+ */
+ ereport(WARNING,
+ (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
+ errmsg("tablespaces are not supported on this platform")));
+#endif
}
/* Add a node for the base directory at the end */