Corey Hickey
2025-Jan-10 19:00 UTC
[PATCH v2] ssh-add: support external parsing of key listing
On 2025-01-10 09:57, Jim Knoble wrote:> >> On Jan 9, 2025, at 19:14, Corey Hickey <bugfood-ml at fatooh.org> wrote: >> >> To address this, modify ssh-add to: >> * [...] >> * exit with a status of 0 instead of 1 > > When Damien wrote: > >> Adding a new exit status for the >> no-keys-in-agent case would be >> acceptable too I think. > > I interpreted that as "make ssh-add exit with status 2 or 3 or 99, for example, as opposed to 1". > > That is differentiate between: > > - There is an agent, and it has keys, and ssh-add listed them (exit status 0). > - There is no agent, or there is a problem communicating with the agent (exit status 1). > - There is an agent, but it has no keys (exit status 2, for example). > > This mirrors the functionality of `diff`, for example, which exits 0, 1, or 2 for different states (no differences, differences found, or some error). > > In that case, the stderr message wouldn't strictly be needed, as the exit status would communicate the reason for no keys to be listed; however, it could be useful to humans. The error message can be suppressed in shell scripts using: > > ssh-add 2>/dev/null > > Or, for both stderr and stdout: > > ssh-add >/dev/null 2>&1 > > (Note, I haven't looked at the OpenSSH code; there may already be more exit statuses that have additional meanings, so 2 may not be the right choice here).Ah, hmm. Yes, I get your meaning. There seem to be several options here and I would like to ask for some consensus or a decision from Damien. I can make a patch for whatever seems best. Here are the options as I understand them. Option 0: do nothing. Pros: * Doesn't alter behavior for people relying on current behavior. Cons: * Doesn't work as well for scripting. Option 1: add a new command-line option (e.g. -p) to support parser-friendly behavior (original PATCH). Pros: * Doesn't alter default behavior. * Allows user to choose. Cons: * Adds a new command-line option. Option 2: when no keys, exit with status 0 (PATCH v2). Pros: * Changes behavior to be work more easily with scripts. * Doesn't need a new command-line option. Cons: * Changes behavior; would break some people's existing usage. Option 3: when no keys, exit with status 3. Pros: * Doesn't alter behavior for people expecting a non-zero status. * Does allow scripts to detect when there are no keys. Cons: * For shell scripting, needs 'set -e' (temporarily) disabled (right?) in order to capture exit status. Separately, there are options for how to handle the message "The agent has no identities." Option A: leave in stdout. Pros: * Doesn't alter behavior. * Informs interactive users. Cons: * Puts non-key information in a key listing. Option B: move to stderr. Pros: * More scriptable; key listing is only keys. * Informs interactive users. Cons: * Will show up for people doing 'ssh-add -l >/dev/null'. Option C: move to stderr, require '-v'. Pros: * More scriptable; key listing is only keys. * Avoids printing a message that isn't really an error. Cons: * Doesn't inform interactive users unless they use '-v'. Thanks, Corey
Steffen Nurpmeso
2025-Jan-10 19:33 UTC
[PATCH v2] ssh-add: support external parsing of key listing
Corey Hickey wrote in <38d76f8e-0744-4bc5-b6e1-db7197e19ad7 at fatooh.org>: |On 2025-01-10 09:57, Jim Knoble wrote: |>> On Jan 9, 2025, at 19:14, Corey Hickey <bugfood-ml at fatooh.org> wrote: |>> |>> To address this, modify ssh-add to: |>> * [...] |>> * exit with a status of 0 instead of 1 |> |> When Damien wrote: |> |>> Adding a new exit status for the |>> no-keys-in-agent case would be |>> acceptable too I think. |> |> I interpreted that as "make ssh-add exit with status 2 or 3 or 99, \ |> for example, as opposed to 1". Fyi there is the >35 years old BSD sysexits.h that unfortunately did not become standardized, but is widely available nonetheless. --steffen | |Der Kragenbaer, The moon bear, |der holt sich munter he cheerfully and one by one |einen nach dem anderen runter wa.ks himself off |(By Robert Gernhardt) | |In Fall and Winter, feel "The Dropbear Bard"s pint(er). | |The banded bear |without a care, |Banged on himself for e'er and e'er | |Farewell, dear collar bear
Maybe Matching Threads
- [PATCH v2] ssh-add: support external parsing of key listing
- [PATCH v2] ssh-add: support external parsing of key listing
- [PATCH v2] ssh-add: support external parsing of key listing
- [PATCH] ssh-add: support parser-friendly operation
- [PATCH v2] ssh-add: support external parsing of key listing