mirror of
https://gitlab.isc.org/isc-projects/bind9
synced 2025-08-30 14:07:59 +00:00
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.
This commit is contained in:
@@ -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
|
||||
|
14
lib/isc/os.c
14
lib/isc/os.c
@@ -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);
|
||||
|
Reference in New Issue
Block a user