Line
Link Here
|
0 |
-- LVM2.2.02.103.orig/lib/commands/toolcontext.c |
0 |
++ LVM2.2.02.103/lib/commands/toolcontext.c |
Lines 1336-1342
Link Here
|
1336 |
/* |
1336 |
/* |
1337 |
* Close and reopen stream on file descriptor fd. |
1337 |
* Close and reopen stream on file descriptor fd. |
1338 |
*/ |
1338 |
*/ |
1339 |
static int _reopen_stream(FILE *stream, int fd, const char *mode, const char *name, FILE **new_stream) |
1339 |
#ifdef __GLIBC__ |
|
|
1340 |
#define _reopen_stream(stream, fd, mode, name) __reopen_stream(stream, fd, mode, name, &stream) |
1341 |
|
1342 |
static int __reopen_stream(FILE *stream, int fd, const char *mode, const char *name, FILE **new_stream) |
1340 |
{ |
1343 |
{ |
1341 |
int fd_copy, new_fd; |
1344 |
int fd_copy, new_fd; |
1342 |
|
1345 |
|
Lines 1363-1368
Link Here
|
1363 |
|
1366 |
|
1364 |
return 1; |
1367 |
return 1; |
1365 |
} |
1368 |
} |
|
|
1369 |
#else |
1370 |
#define _reopen_stream(stream, fd, mode, name) (freopen(NULL, mode, stream) != NULL) |
1371 |
#endif |
1366 |
|
1372 |
|
1367 |
/* Entry point */ |
1373 |
/* Entry point */ |
1368 |
struct cmd_context *create_toolcontext(unsigned is_long_lived, |
1374 |
struct cmd_context *create_toolcontext(unsigned is_long_lived, |
Lines 1371-1377
Link Here
|
1371 |
unsigned threaded) |
1377 |
unsigned threaded) |
1372 |
{ |
1378 |
{ |
1373 |
struct cmd_context *cmd; |
1379 |
struct cmd_context *cmd; |
1374 |
FILE *new_stream; |
|
|
1375 |
int flags; |
1380 |
int flags; |
1376 |
|
1381 |
|
1377 |
#ifdef M_MMAP_MAX |
1382 |
#ifdef M_MMAP_MAX |
Lines 1421-1429
Link Here
|
1421 |
if (is_valid_fd(STDIN_FILENO) && |
1426 |
if (is_valid_fd(STDIN_FILENO) && |
1422 |
((flags = fcntl(STDIN_FILENO, F_GETFL)) > 0) && |
1427 |
((flags = fcntl(STDIN_FILENO, F_GETFL)) > 0) && |
1423 |
(flags & O_ACCMODE) != O_WRONLY) { |
1428 |
(flags & O_ACCMODE) != O_WRONLY) { |
1424 |
if (!_reopen_stream(stdin, STDIN_FILENO, "r", "stdin", &new_stream)) |
1429 |
if (!_reopen_stream(stdin, STDIN_FILENO, "r", "stdin")) |
1425 |
goto_out; |
1430 |
goto_out; |
1426 |
stdin = new_stream; |
|
|
1427 |
if (setvbuf(stdin, cmd->linebuffer, _IOLBF, linebuffer_size)) { |
1431 |
if (setvbuf(stdin, cmd->linebuffer, _IOLBF, linebuffer_size)) { |
1428 |
log_sys_error("setvbuf", ""); |
1432 |
log_sys_error("setvbuf", ""); |
1429 |
goto out; |
1433 |
goto out; |
Lines 1433-1441
Link Here
|
1433 |
if (is_valid_fd(STDOUT_FILENO) && |
1437 |
if (is_valid_fd(STDOUT_FILENO) && |
1434 |
((flags = fcntl(STDOUT_FILENO, F_GETFL)) > 0) && |
1438 |
((flags = fcntl(STDOUT_FILENO, F_GETFL)) > 0) && |
1435 |
(flags & O_ACCMODE) != O_RDONLY) { |
1439 |
(flags & O_ACCMODE) != O_RDONLY) { |
1436 |
if (!_reopen_stream(stdout, STDOUT_FILENO, "w", "stdout", &new_stream)) |
1440 |
if (!_reopen_stream(stdout, STDOUT_FILENO, "w", "stdout")) |
1437 |
goto_out; |
1441 |
goto_out; |
1438 |
stdout = new_stream; |
|
|
1439 |
if (setvbuf(stdout, cmd->linebuffer + linebuffer_size, |
1442 |
if (setvbuf(stdout, cmd->linebuffer + linebuffer_size, |
1440 |
_IOLBF, linebuffer_size)) { |
1443 |
_IOLBF, linebuffer_size)) { |
1441 |
log_sys_error("setvbuf", ""); |
1444 |
log_sys_error("setvbuf", ""); |
Lines 1715-1721
Link Here
|
1715 |
void destroy_toolcontext(struct cmd_context *cmd) |
1718 |
void destroy_toolcontext(struct cmd_context *cmd) |
1716 |
{ |
1719 |
{ |
1717 |
struct dm_config_tree *cft_cmdline; |
1720 |
struct dm_config_tree *cft_cmdline; |
1718 |
FILE *new_stream; |
|
|
1719 |
int flags; |
1721 |
int flags; |
1720 |
|
1722 |
|
1721 |
if (cmd->dump_filter && cmd->filter && cmd->filter->dump && |
1723 |
if (cmd->dump_filter && cmd->filter && cmd->filter->dump && |
Lines 1752-1759
Link Here
|
1752 |
if (is_valid_fd(STDIN_FILENO) && |
1754 |
if (is_valid_fd(STDIN_FILENO) && |
1753 |
((flags = fcntl(STDIN_FILENO, F_GETFL)) > 0) && |
1755 |
((flags = fcntl(STDIN_FILENO, F_GETFL)) > 0) && |
1754 |
(flags & O_ACCMODE) != O_WRONLY) { |
1756 |
(flags & O_ACCMODE) != O_WRONLY) { |
1755 |
if (_reopen_stream(stdin, STDIN_FILENO, "r", "stdin", &new_stream)) { |
1757 |
if (_reopen_stream(stdin, STDIN_FILENO, "r", "stdin")) { |
1756 |
stdin = new_stream; |
|
|
1757 |
setlinebuf(stdin); |
1758 |
setlinebuf(stdin); |
1758 |
} else |
1759 |
} else |
1759 |
cmd->linebuffer = NULL; /* Leave buffer in place (deliberate leak) */ |
1760 |
cmd->linebuffer = NULL; /* Leave buffer in place (deliberate leak) */ |
Lines 1762-1769
Link Here
|
1762 |
if (is_valid_fd(STDOUT_FILENO) && |
1763 |
if (is_valid_fd(STDOUT_FILENO) && |
1763 |
((flags = fcntl(STDOUT_FILENO, F_GETFL)) > 0) && |
1764 |
((flags = fcntl(STDOUT_FILENO, F_GETFL)) > 0) && |
1764 |
(flags & O_ACCMODE) != O_RDONLY) { |
1765 |
(flags & O_ACCMODE) != O_RDONLY) { |
1765 |
if (_reopen_stream(stdout, STDOUT_FILENO, "w", "stdout", &new_stream)) { |
1766 |
if (_reopen_stream(stdout, STDOUT_FILENO, "w", "stdout")) { |
1766 |
stdout = new_stream; |
|
|
1767 |
setlinebuf(stdout); |
1767 |
setlinebuf(stdout); |
1768 |
} else |
1768 |
} else |
1769 |
cmd->linebuffer = NULL; /* Leave buffer in place (deliberate leak) */ |
1769 |
cmd->linebuffer = NULL; /* Leave buffer in place (deliberate leak) */ |
1770 |
-- LVM2.2.02.103.orig/tools/lvmcmdline.c |
1770 |
++ LVM2.2.02.103/tools/lvmcmdline.c |
Lines 1252-1258
Link Here
|
1252 |
int err = is_valid_fd(STDERR_FILENO); |
1252 |
int err = is_valid_fd(STDERR_FILENO); |
1253 |
|
1253 |
|
1254 |
if (!is_valid_fd(STDIN_FILENO) && |
1254 |
if (!is_valid_fd(STDIN_FILENO) && |
1255 |
!(stdin = fopen(_PATH_DEVNULL, "r"))) { |
1255 |
!freopen(_PATH_DEVNULL, "r", stdin)) { |
1256 |
if (err) |
1256 |
if (err) |
1257 |
perror("stdin stream open"); |
1257 |
perror("stdin stream open"); |
1258 |
else |
1258 |
else |
Lines 1262-1268
Link Here
|
1262 |
} |
1262 |
} |
1263 |
|
1263 |
|
1264 |
if (!is_valid_fd(STDOUT_FILENO) && |
1264 |
if (!is_valid_fd(STDOUT_FILENO) && |
1265 |
!(stdout = fopen(_PATH_DEVNULL, "w"))) { |
1265 |
!freopen(_PATH_DEVNULL, "w", stdout)) { |
1266 |
if (err) |
1266 |
if (err) |
1267 |
perror("stdout stream open"); |
1267 |
perror("stdout stream open"); |
1268 |
/* else no stdout */ |
1268 |
/* else no stdout */ |
Lines 1270-1276
Link Here
|
1270 |
} |
1270 |
} |
1271 |
|
1271 |
|
1272 |
if (!is_valid_fd(STDERR_FILENO) && |
1272 |
if (!is_valid_fd(STDERR_FILENO) && |
1273 |
!(stderr = fopen(_PATH_DEVNULL, "w"))) { |
1273 |
!freopen(_PATH_DEVNULL, "w", stderr)) { |
1274 |
printf("stderr stream open: %s\n", |
1274 |
printf("stderr stream open: %s\n", |
1275 |
strerror(errno)); |
1275 |
strerror(errno)); |
1276 |
return 0; |
1276 |
return 0; |