File Attributes 301
A file’s sticky permission bit is set via the chmod command (chmod +t file) or via
the chmod() system call. If the sticky bit for a file is set, ls –l shows a lowercase or
uppercase letter T in the other-execute permission field, depending on whether the
other-execute permission bit is on or off, as in the following:
$ touch tfile
$ ls -l tfile
-rw-r--r-- 1 mtk users 0 Jun 23 14:44 tfile
$ chmod +t tfile
$ ls -l tfile
-rw-r--r-T 1 mtk users 0 Jun 23 14:44 tfile
$ chmod o+x tfile
$ ls -l tfile
-rw-r--r-t 1 mtk users 0 Jun 23 14:44 tfile
15.4.6 The Process File Mode Creation Mask: umask()........................................
We now consider in more detail the permissions that are placed on a newly created
file or directory. For new files, the kernel uses the permissions specified in the mode
argument to open() or creat(). For new directories, permissions are set according to
the mode argument to mkdir(). However, these settings are modified by the file
mode creation mask, also known simply as the umask. The umask is a process
attribute that specifies which permission bits should always be turned off when new
files or directories are created by the process.
Often, a process just uses the umask it inherits from its parent shell, with the
(usually desirable) consequence that the user can control the umask of programs
executed from the shell using the shell built-in command umask, which changes the
umask of the shell process.
The initialization files for most shells set the default umask to the octal value
022 (----w--w-). This value specifies that write permission should always be turned
off for group and other. Thus, assuming the mode argument in a call to open() is
0666 (i.e., read and write permitted for all users, which is typical), then new files are
created with read and write permissions for owner, and only read permission for
everyone else (displayed by ls –l as rw-r--r--). Correspondingly, assuming that the
mode argument to mkdir() is specified as 0777 (i.e., all permissions granted to all
users), new directories are created with all permissions granted for owner, and just
read and execute permissions for group and other (i.e., rwxr-xr-x).
The umask() system call changes a process’s umask to the value specified in mask.
The mask argument can be specified either as an octal number or by ORing (|)
together the constants listed in Table 15-4.
A call to umask() is always successful, and returns the previous umask.
#include <sys/stat.h>
mode_t umask(mode_t mask);
Always successfully returns the previous process umask