About fcntl (FD, f_setfd, fd_cloexec) setting the close attribute during Exec
Snd_ctl_hw_open
# Define sndrv_file_control alsa_device_directory "controlc % I"
Sprintf (filename, sndrv_file_control, card); // path/dev/snd/controlc0
FD = snd_open_device (filename, fmode );
Fcntl (FD,
F_setfd, fd_cloexec );//
If this parameter is set to fd_cloexec, it indicates that when the program executes the exec function, This FD will be automatically disabled by the system, indicating that it will not be passed to the new process created by Exec,
If it is set to fcntl (FD, f_setfd, 0), This FD will remain open and copied to the newly created process [Luther. gliethttp] created by Exec.
Go to kernel system call
Sys_fcntl
Do_fcntl
Case f_setfd:
Err = 0;
Set_close_on_exec (FD, Arg & fd_cloexec );
Void fastcall set_close_on_exec (unsigned int FD, int flag)
{
Struct files_struct * files = Current-> files;
Struct fdtable * FDT;
Spin_lock (& files-> file_lock );
FDT = files_fdtable (files );
If (FLAG)
Fd_set (FD, FDT-> close_on_exec );
Else
Fd_clr (FD, FDT-> close_on_exec );
Spin_unlock (& files-> file_lock );
}
The following is the description of fd_cloexec seen by man fcntl.
File descriptor flags
The following commands manipulate the flags associated with a file descriptor. Currently, only one such flag is
Defined: fd_cloexec, the close-on-exec flag. If the fd_cloexec bit is 0, the file descriptor will remain open
Stored SS an execve (2), otherwise it will be closed.
F_getfd (void)
Read the file descriptor flags; Arg is ignored.
F_setfd (long)
Set the file descriptor flags to the value specified by Arg.