Deleted Added
full compact
main.c (116329) main.c (116533)
1/*-
2 * Copyright (c) 1980, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 28 unchanged lines hidden (view full) ---

37 The Regents of the University of California. All rights reserved.\n";
38#endif /* not lint */
39
40#ifndef lint
41#if 0
42static char sccsid[] = "@(#)from: main.c 8.1 (Berkeley) 6/20/93";
43#endif
44static const char rcsid[] =
1/*-
2 * Copyright (c) 1980, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 28 unchanged lines hidden (view full) ---

37 The Regents of the University of California. All rights reserved.\n";
38#endif /* not lint */
39
40#ifndef lint
41#if 0
42static char sccsid[] = "@(#)from: main.c 8.1 (Berkeley) 6/20/93";
43#endif
44static const char rcsid[] =
45 "$FreeBSD: head/libexec/getty/main.c 116329 2003-06-14 08:26:47Z green $";
45 "$FreeBSD: head/libexec/getty/main.c 116533 2003-06-18 13:22:44Z yar $";
46#endif /* not lint */
47
48#include <sys/param.h>
49#include <sys/ioctl.h>
50#include <sys/time.h>
51#include <sys/resource.h>
52#include <sys/stat.h>
53#include <sys/ttydefaults.h>

--- 31 unchanged lines hidden (view full) ---

85#define PPP_FRAME 0x7e /* PPP Framing character */
86#define PPP_STATION 0xff /* "All Station" character */
87#define PPP_ESCAPE 0x7d /* Escape Character */
88#define PPP_CONTROL 0x03 /* PPP Control Field */
89#define PPP_CONTROL_ESCAPED 0x23 /* PPP Control Field, escaped */
90#define PPP_LCP_HI 0xc0 /* LCP protocol - high byte */
91#define PPP_LCP_LOW 0x21 /* LCP protocol - low byte */
92
46#endif /* not lint */
47
48#include <sys/param.h>
49#include <sys/ioctl.h>
50#include <sys/time.h>
51#include <sys/resource.h>
52#include <sys/stat.h>
53#include <sys/ttydefaults.h>

--- 31 unchanged lines hidden (view full) ---

85#define PPP_FRAME 0x7e /* PPP Framing character */
86#define PPP_STATION 0xff /* "All Station" character */
87#define PPP_ESCAPE 0x7d /* Escape Character */
88#define PPP_CONTROL 0x03 /* PPP Control Field */
89#define PPP_CONTROL_ESCAPED 0x23 /* PPP Control Field, escaped */
90#define PPP_LCP_HI 0xc0 /* LCP protocol - high byte */
91#define PPP_LCP_LOW 0x21 /* LCP protocol - low byte */
92
93struct termios tmode, omode;
93/* original mode; flags've been reset using values from <sys/ttydefaults.h> */
94struct termios omode;
95/* current mode */
96struct termios tmode;
94
95int crmod, digit, lower, upper;
96
97char hostname[MAXHOSTNAMELEN];
98char name[MAXLOGNAME*3];
99char dev[] = _PATH_DEV;
100char ttyn[32];
101
102#define OBUFSIZ 128
103#define TABBUFSIZ 512
104
105char defent[TABBUFSIZ];
106char tabent[TABBUFSIZ];
97
98int crmod, digit, lower, upper;
99
100char hostname[MAXHOSTNAMELEN];
101char name[MAXLOGNAME*3];
102char dev[] = _PATH_DEV;
103char ttyn[32];
104
105#define OBUFSIZ 128
106#define TABBUFSIZ 512
107
108char defent[TABBUFSIZ];
109char tabent[TABBUFSIZ];
110const char *tname;
107
108char *env[128];
109
110char partab[] = {
111 0001,0201,0201,0001,0201,0001,0001,0201,
112 0202,0004,0003,0205,0005,0206,0201,0001,
113 0201,0001,0001,0201,0001,0201,0201,0001,
114 0001,0201,0201,0001,0201,0001,0001,0201,

--- 12 unchanged lines hidden (view full) ---

127};
128
129#define ERASE tmode.c_cc[VERASE]
130#define KILL tmode.c_cc[VKILL]
131#define EOT tmode.c_cc[VEOF]
132
133#define puts Gputs
134
111
112char *env[128];
113
114char partab[] = {
115 0001,0201,0201,0001,0201,0001,0001,0201,
116 0202,0004,0003,0205,0005,0206,0201,0001,
117 0201,0001,0001,0201,0001,0201,0201,0001,
118 0001,0201,0201,0001,0201,0001,0001,0201,

--- 12 unchanged lines hidden (view full) ---

131};
132
133#define ERASE tmode.c_cc[VERASE]
134#define KILL tmode.c_cc[VKILL]
135#define EOT tmode.c_cc[VEOF]
136
137#define puts Gputs
138
139static void defttymode();
135static void dingdong(int);
140static void dingdong(int);
136static void dogettytab(const char *);
141static void dogettytab(void);
137static int getname(void);
138static void interrupt(int);
139static void oflush(void);
140static void prompt(void);
141static void putchr(int);
142static void putf(const char *);
143static void putpad(const char *);
144static void puts(const char *);
145static void timeoverrun(int);
146static char *getline(int);
147static void setttymode(int);
142static int getname(void);
143static void interrupt(int);
144static void oflush(void);
145static void prompt(void);
146static void putchr(int);
147static void putf(const char *);
148static void putpad(const char *);
149static void puts(const char *);
150static void timeoverrun(int);
151static char *getline(int);
152static void setttymode(int);
148static void setdefttymode(void);
149static int opentty(const char *, int);
150
151jmp_buf timeout;
152
153static void
154dingdong(int signo __unused)
155{
156 alarm(0);

--- 18 unchanged lines hidden (view full) ---

175 syslog(LOG_ERR, "getty exiting due to excessive running time");
176 exit(1);
177}
178
179int
180main(int argc, char *argv[])
181{
182 extern char **environ;
153static int opentty(const char *, int);
154
155jmp_buf timeout;
156
157static void
158dingdong(int signo __unused)
159{
160 alarm(0);

--- 18 unchanged lines hidden (view full) ---

179 syslog(LOG_ERR, "getty exiting due to excessive running time");
180 exit(1);
181}
182
183int
184main(int argc, char *argv[])
185{
186 extern char **environ;
183 const char *tname;
184 int first_sleep = 1, first_time = 1;
185 struct rlimit limit;
186 int rval;
187
188 signal(SIGINT, SIG_IGN);
189 signal(SIGQUIT, SIG_IGN);
190
191 openlog("getty", LOG_ODELAY|LOG_CONS|LOG_PID, LOG_AUTH);

--- 18 unchanged lines hidden (view full) ---

210
211 /*
212 * The following is a work around for vhangup interactions
213 * which cause great problems getting window systems started.
214 * If the tty line is "-", we do the old style getty presuming
215 * that the file descriptors are already set up for us.
216 * J. Gettys - MIT Project Athena.
217 */
187 int first_sleep = 1, first_time = 1;
188 struct rlimit limit;
189 int rval;
190
191 signal(SIGINT, SIG_IGN);
192 signal(SIGQUIT, SIG_IGN);
193
194 openlog("getty", LOG_ODELAY|LOG_CONS|LOG_PID, LOG_AUTH);

--- 18 unchanged lines hidden (view full) ---

213
214 /*
215 * The following is a work around for vhangup interactions
216 * which cause great problems getting window systems started.
217 * If the tty line is "-", we do the old style getty presuming
218 * that the file descriptors are already set up for us.
219 * J. Gettys - MIT Project Athena.
220 */
218 if (argc <= 2 || strcmp(argv[2], "-") == 0) {
221 if (argc <= 2 || strcmp(argv[2], "-") == 0)
219 strcpy(ttyn, ttyname(STDIN_FILENO));
222 strcpy(ttyn, ttyname(STDIN_FILENO));
220 dogettytab(tname);
221 } else {
223 else {
222 strcpy(ttyn, dev);
223 strncat(ttyn, argv[2], sizeof(ttyn)-sizeof(dev));
224 if (strcmp(argv[0], "+") != 0) {
225 chown(ttyn, 0, 0);
226 chmod(ttyn, 0600);
227 revoke(ttyn);
228
224 strcpy(ttyn, dev);
225 strncat(ttyn, argv[2], sizeof(ttyn)-sizeof(dev));
226 if (strcmp(argv[0], "+") != 0) {
227 chown(ttyn, 0, 0);
228 chmod(ttyn, 0600);
229 revoke(ttyn);
230
229 /* Init modem sequence has been specified
231 /*
232 * Do the first scan through gettytab.
233 * Terminal mode parameters will be wrong until
234 * defttymode() called, but they're irrelevant for
235 * the initial setup of the terminal device.
230 */
236 */
231 if (IC) {
237 dogettytab();
238
239 /*
240 * Init or answer modem sequence has been specified.
241 */
242 if (IC || AC) {
232 if (!opentty(ttyn, O_RDWR|O_NONBLOCK))
233 exit(1);
243 if (!opentty(ttyn, O_RDWR|O_NONBLOCK))
244 exit(1);
234 dogettytab(tname);
235 setdefttymode();
245 defttymode();
246 setttymode(1);
247 }
248
249 if (IC) {
236 if (getty_chat(IC, CT, DC) > 0) {
237 syslog(LOG_ERR, "modem init problem on %s", ttyn);
238 (void)tcsetattr(STDIN_FILENO, TCSANOW, &tmode);
239 exit(1);
240 }
241 }
242
243 if (AC) {
244 int i, rfds;
245 struct timeval to;
246
250 if (getty_chat(IC, CT, DC) > 0) {
251 syslog(LOG_ERR, "modem init problem on %s", ttyn);
252 (void)tcsetattr(STDIN_FILENO, TCSANOW, &tmode);
253 exit(1);
254 }
255 }
256
257 if (AC) {
258 int i, rfds;
259 struct timeval to;
260
247 if (!opentty(ttyn, O_RDWR|O_NONBLOCK))
248 exit(1);
249 dogettytab(tname);
250 setdefttymode();
251 rfds = 1 << 0; /* FD_SET */
252 to.tv_sec = RT;
253 to.tv_usec = 0;
254 i = select(32, (fd_set*)&rfds, (fd_set*)NULL,
255 (fd_set*)NULL, RT ? &to : NULL);
256 if (i < 0) {
257 syslog(LOG_ERR, "select %s: %m", ttyn);
258 } else if (i == 0) {

--- 5 unchanged lines hidden (view full) ---

264 if (i > 0) {
265 syslog(LOG_ERR, "modem answer problem on %s", ttyn);
266 (void)tcsetattr(STDIN_FILENO, TCSANOW, &tmode);
267 exit(1);
268 }
269 } else { /* maybe blocking open */
270 if (!opentty(ttyn, O_RDWR | (NC ? O_NONBLOCK : 0 )))
271 exit(1);
261 rfds = 1 << 0; /* FD_SET */
262 to.tv_sec = RT;
263 to.tv_usec = 0;
264 i = select(32, (fd_set*)&rfds, (fd_set*)NULL,
265 (fd_set*)NULL, RT ? &to : NULL);
266 if (i < 0) {
267 syslog(LOG_ERR, "select %s: %m", ttyn);
268 } else if (i == 0) {

--- 5 unchanged lines hidden (view full) ---

274 if (i > 0) {
275 syslog(LOG_ERR, "modem answer problem on %s", ttyn);
276 (void)tcsetattr(STDIN_FILENO, TCSANOW, &tmode);
277 exit(1);
278 }
279 } else { /* maybe blocking open */
280 if (!opentty(ttyn, O_RDWR | (NC ? O_NONBLOCK : 0 )))
281 exit(1);
272 dogettytab(tname);
273 }
274 }
275 }
276
282 }
283 }
284 }
285
277 /* Start with default tty settings */
278 if (tcgetattr(STDIN_FILENO, &tmode) < 0) {
279 syslog(LOG_ERR, "tcgetattr %s: %m", ttyn);
280 exit(1);
281 }
282 /*
283 * Don't rely on the driver too much, and initialize crucial
284 * things according to <sys/ttydefaults.h>. Avoid clobbering
285 * the c_cc[] settings however, the console drivers might wish
286 * to leave their idea of the preferred VERASE key value
287 * there.
288 */
289 tmode.c_iflag = TTYDEF_IFLAG;
290 tmode.c_oflag = TTYDEF_OFLAG;
291 tmode.c_lflag = TTYDEF_LFLAG;
292 tmode.c_cflag = TTYDEF_CFLAG;
293 tmode.c_cflag |= (NC ? CLOCAL : 0);
294 omode = tmode;
295
286 defttymode();
296 for (;;) {
297
298 /*
299 * if a delay was specified then sleep for that
300 * number of seconds before writing the initial prompt
301 */
302 if (first_sleep && DE) {
303 sleep(DE);
304 /* remove any noise */
305 (void)tcflush(STDIN_FILENO, TCIOFLUSH);
306 }
307 first_sleep = 0;
308
309 setttymode(0);
310 if (AB) {
311 tname = autobaud();
287 for (;;) {
288
289 /*
290 * if a delay was specified then sleep for that
291 * number of seconds before writing the initial prompt
292 */
293 if (first_sleep && DE) {
294 sleep(DE);
295 /* remove any noise */
296 (void)tcflush(STDIN_FILENO, TCIOFLUSH);
297 }
298 first_sleep = 0;
299
300 setttymode(0);
301 if (AB) {
302 tname = autobaud();
312 dogettytab(tname);
303 dogettytab();
313 continue;
314 }
315 if (PS) {
316 tname = portselector();
304 continue;
305 }
306 if (PS) {
307 tname = portselector();
317 dogettytab(tname);
308 dogettytab();
318 continue;
319 }
320 if (CL && *CL)
321 putpad(CL);
322 edithost(HE);
323
324 /* if this is the first time through this, and an
325 issue file has been given, then send it */

--- 97 unchanged lines hidden (view full) ---

423 syslog(LOG_ERR, "%s: %m", LO);
424 exit(1);
425 }
426 alarm(0);
427 signal(SIGALRM, SIG_DFL);
428 signal(SIGINT, SIG_IGN);
429 if (NX && *NX) {
430 tname = NX;
309 continue;
310 }
311 if (CL && *CL)
312 putpad(CL);
313 edithost(HE);
314
315 /* if this is the first time through this, and an
316 issue file has been given, then send it */

--- 97 unchanged lines hidden (view full) ---

414 syslog(LOG_ERR, "%s: %m", LO);
415 exit(1);
416 }
417 alarm(0);
418 signal(SIGALRM, SIG_DFL);
419 signal(SIGINT, SIG_IGN);
420 if (NX && *NX) {
421 tname = NX;
431 dogettytab(tname);
422 dogettytab();
432 }
433 }
434}
435
436static int
437opentty(const char *tty, int flags)
438{
439 int i, j = 0;

--- 25 unchanged lines hidden (view full) ---

465 return 0;
466 }
467 }
468 return 1;
469 }
470}
471
472static void
423 }
424 }
425}
426
427static int
428opentty(const char *tty, int flags)
429{
430 int i, j = 0;

--- 25 unchanged lines hidden (view full) ---

456 return 0;
457 }
458 }
459 return 1;
460 }
461}
462
463static void
473setdefttymode(void)
464defttymode()
474{
465{
466
467 /* Start with default tty settings. */
475 if (tcgetattr(STDIN_FILENO, &tmode) < 0) {
476 syslog(LOG_ERR, "tcgetattr %s: %m", ttyn);
477 exit(1);
478 }
468 if (tcgetattr(STDIN_FILENO, &tmode) < 0) {
469 syslog(LOG_ERR, "tcgetattr %s: %m", ttyn);
470 exit(1);
471 }
472 omode = tmode; /* fill c_cc for dogettytab() */
473 dogettytab();
474 /*
475 * Don't rely on the driver too much, and initialize crucial
476 * things according to <sys/ttydefaults.h>. Avoid clobbering
477 * the c_cc[] settings however, the console drivers might wish
478 * to leave their idea of the preferred VERASE key value
479 * there.
480 */
479 tmode.c_iflag = TTYDEF_IFLAG;
481 tmode.c_iflag = TTYDEF_IFLAG;
480 tmode.c_oflag = TTYDEF_OFLAG;
481 tmode.c_lflag = TTYDEF_LFLAG;
482 tmode.c_cflag = TTYDEF_CFLAG;
483 omode = tmode;
484 setttymode(1);
482 tmode.c_oflag = TTYDEF_OFLAG;
483 tmode.c_lflag = TTYDEF_LFLAG;
484 tmode.c_cflag = TTYDEF_CFLAG;
485 if (NC)
486 tmode.c_cflag |= CLOCAL;
487 omode = tmode;
485}
486
487static void
488setttymode(int raw)
489{
490 int off = 0;
491
492 (void)tcflush(STDIN_FILENO, TCIOFLUSH); /* clear out the crap */

--- 303 unchanged lines hidden (view full) ---

796 cp++;
797 }
798}
799
800/*
801 * Read a gettytab database entry and perform necessary quirks.
802 */
803static void
488}
489
490static void
491setttymode(int raw)
492{
493 int off = 0;
494
495 (void)tcflush(STDIN_FILENO, TCIOFLUSH); /* clear out the crap */

--- 303 unchanged lines hidden (view full) ---

799 cp++;
800 }
801}
802
803/*
804 * Read a gettytab database entry and perform necessary quirks.
805 */
806static void
804dogettytab(const char *tname)
807dogettytab()
805{
808{
806 struct termios backupmode;
807
809
808 /* Read the database entry */
810 /* Read the database entry. */
809 gettable(tname, tabent);
810
811 /*
812 * Avoid inheriting the parity values from the default entry
813 * if any of them is set in the current entry.
814 * Mixing different parity settings is unreasonable.
815 */
816 if (OPset || EPset || APset || NPset)
817 OPset = EPset = APset = NPset = 1;
818
811 gettable(tname, tabent);
812
813 /*
814 * Avoid inheriting the parity values from the default entry
815 * if any of them is set in the current entry.
816 * Mixing different parity settings is unreasonable.
817 */
818 if (OPset || EPset || APset || NPset)
819 OPset = EPset = APset = NPset = 1;
820
819 /*
820 * Fill in default values for unset capabilities. Since the
821 * defaults are derived from the actual tty mode, save any
822 * changes to the tmode and fetch it temporarily for
823 * setdefaults() to use.
824 */
825 backupmode = tmode;
826 if (tcgetattr(STDIN_FILENO, &tmode) < 0) {
827 syslog(LOG_ERR, "tcgetattr %s: %m", ttyn);
828 exit(1);
829 }
821 /* Fill in default values for unset capabilities. */
830 setdefaults();
822 setdefaults();
831 tmode = backupmode;
832}
823}