diff options
author | Sami Kerola <kerolasa@iki.fi> | 2011-11-13 13:23:17 +0100 |
---|---|---|
committer | Sami Kerola <kerolasa@iki.fi> | 2011-12-20 17:30:53 +0100 |
commit | b40353c91e0a895a442ba43f04909036a3b13ce7 (patch) | |
tree | f2481c77ca1a4aabbc60eab81b4243ffda6f39d9 /skill.c | |
parent | 72e37c7d11ab768b61dedd1787689c9e3d0fb21e (diff) | |
download | procps-ng-b40353c91e0a895a442ba43f04909036a3b13ce7.tar.gz |
skill: use rpmatch() to yes/no question
The patch also removes fixed size of input, which can be problematic.
I do not know how long the string `yes' might be in all of the worlds
languages.
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Diffstat (limited to 'skill.c')
-rw-r--r-- | skill.c | 14 |
1 files changed, 8 insertions, 6 deletions
@@ -82,15 +82,17 @@ static void hurt_proc(int tty, int uid, int pid, const char *restrict const cmd, char dn_buf[1000]; dev_to_tty(dn_buf, 999, tty, pid, ABBREV_DEV); if (run_time->interactive) { - char buf[8]; + char *buf; + size_t len = 0; fprintf(stderr, "%-8s %-8s %5d %-16.16s ? ", (char *)dn_buf, user_from_uid(uid), pid, cmd); - if (!fgets(buf, 7, stdin)) { - printf("\n"); - exit(EXIT_FAILURE); - } - if (*buf != 'y' && *buf != 'Y') + fflush (stdout); + getline(&buf, &len, stdin); + if (rpmatch(buf) < 1) { + free(buf); return; + } + free(buf); } /* do the actual work */ errno = 0; |