Browse Source

KWSys 2017-11-01 (6ffca34c)

Code extracted from:

    https://gitlab.kitware.com/utils/kwsys.git

at commit 6ffca34c008f0aac44db0e0c2826673a0e3f6ecf (master).

Upstream Shortlog
-----------------

Brad King (2):
      7a4cca11 Process: Refactor test compile flag addition
      90886a99 Process: Fix tests under ubsan

Bradley Lowekamp (1):
      b4507c9c Remove dead code from Configure.h.in

Domen Vrankar (1):
      9e0b4d1a SystemTools: set default MakeDirectory permissions mode
KWSys Upstream 8 years ago
parent
commit
7d3f33e612
5 changed files with 50 additions and 25 deletions
  1. 7 2
      CMakeLists.txt
  2. 0 3
      Configure.h.in
  3. 12 5
      SystemTools.cxx
  4. 9 9
      SystemTools.hxx.in
  5. 22 6
      testProcess.c

+ 7 - 2
CMakeLists.txt

@@ -1147,17 +1147,22 @@ IF(KWSYS_STANDALONE OR CMake_SOURCE_DIR)
       SET_TESTS_PROPERTIES(kwsys.testProcess-${n} PROPERTIES TIMEOUT 120)
       SET_TESTS_PROPERTIES(kwsys.testProcess-${n} PROPERTIES TIMEOUT 120)
     ENDFOREACH()
     ENDFOREACH()
 
 
+    SET(testProcess_COMPILE_FLAGS "")
     # Some Apple compilers produce bad optimizations in this source.
     # Some Apple compilers produce bad optimizations in this source.
     IF(APPLE AND CMAKE_C_COMPILER_ID MATCHES "^(GNU|LLVM)$")
     IF(APPLE AND CMAKE_C_COMPILER_ID MATCHES "^(GNU|LLVM)$")
-      SET_SOURCE_FILES_PROPERTIES(testProcess.c PROPERTIES COMPILE_FLAGS -O0)
+      STRING(APPEND testProcess_COMPILE_FLAGS " -O0")
     ELSEIF(CMAKE_C_COMPILER_ID STREQUAL "XL" AND
     ELSEIF(CMAKE_C_COMPILER_ID STREQUAL "XL" AND
            NOT (CMAKE_SYSTEM MATCHES "Linux.*ppc64le" AND
            NOT (CMAKE_SYSTEM MATCHES "Linux.*ppc64le" AND
                 NOT CMAKE_C_COMPILER_VERSION VERSION_LESS "13.1.1"))
                 NOT CMAKE_C_COMPILER_VERSION VERSION_LESS "13.1.1"))
       # Tell IBM XL not to warn about our test infinite loop
       # Tell IBM XL not to warn about our test infinite loop
       # v13.1.1 and newer on Linux ppc64le is clang based and does not accept
       # v13.1.1 and newer on Linux ppc64le is clang based and does not accept
       # the -qsuppress option
       # the -qsuppress option
-      SET_PROPERTY(SOURCE testProcess.c PROPERTY COMPILE_FLAGS -qsuppress=1500-010)
+      STRING(APPEND testProcess_COMPILE_FLAGS " -qsuppress=1500-010")
     ENDIF()
     ENDIF()
+    IF(CMAKE_C_FLAGS MATCHES "-fsanitize=")
+      STRING(APPEND testProcess_COMPILE_FLAGS " -DCRASH_USING_ABORT")
+    ENDIF()
+    SET_PROPERTY(SOURCE testProcess.c PROPERTY COMPILE_FLAGS "${testProcess_COMPILE_FLAGS}")
 
 
     # Test SharedForward
     # Test SharedForward
     CONFIGURE_FILE(${PROJECT_SOURCE_DIR}/testSharedForward.c.in
     CONFIGURE_FILE(${PROJECT_SOURCE_DIR}/testSharedForward.c.in

+ 0 - 3
Configure.h.in

@@ -62,9 +62,6 @@
   !defined(@KWSYS_NAMESPACE@_LFS_NO_DEFINE_FILE_OFFSET_BITS)
   !defined(@KWSYS_NAMESPACE@_LFS_NO_DEFINE_FILE_OFFSET_BITS)
 #define _FILE_OFFSET_BITS 64
 #define _FILE_OFFSET_BITS 64
 #endif
 #endif
-#if 0 && (defined(_FILE_OFFSET_BITS) && _FILE_OFFSET_BITS < 64)
-#error "_FILE_OFFSET_BITS must be defined to at least 64"
-#endif
 #endif
 #endif
 #endif
 #endif
 
 

+ 12 - 5
SystemTools.cxx

@@ -751,15 +751,15 @@ FILE* SystemTools::Fopen(const std::string& file, const char* mode)
 #endif
 #endif
 }
 }
 
 
-bool SystemTools::MakeDirectory(const char* path)
+bool SystemTools::MakeDirectory(const char* path, const mode_t* mode)
 {
 {
   if (!path) {
   if (!path) {
     return false;
     return false;
   }
   }
-  return SystemTools::MakeDirectory(std::string(path));
+  return SystemTools::MakeDirectory(std::string(path), mode);
 }
 }
 
 
-bool SystemTools::MakeDirectory(const std::string& path)
+bool SystemTools::MakeDirectory(const std::string& path, const mode_t* mode)
 {
 {
   if (SystemTools::PathExists(path)) {
   if (SystemTools::PathExists(path)) {
     return SystemTools::FileIsDirectory(path);
     return SystemTools::FileIsDirectory(path);
@@ -774,8 +774,12 @@ bool SystemTools::MakeDirectory(const std::string& path)
   std::string topdir;
   std::string topdir;
   while ((pos = dir.find('/', pos)) != std::string::npos) {
   while ((pos = dir.find('/', pos)) != std::string::npos) {
     topdir = dir.substr(0, pos);
     topdir = dir.substr(0, pos);
-    Mkdir(topdir);
-    pos++;
+
+    if (Mkdir(topdir) == 0 && mode != 0) {
+      SystemTools::SetPermissions(topdir, *mode);
+    }
+
+    ++pos;
   }
   }
   topdir = dir;
   topdir = dir;
   if (Mkdir(topdir) != 0) {
   if (Mkdir(topdir) != 0) {
@@ -790,7 +794,10 @@ bool SystemTools::MakeDirectory(const std::string& path)
           ) {
           ) {
       return false;
       return false;
     }
     }
+  } else if (mode != 0) {
+    SystemTools::SetPermissions(topdir, *mode);
   }
   }
+
   return true;
   return true;
 }
 }
 
 

+ 9 - 9
SystemTools.hxx.in

@@ -553,13 +553,20 @@ public:
    */
    */
   static FILE* Fopen(const std::string& file, const char* mode);
   static FILE* Fopen(const std::string& file, const char* mode);
 
 
+/**
+ * Visual C++ does not define mode_t (note that Borland does, however).
+ */
+#if defined(_MSC_VER)
+  typedef unsigned short mode_t;
+#endif
+
   /**
   /**
    * Make a new directory if it is not there.  This function
    * Make a new directory if it is not there.  This function
    * can make a full path even if none of the directories existed
    * can make a full path even if none of the directories existed
    * prior to calling this function.
    * prior to calling this function.
    */
    */
-  static bool MakeDirectory(const char* path);
-  static bool MakeDirectory(const std::string& path);
+  static bool MakeDirectory(const char* path, const mode_t* mode = 0);
+  static bool MakeDirectory(const std::string& path, const mode_t* mode = 0);
 
 
   /**
   /**
    * Copy the source file to the destination file only
    * Copy the source file to the destination file only
@@ -749,13 +756,6 @@ public:
    */
    */
   static long int CreationTime(const std::string& filename);
   static long int CreationTime(const std::string& filename);
 
 
-/**
- * Visual C++ does not define mode_t (note that Borland does, however).
- */
-#if defined(_MSC_VER)
-  typedef unsigned short mode_t;
-#endif
-
   /**
   /**
    * Get and set permissions of the file.  If honor_umask is set, the umask
    * Get and set permissions of the file.  If honor_umask is set, the umask
    * is queried and applied to the given permissions.  Returns false if
    * is queried and applied to the given permissions.  Returns false if

+ 22 - 6
testProcess.c

@@ -107,6 +107,7 @@ static int test3(int argc, const char* argv[])
 
 
 static int test4(int argc, const char* argv[])
 static int test4(int argc, const char* argv[])
 {
 {
+#ifndef CRASH_USING_ABORT
   /* Prepare a pointer to an invalid address.  Don't use null, because
   /* Prepare a pointer to an invalid address.  Don't use null, because
   dereferencing null is undefined behaviour and compilers are free to
   dereferencing null is undefined behaviour and compilers are free to
   do whatever they want. ex: Clang will warn at compile time, or even
   do whatever they want. ex: Clang will warn at compile time, or even
@@ -114,6 +115,7 @@ static int test4(int argc, const char* argv[])
   'volatile' and a slightly larger address, based on a runtime value. */
   'volatile' and a slightly larger address, based on a runtime value. */
   volatile int* invalidAddress = 0;
   volatile int* invalidAddress = 0;
   invalidAddress += argc ? 1 : 2;
   invalidAddress += argc ? 1 : 2;
+#endif
 
 
 #if defined(_WIN32)
 #if defined(_WIN32)
   /* Avoid error diagnostic popups since we are crashing on purpose.  */
   /* Avoid error diagnostic popups since we are crashing on purpose.  */
@@ -128,9 +130,13 @@ static int test4(int argc, const char* argv[])
   fprintf(stderr, "Output before crash on stderr from crash test.\n");
   fprintf(stderr, "Output before crash on stderr from crash test.\n");
   fflush(stdout);
   fflush(stdout);
   fflush(stderr);
   fflush(stderr);
+#ifdef CRASH_USING_ABORT
+  abort();
+#else
   assert(invalidAddress); /* Quiet Clang scan-build. */
   assert(invalidAddress); /* Quiet Clang scan-build. */
   /* Provoke deliberate crash by writing to the invalid address. */
   /* Provoke deliberate crash by writing to the invalid address. */
   *invalidAddress = 0;
   *invalidAddress = 0;
+#endif
   fprintf(stdout, "Output after crash on stdout from crash test.\n");
   fprintf(stdout, "Output after crash on stdout from crash test.\n");
   fprintf(stderr, "Output after crash on stderr from crash test.\n");
   fprintf(stderr, "Output after crash on stderr from crash test.\n");
   return 0;
   return 0;
@@ -149,7 +155,12 @@ static int test5(int argc, const char* argv[])
   fprintf(stderr, "Output on stderr before recursive test.\n");
   fprintf(stderr, "Output on stderr before recursive test.\n");
   fflush(stdout);
   fflush(stdout);
   fflush(stderr);
   fflush(stderr);
-  r = runChild(cmd, kwsysProcess_State_Exception, kwsysProcess_Exception_Fault,
+  r = runChild(cmd, kwsysProcess_State_Exception,
+#ifdef CRASH_USING_ABORT
+               kwsysProcess_Exception_Other,
+#else
+               kwsysProcess_Exception_Fault,
+#endif
                1, 1, 1, 0, 15, 0, 1, 0, 0, 0);
                1, 1, 1, 0, 15, 0, 1, 0, 0, 0);
   fprintf(stdout, "Output on stdout after recursive test.\n");
   fprintf(stdout, "Output on stdout after recursive test.\n");
   fprintf(stderr, "Output on stderr after recursive test.\n");
   fprintf(stderr, "Output on stderr after recursive test.\n");
@@ -628,11 +639,16 @@ int main(int argc, const char* argv[])
       kwsysProcess_State_Exception /* Process group test */
       kwsysProcess_State_Exception /* Process group test */
     };
     };
     int exceptions[10] = {
     int exceptions[10] = {
-      kwsysProcess_Exception_None, kwsysProcess_Exception_None,
-      kwsysProcess_Exception_None, kwsysProcess_Exception_Fault,
-      kwsysProcess_Exception_None, kwsysProcess_Exception_None,
-      kwsysProcess_Exception_None, kwsysProcess_Exception_None,
-      kwsysProcess_Exception_None, kwsysProcess_Exception_Interrupt
+      kwsysProcess_Exception_None,  kwsysProcess_Exception_None,
+      kwsysProcess_Exception_None,
+#ifdef CRASH_USING_ABORT
+      kwsysProcess_Exception_Other,
+#else
+      kwsysProcess_Exception_Fault,
+#endif
+      kwsysProcess_Exception_None,  kwsysProcess_Exception_None,
+      kwsysProcess_Exception_None,  kwsysProcess_Exception_None,
+      kwsysProcess_Exception_None,  kwsysProcess_Exception_Interrupt
     };
     };
     int values[10] = { 0, 123, 1, 1, 0, 0, 0, 0, 1, 1 };
     int values[10] = { 0, 123, 1, 1, 0, 0, 0, 0, 1, 1 };
     int shares[10] = { 0, 0, 0, 0, 0, 0, 0, 0, 1, 1 };
     int shares[10] = { 0, 0, 0, 0, 0, 0, 0, 0, 1, 1 };