PKUOS - Pintos
Pintos source browser for PKU Operating System course
Macros | Functions | Variables
squish-pty.c File Reference
#include <errno.h>
#include <fcntl.h>
#include <signal.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <termios.h>
#include <unistd.h>
Include dependency graph for squish-pty.c:

Go to the source code of this file.

Macros

#define _GNU_SOURCE   1
 

Functions

static void fail_io (const char *msg,...)
 Prints MSG, formatting as with printf(), plus an error message based on errno, and exits. More...
 
static void make_noncanon (int fd, int vmin, int vtime)
 If FD is a terminal, configures it for noncanonical input mode with VMIN and VTIME set as indicated. More...
 
static void make_nonblocking (int fd, bool nonblocking)
 Make FD non-blocking if NONBLOCKING is true, or blocking if NONBLOCKING is false. More...
 
static void handle_error (ssize_t retval, int *fd, bool fd_is_pty, const char *call)
 Handle a read or write on *FD, which is the pty if FD_IS_PTY is true, that returned end-of-file or error indication RETVAL. More...
 
static void relay (int pty, int dead_child_fd)
 Copies data from stdin to PTY and from PTY to stdout until no more data can be read or written. More...
 
static void sigchld_handler (int signo __attribute__((unused)))
 
int main (int argc __attribute__((unused)), char *argv[])
 

Variables

static int dead_child_fd
 

Macro Definition Documentation

◆ _GNU_SOURCE

#define _GNU_SOURCE   1

Definition at line 1 of file squish-pty.c.

Function Documentation

◆ fail_io()

static void static void fail_io ( const char *  msg,
  ... 
)
static

Prints MSG, formatting as with printf(), plus an error message based on errno, and exits.

Definition at line 28 of file squish-pty.c.

References exit(), EXIT_FAILURE, msg(), va_end, and va_start.

Referenced by handle_error(), main(), make_nonblocking(), make_noncanon(), and relay().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ handle_error()

static void handle_error ( ssize_t  retval,
int *  fd,
bool  fd_is_pty,
const char *  call 
)
static

Handle a read or write on *FD, which is the pty if FD_IS_PTY is true, that returned end-of-file or error indication RETVAL.

The system call is named CALL, for use in error messages. Sets *FD to -1 if the fd is no longer readable or writable.

Definition at line 82 of file squish-pty.c.

References close(), and fail_io().

Referenced by relay().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ main()

int main ( int argc   __attribute__(unused),
char *  argv[] 
)

Definition at line 251 of file squish-pty.c.

References close(), dead_child_fd, EXIT_FAILURE, fail_io(), memset(), name, NULL, open(), relay(), sigchld_handler(), and STDOUT_FILENO.

Here is the call graph for this function:

◆ make_nonblocking()

static void make_nonblocking ( int  fd,
bool  nonblocking 
)
static

Make FD non-blocking if NONBLOCKING is true, or blocking if NONBLOCKING is false.

Definition at line 64 of file squish-pty.c.

References fail_io().

Referenced by relay().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ make_noncanon()

static void make_noncanon ( int  fd,
int  vmin,
int  vtime 
)
static

If FD is a terminal, configures it for noncanonical input mode with VMIN and VTIME set as indicated.

If FD is not a terminal, has no effect.

Definition at line 46 of file squish-pty.c.

References fail_io().

Referenced by relay().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ relay()

static void relay ( int  pty,
int  dead_child_fd 
)
static

Copies data from stdin to PTY and from PTY to stdout until no more data can be read or written.

Definition at line 112 of file squish-pty.c.

References buf, dead_child_fd, fail_io(), handle_error(), make_nonblocking(), make_noncanon(), memmove(), memset(), NULL, read(), STDIN_FILENO, STDOUT_FILENO, and write().

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sigchld_handler()

static void sigchld_handler ( int signo   __attribute__(unused))
static

Definition at line 244 of file squish-pty.c.

References dead_child_fd, and write().

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ dead_child_fd

int dead_child_fd
static

Definition at line 241 of file squish-pty.c.

Referenced by main(), relay(), and sigchld_handler().