aboutsummaryrefslogtreecommitdiffstats
path: root/src/testtty.c
blob: 2cef3e0bda8e59956cbf74a32118ab3eeca23dee (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/*
 * testtty.c:
 *
 * Copyright (c) 2008 James McKenzie <james@fishsoup.dhs.org>,
 * All rights reserved.
 *
 */

static char rcsid[] = "$Id$";

/*
 * $Log$
 * Revision 1.1  2008/02/04 01:32:39  james
 * *** empty log message ***
 *
 */

#include "project.h"

static void  default_termios(struct termios *termios)
{

memset(termios,0,sizeof(termios));

termios->c_iflag=ICRNL|IXON;
termios->c_oflag=OPOST | ONLCR | NL0 | CR0 | TAB0 | BS0 | VT0 | FF0;
termios->c_lflag=ISIG | ICANON | IEXTEN | ECHO | ECHOE | ECHOK | ECHOCTL | ECHOKE;

termios->c_cc[VINTR]=003;
termios->c_cc[VQUIT]=034;
termios->c_cc[VERASE]=0177;
termios->c_cc[VKILL]=025;
termios->c_cc[VEOF]=004;
termios->c_cc[VEOL]=0;
termios->c_cc[VEOL2]=0;
termios->c_cc[VSTART]=021;
termios->c_cc[VSTOP]=023;
termios->c_cc[VSUSP]=032;
termios->c_cc[VLNEXT]=026;
termios->c_cc[VWERASE]=027;
termios->c_cc[VREPRINT]=022;
termios->c_cc[VDISCARD]=017;

termios->c_cflag=CS8 | CREAD | CLOCAL;

cfsetispeed(termios,B9600);
cfsetospeed(termios,B9600);
}


int open_fd_to_bash(void) /*thump*/
{
pid_t child;
int fd;
struct winsize winsize={0};
struct termios termios;

default_termios(&termios);

winsize.ws_row=CRT_ROWS;
winsize.ws_col=CRT_COLS;

child=forkpty(&fd,NULL,&termios,&winsize);

switch (child) 
{
case -1:/*boo hiss*/
	return -1;
case 0: /*waaah*/
	setenv("TERM","vt102",1);
	execl("/bin/sh","-",(char *) 0);
	_exit(-1);
}

return fd;
}