I'm writing an application to control the system shutdown if a pendrive is connected to the system.
When pendrive is connected, It writes its identifier in a file. If pendrive is disconnected, it remove its identifier of the file and, after this, if the file is empty, remove the file.
Then, I want to set a polkit rule to control the shutdown, using this file. The polkit rule detect the shutdown order and check if the file exists. If it exists, don't allow the shutdown, else allow it.
I try to set it as this form:
polkit.addRule(function(action, subject) {
if (action.id == "org.freedesktop.consolekit.system.stop") ||
action.id.indexOf("org.freedesktop.login1.power-off") == 0)
{
try{
polkit.spawn(["/usr/bin/detect_pendrive.sh", subject.user]);
return polkit.Result.YES;
}catch(error){
return polkit.Result.NO;
}
}
});
The polkit rule use a helper, with a script that check the existence os the file
The detect_pendrive.sh is this:
#!/bin/bash
if ! test -e "/tmp/usbdevinfo"
then
exit 0
else
exit 1
fi
I copy the rule in /usr/share/polkit-1/rules.d/. But, when I try to shutdown with a pendrive connected, the system simply poweroff and ignore the rule.
I tested it on Debian GNOME and Gentoo Cinnamon
Where can be the problem?