Commit 0642ce47 authored by Max Kellermann's avatar Max Kellermann

fs/io/FileOutputStream: make linkat() mandatory on Linux

parent d11e1d58
...@@ -240,10 +240,6 @@ fi ...@@ -240,10 +240,6 @@ fi
AC_SEARCH_LIBS([socket], [network socket]) AC_SEARCH_LIBS([socket], [network socket])
AC_SEARCH_LIBS([gethostbyname], [nsl]) AC_SEARCH_LIBS([gethostbyname], [nsl])
if test x$host_is_linux = xyes; then
AC_CHECK_FUNCS(linkat)
fi
AC_CHECK_FUNCS(getpwnam_r getpwuid_r) AC_CHECK_FUNCS(getpwnam_r getpwuid_r)
AC_CHECK_FUNCS(initgroups) AC_CHECK_FUNCS(initgroups)
AC_CHECK_FUNCS(fnmatch) AC_CHECK_FUNCS(fnmatch)
......
...@@ -138,7 +138,7 @@ FileOutputStream::Cancel() noexcept ...@@ -138,7 +138,7 @@ FileOutputStream::Cancel() noexcept
#include <unistd.h> #include <unistd.h>
#include <errno.h> #include <errno.h>
#ifdef HAVE_LINKAT #ifdef __linux__
#ifndef O_TMPFILE #ifndef O_TMPFILE
/* supported since Linux 3.11 */ /* supported since Linux 3.11 */
#define __O_TMPFILE 020000000 #define __O_TMPFILE 020000000
...@@ -159,12 +159,12 @@ OpenTempFile(FileDescriptor &fd, Path path) ...@@ -159,12 +159,12 @@ OpenTempFile(FileDescriptor &fd, Path path)
return fd.Open(directory.c_str(), O_TMPFILE|O_WRONLY, 0666); return fd.Open(directory.c_str(), O_TMPFILE|O_WRONLY, 0666);
} }
#endif /* HAVE_LINKAT */ #endif /* __linux__ */
inline void inline void
FileOutputStream::OpenCreate(bool visible) FileOutputStream::OpenCreate(bool visible)
{ {
#ifdef HAVE_LINKAT #ifdef __linux__
/* try Linux's O_TMPFILE first */ /* try Linux's O_TMPFILE first */
is_tmpfile = !visible && OpenTempFile(fd, GetPath()); is_tmpfile = !visible && OpenTempFile(fd, GetPath());
if (!is_tmpfile) { if (!is_tmpfile) {
...@@ -175,7 +175,7 @@ FileOutputStream::OpenCreate(bool visible) ...@@ -175,7 +175,7 @@ FileOutputStream::OpenCreate(bool visible)
0666)) 0666))
throw FormatErrno("Failed to create %s", throw FormatErrno("Failed to create %s",
GetPath().c_str()); GetPath().c_str());
#ifdef HAVE_LINKAT #ifdef __linux__
} }
#else #else
(void)visible; (void)visible;
...@@ -218,7 +218,7 @@ FileOutputStream::Commit() ...@@ -218,7 +218,7 @@ FileOutputStream::Commit()
{ {
assert(IsDefined()); assert(IsDefined());
#ifdef HAVE_LINKAT #ifdef __linux__
if (is_tmpfile) { if (is_tmpfile) {
unlink(GetPath().c_str()); unlink(GetPath().c_str());
...@@ -251,7 +251,7 @@ FileOutputStream::Cancel() noexcept ...@@ -251,7 +251,7 @@ FileOutputStream::Cancel() noexcept
switch (mode) { switch (mode) {
case Mode::CREATE: case Mode::CREATE:
#ifdef HAVE_LINKAT #ifdef __linux__
if (!is_tmpfile) if (!is_tmpfile)
#endif #endif
unlink(GetPath().c_str()); unlink(GetPath().c_str());
......
...@@ -57,7 +57,7 @@ class FileOutputStream final : public OutputStream { ...@@ -57,7 +57,7 @@ class FileOutputStream final : public OutputStream {
FileDescriptor fd = FileDescriptor::Undefined(); FileDescriptor fd = FileDescriptor::Undefined();
#endif #endif
#ifdef HAVE_LINKAT #ifdef __linux__
/** /**
* Was O_TMPFILE used? If yes, then linkat() must be used to * Was O_TMPFILE used? If yes, then linkat() must be used to
* create a link to this file. * create a link to this file.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment