From libssh2-devel-bounces@cool.haxx.se Wed May 27 17:22:47 2020 Return-Path: Received: from www.haxx.se (mail [127.0.0.1]) by giant.haxx.se (8.15.2/8.15.2/Debian-4) with ESMTP id 04RFM9H8014555; Wed, 27 May 2020 17:22:36 +0200 Received: from mail-io1-xd2c.google.com (mail-io1-xd2c.google.com [IPv6:2607:f8b0:4864:20:0:0:0:d2c]) by giant.haxx.se (8.15.2/8.15.2/Debian-4) with ESMTPS id 04RFM7GO014487 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Wed, 27 May 2020 17:22:07 +0200 Received: by mail-io1-xd2c.google.com with SMTP id r2so16061407ioo.4 for ; Wed, 27 May 2020 08:22:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=B99X/C9jbyDEnT5+nxne273Cwpp0bSQPNuUzh/fvVEE=; b=kn5C7tcKpensKJ2knju1emYEeyOs32sSvLdUO10JMN1hVJOuun5ujsYJ+JkH0NrJPB UVhTyrSvy1o914PX+VjrVjaSFOjVlt1gKzYGZujWafr41g5yaY7kh7R9/BtkyBTdENLH ltgQb7MX3lbq2JMtl4Hvm+7HSv7MM15oOB4Nfo0kpB9RWA51SA5F+IpmZJJl4/Fg1hxx +zhIQwxDGIaAp229EqTeoEQtYSj4wxnrwJNYdv01Afc/AL5Ea1ReOzhzWV8W8jlJ7y70 2/S8QKzOT8SHuv+D5RXNaotdTo2e603GyodX5JSjz3/iBZC4KjdhDI9JU6iT4bv+4kan dczg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=B99X/C9jbyDEnT5+nxne273Cwpp0bSQPNuUzh/fvVEE=; b=rqWEYCDSDBvuxvlbx4zSAemLNSrq0ZcOu/ykgYESCMSTTH1eUpw7rouuYF0M9uuClC NYp3OmEZXieYWOEMS7DklXRwEs+en7qbk/goY51xFckVMDU7oOkxIrIFHNzsDzNtSr28 RBkUt/wtLz9u0p3K90IO0Y9c1iHfwwehwaI7GHcuB95k0mDEEYs6tAQt6NViVIBFBAPJ F5PcjOJ/MEDHKXalNZPpg+yAoZ7zHx2FdwG5B6Qaj8pIMAV9KIgw8QM3C7IU8VLm5nxZ ClqVyO5T05UyqX4lEdJ0OqrAmEQj9MTmg3b9CxZAmqFvOVSz5BWs5GZVReASm3L+6Tuv 7gsQ== X-Gm-Message-State: AOAM533hMEvuWnzhiK2jVUcKh7OoU5J/8FM0ypm/7l8I2jLZouMKRwP9 ROhHLIX0ZAaJndELtNBLVEfT1zJtKfNFLSv6VGQBDad4PyM= X-Google-Smtp-Source: ABdhPJwonNUWRIA1wiQLlMhf3h62YowXxZ1Z3SQPFeVB/RET1xp+eDvfUw3z7RnYxp597DDOgI0GTtIlDuCfaIXZ6kM= X-Received: by 2002:a5d:94c5:: with SMTP id y5mr21100060ior.43.1590592921881; Wed, 27 May 2020 08:22:01 -0700 (PDT) MIME-Version: 1.0 From: Shawn Singh Date: Wed, 27 May 2020 08:21:50 -0700 Message-ID: Subject: How to kill a process launched using libssh2_channel_process_startup To: libssh2-devel@cool.haxx.se X-BeenThere: libssh2-devel@cool.haxx.se X-Mailman-Version: 2.1.22 Precedence: list List-Id: libssh2 development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: libssh2 development Content-Type: multipart/mixed; boundary="===============0125652851==" Errors-To: libssh2-devel-bounces@cool.haxx.se Sender: "libssh2-devel" --===============0125652851== Content-Type: multipart/alternative; boundary="0000000000001750ac05a6a2c69e" --0000000000001750ac05a6a2c69e Content-Type: text/plain; charset="UTF-8" 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(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 --0000000000001750ac05a6a2c69e Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hello,

I've got a custom app that u= ses libssh2 to run a series of commands on a host.
There basicall= y end up being 2 process trees.

1. The first tree.= .. the user logging in and launching the app:
sshd->sshd [ pri= v ] -> 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 o= ne being a ruby program) -> ruby

The user does = a control+c, which causes the app (in the first tree) to die; however the 2= nd 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 be= ing the last program in the list, would be last child, so the parent bash p= rocess won't have anything else to execute, so the bash will go away, e= tc.

What I'm wondering... is there a way I can= send my signal to a child process in this example that ruby program to ach= ieve the same effect as if I were on the command-line?

=
If it helps, the call that is spawning the 2nd tree looks like:
lib= ssh2_channel_process_startup(channel, "exec", sizeof("exec&q= uot;) - 1, ecmd.c_str(), static_cast<unsigned int>(commandLength))=C2= =A0

Once started, the process is polled using = libssh2_channel_read_ex to read data from the channel. I tried to send an e= of 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=
--0000000000001750ac05a6a2c69e-- --===============0125652851== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: base64 Content-Disposition: inline X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX18KbGlic3NoMi1k ZXZlbCBodHRwczovL2Nvb2wuaGF4eC5zZS9jZ2ktYmluL21haWxtYW4vbGlzdGluZm8vbGlic3No Mi1kZXZlbAo= --===============0125652851==-- From libssh2-devel-bounces@cool.haxx.se Wed May 27 18:54:08 2020 Return-Path: Received: from www.haxx.se (mail [127.0.0.1]) by giant.haxx.se (8.15.2/8.15.2/Debian-4) with ESMTP id 04RGrgSO009805; Wed, 27 May 2020 18:54:00 +0200 Received: from mail-il1-x12e.google.com (mail-il1-x12e.google.com [IPv6:2607:f8b0:4864:20:0:0:0:12e]) by giant.haxx.se (8.15.2/8.15.2/Debian-4) with ESMTPS id 04RGrc4R009712 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Wed, 27 May 2020 18:53:39 +0200 Received: by mail-il1-x12e.google.com with SMTP id 9so6263580ilg.12 for ; Wed, 27 May 2020 09:53:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=PV/8kfVT7qPVkwlrPzTWVXkpuq+OUKgFzJ1UsdZF0os=; b=NRNRP1h3yDET5FkhdiuVMz0tlr+4q97yYT3rhlXlm3gfRYRIL7EdOVBmNbsqesJn6z QCcNNCc6Od8TFIfLVVGlU458ywUmh/Jb9N4TaExozJOACkcr/8eJjmz2EG03OAfvcDRM v7i1k/lnPahLf9RbzmK0xZhzWAAK03vpdY5uPVkxEl6ViM744hrINmZniGZTfqWCVyN9 AOccptmVl/3T4WlttmoIBhlkHiKSJrHR86GDsRCWnKIciToWpdISZXeOeEdB5QiNDL/m LU1ZLGl5ZjEv8bCs81jQ5KWfNi+jI0WlGaMO21TtuHkA7KBDdAul8PcTveZbqMTIoZGh F3gw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=PV/8kfVT7qPVkwlrPzTWVXkpuq+OUKgFzJ1UsdZF0os=; b=VdmIdIzSDECIGfut5wVlPjtzkmbKX4RpUbHj/I+tPQz7FOQhigw9kIGyCxZER2dnUo uJzJlgJDGP74kDx0M7/tI3RmRLVGCFldcvZ5zaaIdh2HNBqjlNJLazI1l1oStEuns6G3 NTcpFXPwd1/TmobZ50ggQyWlqW0l1w4eRn/Otv2masIRz+tWb7QGIOyHEavijeP7vwQN 7NVpKbgUJf4j/5Zb4m/3Rpi/w70ZRtaE08ygkLLpDyFJK8fZKogG0+8CKusGHuIrPeeV wlyZtFPlLJLnNz9ojCpV4bsW6aWcuo76bI9fPKpvKXLWkJsOjxIRNXHRhjTSfN+BOF2g nUwA== X-Gm-Message-State: AOAM5315UDham1AtjnHRO+Z1U+n8PYiCufva6OrI+/h2nWsR040TOB7N b0ix7c0PN/vLWslu4dbPMKP98x80HcKt4rP7g9WCnXuBV9M= X-Google-Smtp-Source: ABdhPJwlq/Gba3zcvBtIeaU12io+NQLJr2jU8criYAQj5keXYNk/zF4ZfAjCNMAh1mi3uPKygyvd772SrY0UJMjhIoc= X-Received: by 2002:a92:8d03:: with SMTP id s3mr6642983ild.256.1590598413882; Wed, 27 May 2020 09:53:33 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Shawn Singh Date: Wed, 27 May 2020 09:53:21 -0700 Message-ID: Subject: Re: How to kill a process launched using libssh2_channel_process_startup To: libssh2-devel@cool.haxx.se X-BeenThere: libssh2-devel@cool.haxx.se X-Mailman-Version: 2.1.22 Precedence: list List-Id: libssh2 development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: libssh2 development Content-Type: multipart/mixed; boundary="===============0251159382==" Errors-To: libssh2-devel-bounces@cool.haxx.se Sender: "libssh2-devel" --===============0251159382== Content-Type: multipart/alternative; boundary="000000000000709b9505a6a40d9f" --000000000000709b9505a6a40d9f Content-Type: text/plain; charset="UTF-8" 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 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(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 --000000000000709b9505a6a40d9f Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Did some more testing and realized when I hit ctrl+c, ever= ything except this part of the 2nd tree is killed:
bash -c exec 1>/d= ev/null; ... (several commands, last one being a ruby program) -> ruby= =C2=A0

So, since the 2nd set of ssh sessions are g= etting 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@gmail.com> wrote:
Hello,

=
I've got a custom app that uses libssh2 to run a series of command= s on a host.
There basically end up being 2 process trees.
<= div>
1. The first tree... the user logging in and launching t= he app:
sshd->sshd [ priv ] -> sshd -> bash -> app

2. The second tree that's being created by the a= pp:
sshd->sshd [ priv ] -> sshd -> bash -c exec 1>/de= v/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, woul= d be last child, so the parent bash process won't have anything else to= execute, so the bash will go away, etc.

What I= 9;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 t= he command-line?

If it helps, the call that is spa= wning the 2nd tree looks like:
libssh2_channel_process_startup(channel, = "exec", sizeof("exec") - 1, ecmd.c_str(), static_cast&l= t;unsigned int>(commandLength))=C2=A0

Once = started, the process is polled using libssh2_channel_read_ex to read data f= rom the channel. I tried to send an eof to the channel; however, learned th= at the EOF will cause the ssh session to terminate; however, killing the pa= rent doesn't affect the child (as should have been expected).

I've read online where one user back in '09 suggest= ed 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 w= e should grow too fond of it. - Gen. R. E. Lee
--000000000000709b9505a6a40d9f-- --===============0251159382== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: base64 Content-Disposition: inline X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX18KbGlic3NoMi1k ZXZlbCBodHRwczovL2Nvb2wuaGF4eC5zZS9jZ2ktYmluL21haWxtYW4vbGlzdGluZm8vbGlic3No Mi1kZXZlbAo= --===============0251159382==--