summaryrefslogtreecommitdiffstats
path: root/src/lib
diff options
context:
space:
mode:
authorThomas Graf <tgraf@suug.ch>2010-10-20 14:20:37 (GMT)
committerThomas Graf <tgraf@suug.ch>2010-10-20 14:20:37 (GMT)
commitcefe7db730cae80133c7811cf34b83985857ab25 (patch)
tree4ebbd95beaf074bb7fecb17e0f9a8faceea1da32 /src/lib
parent420438c71f2951b4ad1525de0d805fbf1cc9b15c (diff)
downloadlibnl-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.c34
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,