When learning SELinux, I executed semanage fcontext -l > fcontext.txt under /root directory to dump massive fcontext information to a file. The funny result is: fcontext.txt was created, but the size of it is 0.I asked in #fedora-selinux IRC channel, a Fedora QA told me try change the type of SELinux context of fcontext.txt to semanage_tmp_t. It works finally.But what still confusing me is:Which process/program create/write the standard output to the redirected file ? (so that SELinux targetd policy should applied to that process/program)The bash shell ? /bin/bashor semanage (it's a python script) ? /usr/sbin/semanageor the interpreter - python ? /usr/bin/pythonI thought it should be the bash shell, because I/O redirection is controlled by shell (right?), not the program itself. so semanage/python didn't create the file directly.
Which process/program create/write the file which I/O is redirected to?
shell;fedora;io redirection;selinux
You're right: redirection for input and output streams is done by the shell.In more detail, when you execute a command through the shell thefollowing procedure is run:The shell forks to create a new process.The newly-created shell (child shell) applies redirections: itopens the file specified as output target (resp. input source) and setsit as the new STDOUT (resp. STDIN) stream (using thedup2 system call).Thechild shell execs the command you asked to run, using theexecve(2) system call, whichreplaces the shell process with a new program.