devlib icon indicating copy to clipboard operation
devlib copied to clipboard

Sudo message breaks devlib

Open douglas-raillard-arm opened this issue 1 year ago • 1 comments

sudo sometimes emits a message like:

Your password will expire in XXX days.

This unfortunately gets mixed with the actual command's output, completely breaking a number of devlib functions such as Target.file_exists().

douglas-raillard-arm avatar Sep 23 '24 17:09 douglas-raillard-arm

Unfortunately, there does not seem to be any direct way to silence that. It's not actually sudo but a PAM module that just writes to stdout ... If we only had Target.execute(), we could still work around that by just accumulating the output in some buffer and e.g. doing a base64 encoding of it, ignoring every other output line. But with Target.background() this is much more challenging, as the output can be read as it comes.

The only way I can see to avoid that is to make a call to sudo before without any interesting command and hope that there is a grace period during which sudo will not ask again for the password for the user. Then the 2nd call just goes through without the annoying message. This is super hacky though.

Alternatively, we could do a sanity check on the sudo output when connecting to the target and just raise early with a clear message, quoting the output of sudo and stating that the configuration of the target is unsuitable.

douglas-raillard-arm avatar Sep 23 '24 17:09 douglas-raillard-arm