From 190c09059122542971530169746effff769e583a Mon Sep 17 00:00:00 2001
From: Mattias Ellert <mattias.ellert@physics.uu.se>
Date: Sat, 28 Oct 2023 15:54:24 +0200
Subject: [PATCH 1/3] Posix open() called with wrong flags in test
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
OpenFlags::Flags should not be used for the flags argument in a posix
open() call, since they use different values.
The OpenFlags::Flags values are defined in src/XrdCl/XrdClFileSystem.hh:
MakePath = kXR_mkpath, //!< Create directory path if it does not
//!< already exist
New = kXR_new, //!< Open the file only if it does not already
Update = kXR_open_updt, //!< Open for reading and writing
The kXR_* values are defined in src/XProtocol/XProtocol.hh:
kXR_new = 0x0008, // 8
kXR_mkpath = 0x0100, // 256
kXR_open_updt= 0x0020, // 32
As can be seen these do not correspond to the O_* values used in the
posix open() call. What they actually mean depends on the system and
varies between architectures.
On hppa Linux O_CREAT is defind in /usr/include/hppa-linux-gnu/asm/fcntl.h:
#define O_CREAT 000000400 /* not fcntl */
Since 0o400 = 0x100 = 256 this by chance matches kXR_mkpath and
triggers the error below. On other architectures the wrong flags are
just silently accepted.
In file included from /usr/include/fcntl.h:342,
from /<<PKGBUILDDIR>>/tests/XrdClTests/LocalFileHandlerTest.cc:25:
In function ‘int open(const char*, int, ...)’,
inlined from ‘void LocalFileHandlerTest::WriteMkdirTest()’ at /<<PKGBUILDDIR>>/tests/XrdClTests/LocalFileHandlerTest.cc:210:17:
/usr/include/hppa-linux-gnu/bits/fcntl2.h:50:31: error: call to ‘__open_missing_mode’ declared with attribute error: open with O_CREAT or O_TMPFILE in second argument needs 3 arguments
50 | __open_missing_mode ();
| ~~~~~~~~~~~~~~~~~~~~^~
---
tests/XrdClTests/LocalFileHandlerTest.cc | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/tests/XrdClTests/LocalFileHandlerTest.cc b/tests/XrdClTests/LocalFileHandlerTest.cc
index 0a58ed6ef..f8618c14f 100644
--- a/tests/XrdClTests/LocalFileHandlerTest.cc
+++ b/tests/XrdClTests/LocalFileHandlerTest.cc
@@ -142,7 +142,7 @@ void LocalFileHandlerTest::WriteTest(){
//----------------------------------------------------------------------------
// Read file with POSIX calls to confirm correct write
//----------------------------------------------------------------------------
- int fd = open( targetURL.c_str(), flags );
+ int fd = open( targetURL.c_str(), O_RDWR );
int rc = read( fd, buffer, int( writeSize ) );
CPPUNIT_ASSERT_EQUAL( rc, int( writeSize ) );
std::string read( (char *)buffer, writeSize );
@@ -176,7 +176,7 @@ void LocalFileHandlerTest::WriteWithOffsetTest(){
//----------------------------------------------------------------------------
// Read file with POSIX calls to confirm correct write
//----------------------------------------------------------------------------
- int fd = open( targetURL.c_str(), flags );
+ int fd = open( targetURL.c_str(), O_RDWR );
int rc = read( fd, buffer, offset );
CPPUNIT_ASSERT_EQUAL( rc, int( offset ) );
std::string read( (char *)buffer, offset );
@@ -207,7 +207,7 @@ void LocalFileHandlerTest::WriteMkdirTest(){
//----------------------------------------------------------------------------
// Read file with POSIX calls to confirm correct write
//----------------------------------------------------------------------------
- int fd = open( targetURL.c_str(), flags );
+ int fd = open( targetURL.c_str(), O_RDWR );
int rc = read( fd, buffer, writeSize );
CPPUNIT_ASSERT_EQUAL( rc, int( writeSize ) );
std::string read( buffer, writeSize );
--
2.41.0