README: add link for automatic readme display
[sudo-osx-update.git] / patches / 0010-Handle-EINTR-when-calling-tcsetattr.patch.txt
blobd843497c3ff28ada93884f43e92d984ecacd9787
1 Subject: [PATCH] Handle EINTR when calling tcsetattr
3 The OS X version of sudo properly handles EINTR when returned from
4 tcsetattr in the term_restore and term_noecho functions by simply
5 repeating the function call again.
6 ---
7  term.c | 18 ++++++++++++++----
8  1 file changed, 14 insertions(+), 4 deletions(-)
10 diff --git a/term.c b/term.c
11 index 4aa71284..596d79d2 100644
12 --- a/term.c
13 +++ b/term.c
14 @@ -16,6 +16,7 @@
16  #include <config.h>
18 +#include <sys/errno.h>
19  #include <sys/types.h>
20  #include <sys/param.h>
21  #include <stdio.h>
22 @@ -111,8 +112,13 @@ term_restore(fd, flush)
23      if (changed) {
24         int flags = TCSASOFT;
25         flags |= flush ? TCSAFLUSH : TCSADRAIN;
26 -       if (tcsetattr(fd, flags, &oterm) != 0)
27 +       for (;;) {
28 +           if (tcsetattr(fd, flags, &oterm) == 0)
29 +               break;
30 +           if (errno == EINTR)
31 +               continue;
32             return 0;
33 +       }
34         changed = 0;
35      }
36      return 1;
37 @@ -129,9 +135,13 @@ term_noecho(fd)
38  #ifdef VSTATUS
39      term.c_cc[VSTATUS] = _POSIX_VDISABLE;
40  #endif
41 -    if (tcsetattr(fd, TCSADRAIN|TCSASOFT, &term) == 0) {
42 -       changed = 1;
43 -       return 1;
44 +    for (;;) {
45 +       if (tcsetattr(fd, TCSADRAIN|TCSASOFT, &term) == 0) {
46 +           changed = 1;
47 +           return 1;
48 +       }
49 +       if (errno != EINTR)
50 +           break;
51      }
52      return 0;
53  }
54 -- 
55 1.8.3