I'm trying to use kdialog with sudo in a bash script, by exporting SUDO_ASKPASS to a script that has the line
kdialog --password "enter password: "
and using sudo -A. This works well, except that if I click cancel in the dialogue, sudo ignores that, and retries the password entry after a delay. The one-line script exits with kdialog's exit status, which is non-zero if cancel is clicked.
Is there any way to persuade sudo to give up, as one can with the text interface by typing control-C?
Edit - eventually I worked out what was going on. If you click cancel, kdialog outputs a newline. Sudo --askpass interprets this as a blank password, and starts its wrong password processing. The askpass script must not emit that newline if cancel is clicked. A way to do this is
pe=$(kdialog --password 'enter password: ') && echo "$pe"