De acuerdo con los manuales de bash
y zsh
, sí, de hecho puede trap
cualquier señal.
bash
:
trap [-lp] [[arg] sigspec...]
The command arg is to be read and executed when the shell receives signal(s) sigspec. If arg is absent (and there is a single sigspec) or -, each specified signal is
reset to its original disposition (the value it had upon entrance to the shell). If arg is the null string the signal specified by each sigspec is ignored by the shell
and by the commands it invokes. If arg is not present and -p has been supplied, then the trap commands associated with each sigspec are displayed. If no arguments are
supplied or if only -p is given, trap prints the list of commands associated with each signal. The -l option causes the shell to print a list of signal names and their
corresponding numbers. Each sigspec is either a signal name defined in <signal.h>, or a signal number. Signal names are case insensitive and the SIG prefix is optional.
zsh
:
trap [ arg ] [ sig... ]
arg is a series of commands (usually quoted to protect it from immediate evaluation by the shell) to be read and executed when the shell receives any of the signals speci-
fied by one or more sig args. Each sig can be given as a number, or as the name of a signal either with or without the string SIG in front (e.g. 1, HUP, and SIGHUP are
all the same signal).
Вы можете попробовать сопоставить интерфейс tun по его аппаратному адресу, а не по имени (вы можете получить это с помощью ioctl(SIOCGIFHWADDR)
в дескрипторе файла tun/tap ).
Я не думаю, что есть что-то проще, иначе не понадобилось бы недавнее изменение вроде this (, которое добавляет возможность получения сетевого пространства имен интерфейса через tun fd ). и принято.