From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Daniel Golle Date: Sat, 25 Apr 2015 23:34:05 +0200 Subject: [PATCH] const-stdio: guard glibc-specific stream buffering behind __GLIBC__ create_toolcontext()/destroy_toolcontext() tune glibc's stdio stream buffering directly via glibc-only internals; _check_standard_fds() has a musl-compatible fallback path already available. Wrap the glibc-specific code in #ifdef __GLIBC__ so this builds against musl. Signed-off-by: Daniel Golle --- lib/commands/toolcontext.c | 4 ++++ tools/lvmcmdline.c | 7 +++++++ 2 files changed, 11 insertions(+) --- a/lib/commands/toolcontext.c +++ b/lib/commands/toolcontext.c @@ -1666,6 +1666,7 @@ struct cmd_context *create_toolcontext(c /* FIXME Make this configurable? */ reset_lvm_errno(1); +#ifdef __GLIBC__ /* Set in/out stream buffering before glibc */ if (set_buffering && !cmd->running_on_valgrind /* Skipping within valgrind execution. */ @@ -1710,6 +1711,7 @@ struct cmd_context *create_toolcontext(c } else if (!set_buffering) /* Without buffering, must not use stdin/stdout */ init_silent(1); +#endif /* * Environment variable LVM_SYSTEM_DIR overrides this below. @@ -2048,6 +2050,7 @@ void destroy_toolcontext(struct cmd_cont if (cmd->cft_def_hash) dm_hash_destroy(cmd->cft_def_hash); +#ifdef __GLIBC__ if (!cmd->running_on_valgrind && cmd->linebuffer) { int flags; /* Reset stream buffering to defaults */ @@ -2071,6 +2074,7 @@ void destroy_toolcontext(struct cmd_cont free(cmd->linebuffer); } +#endif destroy_config_context(cmd); --- a/tools/lvmcmdline.c +++ b/tools/lvmcmdline.c @@ -3395,6 +3395,7 @@ int lvm_split(char *str, int *argc, char /* Make sure we have always valid filedescriptors 0,1,2 */ static int _check_standard_fds(void) { +#ifdef __GLIBC__ int err = is_valid_fd(STDERR_FILENO); if (!is_valid_fd(STDIN_FILENO) && @@ -3421,6 +3422,12 @@ static int _check_standard_fds(void) strerror(errno)); return 0; } +#else + if (!is_valid_fd(STDERR_FILENO) || + !is_valid_fd(STDOUT_FILENO) || + !is_valid_fd(STDIN_FILENO)) + return 0; +#endif return 1; }