Pass in output function to lbuf_init() instead of writing to stdout.

A side effect is that the usage info can now go to stderr as it should.
This commit is contained in:
Todd C. Miller
2010-03-18 06:42:17 -04:00
parent 038ec569de
commit b4f4afdf69
8 changed files with 50 additions and 23 deletions

View File

@@ -373,6 +373,12 @@ parse_args(int argc, char **argv, int *nargc, char ***nargv, char ***settingsp,
return(mode | flags);
}
static int
usage_out(const char *buf)
{
return fputs(buf, stderr);
}
/*
* Give usage message and exit.
* The actual usage strings are in sudo_usage.h for configure substitution.
@@ -404,7 +410,7 @@ usage(int exit_val)
* tty width.
*/
ulen = (int)strlen(getprogname()) + 8;
lbuf_init(&lbuf, NULL, ulen, 0, user_details.ts_cols);
lbuf_init(&lbuf, usage_out, ulen, NULL, user_details.ts_cols);
for (i = 0; uvec[i] != NULL; i++) {
lbuf_append(&lbuf, "usage: ", getprogname(), uvec[i], NULL);
lbuf_print(&lbuf);