From 3da422ad05c1cf00bf02707d3b1bd4accdc0c378 Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Sat, 25 May 2013 02:38:52 +0200 Subject: [PATCH] libroot_build: Fix issues with attribute FD for symlink AttributeDescriptor: Don't use dup() directly. Check, if the given FD is one we track and clone it respectively. This allows use with symlink FDs which we have to fake on Linux (since symlinks cannot be opened). Fixes extraction of packages containing symlinks with attributes. --- src/build/libroot/fs_descriptors.cpp | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/src/build/libroot/fs_descriptors.cpp b/src/build/libroot/fs_descriptors.cpp index 68103e341c..1f9e1c8aa5 100644 --- a/src/build/libroot/fs_descriptors.cpp +++ b/src/build/libroot/fs_descriptors.cpp @@ -23,6 +23,8 @@ #include +#include + #include "fs_impl.h" using std::map; @@ -35,6 +37,27 @@ static DescriptorMap *sDescriptors; namespace BPrivate { +static int +dup_maybe_system(int fd) +{ + if (get_descriptor(fd) != NULL) + return _kern_dup(fd); + + int clonedFD = dup(fd); + return clonedFD >= 0 ? clonedFD : errno; +} + + +static status_t +close_maybe_system(int fd) +{ + if (get_descriptor(fd) != NULL) + return _kern_close(fd); + + return close(fd) == 0 ? B_OK : errno; +} + + // #pragma mark - Descriptor @@ -263,7 +286,7 @@ SymlinkDescriptor::GetPath(string& path) const AttributeDescriptor::AttributeDescriptor(int fileFD, const char* attribute, uint32 type, int openMode) : - fFileFD(dup(fileFD)), + fFileFD(dup_maybe_system(fileFD)), fType(type), fOpenMode(openMode), fData(NULL), @@ -377,7 +400,7 @@ AttributeDescriptor::Close() if (fFileFD < 0) return B_BAD_VALUE; - close(fFileFD); + close_maybe_system(fFileFD); fFileFD = -1; free(fData);