From aca7dd39618ee5e4945bdebc59fcda91dc51352f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Sur=C3=BD?= Date: Fri, 31 Mar 2023 10:06:03 +0200 Subject: [PATCH] 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. --- lib/isc/include/isc/os.h | 9 ++++++++- lib/isc/os.c | 14 ++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/lib/isc/include/isc/os.h b/lib/isc/include/isc/os.h index b0a7d7cc9b..32770b992f 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 a82e92bc89..0ba0fab43c 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);