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

Commit 1f422db

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 16d8e59 commit 1f422db

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

src/backend/replication/basebackup.c

+22-3
Original file line numberDiff line numberDiff line change
@@ -109,26 +109,45 @@ perform_base_backup(basebackup_options *opt, DIR *tblspcdir)
109109
{
110110
char fullpath[MAXPGPATH];
111111
char linkpath[MAXPGPATH];
112+
int rllen;
112113

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

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

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

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

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

0 commit comments

Comments
 (0)