Skip to content
Snippets Groups Projects
Commit 679fcb9f authored by Michael Whittaker's avatar Michael Whittaker
Browse files

A couple small lockserver client improvements.

1. Previously, typing ` `, `lock`, or `unlock` into a lockserver
   client's REPL would cause the client to crash because of some
   `strtok` calls that were returning `NULL`. Now, this bug is fixed;
   `strtok` returns are checked to be `NULL`, and no input should crash
   the client.
2. Previously, typing in an unrecognized command into the lockserver
   client's repl would print `Unknown command.. Try again!`. Now, it
   also prints out the set of legal commands `Usage: exit | q | lock
   <key> | unlock <key>`. This makes it a bit easier for someone
   tinkering around with TAPIR for the first time (like me) to know what
   to type.
parent 177425b0
No related branches found
No related tags found
No related merge requests found
......@@ -30,6 +30,17 @@
#include "lockserver/client.h"
namespace {
void
usage()
{
printf("Unknown command.. Try again!\n");
printf("Usage: exit | q | lock <key> | unlock <key>\n");
}
} // namespace
int
main(int argc, char **argv)
{
......@@ -68,14 +79,18 @@ main(int argc, char **argv)
cmd[clen++] = c;
cmd[clen] = '\0';
if (clen == 0) continue;
tok = strtok(cmd, " ,.-");
if (tok == NULL) continue;
if (strcasecmp(tok, "exit") == 0 || strcasecmp(tok, "q") == 0) {
printf("Exiting..\n");
break;
} else if (strcasecmp(tok, "lock") == 0) {
tok = strtok(NULL, " ,.-");
if (tok == NULL) {
usage();
continue;
}
key = string(tok);
status = locker.lock(key);
......@@ -86,11 +101,15 @@ main(int argc, char **argv)
}
} else if (strcasecmp(tok, "unlock") == 0) {
tok = strtok(NULL, " ,.-");
if (tok == NULL) {
usage();
continue;
}
key = string(tok);
locker.unlock(key);
printf("Unlock Successful\n");
} else {
printf("Unknown command.. Try again!\n");
usage();
}
fflush(stdout);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment