Name

fdredir — redirect a file descriptor then chain

Synopsis

fdredir {fd} {name} {next-prog}

Description

fdredir is a chain-loading utility that opens the file name as the file descriptor fd (closing that descriptor if it is already open) and then chain loads to next-prog with the execvp(3) function.

next-prog may contain its own command line options, which fdredir will ignore.

Command line options determine the mode in which name is opened:

--non-blocking

The file is opened in non-blocking mode (and blocking mode is restored once it has been opened). Non-blocking mode allows one to open serial devices without waiting for a carrier, to open FIFOs without waiting for the opposite end to be opened, and so forth. Blocking mode is restored because most shell-level utilities do not expect to inherit file descriptors in non-blocking mode.

[--mode]

Specify the (numeric) permissions to use when creating a file. These are of course subject to the process' file creation mask as set by umask(1). The default permissions are 0666.

[--read]

Open the file in input mode. If the file does not exist, fdredir will fail. If the file exists it will be opened for read-only access.

[--write]

Open the file in output mode. If the file does not exist, it will be created with the specified permissions. If the file exists, it will be opened and truncated to zero length. In both cases, it will be opened for write-only access.

[--write-noclobber]

Open the file in output mode. If the file does not exist, it will be created with the specified permissions and opened with write-only access. If the file exists, fdredir will fail.

[--append]

Open the file in append write mode. If the file does not exist, it will be created with the specified permissions. If the file exists, it will be opened. In both cases, it will be opened for write-only access and the file pointer initially set to the end of the file.

[--append-noclobber]

Open the file in append write mode. If the file does not exist, it will be created with the specified permissions and opened with write-only access and the file pointer initially set to the end of the file. If the file exists, fdredir will fail.

[--update]

Open the file in read-write mode. If the file does not exist, it will be created with the specified permissions. If the file exists, it will be opened. In both cases, it will be opened for read-write access.

[--directory]

Open the file in directory mode. If the file does not exist, or if the file exists and is not a directory, fdredir will fail. If the file exists and is a directory, it will be opened in directory read mode. This requires appropriate operating system kernel support, and on some systems, this is the same as read mode and the check to see whether the file is a directory is not made.

In all cases, opening the file will not affect the process's controlling TTY, if it has one. (For that, see open-controlling-tty(1).) Nor will it set synchronous mode or (which would be silly given what fdredir does) mark the file descriptor as close-on-exec.

Author

Jonathan de Boyne Pollard