diff options
author | Thomas Graf <tgraf@suug.ch> | 2010-10-20 14:20:37 (GMT) |
---|---|---|
committer | Thomas Graf <tgraf@suug.ch> | 2010-10-20 14:20:37 (GMT) |
commit | cefe7db730cae80133c7811cf34b83985857ab25 (patch) | |
tree | 4ebbd95beaf074bb7fecb17e0f9a8faceea1da32 /src/lib | |
parent | 420438c71f2951b4ad1525de0d805fbf1cc9b15c (diff) | |
download | libnl-cefe7db730cae80133c7811cf34b83985857ab25.zip libnl-cefe7db730cae80133c7811cf34b83985857ab25.tar.gz libnl-cefe7db730cae80133c7811cf34b83985857ab25.tar.bz2 |
Make nl-qdisc-delete installable
Fixes nl_cli_confirm() and adds a check enforcing --yes before deleting
all qdiscs on all devices.
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/utils.c | 34 |
1 files changed, 24 insertions, 10 deletions
diff --git a/src/lib/utils.c b/src/lib/utils.c index ef76c84..78ad260 100644 --- a/src/lib/utils.c +++ b/src/lib/utils.c @@ -134,20 +134,34 @@ int nl_cli_parse_dumptype(const char *str) int nl_cli_confirm(struct nl_object *obj, struct nl_dump_params *params, int default_yes) { - int answer; - nl_object_dump(obj, params); - printf("Delete? (%c/%c) ", - default_yes ? 'Y' : 'y', - default_yes ? 'n' : 'N'); - do { - answer = tolower(getchar()); - if (answer == '\n') + for (;;) { + char buf[32] = { 0 }; + int answer; + + printf("Delete? (%c/%c) ", + default_yes ? 'Y' : 'y', + default_yes ? 'n' : 'N'); + + if (!fgets(buf, sizeof(buf), stdin)) { + fprintf(stderr, "Error while reading\n."); + continue; + } + + switch ((answer = tolower(buf[0]))) { + case '\n': answer = default_yes ? 'y' : 'n'; - } while (answer != 'y' && answer != 'n'); + case 'y': + case 'n': + return answer == 'y'; + } + + fprintf(stderr, "Invalid input, try again.\n"); + } + + return 0; - return answer == 'y'; } struct nl_cache *nl_cli_alloc_cache(struct nl_sock *sock, const char *name, |