]> granicus.if.org Git - procps-ng/commitdiff
skill: use rpmatch() to yes/no question
authorSami Kerola <kerolasa@iki.fi>
Sun, 13 Nov 2011 12:23:17 +0000 (13:23 +0100)
committerSami Kerola <kerolasa@iki.fi>
Tue, 20 Dec 2011 16:30:53 +0000 (17:30 +0100)
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>
configure.ac
skill.c

index b130cea8b6bcfb0f0e613f552dd49f34a9785a09..1582d0c522ee564c30eea66e79dba0440e3c8567 100644 (file)
@@ -73,6 +73,7 @@ AC_FUNC_REALLOC
 AC_FUNC_STRTOD
 AC_CHECK_FUNCS([\
        alarm \
+       getline \
        getpagesize \
        gettimeofday \
        iswprint \
@@ -83,6 +84,7 @@ AC_CHECK_FUNCS([\
        nl_langinfo \
        putenv \
        regcomp \
+       rpmatch \
        select \
        setlocale \
        strcasecmp \
diff --git a/skill.c b/skill.c
index 8e11cde52d582cca3377482d2dc78b67ccd0fcfb..2d7982727c3141bded8f0e488e3547c1fe1ec8dc 100644 (file)
--- a/skill.c
+++ b/skill.c
@@ -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;