0

Ubuntu Linux: How can one acquire a path that refers to the master side of a
of a pseudo terminal pair?... the slave side is easy... but the master side only seems to exist as an open file descriptor, but seems not possess a valid Linux path.

With respect to the working Linux pseudo terminal example http://www.man7.org/tlpi/code/online/all_files_by_chapter.html#ch64 covered in the last chapter of this very good Liunx API book: http://www.nostarch.com/tlpi

A questions regarding the current state of Linux linux pseudo terminal API. The example mentioned above, redirects the forked/exec'ed program's stdin/stdout/stderr streams as required to the PTY slave...all is happy on that side of the PTY.

But the pseudo terminal master's path that I need to pass as an argument to a multi tabbed terminal emulator process seems not yet to exist.

My question is with regard to creating a named path forthe Master side of the pseudo terminal pair...as best as I can disern, in the example code mentioned above, only the PTY slave side actually has a name, as the PTY Master side is referred only by way of of an open file descriptor... and when I query the master side path by way of a "readlink("/dev/fd/3"...) it returns the PTY master clone path "/dev/ptmx", thus I gather that the PTY Master side may not yet have a path name as of yet? .. I thought I might be needing to create a valid path by calling link().... but link() only takes an existing path, not an open File descriptor as its argument?... so I tried calling link("/dev/ptmx", NewPTM_name) refurning to the PTY cloan device hoping it might create a link to the resulting PTY master side, but that call fails, returning -1.

I would like to then pass this PTY Master side path string argument to the terminal emulator, perhaps by way of it's command line, or in RoxTerm's case possibly DBus...

I realize that many terminal emulator programs have a -e or -x argument that allows one to run a program inside of a terminal window... Unfortunately taking this approach does not tend to leave one with much control of the parent/child process tree... such is requred as this work is in support of a shared memory multiprocessing system.

Peter Li
  • 285
  • 1
  • 2
  • 9
  • Why do you want to pass the master side path as an argument? Can you show some code that you are trying to make work? – n. 'pronouns' m. Nov 27 '12 at 04:24
  • Yes, I could post code, but my question is far more basic than that and the example code from book, I refer to is fully documented. I Think it is reasonable to expect that the Linux PTY API would provide a way to refer to both sides of a PTY outside of ones running program.. In this particular case, I am needing to build up a Linux process tree that fits the shape of my multi processing problem.. – Peter Li Nov 27 '12 at 22:49
  • Let me ask it again. Why do you want to pass the master side path as an argument? Is it because you want to write some code that is difficult to express otherwise? If so, what this code is supposed to do? Multitabbed terminal emulators exist and work reasonably well. Do you want to extend their functionality? With what functions? – n. 'pronouns' m. Nov 27 '12 at 22:58
  • I am wishing to route the Stdio of each cooperating shared memory process to a separate tab in the terminal emulator.. RoxTerm runs all of it's tab's from a single process... There will be much more going on that relates to the Linux process tree... so I am wanting the flexability to interconnect my stdio streams independently. – Peter Li Nov 27 '12 at 23:11
  • Instead of asking a terminal emulator to use a given master, which obviously requires some modifications of the emulator, you may ask your process to use a given slave. If you insist on doing the former, you can pass the master not as a path but as an open file descriptor (google for `SCM_RIGHTS`) . – n. 'pronouns' m. Nov 28 '12 at 05:41
  • n.m- Your suggestion seems to be on the right track.. I would point out the slave side of a PTY does have a pathName... and so if the TerminalEmulator on request would manufacture a PTY slave side object – Peter Li Nov 28 '12 at 20:32
  • PTY slave side object on request, that one could then redirect one's process Stdio to and from... it seems one might have a workable solution.... But I have yet to find a multi tabbed Terminal emulator that publishes an array of PTY slave side interfaces.. so it seems where back at needing to modify the terminal emulator to make up for deficiency in the Linux pseudo terminal API.. – Peter Li Nov 28 '12 at 20:44
  • Run a small helper program from the emulator, that would discover its pty name (or an open file descriptor, indeed) and pass it to your main program/thread/whatever. Thus, no published list is needed. – n. 'pronouns' m. Nov 28 '12 at 21:50
  • I'm not sure if a helper program would do the trick, Since the Terminal emulator is multi tabbed, one would need to resolve the PTY slave paths associated with it as one creates more terminal tab windows... But this approach does seem to be workable, even if some PTY related enchantments might need to be made to the multi tabbed terminal emulation program. – Peter Li Nov 28 '12 at 22:36
  • Possibly related https://stackoverflow.com/q/65152924/1569204 – Bruce Adams Dec 05 '20 at 01:34

1 Answers1

0

The current state of the Liunx pseudo terminal API does not make it practical to robustly pass a master side Linux PTY path to a terminal emulation program, as the master side of the pseudo terminal interface is only available as an open file descriptor... .. But the slave side of a PTY interface does possess a path name that one can pass as an argument between programs.. as suggested by n.m,. one can work around this interface limitation of how one would interconnect the stdio of a program to a new tab in a terminal emulation window.... by requesting via DBus that the terminal emulation program create a new (named) terminal tab, and return the associated slave side path as a result of that DBus call..
.. this leads to this follow on question "How to: C++, DBus call to a terminal emulation program that creates new terminal, return slave PTY"

Peter Li
  • 285
  • 1
  • 2
  • 9