0

I assumed the umask() function is a:

shell function containing a variable commonly referred to as file creation mask

but I was wrong because umask() is not a shell function and doesn't contain such variable.

If the umask() function is not a "shell function" is it true to name it a "kernel function"?

terdon
  • 242,166

2 Answers2

2

The manual for umask says:

A child process created via fork(2) inherits its parent's umask. The umask is left unchanged by execve(2).

Therefore because it persists after a call to exec (execve), it must be implemented in the kernel, as all exec calls replace the running program (except some structures stored in the kernel).

1

There is no such thing as a "kernel function", unless you mean this.

umask(2) is a system call. And it was so since the dawn of time [1].

But it doesn't have to be that way -- you can implement it by having the actual bitmask be part of a chunk of memory that's always mapped at the same address and preserved through execve(2), and have the open(2), creat(2), etc userland wrappers pick it up from there. That would be just as POSIX-compliant.

[1] in the original implementation, the u.u_cmask field that function sets is only used in a single place elsewhere -- in the "Make a new file" maknode() function.