-
Notifications
You must be signed in to change notification settings - Fork 49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
multipathd: replace libreadline with fgets() #41
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,8 +15,7 @@ | |
#include <sys/socket.h> | ||
#include <sys/un.h> | ||
#include <poll.h> | ||
#include <readline/readline.h> | ||
#include <readline/history.h> | ||
#include <ctype.h> | ||
|
||
#include "mpath_cmd.h" | ||
#include "uxsock.h" | ||
|
@@ -70,20 +69,20 @@ static int need_quit(char *str, size_t len) | |
*/ | ||
static void process(int fd, unsigned int timeout) | ||
{ | ||
char *line; | ||
char line[256]; | ||
char *reply; | ||
unsigned int i; | ||
int ret; | ||
char prompt[] = "multipathd> "; | ||
|
||
cli_init(); | ||
rl_readline_name = "multipathd"; | ||
rl_completion_entry_function = key_generator; | ||
while ((line = readline("multipathd> "))) { | ||
for (i = 0; i < strlen(prompt); i++) | ||
fputc(prompt[i], stdout); | ||
while (fgets(line, 256, stdin)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We'd need some error handling here, especially for overflow, and we should strip training newline. I'd prefer using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, sure. The really was a quick-and-dirty hack, and fgets() was the first function which came to my mind. getline() is fine, too. |
||
size_t llen = strlen(line); | ||
|
||
if (!llen) { | ||
free(line); | ||
if (!llen) | ||
continue; | ||
} | ||
|
||
if (need_quit(line, llen)) | ||
break; | ||
|
@@ -94,11 +93,9 @@ static void process(int fd, unsigned int timeout) | |
|
||
print_reply(reply); | ||
|
||
if (line && *line) | ||
add_history(line); | ||
|
||
free(line); | ||
free(reply); | ||
for (i = 0; i < strlen(prompt); i++) | ||
fputc(prompt[i], stdout); | ||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not just use
fputs()
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because fputs() always attaches a newline, and we want to display a prompt (ie without a newline).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
puts()
does this butfputs()
does not.