This seems to work for me to tell whether the timeout is reached:
sudo_expired() [[ $(
trap "" XFSZ
limit filesize 0
LC_ALL=C sudo -n true 2>&1) = *"password is required" ]]
That is, set the filesize limit to 0 for the update of the timestamp file to fail, but as long as we don't let that limit to kill sudo
, we're still able to tell if a password was required or not.