1
0
mirror of https://github.com/libssh2/libssh2.git synced 2026-10-24 03:48:58 +03:00
Files
libssh2/docs/libssh2_channel_has_exit_status.md
Huang Rui 4dbbcf9261 channel: add public API libssh2_channel_has_exit_status()
`libssh2_channel_get_exit_status()` returns 0 both for a real exit
status of 0 and for a channel that never received an `exit-status`
request. A server that force-closes a session, like OpenSSH under
`ChannelTimeout`, makes a still-running command look like a clean exit
0. Reproduction with the stock `example/ssh2_exec` is in #2515.

This adds `libssh2_channel_has_exit_status()`, returning 1 once the
request arrived, the name you suggested.

The new field sits in `_LIBSSH2_CHANNEL` in `libssh2_priv.h` and callers
only ever hold a pointer, so no ABI change.
`libssh2_channel_get_exit_signal()` already lets a caller see whether
that request arrived by leaving the pointer NULL, exit-status was the
odd one out.

Man page and a `test_exit_status` covering both states are included.

Follow-up to 77bd3c1215
Fixes #2515
Closes #2516
2026-08-14 01:31:20 +02:00

1.2 KiB

c, SPDX-License-Identifier, Title, Section, Source, See-also
c SPDX-License-Identifier Title Section Source See-also
Copyright (C) The libssh2 project and its contributors. BSD-3-Clause libssh2_channel_has_exit_status 3 libssh2
libssh2_channel_get_exit_status(3)

NAME

libssh2_channel_has_exit_status - check if an exit status arrived

SYNOPSIS

#include <libssh2.h>

int libssh2_channel_has_exit_status(LIBSSH2_CHANNEL *channel);

DESCRIPTION

channel - Closed channel stream to query.

Report whether the remote host sent an exit-status request for the named channel. libssh2_channel_get_exit_status(3) returns 0 both for a real exit status of 0 and for a channel that never received the request, so it cannot tell the two apart on its own. A server may close a channel without sending the request, for example when OpenSSH enforces ChannelTimeout, and the command then keeps running on the remote host.

RETURN VALUE

Returns 1 if an exit-status request was received for the channel, otherwise 0. Also returns 0 when channel is NULL.

EXAMPLE

if(libssh2_channel_close(channel) == 0 &&
   libssh2_channel_has_exit_status(channel))
    exitcode = libssh2_channel_get_exit_status(channel);

AVAILABILITY

Added in libssh2 1.12.0