844
844
Bres("messages", "Messages", messages, True),
845
845
Ires("minBufSize", "MinBufSize", minBufSize, 4096),
846
846
Ires("maxBufSize", "MaxBufSize", maxBufSize, 32768),
847
Sres("menuLocale", "MenuLocale", menuLocale, ""),
847
Sres("menuLocale", "MenuLocale", menuLocale, DEF_MENU_LOCALE),
848
848
Sres("keyboardType", "KeyboardType", keyboardType, "unknown"),
849
849
#if OPT_SUNPC_KBD
850
850
Bres("sunKeyboard", "SunKeyboard", sunKeyboard, False),
1295
1295
#if defined(_PC_VDISABLE)
1296
1296
if (value == -1) {
1297
value = fpathconf(0, _PC_VDISABLE);
1297
value = (int) fpathconf(0, _PC_VDISABLE);
1298
1298
if (value == -1) {
1299
1299
if (errno != 0)
1300
1300
break; /* skip this (error) */
1316
1316
} else if (termcap && (*string == '\\')) {
1318
int temp = strtol(string + 1, &d, 8);
1318
int temp = (int) strtol(string + 1, &d, 8);
1319
1319
if (temp > 0 && d != string) {
1819
1819
} else if (abbrev(argv[n], "-help", unique)) {
1821
} else if (abbrev(argv[n], "-class", 3)) {
1821
} else if (abbrev(argv[n], "-class", (size_t) 3)) {
1822
1822
if ((my_class = argv[++n]) == 0) {
1829
1829
#if OPT_COLOR_RES
1830
if (abbrev(argv[n], "-reverse", 2)
1830
if (abbrev(argv[n], "-reverse", (size_t) 2)
1831
1831
|| !strcmp("-rv", argv[n])) {
1832
1832
reversed = True;
1833
1833
} else if (!strcmp("+rv", argv[n])) {
2911
TRACE(("set_owner(%s, uid=%d, gid=%d, mode=%#o\n", device, uid, gid, mode));
2911
TRACE(("set_owner(%s, uid=%d, gid=%d, mode=%#o\n",
2912
device, uid, gid, (unsigned) mode));
2913
2914
if (chown(device, uid, gid) < 0) {
2936
2937
(unsigned long) (sb.st_mode & 0777U),
2937
2938
strerror(why));
2938
2939
TRACE(("...stat uid=%d, gid=%d, mode=%#o\n",
2939
sb.st_uid, sb.st_gid, sb.st_mode));
2940
sb.st_uid, sb.st_gid, (unsigned) sb.st_mode));
2942
2943
TRACE(("...chmod failed: %s\n", strerror(why)));
2991
2992
#define close_fd(fd) close(fd), fd = -1
2994
#if defined(TIOCNOTTY) && (!defined(__GLIBC__) || (__GLIBC__ < 2) || ((__GLIBC__ == 2) && (__GLIBC_MINOR__ < 1)))
2995
#define USE_NO_DEV_TTY 1
2997
#define USE_NO_DEV_TTY 0
2994
3001
* Inits pty and tty and forks a login process.
2995
3002
* Does not close fd Xsocket.
3039
3046
#endif /* TERMIO_STRUCT */
3041
3048
char *ptr, *shname, *shname_minus;
3042
int i, no_dev_tty = False;
3051
int no_dev_tty = False;
3043
3053
const char **envnew; /* new environment */
3045
3055
char *TermName = NULL;
3173
3187
lmode = d_lmode;
3174
3188
#endif /* TIOCLSET */
3175
3189
#ifdef TERMIO_STRUCT
3176
if ((rc = ttyGetAttr(ttyfd, &tio)) == -1)
3190
rc = ttyGetAttr(ttyfd, &tio);
3178
3193
#else /* !TERMIO_STRUCT */
3179
if ((rc = ioctl(ttyfd, TIOCGETP, (char *) &sg)) == -1)
3194
rc = ioctl(ttyfd, TIOCGETP, (char *) &sg);
3181
3197
if (ioctl(ttyfd, TIOCGETC, (char *) &tc) == -1)
3225
3241
if (resource.ptyInitialErase) {
3226
3242
#ifdef TERMIO_STRUCT
3227
3243
TERMIO_STRUCT my_tio;
3228
if ((rc = ttyGetAttr(screen->respond, &my_tio)) == 0)
3244
rc = ttyGetAttr(screen->respond, &my_tio);
3229
3246
initial_erase = my_tio.c_cc[VERASE];
3230
3247
#else /* !TERMIO_STRUCT */
3231
3248
struct sgttyb my_sg;
3232
if ((rc = ioctl(screen->respond, TIOCGETP, (char *) &my_sg)) == 0)
3249
rc = ioctl(screen->respond, TIOCGETP, (char *) &my_sg);
3233
3251
initial_erase = my_sg.sg_erase;
3234
3252
#endif /* TERMIO_STRUCT */
3235
3253
TRACE(("%s initial_erase:%d (from pty)\n",
3332
3350
resource.backarrow_is_erase ? "" : "not "));
3333
3351
if (resource.backarrow_is_erase) { /* see input.c */
3334
3352
if (initial_erase == ANSI_DEL) {
3335
xw->keyboard.flags &= ~MODE_DECBKM;
3353
UIntClr(xw->keyboard.flags, MODE_DECBKM);
3337
3355
xw->keyboard.flags |= MODE_DECBKM;
3338
3356
xw->keyboard.reset_DECBKM = 1;
3360
TTYSIZE_ROWS(ts) = MaxRows(screen);
3361
TTYSIZE_COLS(ts) = MaxCols(screen);
3378
TTYSIZE_ROWS(ts) = (ttySize_t) MaxRows(screen);
3379
TTYSIZE_COLS(ts) = (ttySize_t) MaxCols(screen);
3362
3380
#if defined(USE_STRUCT_WINSIZE)
3363
ts.ws_xpixel = FullWidth(screen);
3364
ts.ws_ypixel = FullHeight(screen);
3381
ts.ws_xpixel = (ttySize_t) FullWidth(screen);
3382
ts.ws_ypixel = (ttySize_t) FullHeight(screen);
3367
i = SET_TTYSIZE(screen->respond, ts);
3385
TRACE_RC(i, SET_TTYSIZE(screen->respond, ts));
3368
3386
TRACE(("spawn SET_TTYSIZE %dx%d return %d\n",
3369
3387
TTYSIZE_ROWS(ts),
3370
3388
TTYSIZE_COLS(ts), i));
3411
3429
#ifdef USE_ISPTS_FLAG
3412
3430
if (IsPts) { /* SYSV386 supports both, which did we open? */
3418
3433
grantpt(screen->respond);
3419
3434
unlockpt(screen->respond);
3420
3435
if ((pty_name = ptsname(screen->respond)) == 0) {
3421
3436
SysError(ERROR_PTSNAME);
3423
if ((ptyfd = open(pty_name, O_RDWR)) < 0) {
3437
} else if ((ptyfd = open(pty_name, O_RDWR)) < 0) {
3424
3438
SysError(ERROR_OPPTSNAME);
3427
if (ioctl(ptyfd, I_PUSH, "ptem") < 0) {
3441
else if (ioctl(ptyfd, I_PUSH, "ptem") < 0) {
3428
3442
SysError(ERROR_PTEM);
3430
3444
#if !defined(SVR4) && !(defined(SYSV) && defined(i386))
3431
if (!x_getenv("CONSEM") && ioctl(ptyfd, I_PUSH, "consem") < 0) {
3445
else if (!x_getenv("CONSEM")
3446
&& ioctl(ptyfd, I_PUSH, "consem") < 0) {
3432
3447
SysError(ERROR_CONSEM);
3434
3449
#endif /* !SVR4 */
3435
if (ioctl(ptyfd, I_PUSH, "ldterm") < 0) {
3450
else if (ioctl(ptyfd, I_PUSH, "ldterm") < 0) {
3436
3451
SysError(ERROR_LDTERM);
3438
3453
#ifdef SVR4 /* from Sony */
3439
if (ioctl(ptyfd, I_PUSH, "ttcompat") < 0) {
3454
else if (ioctl(ptyfd, I_PUSH, "ttcompat") < 0) {
3440
3455
SysError(ERROR_TTCOMPAT);
3442
3457
#endif /* SVR4 */
3460
3475
#endif /* OPT_TEK4014 */
3462
TTYSIZE_ROWS(ts) = MaxRows(screen);
3463
TTYSIZE_COLS(ts) = MaxCols(screen);
3477
TTYSIZE_ROWS(ts) = (ttySize_t) MaxRows(screen);
3478
TTYSIZE_COLS(ts) = (ttySize_t) MaxCols(screen);
3464
3479
#ifdef USE_STRUCT_WINSIZE
3465
ts.ws_xpixel = FullWidth(screen);
3466
ts.ws_ypixel = FullHeight(screen);
3480
ts.ws_xpixel = (ttySize_t) FullWidth(screen);
3481
ts.ws_ypixel = (ttySize_t) FullHeight(screen);
3469
3484
#endif /* TTYSIZE_STRUCT */
3488
3503
if (cp_pipe[1] <= 2) {
3489
3504
if ((i = fcntl(cp_pipe[1], F_DUPFD, 3)) >= 0) {
3490
(void) close(cp_pipe[1]);
3505
IGNORE_RC(close(cp_pipe[1]));
3491
3506
cp_pipe[1] = i;
3494
3509
if (pc_pipe[0] <= 2) {
3495
3510
if ((i = fcntl(pc_pipe[0], F_DUPFD, 3)) >= 0) {
3496
(void) close(pc_pipe[0]);
3511
IGNORE_RC(close(pc_pipe[0]));
3497
3512
pc_pipe[0] = i;
3501
3516
/* we don't need the socket, or the pty master anymore */
3502
3517
close(ConnectionNumber(screen->display));
3503
3518
#ifndef __MVS__
3504
close(screen->respond);
3519
if (screen->respond >= 0)
3520
close(screen->respond);
3505
3521
#endif /* __MVS__ */
3507
3523
/* Now is the time to set up our process group and
3533
#if defined(TIOCNOTTY) && (!defined(__GLIBC__) || (__GLIBC__ < 2) || ((__GLIBC__ == 2) && (__GLIBC_MINOR__ < 1)))
3534
3550
if (!no_dev_tty
3535
3551
&& (ttyfd = open("/dev/tty", O_RDWR)) >= 0) {
3536
3552
ioctl(ttyfd, TIOCNOTTY, (char *) NULL);
3537
3553
close_fd(ttyfd);
3539
#endif /* TIOCNOTTY && !glibc >= 2.1 */
3555
#endif /* USE_NO_DEV_TTY */
3540
3556
#ifdef CSRG_BASED
3541
(void) revoke(ttydev);
3557
IGNORE_RC(revoke(ttydev));
3543
3559
if ((ttyfd = open(ttydev, O_RDWR)) >= 0) {
3544
3560
#if defined(CRAY) && defined(TCSETCTTY)
3578
3594
sizeof(handshake)));
3580
3596
/* get reply from parent */
3581
i = read(pc_pipe[0], (char *) &handshake,
3597
i = (int) read(pc_pipe[0], (char *) &handshake,
3584
3600
/* parent terminated */
3593
3609
/* We have a new pty to try */
3595
ttydev = CastMallocN(char, strlen(handshake.buffer));
3596
if (ttydev == NULL) {
3597
SysError(ERROR_SPREALLOC);
3599
strcpy(ttydev, handshake.buffer);
3611
ttydev = x_strdup(handshake.buffer);
3602
3614
/* use the same tty name that everyone else will use
3603
3615
* (from ttyname)
3605
3617
if ((ptr = ttyname(ttyfd)) != 0) {
3606
/* it may be bigger */
3607
ttydev = TypeRealloc(char, strlen(ptr) + 1, ttydev);
3608
if (ttydev == NULL) {
3609
SysError(ERROR_SPREALLOC);
3611
(void) strcpy(ttydev, ptr);
3619
ttydev = x_strdup(ptr);
3614
3622
#endif /* OPT_PTY_HANDSHAKE -- from near fork */
3643
3651
/* input: nl->nl, don't ignore cr, cr->nl */
3644
tio.c_iflag &= ~(INLCR | IGNCR);
3652
UIntClr(tio.c_iflag, (INLCR | IGNCR));
3645
3653
tio.c_iflag |= ICRNL;
3646
3654
#if OPT_WIDE_CHARS && defined(linux) && defined(IUTF8)
3647
3655
#if OPT_LUIT_PROG
3653
3661
/* ouput: cr->cr, nl is not return, no delays, ln->cr/nl */
3654
3662
#ifndef USE_POSIX_TERMIOS
3663
UIntClr(tio.c_oflag,
3664
3672
#endif /* USE_POSIX_TERMIOS */
3666
3674
tio.c_oflag |= ONLCR;
3672
3680
# if defined(Lynx) && !defined(CBAUD)
3673
3681
# define CBAUD V_CBAUD
3675
tio.c_cflag &= ~(CBAUD);
3683
UIntClr(tio.c_cflag, CBAUD);
3677
3685
/* baud rate is 0 (don't care) */
3678
3686
#elif defined(HAVE_TERMIO_C_ISPEED)
3752
3760
HsSysError(ERROR_TIOCSETP);
3754
3762
/* ignore errors here - some platforms don't work */
3755
tio.c_cflag &= ~CSIZE;
3763
UIntClr(tio.c_cflag, CSIZE);
3756
3764
if (screen->input_eight_bits)
3757
3765
tio.c_cflag |= CS8;
3827
3835
if (fd == -1 || ioctl(fd, SRIOCSREDIR, ttyfd) == -1)
3828
3836
fprintf(stderr, "%s: cannot open console: %s\n",
3829
3837
ProgramName, strerror(errno));
3838
IGNORE_RC(close(fd));
3833
3841
#endif /* TIOCCONS */
3868
3876
old_erase = tio.c_cc[VERASE];
3870
3878
tio.c_cc[VERASE] = initial_erase;
3871
rc = ttySetAttr(ttyfd, &tio);
3879
TRACE_RC(rc, ttySetAttr(ttyfd, &tio));
3872
3880
#else /* !TERMIO_STRUCT */
3873
3881
if (ioctl(ttyfd, TIOCGETP, (char *) &sg) == -1)
4016
4024
/* position to entry in utmp file */
4017
4025
/* Test return value: beware of entries left behind: PSz 9 Mar 00 */
4018
if (!(utret = find_utmp(&utmp))) {
4026
utret = find_utmp(&utmp);
4019
4028
(void) call_setutent();
4020
4029
init_utmp(USER_PROCESS, &utmp);
4021
if (!(utret = find_utmp(&utmp))) {
4030
utret = find_utmp(&utmp);
4022
4032
(void) call_setutent();
4027
4037
TRACE(("getutid: NULL\n"));
4029
4039
TRACE(("getutid: pid=%d type=%d user=%s line=%s id=%s\n",
4030
utret->ut_pid, utret->ut_type, utret->ut_user,
4040
(int) utret->ut_pid, utret->ut_type, utret->ut_user,
4031
4041
utret->ut_line, utret->ut_id));
4196
4206
handshake.error = 0;
4197
4207
strcpy(handshake.buffer, ttydev);
4198
4208
TRACE_HANDSHAKE("writing", &handshake);
4199
(void) write(cp_pipe[1], (char *) &handshake, sizeof(handshake));
4209
IGNORE_RC(write(cp_pipe[1], (char *) &handshake, sizeof(handshake)));
4201
4211
#endif /* OPT_PTY_HANDSHAKE */
4202
4212
#endif /* USE_UTEMPTER */
4203
4213
#endif /* HAVE_UTMP */
4205
(void) setgid(screen->gid);
4215
IGNORE_RC(setgid(screen->gid));
4207
4217
#ifdef HAS_BSD_GROUPS
4208
4218
if (geteuid() == 0 && pw) {
4235
4245
sizeof(handshake)));
4237
4247
if (resource.wait_for_map) {
4238
i = read(pc_pipe[0], (char *) &handshake,
4248
i = (int) read(pc_pipe[0], (char *) &handshake,
4240
4250
if (i != sizeof(handshake) ||
4241
4251
handshake.status != PTY_EXEC) {
4242
4252
/* some very bad problem occurred */
4249
4259
set_max_col(screen, handshake.cols);
4250
4260
#ifdef TTYSIZE_STRUCT
4251
4261
got_handshake_size = True;
4252
TTYSIZE_ROWS(ts) = MaxRows(screen);
4253
TTYSIZE_COLS(ts) = MaxCols(screen);
4262
TTYSIZE_ROWS(ts) = (ttySize_t) MaxRows(screen);
4263
TTYSIZE_COLS(ts) = (ttySize_t) MaxCols(screen);
4254
4264
#if defined(USE_STRUCT_WINSIZE)
4255
ts.ws_xpixel = FullWidth(screen);
4256
ts.ws_ypixel = FullHeight(screen);
4265
ts.ws_xpixel = (ttySize_t) FullWidth(screen);
4266
ts.ws_ypixel = (ttySize_t) FullHeight(screen);
4258
4268
#endif /* TTYSIZE_STRUCT */
4302
4312
#if OPT_INITIAL_ERASE
4304
4314
remove_termcap_entry(newtc, TERMCAP_ERASE "=");
4305
len = strlen(newtc);
4315
len = (unsigned) strlen(newtc);
4306
4316
if (len != 0 && newtc[len - 1] == ':')
4308
4318
sprintf(newtc + len, ":%s=\\%03o:",
4325
4335
&& resource.ptySttySize
4326
4336
&& (got_handshake_size || !resource.wait_for_map0)) {
4327
4337
#ifdef TTYSIZE_STRUCT
4328
i = SET_TTYSIZE(0, ts);
4338
TRACE_RC(i, SET_TTYSIZE(0, ts));
4329
4339
TRACE(("ptyHandshake SET_TTYSIZE %dx%d return %d\n",
4330
4340
TTYSIZE_ROWS(ts),
4331
4341
TTYSIZE_COLS(ts), i));
4456
4466
/* The open of the pty failed! Let's get
4459
(void) close(screen->respond);
4469
IGNORE_RC(close(screen->respond));
4460
4470
if (get_pty(&screen->respond, XDisplayString(screen->display))) {
4461
4471
/* no more ptys! */
4462
4472
fprintf(stderr,