New answers tagged

3

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 ...


0

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".


0

One partial answer is to launch a small script instead of konsole directly: #!/bin/bash #SIGTERM handler on_term () { echo "SIGTERM got, sending to worker" kill -TERM $WORKERID } #intercept SIGTERM trap _term SIGTERM # launch console konsole --hide-menubar --hide-tabbar --nofork -e worker & #get Konsole pid KONSOLEID=$! # wait for worker ...


1

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 ...


2

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()). ...


0

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 "...


1

/proc/{pid}/mounts shows the device. Get major and minor id, then /sys/dev/block/{major}:{minor} is a symlink to the USB device.


2

The way to read void ( *signal(int sig, void (*handler)(int)) ) (int); is that it declares a function, signal, which takes as arguments an int 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 ...


Top 50 recent answers are included