]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Add isc_os_umask() function to get current umask
authorOndřej Surý <ondrej@isc.org>
Fri, 31 Mar 2023 08:06:03 +0000 (10:06 +0200)
committerOndřej Surý <ondrej@isc.org>
Fri, 31 Mar 2023 12:52:59 +0000 (12:52 +0000)
As it's impossible to get the current umask without modifying it at the
same time, initialize the current umask at the program start and keep
the loaded value internally.  Add isc_os_umask() function to access the
starttime umask.

lib/isc/include/isc/os.h
lib/isc/os.c

index b0a7d7cc9b831f31f38ad5857b63f238acdf7167..32770b992f9597917a1ebf7e0ae2d6b67320b8d4 100644 (file)
@@ -14,6 +14,7 @@
 #pragma once
 
 /*! \file isc/os.h */
+#include <sys/stat.h>
 
 #include <isc/lang.h>
 #include <isc/types.h>
@@ -37,9 +38,15 @@ isc_os_ncpus(void);
 unsigned long
 isc_os_cacheline(void);
 /*%<
- * Return L1 caheline size of the CPU.
+ * Return L1 cacheline size of the CPU.
  * If L1 cache is greater than ISC_OS_CACHELINE_SIZE, ensure it is used
  * instead of constant. Is common on ppc64le architecture.
  */
 
+mode_t
+isc_os_umask(void);
+/*%<
+ * Return umask of the current process as initialized at the program start
+ */
+
 ISC_LANG_ENDDECLS
index a82e92bc89c426d4f92e18da1d30aad92095c698..0ba0fab43cbeb61556251b61d8df238d08192cfc 100644 (file)
@@ -12,6 +12,7 @@
  */
 
 #include <inttypes.h>
+#include <sys/stat.h>
 
 #include <isc/os.h>
 #include <isc/types.h>
@@ -21,6 +22,7 @@
 
 static unsigned int isc__os_ncpus = 0;
 static unsigned long isc__os_cacheline = ISC_OS_CACHELINE_SIZE;
+static mode_t isc__os_umask = 0;
 
 #ifdef HAVE_SYSCONF
 
@@ -72,6 +74,12 @@ ncpus_initialize(void) {
        }
 }
 
+static void
+umask_initialize(void) {
+       isc__os_umask = umask(0);
+       (void)umask(isc__os_umask);
+}
+
 unsigned int
 isc_os_ncpus(void) {
        return (isc__os_ncpus);
@@ -82,8 +90,14 @@ isc_os_cacheline(void) {
        return (isc__os_cacheline);
 }
 
+mode_t
+isc_os_umask(void) {
+       return (isc__os_umask);
+}
+
 void
 isc__os_initialize(void) {
+       umask_initialize();
        ncpus_initialize();
 #if defined(HAVE_SYSCONF) && defined(_SC_LEVEL1_DCACHE_LINESIZE)
        long s = sysconf(_SC_LEVEL1_DCACHE_LINESIZE);