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

Commit 2b1f580

Browse files
committed
Remove configure probes for symlink/readlink, and dead code.
symlink() and readlink() are in SUSv2 and all targeted Unix systems have them. We have partial emulation on Windows. Code that raised runtime errors on systems without it has been dead for years, so we can remove that and also references to such systems in the documentation. Define HAVE_READLINK and HAVE_SYMLINK macros on Unix. Our Windows replacement functions based on junction points can't be used for relative paths or for non-directories, so the macros can be used to check for full symlink support. The places that deal with tablespaces can just use symlink functions without checking the macros. (If they did check the macros, they'd need to provide an #else branch with a runtime or compile time error, and it'd be dead code.) Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us> Reviewed-by: Andres Freund <andres@anarazel.de> Discussion: https://postgr.es/m/CA+hUKGJ3LHeP9w5Fgzdr4G8AnEtJ=z=p6hGDEm4qYGEUX5B6fQ@mail.gmail.com
1 parent adeef67 commit 2b1f580

File tree

15 files changed

+13
-86
lines changed

15 files changed

+13
-86
lines changed

configure

+1-4
Original file line numberDiff line numberDiff line change
@@ -16039,7 +16039,7 @@ fi
1603916039
LIBS_including_readline="$LIBS"
1604016040
LIBS=`echo "$LIBS" | sed -e 's/-ledit//g' -e 's/-lreadline//g'`
1604116041

16042-
for ac_func in backtrace_symbols clock_gettime copyfile fdatasync getifaddrs getpeerucred inet_pton kqueue mbstowcs_l memset_s poll posix_fallocate ppoll pthread_is_threaded_np readlink readv setproctitle setproctitle_fast strchrnul strsignal symlink syncfs sync_file_range uselocale wcstombs_l writev
16042+
for ac_func in backtrace_symbols clock_gettime copyfile fdatasync getifaddrs getpeerucred inet_pton kqueue mbstowcs_l memset_s poll posix_fallocate ppoll pthread_is_threaded_np readv setproctitle setproctitle_fast strchrnul strsignal syncfs sync_file_range uselocale wcstombs_l writev
1604316043
do :
1604416044
as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
1604516045
ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"
@@ -17083,9 +17083,6 @@ esac
1708317083
;;
1708417084
esac
1708517085

17086-
17087-
$as_echo "#define HAVE_SYMLINK 1" >>confdefs.h
17088-
1708917086
ac_fn_c_check_type "$LINENO" "MINIDUMP_TYPE" "ac_cv_type_MINIDUMP_TYPE" "
1709017087
#define WIN32_LEAN_AND_MEAN
1709117088
#include <windows.h>

configure.ac

-4
Original file line numberDiff line numberDiff line change
@@ -1805,13 +1805,11 @@ AC_CHECK_FUNCS(m4_normalize([
18051805
posix_fallocate
18061806
ppoll
18071807
pthread_is_threaded_np
1808-
readlink
18091808
readv
18101809
setproctitle
18111810
setproctitle_fast
18121811
strchrnul
18131812
strsignal
1814-
symlink
18151813
syncfs
18161814
sync_file_range
18171815
uselocale
@@ -1963,8 +1961,6 @@ if test "$PORTNAME" = "win32"; then
19631961
AC_LIBOBJ(win32security)
19641962
AC_LIBOBJ(win32setlocale)
19651963
AC_LIBOBJ(win32stat)
1966-
AC_DEFINE([HAVE_SYMLINK], 1,
1967-
[Define to 1 if you have the `symlink' function.])
19681964
AC_CHECK_TYPES(MINIDUMP_TYPE, [pgac_minidump_type=yes], [pgac_minidump_type=no], [
19691965
#define WIN32_LEAN_AND_MEAN
19701966
#include <windows.h>

doc/src/sgml/manage-ag.sgml

-7
Original file line numberDiff line numberDiff line change
@@ -530,13 +530,6 @@ SELECT spcname FROM pg_tablespace;
530530
is also useful for listing the existing tablespaces.
531531
</para>
532532

533-
<para>
534-
<productname>PostgreSQL</productname> makes use of symbolic links
535-
to simplify the implementation of tablespaces. This
536-
means that tablespaces can be used <emphasis>only</emphasis> on systems
537-
that support symbolic links.
538-
</para>
539-
540533
<para>
541534
The directory <filename>$PGDATA/pg_tblspc</filename> contains symbolic links that
542535
point to each of the non-built-in tablespaces defined in the cluster.

doc/src/sgml/ref/create_tablespace.sgml

-4
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,6 @@ CREATE TABLESPACE <replaceable class="parameter">tablespace_name</replaceable>
127127
<refsect1>
128128
<title>Notes</title>
129129

130-
<para>
131-
Tablespaces are only supported on systems that support symbolic links.
132-
</para>
133-
134130
<para>
135131
<command>CREATE TABLESPACE</command> cannot be executed inside a transaction
136132
block.

src/backend/access/transam/xlog.c

-12
Original file line numberDiff line numberDiff line change
@@ -8305,7 +8305,6 @@ do_pg_backup_start(const char *backupidstr, bool fast, TimeLineID *starttli_p,
83058305
if (get_dirent_type(fullpath, de, false, ERROR) != PGFILETYPE_LNK)
83068306
continue;
83078307

8308-
#if defined(HAVE_READLINK) || defined(WIN32)
83098308
rllen = readlink(fullpath, linkpath, sizeof(linkpath));
83108309
if (rllen < 0)
83118310
{
@@ -8358,17 +8357,6 @@ do_pg_backup_start(const char *backupidstr, bool fast, TimeLineID *starttli_p,
83588357
ti->oid, escapedpath.data);
83598358

83608359
pfree(escapedpath.data);
8361-
#else
8362-
8363-
/*
8364-
* If the platform does not have symbolic links, it should not be
8365-
* possible to have tablespaces - clearly somebody else created
8366-
* them. Warn about it and ignore.
8367-
*/
8368-
ereport(WARNING,
8369-
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
8370-
errmsg("tablespaces are not supported on this platform")));
8371-
#endif
83728360
}
83738361
FreeDir(tblspcdir);
83748362

src/backend/commands/tablespace.c

-13
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,6 @@ TablespaceCreateDbspace(Oid spcOid, Oid dbOid, bool isRedo)
213213
Oid
214214
CreateTableSpace(CreateTableSpaceStmt *stmt)
215215
{
216-
#ifdef HAVE_SYMLINK
217216
Relation rel;
218217
Datum values[Natts_pg_tablespace];
219218
bool nulls[Natts_pg_tablespace] = {0};
@@ -391,12 +390,6 @@ CreateTableSpace(CreateTableSpaceStmt *stmt)
391390
table_close(rel, NoLock);
392391

393392
return tablespaceoid;
394-
#else /* !HAVE_SYMLINK */
395-
ereport(ERROR,
396-
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
397-
errmsg("tablespaces are not supported on this platform")));
398-
return InvalidOid; /* keep compiler quiet */
399-
#endif /* HAVE_SYMLINK */
400393
}
401394

402395
/*
@@ -407,7 +400,6 @@ CreateTableSpace(CreateTableSpaceStmt *stmt)
407400
void
408401
DropTableSpace(DropTableSpaceStmt *stmt)
409402
{
410-
#ifdef HAVE_SYMLINK
411403
char *tablespacename = stmt->tablespacename;
412404
TableScanDesc scandesc;
413405
Relation rel;
@@ -573,11 +565,6 @@ DropTableSpace(DropTableSpaceStmt *stmt)
573565

574566
/* We keep the lock on pg_tablespace until commit */
575567
table_close(rel, NoLock);
576-
#else /* !HAVE_SYMLINK */
577-
ereport(ERROR,
578-
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
579-
errmsg("tablespaces are not supported on this platform")));
580-
#endif /* HAVE_SYMLINK */
581568
}
582569

583570

src/backend/replication/basebackup.c

-13
Original file line numberDiff line numberDiff line change
@@ -1330,7 +1330,6 @@ sendDir(bbsink *sink, const char *path, int basepathlen, bool sizeonly,
13301330
#endif
13311331
)
13321332
{
1333-
#if defined(HAVE_READLINK) || defined(WIN32)
13341333
char linkpath[MAXPGPATH];
13351334
int rllen;
13361335

@@ -1349,18 +1348,6 @@ sendDir(bbsink *sink, const char *path, int basepathlen, bool sizeonly,
13491348

13501349
size += _tarWriteHeader(sink, pathbuf + basepathlen + 1, linkpath,
13511350
&statbuf, sizeonly);
1352-
#else
1353-
1354-
/*
1355-
* If the platform does not have symbolic links, it should not be
1356-
* possible to have tablespaces - clearly somebody else created
1357-
* them. Warn about it and ignore.
1358-
*/
1359-
ereport(WARNING,
1360-
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1361-
errmsg("tablespaces are not supported on this platform")));
1362-
continue;
1363-
#endif /* HAVE_READLINK */
13641351
}
13651352
else if (S_ISDIR(statbuf.st_mode))
13661353
{

src/backend/utils/adt/misc.c

-8
Original file line numberDiff line numberDiff line change
@@ -302,8 +302,6 @@ pg_tablespace_location(PG_FUNCTION_ARGS)
302302
tablespaceOid == GLOBALTABLESPACE_OID)
303303
PG_RETURN_TEXT_P(cstring_to_text(""));
304304

305-
#if defined(HAVE_READLINK) || defined(WIN32)
306-
307305
/*
308306
* Find the location of the tablespace by reading the symbolic link that
309307
* is in pg_tblspc/<oid>.
@@ -349,12 +347,6 @@ pg_tablespace_location(PG_FUNCTION_ARGS)
349347
targetpath[rllen] = '\0';
350348

351349
PG_RETURN_TEXT_P(cstring_to_text(targetpath));
352-
#else
353-
ereport(ERROR,
354-
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
355-
errmsg("tablespaces are not supported on this platform")));
356-
PG_RETURN_NULL();
357-
#endif
358350
}
359351

360352
/*

src/bin/initdb/initdb.c

-4
Original file line numberDiff line numberDiff line change
@@ -2646,13 +2646,9 @@ create_xlog_or_symlink(void)
26462646
pg_fatal("could not access directory \"%s\": %m", xlog_dir);
26472647
}
26482648

2649-
#ifdef HAVE_SYMLINK
26502649
if (symlink(xlog_dir, subdirloc) != 0)
26512650
pg_fatal("could not create symbolic link \"%s\": %m",
26522651
subdirloc);
2653-
#else
2654-
pg_fatal("symlinks are not supported on this platform");
2655-
#endif
26562652
}
26572653
else
26582654
{

src/bin/pg_basebackup/pg_basebackup.c

-4
Original file line numberDiff line numberDiff line change
@@ -2763,12 +2763,8 @@ main(int argc, char **argv)
27632763
PQserverVersion(conn) < MINIMUM_VERSION_FOR_PG_WAL ?
27642764
"pg_xlog" : "pg_wal");
27652765

2766-
#ifdef HAVE_SYMLINK
27672766
if (symlink(xlog_dir, linkloc) != 0)
27682767
pg_fatal("could not create symbolic link \"%s\": %m", linkloc);
2769-
#else
2770-
pg_fatal("symlinks are not supported on this platform");
2771-
#endif
27722768
free(linkloc);
27732769
}
27742770

src/bin/pg_rewind/file_ops.c

-5
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,6 @@ recurse_dir(const char *datadir, const char *parentpath,
437437
else if (pgwin32_is_junction(fullpath))
438438
#endif
439439
{
440-
#if defined(HAVE_READLINK) || defined(WIN32)
441440
char link_target[MAXPGPATH];
442441
int len;
443442

@@ -460,10 +459,6 @@ recurse_dir(const char *datadir, const char *parentpath,
460459
if ((parentpath && strcmp(parentpath, "pg_tblspc") == 0) ||
461460
strcmp(path, "pg_wal") == 0)
462461
recurse_dir(datadir, path, callback);
463-
#else
464-
pg_fatal("\"%s\" is a symbolic link, but symbolic links are not supported on this platform",
465-
fullpath);
466-
#endif /* HAVE_READLINK */
467462
}
468463
}
469464

src/common/exec.c

+4
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,10 @@ find_my_exec(const char *argv0, char *retpath)
250250
* Note: we are not particularly tense about producing nice error messages
251251
* because we are not really expecting error here; we just determined that
252252
* the symlink does point to a valid executable.
253+
*
254+
* Here we test HAVE_READLINK, which excludes Windows. There's no point in
255+
* using our junction point-based replacement code for this, because that only
256+
* works for directories.
253257
*/
254258
static int
255259
resolve_symlinks(char *path)

src/include/pg_config.h.in

-6
Original file line numberDiff line numberDiff line change
@@ -427,9 +427,6 @@
427427
/* Define to 1 if you have the <readline/readline.h> header file. */
428428
#undef HAVE_READLINE_READLINE_H
429429

430-
/* Define to 1 if you have the `readlink' function. */
431-
#undef HAVE_READLINK
432-
433430
/* Define to 1 if you have the `readv' function. */
434431
#undef HAVE_READV
435432

@@ -556,9 +553,6 @@
556553
/* Define to 1 if `tm_zone' is a member of `struct tm'. */
557554
#undef HAVE_STRUCT_TM_TM_ZONE
558555

559-
/* Define to 1 if you have the `symlink' function. */
560-
#undef HAVE_SYMLINK
561-
562556
/* Define to 1 if you have the `syncfs' function. */
563557
#undef HAVE_SYNCFS
564558

src/include/port.h

+8
Original file line numberDiff line numberDiff line change
@@ -522,11 +522,19 @@ extern bool wait_result_is_any_signal(int exit_status, bool include_command_not_
522522
/*
523523
* Interfaces that we assume all Unix system have. We retain individual macros
524524
* for better documentation.
525+
*
526+
* For symlink-related functions, there is often no need to test these macros,
527+
* because we provided basic support on Windows that can work with absolute
528+
* paths to directories. Code that wants to test for complete symlink support
529+
* (including relative paths and non-directories) should be conditional on
530+
* HAVE_READLINK or HAVE_SYMLINK.
525531
*/
526532
#ifndef WIN32
527533
#define HAVE_GETRLIMIT 1
534+
#define HAVE_READLINK 1
528535
#define HAVE_SETSID 1
529536
#define HAVE_SHM_OPEN 1
537+
#define HAVE_SYMLINK 1
530538
#endif
531539

532540
#endif /* PG_PORT_H */

src/tools/msvc/Solution.pm

-2
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,6 @@ sub GenerateFiles
337337
HAVE_READLINE_H => undef,
338338
HAVE_READLINE_HISTORY_H => undef,
339339
HAVE_READLINE_READLINE_H => undef,
340-
HAVE_READLINK => undef,
341340
HAVE_READV => undef,
342341
HAVE_RL_COMPLETION_MATCHES => undef,
343342
HAVE_RL_COMPLETION_SUPPRESS_QUOTE => undef,
@@ -380,7 +379,6 @@ sub GenerateFiles
380379
HAVE_STRUCT_SOCKADDR_UN => undef,
381380
HAVE_STRUCT_TM_TM_ZONE => undef,
382381
HAVE_SYNC_FILE_RANGE => undef,
383-
HAVE_SYMLINK => 1,
384382
HAVE_SYNCFS => undef,
385383
HAVE_SYSLOG => undef,
386384
HAVE_SYS_EPOLL_H => undef,

0 commit comments

Comments
 (0)