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


Ignore:
Timestamp:
2021-03-04T19:14:30Z (4 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/tetris/screen.c

    r760a392 r87822ce  
    5454 */
    5555
     56#include <errno.h>
    5657#include <stdio.h>
    5758#include <stdlib.h>
     
    340341{
    341342        usec_t timeout = fallrate;
     343        errno_t rc;
    342344
    343345        while (timeout > 0) {
    344346                cons_event_t event;
    345347
    346                 if (!console_get_event_timeout(console, &event, &timeout))
     348                rc = console_get_event_timeout(console, &event, &timeout);
     349                if (rc == ETIMEOUT)
    347350                        break;
     351                if (rc != EOK)
     352                        exit(1);
    348353        }
    349354}
     
    354359int tgetchar(void)
    355360{
     361        errno_t rc;
     362
    356363        /*
    357364         * Reset timeleft to fallrate whenever it is not positive
     
    376383                cons_event_t event;
    377384
    378                 if (!console_get_event_timeout(console, &event, &timeleft)) {
     385                rc = console_get_event_timeout(console, &event, &timeleft);
     386                if (rc == ETIMEOUT) {
    379387                        timeleft = 0;
    380388                        return -1;
    381389                }
     390                if (rc != EOK)
     391                        exit(1);
    382392
    383393                if (event.type == CEV_KEY && event.ev.key.type == KEY_PRESS)
     
    394404{
    395405        char32_t c = 0;
     406        errno_t rc;
    396407
    397408        while (c == 0) {
    398409                cons_event_t event;
    399410
    400                 if (!console_get_event(console, &event))
     411                rc = console_get_event(console, &event);
     412                if (rc == ETIMEOUT)
    401413                        return -1;
     414                if (rc != EOK)
     415                        exit(1);
    402416
    403417                if (event.type == CEV_KEY && event.ev.key.type == KEY_PRESS)
Note: See TracChangeset for help on using the changeset viewer.