KPty

Search for usage in LXR

#include <kpty.h>

Inheritance diagram for KPty:

Public Member Functions

 KPty ()
 
 KPty (const KPty &)=delete
 
 ~KPty ()
 
void close ()
 
void closeSlave ()
 
void login (const char *user=nullptr, const char *remotehost=nullptr)
 
void logout ()
 
int masterFd () const
 
bool open ()
 
bool open (int fd)
 
bool openSlave ()
 
KPtyoperator= (const KPty &)=delete
 
void setCTty ()
 
void setCTtyEnabled (bool enable)
 
bool setEcho (bool echo)
 
bool setWinSize (int lines, int columns)
 
bool setWinSize (int lines, int columns, int height, int width)
 
int slaveFd () const
 
bool tcGetAttr (struct ::termios *ttmode) const
 
bool tcSetAttr (struct ::termios *ttmode)
 
const char * ttyName () const
 

Protected Member Functions

KPTY_NO_EXPORT KPty (KPtyPrivate *d)
 

Protected Attributes

std::unique_ptr< KPtyPrivate > const d_ptr
 

Detailed Description

Provides primitives for opening & closing a pseudo TTY pair, assigning the controlling TTY, utmp registration and setting various terminal attributes.

Definition at line 25 of file kpty.h.

Constructor & Destructor Documentation

◆ KPty() [1/2]

KPty::KPty ( )

Constructor.

Definition at line 170 of file kpty.cpp.

◆ ~KPty()

KPty::~KPty ( )

Destructor:

If the pty is still open, it will be closed. Note, however, that an utmp registration is not undone.

Definition at line 181 of file kpty.cpp.

◆ KPty() [2/2]

KPty::KPty ( KPtyPrivate * d)
explicitprotected

Definition at line 175 of file kpty.cpp.

Member Function Documentation

◆ close()

void KPty::close ( )

Close the pty master/slave pair.

Definition at line 398 of file kpty.cpp.

◆ closeSlave()

void KPty::closeSlave ( )

Close the pty slave descriptor.

When creating the pty, KPty also opens the slave and keeps it open. Consequently the master will never receive an EOF notification. Usually this is the desired behavior, as a closed pty slave can be reopened any time - unlike a pipe or socket. However, in some cases pipe-alike behavior might be desired.

After this function was called, slaveFd() and setCTty() cannot be used.

Definition at line 367 of file kpty.cpp.

◆ login()

void KPty::login ( const char * user = nullptr,
const char * remotehost = nullptr )

Creates an utmp entry for the tty.

This function must be called after calling setCTty and making this pty the stdin.

Parameters
userthe user to be logged on
remotehostthe host from which the login is coming. This is not the local host. For remote logins it should be the hostname of the client. For local logins from inside an X session it should be the name of the X display. Otherwise it should be empty.

Definition at line 449 of file kpty.cpp.

◆ logout()

void KPty::logout ( )

Removes the utmp entry for this tty.

Definition at line 538 of file kpty.cpp.

◆ masterFd()

int KPty::masterFd ( ) const
Returns
the file descriptor of the master pty

This function should be called only while the pty is open.

Definition at line 669 of file kpty.cpp.

◆ open() [1/2]

bool KPty::open ( )

Create a pty master/slave pair.

Returns
true if a pty pair was successfully opened

Definition at line 186 of file kpty.cpp.

◆ open() [2/2]

bool KPty::open ( int fd)

Open using an existing pty master.

Parameters
fdan open pty master file descriptor. The ownership of the fd remains with the caller; it will not be automatically closed at any point.
Returns
true if a pty pair was successfully opened

Definition at line 326 of file kpty.cpp.

◆ openSlave()

bool KPty::openSlave ( )

Open the pty slave descriptor.

This undoes the effect of closeSlave().

Returns
true if the pty slave was successfully opened

Definition at line 378 of file kpty.cpp.

◆ setCTty()

void KPty::setCTty ( )

Creates a new session and process group and makes this pty the controlling tty.

Definition at line 427 of file kpty.cpp.

◆ setCTtyEnabled()

void KPty::setCTtyEnabled ( bool enable)

Whether this will be a controlling terminal.

This is on by default. Disabling the controllig aspect only makes sense if another process will take over control or there is nothing to control or for technical reasons control cannot be set (this notably is the case with flatpak-spawn when used inside a sandbox).

Parameters
enablewhether to enable ctty set up

Definition at line 683 of file kpty.cpp.

◆ setEcho()

bool KPty::setEcho ( bool echo)

Set whether the pty should echo input.

Echo is on by default. If the output of automatically fed (non-interactive) PTY clients needs to be parsed, disabling echo often makes it much simpler.

This function can be used only while the PTY is open.

Parameters
echotrue if input should be echoed.
Returns
true on success, false otherwise

Definition at line 648 of file kpty.cpp.

◆ setWinSize() [1/2]

bool KPty::setWinSize ( int lines,
int columns )

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Change the logical (screen) size of the pty.

The pixel size is set to zero.

Definition at line 643 of file kpty.cpp.

◆ setWinSize() [2/2]

bool KPty::setWinSize ( int lines,
int columns,
int height,
int width )

Change the logical (screen) size of the pty.

The default is 24 lines by 80 columns in characters, and zero pixels.

This function can be used only while the PTY is open.

Parameters
linesthe number of character rows
columnsthe number of character columns
heightthe view height in pixels
widththe view width in pixels
Returns
true on success, false otherwise
Since
5.93

Definition at line 631 of file kpty.cpp.

◆ slaveFd()

int KPty::slaveFd ( ) const
Returns
the file descriptor of the slave pty

This function should be called only while the pty slave is open.

Definition at line 676 of file kpty.cpp.

◆ tcGetAttr()

bool KPty::tcGetAttr ( struct ::termios * ttmode) const

Wrapper around tcgetattr(3).

This function can be used only while the PTY is open. You will need an #include <termios.h> to do anything useful with it.

Parameters
ttmodea pointer to a termios structure. Note: when declaring ttmode, struct ::termios must be used - without the '::' some version of HP-UX thinks, this declares the struct in your class, in your method.
Returns
true on success, false otherwise

Definition at line 617 of file kpty.cpp.

◆ tcSetAttr()

bool KPty::tcSetAttr ( struct ::termios * ttmode)

Wrapper around tcsetattr(3) with mode TCSANOW.

This function can be used only while the PTY is open.

Parameters
ttmodea pointer to a termios structure.
Returns
true on success, false otherwise. Note that success means that at least one attribute could be set.

Definition at line 624 of file kpty.cpp.

◆ ttyName()

const char * KPty::ttyName ( ) const
Returns
the name of the slave pty device.

This function should be called only while the pty is open.

Definition at line 662 of file kpty.cpp.

Member Data Documentation

◆ d_ptr

std::unique_ptr<KPtyPrivate> const KPty::d_ptr
protected

Definition at line 220 of file kpty.h.


The documentation for this class was generated from the following files:
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 29 2024 11:58:51 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.