From: Ondřej Surý Date: Fri, 31 Mar 2023 08:06:03 +0000 (+0200) Subject: Add isc_os_umask() function to get current umask X-Git-Tag: v9.19.12~42^2~2 X-Git-Url: http://git.ipfire.org/gitweb/index.cgi?a=commitdiff_plain;h=aca7dd39618ee5e4945bdebc59fcda91dc51352f;p=thirdparty%2Fbind9.git Add isc_os_umask() function to get current umask 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. --- diff --git a/lib/isc/include/isc/os.h b/lib/isc/include/isc/os.h index b0a7d7cc9b8..32770b992f9 100644 --- a/lib/isc/include/isc/os.h +++ b/lib/isc/include/isc/os.h @@ -14,6 +14,7 @@ #pragma once /*! \file isc/os.h */ +#include #include #include @@ -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 diff --git a/lib/isc/os.c b/lib/isc/os.c index a82e92bc89c..0ba0fab43cb 100644 --- a/lib/isc/os.c +++ b/lib/isc/os.c @@ -12,6 +12,7 @@ */ #include +#include #include #include @@ -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);