Better error reporting if the link target is too long

This situation won't set errno, so using %m will give an incorrect
error message.
This commit is contained in:
Magnus Hagander 2011-12-07 12:17:55 +01:00
parent 1f422db663
commit 0d9b09282f

View File

@ -287,9 +287,12 @@ pg_tablespace_location(PG_FUNCTION_ARGS)
*/
snprintf(sourcepath, sizeof(sourcepath), "pg_tblspc/%u", tablespaceOid);
rllen =readlink(sourcepath, targetpath, sizeof(targetpath));
if (rllen < 0 || rllen >= sizeof(targetpath))
if (rllen < 0)
ereport(ERROR,
(errmsg("could not read symbolic link \"%s\": %m", sourcepath)));
else if (rllen >= sizeof(targetpath))
ereport(ERROR,
(errmsg("symbolic link \"%s\" target is too long", sourcepath)));
targetpath[rllen] = '\0';
PG_RETURN_TEXT_P(cstring_to_text(targetpath));