From mboxrd@z Thu Jan 1 00:00:00 1970 Message-ID: <9705091025.ZM20479@fabsoft2.zarm.uni-bremen.de> Date: Fri, 9 May 1997 10:25:09 +0200 From: Zarmfab Software Development Subject: procps-1.01: top problems with glibc-2 and patch Just built procps-1.01 at my linux-axp machine with glibc-2.03 and noted, that terminal-mode switching in top did not work. After replacing all ioctl-calls with their termios-counterparts, top works fine. Maybe this is an alpha-specific problem, anyway, this are my patches to top.h and top.c : diff -u procps-1.01/top.h procps-1.01-axp/top.h --- procps-1.01/top.h Mon Jun 10 11:09:20 1996 +++ procps-1.01-axp/top.h Fri May 9 09:19:20 1997 @@ -69,9 +69,9 @@ }; /* The original terminal attributes. */ -struct termio Savetty; +struct termios Savetty; /* The new terminal attributes. */ -struct termio Rawtty; +struct termios Rawtty; /* Cached termcap entries. */ char *cm, *cl, *top_clrtobot, *top_clrtoeol, *ho, *md, *me, *mr; /* Current window size. Note that it is legal to set Display_procs diff -u procps-1.01/top.c procps-1.01-axp/top.c --- procps-1.01/top.c Thu Jun 13 05:20:00 1996 +++ procps-1.01-axp/top.c Fri May 9 09:44:42 1997 @@ -61,10 +61,9 @@ #include #include #include -#include #include -#include -#include +#include +#include #include #include #include @@ -73,6 +72,7 @@ #include #include #include +#include #include "proc/sysinfo.h" #include "proc/ps.h" @@ -80,6 +80,9 @@ #include "proc/signals.h" #include "proc/version.h" #include "proc/readproc.h" + +#include + /* these should be in the readproc.h header or in the ps.h header */ typedef int (*cmp_t)(void*,void*); extern void reset_sort_options (void); @@ -231,7 +234,8 @@ void setup_terminal(void) { char *termtype; - struct termio newtty; + struct termios newtty; + int result; termtype = getenv("TERM"); if (!termtype) { @@ -242,8 +246,8 @@ /* fprintf(stderr, PROGNAME ": $TERM not set\n"); */ /* exit(1); */ } - if (ioctl(0, TCGETA, &Savetty) == -1) { - perror(PROGNAME ": ioctl() failed"); + if (tcgetattr(STDIN_FILENO,&Savetty)) { + perror(PROGNAME ": tcgetattr() failed"); error_end(errno); } newtty = Savetty; @@ -251,16 +255,19 @@ newtty.c_lflag &= ~ECHO; newtty.c_cc[VMIN] = 1; newtty.c_cc[VTIME] = 0; - if (ioctl(0, TCSETAF, &newtty) == -1) { + if (tcsetattr(STDIN_FILENO,TCSANOW,&newtty)) { printf("cannot put tty into raw mode\n"); - error_end(1); + error_end(errno); } - ioctl(0, TCGETA, &Rawtty); + tcgetattr(STDIN_FILENO,&Rawtty); /* * Get termcap entries and window size. */ - tgetent(NULL, termtype); + if (tgetent(NULL, termtype)!=1) { + fprintf(stderr,PROGNAME ": no terminal info for %s found\n",termtype); + error_end(1); + } cm = tgetstr("cm", 0); top_clrtobot = tgetstr("cd", 0); cl = tgetstr("cl", 0); @@ -383,8 +390,12 @@ tv.tv_usec = (Sleeptime - (int) Sleeptime) * 1000000; FD_ZERO(&in); FD_SET(0, &in); - if (select(16, &in, 0, 0, &tv) > 0 && read(0, &c, 1) == 1) + if (select(16, &in, 0, 0, &tv) > 0 ) { + char count=read(0, &c, 1); + ; + if (count>0) do_key(c); + } } } @@ -402,7 +413,7 @@ { if (psdbsucc) close_psdb(); - ioctl(0, TCSETAF, &Savetty); + tcsetattr(STDIN_FILENO, TCSAFLUSH, &Savetty); PUTP(tgoto(cm, 0, Lines - 1)); fputs("\r\n", stdout); exit(rno); @@ -414,7 +425,7 @@ { if (psdbsucc) close_psdb(); - ioctl(0, TCSETAF, &Savetty); + tcsetattr(STDIN_FILENO, TCSAFLUSH, &Savetty); PUTP(tgoto(cm, 0, Lines - 1)); fputs("\r\n", stdout); exit(0); @@ -428,12 +439,12 @@ /* Reset terminal. */ if (psdbsucc) close_psdb(); - ioctl(0, TCSETAF, &Savetty); + tcsetattr(STDIN_FILENO, TCSAFLUSH, &Savetty); PUTP(tgoto(cm, 0, Lines - 3)); fflush(stdout); raise(SIGTSTP); /* Later... */ - ioctl(0, TCSETAF, &Rawtty); + tcsetattr(STDIN_FILENO, TCSAFLUSH, &Rawtty); signal(SIGTSTP, (void *) (int) stop); longjmp(redraw_jmp, 1); } @@ -666,9 +677,9 @@ PUTP(tgoto(cm, 0, 1)); printf("Upper case characters move a field to the left, lower case to the right"); fflush(stdout); - ioctl(0, TCSETAF, &Rawtty); + tcsetattr(STDIN_FILENO, TCSAFLUSH, &Rawtty); read(0, &c, 1); - ioctl(0, TCSETAF, &Savetty); + tcsetattr(STDIN_FILENO, TCSAFLUSH, &Savetty); i = toupper(c) - 'A'; if ((p = strchr(Fields, i + 'A')) != NULL) { if (isupper(c)) @@ -714,9 +725,9 @@ PUTP(tgoto(cm, 0, 1)); printf("Toggle fields with a-x, any other key to return: "); fflush(stdout); - ioctl(0, TCSETAF, &Rawtty); + tcsetattr(STDIN_FILENO, TCSAFLUSH, &Rawtty); read(0, &c, 1); - ioctl(0, TCSETAF, &Savetty); + tcsetattr(STDIN_FILENO, TCSAFLUSH, &Savetty); i = toupper(c) - 'A'; if (i >= 0 && i < sizeof headers / sizeof headers[0]) { row = i % (Lines - 3) + 3; @@ -1147,7 +1158,7 @@ * attributes always be normal? Does it matter? I suppose the * shell will be set up the way the user wants it.) */ - ioctl(0, TCSETA, &Savetty); + tcsetattr(STDIN_FILENO, TCSANOW, &Savetty); /* * Handle the rest of the commands. @@ -1172,7 +1183,7 @@ PUTP(me); fputs("\n\n", stdout); printf("%s\n\nPress any key to continue\n", Secure ? SECURE_HELP_SCREEN : HELP_SCREEN); - ioctl(0, TCSETA, &Rawtty); + tcsetattr(STDIN_FILENO, TCSANOW, &Rawtty); (void) getchar(); break; case 'i': @@ -1358,7 +1369,7 @@ /* * Return to raw mode. */ - ioctl(0, TCSETA, &Rawtty); + tcsetattr(STDIN_FILENO, TCSANOW, &Rawtty); return; } -- Martin Cornelius, ZARMFAB software development, University of Bremen phone: 49-421-218-4807 FAX: 49-421-218-3889 email: fabsoft@zarm.uni-bremen.de paper-mail: Hochschulring / Am Fallturm, 28359 BREMEN, Germany -- To unsubscribe: send e-mail to axp-list-request@redhat.com with 'unsubscribe' as the subject. Do not send it to axp-list@redhat.com