Changeset 87822ce in mainline for uspace/app/top/screen.c


Ignore:
Timestamp:
2021-03-04T19:14:30Z (3 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
d6c4d40
Parents:
760a392
Message:

Avoid infinite loop when console communication is broken

Need to make sure callers of console_get_event_timeout() can distinguish
between timeout and I/O error. Fix all callers of console_get_event()
and console_get_event_timeout() not to enter infinite loop when console
connection is broken. Also avoid setting of errno variable.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/top/screen.c

    r760a392 r87822ce  
    534534/** Get char with timeout
    535535 *
     536 * @param sec Timeout in seconds
     537 * @param rch Place to store character on success
     538 * @return EOK on success, ETIMEOUT on time out, EIO on other error
    536539 */
    537 int tgetchar(sec_t sec)
    538 {
     540errno_t tgetchar(sec_t sec, int *rch)
     541{
     542        errno_t rc;
     543
    539544        /*
    540545         * Reset timeleft whenever it is not positive.
     
    548553         * update timeleft so that the next call to tgetchar()
    549554         * will not wait as long. If there is no input,
    550          * make timeleft zero and return -1.
     555         * make timeleft zero and return ETIMEOUT.
    551556         */
    552557
     
    557562
    558563                warning_timeleft -= timeleft;
    559                 if (!console_get_event_timeout(console, &event, &timeleft)) {
     564                rc = console_get_event_timeout(console, &event, &timeleft);
     565                if (rc == ETIMEOUT) {
    560566                        timeleft = 0;
    561                         return -1;
    562                 }
     567                        return ETIMEOUT;
     568                }
     569
     570                if (rc != EOK)
     571                        return EIO;
     572
    563573                warning_timeleft += timeleft;
    564574
     
    567577        }
    568578
    569         return (int) c;
     579        *rch = (int) c;
     580        return EOK;
    570581}
    571582
Note: See TracChangeset for help on using the changeset viewer.