I suspect this is happening because you’re running your program from a terminal which isn’t a virtual console. /dev/tty is a special device which provides access to the controlling terminal, and that’s not necessarily a virtual console; but the ioctl you’re using only works on virtual consoles.
Your program will work reliably if you ensure that fd points at ...
It turns out that it's best not to listen for USB device attach events, but mount point attach events instead. In other words, instead of filtering on "usb" subsystem and "usb_device" devtype, use "block" subsystem and "partition" devtype, then check that the event contains ID_BUS="usb".
What you want to do is impossible. This has nothing to do with C or SUID and everything to do with how the shell expands variables.
Parsing input to the shell into individual shell commands happens before expanding environment variables. The contents of the variable are not interpreted according to shell syntax (otherwise foo='$foo' ; : $foo would be an ...
The kernel will restore the signal mask upon returning from a signal handler. This is specified by the standard:
When a thread's signal mask is changed in a signal-catching function
that is installed by sigaction(), the restoration of the signal mask
on return from the signal-catching function overrides that change
(see sigaction()). ...
Assuming that you are using udev, libudev can be a good option. Udev is the subsystem of linux that is responsible of automatically creating device nodes when a new device is inserted to the system. With udev you can also monitor new devices as they are inserted to the system and get all the info that you want. It provides nice functions such as the "...
The way to read
void ( *signal(int sig, void (*handler)(int)) ) (int);
is that it declares a function, signal, which takes as arguments
and a pointer to a function which itself takes an int and doesn’t return anything
and returns a pointer to a function which takes an int and doesn’t return anything.
The extra brackets correspond to the returned ...