Rocksolid Light

Welcome to Rocksolid Light

mail  files  register  newsreader  groups  login

Message-ID:  

The only perfect science is hind-sight.


devel / comp.unix.programmer / Re: Changing the "controlling terminal" of a process?

SubjectAuthor
* Changing the "controlling terminal" of a process?Kenny McCormack
+* Changing the "controlling terminal" of a process?Scott Lurndal
|`* Changing the "controlling terminal" of a process?Kenny McCormack
| `- Changing the "controlling terminal" of a process?Kaz Kylheku
`- Changing the "controlling terminal" of a process?Kaz Kylheku

1
Changing the "controlling terminal" of a process?

<ubitne$3l6qi$1@news.xmission.com>

  copy mid

http://rslight.i2p/devel/article-flat.php?id=2252&group=comp.unix.programmer#2252

  copy link   Newsgroups: comp.unix.programmer
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!xmission!nnrp.xmission!.POSTED.shell.xmission.com!not-for-mail
From: gazelle@shell.xmission.com (Kenny McCormack)
Newsgroups: comp.unix.programmer
Subject: Changing the "controlling terminal" of a process?
Date: Wed, 16 Aug 2023 16:32:46 -0000 (UTC)
Organization: The official candy of the new Millennium
Message-ID: <ubitne$3l6qi$1@news.xmission.com>
Injection-Date: Wed, 16 Aug 2023 16:32:46 -0000 (UTC)
Injection-Info: news.xmission.com; posting-host="shell.xmission.com:166.70.8.4";
logging-data="3840850"; mail-complaints-to="abuse@xmission.com"
X-Newsreader: trn 4.0-test77 (Sep 1, 2010)
Originator: gazelle@shell.xmission.com (Kenny McCormack)
 by: Kenny McCormack - Wed, 16 Aug 2023 16:32 UTC

(In Linux)
I need to be able to change the "controlling terminal" of an arbitrary
process. I have read the doc for the ioctl TIOCSCTTY, but as far as I can
tell, that only works for the calling process. Also, it seems to have some
(IMHO) weird limitations. So, Q1: Is there any other system call for this?

Note: I note that a lot of the "classic Unix" calls in this general area
(process/session/controlling tty stuff) are specifically only able to
affect the calling process, but that Linux has expanded on this - often
allowing arbitrary processes to be affected.

Also, Q2: Is it true that any given tty can only be the controlling
terminal of (at most) one session? The doc for TIOCSCTTY seems to imply
this.

--
"Everything Roy (aka, AU8YOG) touches turns to crap."
--citizens of alt.obituaries--

Re: Changing the "controlling terminal" of a process?

<fO7DM.428700$U3w1.203718@fx09.iad>

  copy mid

http://rslight.i2p/devel/article-flat.php?id=2254&group=comp.unix.programmer#2254

  copy link   Newsgroups: comp.unix.programmer
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!newsreader4.netcologne.de!news.netcologne.de!peer01.ams1!peer.ams1.xlned.com!news.xlned.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx09.iad.POSTED!not-for-mail
X-newsreader: xrn 9.03-beta-14-64bit
Sender: scott@dragon.sl.home (Scott Lurndal)
From: scott@slp53.sl.home (Scott Lurndal)
Reply-To: slp53@pacbell.net
Subject: Re: Changing the "controlling terminal" of a process?
Newsgroups: comp.unix.programmer
References: <ubitne$3l6qi$1@news.xmission.com>
Lines: 26
Message-ID: <fO7DM.428700$U3w1.203718@fx09.iad>
X-Complaints-To: abuse@usenetserver.com
NNTP-Posting-Date: Wed, 16 Aug 2023 17:36:11 UTC
Organization: UsenetServer - www.usenetserver.com
Date: Wed, 16 Aug 2023 17:36:11 GMT
X-Received-Bytes: 1818
 by: Scott Lurndal - Wed, 16 Aug 2023 17:36 UTC

gazelle@shell.xmission.com (Kenny McCormack) writes:
>(In Linux)
>I need to be able to change the "controlling terminal" of an arbitrary
>process. I have read the doc for the ioctl TIOCSCTTY, but as far as I can
>tell, that only works for the calling process. Also, it seems to have some
>(IMHO) weird limitations. So, Q1: Is there any other system call for this?
>
>Note: I note that a lot of the "classic Unix" calls in this general area
>(process/session/controlling tty stuff) are specifically only able to
>affect the calling process, but that Linux has expanded on this - often
>allowing arbitrary processes to be affected.

https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap11.html

11.1.3 The Controlling Terminal

"Each process of a session that has a controlling terminal
has the same controlling terminal"

"A terminal may be the controlling terminal for at most one session."

I believe there are security issues that would in general
prevent one from willy-nilly changing the controlling terminal
for an arbitrary process outside of the standard mechanisms like
setsid.

Re: Changing the "controlling terminal" of a process?

<20230816112851.276@kylheku.com>

  copy mid

http://rslight.i2p/devel/article-flat.php?id=2257&group=comp.unix.programmer#2257

  copy link   Newsgroups: comp.unix.programmer
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: 864-117-4973@kylheku.com (Kaz Kylheku)
Newsgroups: comp.unix.programmer
Subject: Re: Changing the "controlling terminal" of a process?
Date: Wed, 16 Aug 2023 18:41:01 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 25
Message-ID: <20230816112851.276@kylheku.com>
References: <ubitne$3l6qi$1@news.xmission.com>
Injection-Date: Wed, 16 Aug 2023 18:41:01 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="d89b22cba778372e2da36441b02fe0e1";
logging-data="3586021"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+F+QMpOREH/hiAvzuDu5Xigs22sR5FMyI="
User-Agent: slrn/1.0.3 (Linux)
Cancel-Lock: sha1:OR/vtnNgzGpdW6deB31Xkcil4yw=
 by: Kaz Kylheku - Wed, 16 Aug 2023 18:41 UTC

On 2023-08-16, Kenny McCormack <gazelle@shell.xmission.com> wrote:
> (In Linux)
> I need to be able to change the "controlling terminal" of an arbitrary
> process. I have read the doc for the ioctl TIOCSCTTY, but as far as I can
> tell, that only works for the calling process. Also, it seems to have some
> (IMHO) weird limitations. So, Q1: Is there any other system call for this?

I don't think there is any system call where you can do this to another
process, passed as an argument.

This would be something that would likely fall under the prctl system call.

In an embedded situation where I control the kernel, I'd hack it into
prctl.

Do you have an X/Y problem here?

Utilities like tmux and screen give processes a virtual terminal which
is their controlling TTY, and can then detach and attach that session to
a real TTY. Can that help in any way?

--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca

Re: Changing the "controlling terminal" of a process?

<ubjbhe$3le6o$1@news.xmission.com>

  copy mid

http://rslight.i2p/devel/article-flat.php?id=2262&group=comp.unix.programmer#2262

  copy link   Newsgroups: comp.unix.programmer
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!xmission!nnrp.xmission!.POSTED.shell.xmission.com!not-for-mail
From: gazelle@shell.xmission.com (Kenny McCormack)
Newsgroups: comp.unix.programmer
Subject: Re: Changing the "controlling terminal" of a process?
Date: Wed, 16 Aug 2023 20:28:30 -0000 (UTC)
Organization: The official candy of the new Millennium
Message-ID: <ubjbhe$3le6o$1@news.xmission.com>
References: <ubitne$3l6qi$1@news.xmission.com> <fO7DM.428700$U3w1.203718@fx09.iad>
Injection-Date: Wed, 16 Aug 2023 20:28:30 -0000 (UTC)
Injection-Info: news.xmission.com; posting-host="shell.xmission.com:166.70.8.4";
logging-data="3848408"; mail-complaints-to="abuse@xmission.com"
X-Newsreader: trn 4.0-test77 (Sep 1, 2010)
Originator: gazelle@shell.xmission.com (Kenny McCormack)
 by: Kenny McCormack - Wed, 16 Aug 2023 20:28 UTC

In article <fO7DM.428700$U3w1.203718@fx09.iad>,
Scott Lurndal <slp53@pacbell.net> wrote:
....
>https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap11.html
>
>11.1.3 The Controlling Terminal
>
> "Each process of a session that has a controlling terminal
> has the same controlling terminal"
>
> "A terminal may be the controlling terminal for at most one session."
>
>I believe there are security issues that would in general
>prevent one from willy-nilly changing the controlling terminal
>for an arbitrary process outside of the standard mechanisms like
>setsid.

It looks like setsid(), followed by opening the desired terminal device,
may solve my problem. Yes, I get it that this doesn't allow you to do it
to an arbitrary process - it still has to be the process itself - but I
think I can live with that.

Q3: What happens if I follow the recipe above, but that terminal device
that I open() is already the controlling terminal of some other session? I
assume the open() doesn't fail, but that the calling process doesn't get a
controlling terminal out of the deal. Is that right?

P.S. No "XY problem" here, but the actual use case is way too complex to
explain in a Usenet post.

--
Politics is show business for ugly people.

Sports is politics for stupid people.

Re: Changing the "controlling terminal" of a process?

<20230816140926.227@kylheku.com>

  copy mid

http://rslight.i2p/devel/article-flat.php?id=2264&group=comp.unix.programmer#2264

  copy link   Newsgroups: comp.unix.programmer
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: 864-117-4973@kylheku.com (Kaz Kylheku)
Newsgroups: comp.unix.programmer
Subject: Re: Changing the "controlling terminal" of a process?
Date: Wed, 16 Aug 2023 21:14:01 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 53
Message-ID: <20230816140926.227@kylheku.com>
References: <ubitne$3l6qi$1@news.xmission.com>
<fO7DM.428700$U3w1.203718@fx09.iad> <ubjbhe$3le6o$1@news.xmission.com>
Injection-Date: Wed, 16 Aug 2023 21:14:01 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="d89b22cba778372e2da36441b02fe0e1";
logging-data="3625471"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19pnC0EXv9Z+EEfofGq1zJ96su3uYGZSJo="
User-Agent: slrn/1.0.3 (Linux)
Cancel-Lock: sha1:E1t8f562uJhb0yA44IPbRoJq7Ek=
 by: Kaz Kylheku - Wed, 16 Aug 2023 21:14 UTC

On 2023-08-16, Kenny McCormack <gazelle@shell.xmission.com> wrote:
> In article <fO7DM.428700$U3w1.203718@fx09.iad>,
> Scott Lurndal <slp53@pacbell.net> wrote:
> ...
>>https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap11.html
>>
>>11.1.3 The Controlling Terminal
>>
>> "Each process of a session that has a controlling terminal
>> has the same controlling terminal"
>>
>> "A terminal may be the controlling terminal for at most one session."
>>
>>I believe there are security issues that would in general
>>prevent one from willy-nilly changing the controlling terminal
>>for an arbitrary process outside of the standard mechanisms like
>>setsid.
>
> It looks like setsid(), followed by opening the desired terminal device,
> may solve my problem. Yes, I get it that this doesn't allow you to do it
> to an arbitrary process - it still has to be the process itself - but I
> think I can live with that.

There are ways to make compiled programs do things!

Using LD_PRELOAD you can force an executable to load shared libraries
of your choice.

This is famously used for overriding functions. But it could also
introduce code that doesn't override anything.

A shared library can have global initialization code that is run
automatically, which you could use for manipulating the process'
environment. I think that would be called before main.

Your shared library could host a little server that listens for messages
of your own design, which make the process do whatever you want at any
point in its lifetime.

This is why Linux mostly doesn't suffer from viruses; that's
integrated as a feature.

> P.S. No "XY problem" here, but the actual use case is way too complex to
> explain in a Usenet post.

n
Ah, XY problem. :)

--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca


devel / comp.unix.programmer / Re: Changing the "controlling terminal" of a process?

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor