diff --git a/fs/mqueue/mq_open.c b/fs/mqueue/mq_open.c index 7895abaa2a..bd6feeec20 100644 --- a/fs/mqueue/mq_open.c +++ b/fs/mqueue/mq_open.c @@ -24,6 +24,7 @@ #include +#include #include #include #include @@ -188,6 +189,8 @@ static int file_mq_vopen(FAR struct file *mq, FAR const char *mq_name, attr = va_arg(ap, FAR struct mq_attr *); } + mode &= ~getumask(); + /* Skip over any leading '/'. All message queue paths are relative to * CONFIG_FS_MQUEUE_MPATH. */ diff --git a/fs/semaphore/sem_open.c b/fs/semaphore/sem_open.c index 3e34d1ef42..ad5246a1cb 100644 --- a/fs/semaphore/sem_open.c +++ b/fs/semaphore/sem_open.c @@ -24,6 +24,7 @@ #include +#include #include #include #include @@ -86,7 +87,7 @@ * ****************************************************************************/ -FAR sem_t *sem_open (FAR const char *name, int oflags, ...) +FAR sem_t *sem_open(FAR const char *name, int oflags, ...) { FAR struct inode *inode; FAR struct nsem_inode_s *nsem; @@ -174,7 +175,7 @@ FAR sem_t *sem_open (FAR const char *name, int oflags, ...) */ va_start(ap, oflags); - mode = va_arg(ap, mode_t); + mode = va_arg(ap, mode_t) & ~getumask(); value = va_arg(ap, unsigned); va_end(ap); diff --git a/fs/vfs/fs_mkdir.c b/fs/vfs/fs_mkdir.c index 0ecf95ee3b..aae409afec 100644 --- a/fs/vfs/fs_mkdir.c +++ b/fs/vfs/fs_mkdir.c @@ -63,6 +63,8 @@ int mkdir(const char *pathname, mode_t mode) int errcode; int ret; + mode &= ~getumask(); + /* Find the inode that includes this path */ SETUP_SEARCH(&desc, pathname, false); diff --git a/fs/vfs/fs_open.c b/fs/vfs/fs_open.c index 2804c2c0d6..201875eea3 100644 --- a/fs/vfs/fs_open.c +++ b/fs/vfs/fs_open.c @@ -25,6 +25,7 @@ #include #include +#include #include #include #include @@ -69,6 +70,8 @@ static int file_vopen(FAR struct file *filep, { mode = va_arg(ap, mode_t); } + + mode &= ~getumask(); #endif /* Get an inode for this file */ diff --git a/include/nuttx/tls.h b/include/nuttx/tls.h index a7d28f3d3d..d893059ef1 100644 --- a/include/nuttx/tls.h +++ b/include/nuttx/tls.h @@ -63,15 +63,14 @@ struct task_info_s { - sem_t ta_sem; - + sem_t ta_sem; + mode_t ta_umask; /* File mode creation mask */ #if CONFIG_TLS_NELEM > 0 - tls_ndxset_t ta_tlsset; /* Set of TLS indexes allocated */ - tls_dtor_t ta_tlsdtor[CONFIG_TLS_NELEM]; /* List of TLS destructors */ + tls_ndxset_t ta_tlsset; /* Set of TLS indexes allocated */ + tls_dtor_t ta_tlsdtor[CONFIG_TLS_NELEM]; /* List of TLS destructors */ #endif - #ifndef CONFIG_BUILD_KERNEL - struct getopt_s ta_getopt; /* Globals used by getopt() */ + struct getopt_s ta_getopt; /* Globals used by getopt() */ #endif }; diff --git a/include/sys/stat.h b/include/sys/stat.h index 61e2afd30a..b1e8bcce21 100644 --- a/include/sys/stat.h +++ b/include/sys/stat.h @@ -166,6 +166,7 @@ int fchmod(int fd, mode_t mode); int futimens(int fd, const struct timespec times[2]); mode_t umask(mode_t mask); +mode_t getumask(void); #undef EXTERN #if defined(__cplusplus) diff --git a/libs/libc/misc/lib_umask.c b/libs/libc/misc/lib_umask.c index 6cf6214979..995046c30d 100644 --- a/libs/libc/misc/lib_umask.c +++ b/libs/libc/misc/lib_umask.c @@ -23,12 +23,7 @@ ****************************************************************************/ #include - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -static mode_t g_mask; +#include /**************************************************************************** * Public Functions @@ -50,8 +45,24 @@ static mode_t g_mask; mode_t umask(mode_t mask) { - mode_t prev = g_mask; + FAR struct task_info_s *info; + mode_t prev; + + info = task_get_info(); + prev = info->ta_umask; + info->ta_umask = mask; - g_mask = mask & 0777; return prev; } + +/**************************************************************************** + * Name: getumask + ****************************************************************************/ + +mode_t getumask(void) +{ + FAR struct task_info_s *info; + + info = task_get_info(); + return info->ta_umask; +}