Subject: Re: How to kill a process launched using libssh2_channel_process_startup

Re: How to kill a process launched using libssh2_channel_process_startup

From: Shawn Singh <callmeshawn_at_gmail.com>
Date: Wed, 27 May 2020 09:53:21 -0700

Did some more testing and realized when I hit ctrl+c, everything except
this part of the 2nd tree is killed:
bash -c exec 1>/dev/null; ... (several commands, last one being a ruby
program) -> ruby

So, since the 2nd set of ssh sessions are getting killed, the bash process
is getting re-parented to init and it keeps on...

Shawn

On Wed, May 27, 2020 at 8:21 AM Shawn Singh <callmeshawn_at_gmail.com> wrote:

> Hello,
>
> I've got a custom app that uses libssh2 to run a series of commands on a
> host.
> There basically end up being 2 process trees.
>
> 1. The first tree... the user logging in and launching the app:
> sshd->sshd [ priv ] -> sshd -> bash -> app
>
> 2. The second tree that's being created by the app:
> sshd->sshd [ priv ] -> sshd -> bash -c exec 1>/dev/null; ... (several
> commands, last one being a ruby program) -> ruby
>
> The user does a control+c, which causes the app (in the first tree) to
> die; however the 2nd tree is alive and well, which makes sense to me.
>
> If I were on the command-line, I'd just kill the ruby process, and being
> the last program in the list, would be last child, so the parent bash
> process won't have anything else to execute, so the bash will go away, etc.
>
> What I'm wondering... is there a way I can send my signal to a child
> process in this example that ruby program to achieve the same effect as if
> I were on the command-line?
>
> If it helps, the call that is spawning the 2nd tree looks like:
> libssh2_channel_process_startup(channel, "exec", sizeof("exec") - 1,
> ecmd.c_str(), static_cast<unsigned int>(commandLength))
>
> Once started, the process is polled using libssh2_channel_read_ex to read
> data from the channel. I tried to send an eof to the channel; however,
> learned that the EOF will cause the ssh session to terminate; however,
> killing the parent doesn't affect the child (as should have been expected).
>
> I've read online where one user back in '09 suggested sending ETX;
> however, I'm not sure how to do that, and even if I do that, will that do
> what I want?
>
> Thanks,
>
> Shawn
>
>
>
> --
> It is well that war is so terrible, otherwise we should grow too fond of
> it. - Gen. R. E. Lee
>

-- 
It is well that war is so terrible, otherwise we should grow too fond of
it. - Gen. R. E. Lee

_______________________________________________
libssh2-devel https://cool.haxx.se/cgi-bin/mailman/listinfo/libssh2-devel
Received on 2020-05-27