1 --- fgetty-0.6/fgetty.c.orig 2005-11-25 12:35:04.000000000 -0400
2 +++ fgetty-0.6/fgetty.c 2005-11-25 12:35:47.000000000 -0400
3 @@ -10,9 +10,13 @@
4 #include <sys/ioctl.h>
5 #include <errno.h>
6 #include <termios.h>
7 +#include <stdlib.h>
8
9 #include "fmt.h"
10
11 +#undef TEST
12 +#undef DEBUG
13 +
14 static struct utsname uts;
15 static char hn[MAXHOSTNAMELEN + 6]="HOST=";
16 static int hn_len=5;
17 @@ -21,8 +25,12 @@
18
19 static int noclear=0;
20
21 -void error(char *message,int exitcode) {
22 +void whine(const char* message) {
23 write(2,message,strlen(message));
24 +}
25 +
26 +void error(char *message,int exitcode) {
27 + whine(message);
28 exit(exitcode);
29 }
30
31 @@ -77,22 +85,26 @@
32 struct sigaction sa;
33 int fd;
34 if (chown(tty,0,0) || chmod(tty,0600))
35 - error("could not chown/chmod tty device\n",1);
36 + error("fgetty: could not chown/chmod tty device\n",1);
37 sa.sa_handler=SIG_IGN;
38 sa.sa_flags=0;
39 sigemptyset(&sa.sa_mask);
40 sigaction(SIGHUP,&sa,NULL);
41 sa.sa_handler=sigquit_handler;
42 sigaction(SIGQUIT,&sa,NULL);
43 - if ((fd=open(tty, O_RDWR, 0))<0 || ioctl (fd, TIOCSCTTY, (void *)1)==-1)
44 - error("could not open tty device\n",3);
45 + setsid();
46 + if ((fd=open(tty, O_RDWR, 0))<0)
47 + error("fgetty: could not open tty device\n",3);
48 if (!isatty(fd))
49 - error("\"not a typewriter\" ;-)\n",4);
50 - if (vhangup()) /* linux specific */
51 - error("vhangup failed\n",5);
52 + error("fgetty: \"not a typewriter\" ;-)\n",4);
53 + if (ioctl (fd, TIOCSCTTY, (void *)1)==0) {
54 + if (vhangup()) /* linux specific */
55 + error("fgetty: vhangup failed\n",5);
56 + } else
57 + whine("fgetty: warning: could not set controlling tty!\n");
58 close(2); close(1); close(0); close(fd);
59 if (open(tty,O_RDWR,0) != 0)
60 - error("could not open tty\n",6);
61 + error("fgetty: could not open tty\n",6);
62 if (dup(0) != 1 || dup(0) != 2)
63 error("could not dup stdout and stderr\n",7);
64 if (!noclear)
65 @@ -211,7 +223,7 @@
66 write(1," login: ",8);
67 }
68
69 -static inline int isprint(char c) {
70 +static inline int _isprint(char c) {
71 return ((c>='A' && c<='Z') ||
72 (c>='a' && c<='z') ||
73 (c>='0' && c<='9') ||
74 @@ -233,7 +245,7 @@
75 if (*c == '\n' || *c == '\r') {
76 *c=0;
77 break;
78 - } else if (!isprint(*c))
79 + } else if (!_isprint(*c))
80 error("unprintable character in login name\n",10);
81 else if (c-logname >= sizeof(logname)-1)
82 error("login name too long\n",11);
83 @@ -260,9 +272,20 @@
84 int i;
85 char hostname_end='.';
86 tty=argv[1];
87 + if (!tty)
88 + error("usage: fgetty 1\n"
89 + " fgetty vc/1\n"
90 + " fgetty /dev/tty1\n",111);
91 if (tty[0]=='/')
92 strncpy(ttybuf,tty,15);
93 - else
94 + else if (isdigit(tty[0])) {
95 + struct stat ss;
96 + /* try prepending /dev/vc/1 and /dev/tty1 */
97 + strcpy(ttybuf,"/dev/vc/"); strncpy(ttybuf+8,tty,3);
98 + if (stat(ttybuf,&ss) && errno==ENOENT) {
99 + ttybuf[5]=ttybuf[6]='t'; ttybuf[7]='y';
100 + }
101 + } else
102 strncpy(ttybuf+5,tty,10);
103 tty=ttybuf;
104 strcpy(ttybuf2+4,ttybuf);
|