Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 9c32da5

Browse files
committed
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.
1 parent 75594e0 commit 9c32da5

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

src/backend/replication/basebackup.c

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,26 +108,45 @@ perform_base_backup(basebackup_options *opt, DIR *tblspcdir)
108108
{
109109
char fullpath[MAXPGPATH];
110110
char linkpath[MAXPGPATH];
111+
int rllen;
111112

112113
/* Skip special stuff */
113114
if (strcmp(de->d_name, ".") == 0 || strcmp(de->d_name, "..") == 0)
114115
continue;
115116

116117
snprintf(fullpath, sizeof(fullpath), "pg_tblspc/%s", de->d_name);
117118

118-
MemSet(linkpath, 0, sizeof(linkpath));
119-
if (readlink(fullpath, linkpath, sizeof(linkpath) - 1) == -1)
119+
#if defined(HAVE_READLINK) || defined(WIN32)
120+
rllen = readlink(fullpath, linkpath, sizeof(linkpath) - 1);
121+
if (rllen < 0)
122+
{
123+
ereport(WARNING,
124+
(errmsg("could not read symbolic link \"%s\": %m", fullpath)));
125+
continue;
126+
}
127+
else if (rllen >= sizeof(linkpath))
120128
{
121129
ereport(WARNING,
122-
(errmsg("could not read symbolic link \"%s\": %m", fullpath)));
130+
(errmsg("symbolic link \"%s\" target is too long", fullpath)));
123131
continue;
124132
}
133+
linkpath[rllen] = '\0';
125134

126135
ti = palloc(sizeof(tablespaceinfo));
127136
ti->oid = pstrdup(de->d_name);
128137
ti->path = pstrdup(linkpath);
129138
ti->size = opt->progress ? sendDir(linkpath, strlen(linkpath), true) : -1;
130139
tablespaces = lappend(tablespaces, ti);
140+
#else
141+
/*
142+
* If the platform does not have symbolic links, it should not be possible
143+
* to have tablespaces - clearly somebody else created them. Warn about it
144+
* and ignore.
145+
*/
146+
ereport(WARNING,
147+
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
148+
errmsg("tablespaces are not supported on this platform")));
149+
#endif
131150
}
132151

133152
/* Add a node for the base directory at the end */

0 commit comments

Comments
 (0)