search for: stdout_fileno

Displaying 20 results from an estimated 128 matches for "stdout_fileno".

2012 Nov 29
3
[LLVMdev] Different behavoir when writing to stdout with 2 raw_fd_ostreams with or w/o redirection
Dear all, Consider there is a program that writes to stdout using two different raw_fd_ostream-s: #include "llvm/LLVMContext.h" #include "llvm/Module.h" #include "llvm/Support/raw_ostream.h" using namespace llvm; int main() { raw_fd_ostream S(STDOUT_FILENO, false); outs() << "Hello"; S << ", world!"; return 0; } With this layout everything is fine, it prints ", world!Hello" Now, make S definition global: #include "llvm/LLVMContext.h" #include "llvm/Module.h" #i...
2009 Oct 25
0
alternate output for progressmeter
...win_resized; /* for window resizing */ +int ? ?progresstype = 0; ? ? ? /* use default tty progress reporting */ + ?/* units for format_size */ ?static const char unit[] = " KMGT"; ?static int ?can_output(void) ?{ + ? ? ? if (progresstype) return 1; ? ? ? ?return (getpgrp() == tcgetpgrp(STDOUT_FILENO)); ?} @@ -158,9 +161,9 @@ ? ? ? ?/* filename */ ? ? ? ?buf[0] = '\0'; - ? ? ? file_len = win_size - 35; + ? ? ? file_len = (progresstype)?(strlen(file)+11):(win_size - 35); ? ? ? ?if (file_len > 0) { - ? ? ? ? ? ? ? len = snprintf(buf, file_len + 1, "\r%s", file); + ? ? ? ? ?...
2017 Oct 09
5
Why dup()?
...he remote session.? It was being sent, but lost.? I tracked it down to the following code, in ssh.c, at ssh_session2_open: ??????? if (stdin_null_flag) { ??????????????? in = open(_PATH_DEVNULL, O_RDONLY); ??????? } else { ??????????????? in = dup(STDIN_FILENO); ??????? } ??????? out = dup(STDOUT_FILENO); ??????? err = dup(STDERR_FILENO); The remote session did close stdout.? The sshd from which it was spawned signaled to close stdout.? The ssh program received that signal and closed, well, something, but not stdout.? It closed a copy.? Importantly, it left a copy open, so my program got no E...
2011 Jan 06
1
Dovecot 2.0.7 doesn't disassociate STDERR when it daemonizes.
...fd_close_on_exec(null_fd, TRUE); } while (null_fd <= STDERR_FILENO); But stderr is missing when a later dup2() is used to release any inherited values not covered by the above: if (dup2(null_fd, STDIN_FILENO) < 0 || dup2(null_fd, STDOUT_FILENO) < 0) i_fatal("dup2(null_fd) failed: %m"); Adding a dup2 for stderr to the above statement works in my simple test case but I'm unsure if there are other issues which may require delaying it. Dovecot 1.2.16 approaches this a little differently & does slightly...
2012 Nov 29
0
[LLVMdev] Different behavoir when writing to stdout with 2 raw_fd_ostreams with or w/o redirection
...does buffered I/O, so it's not really meant to be used like this. > #include "llvm/LLVMContext.h" > #include "llvm/Module.h" > #include "llvm/Support/raw_ostream.h" > > using namespace llvm; > > int main() > { > raw_fd_ostream S(STDOUT_FILENO, false); > > outs() << "Hello"; > S << ", world!"; > > return 0; > } > > With this layout everything is fine, it prints ", world!Hello" > Yes. raw_ostream does buffering. The output you see is a classic sy...
2012 Dec 13
2
[PATCH 1/2] daemon: NFC Use symbolic names in commandrvf
...ignore_value (open ("/dev/null", O_RDONLY|O_CLOEXEC)); } - close (so_fd[0]); - close (se_fd[0]); + close (so_fd[PIPE_READ]); + close (se_fd[PIPE_READ]); if (!(flags & COMMAND_FLAG_FOLD_STDOUT_ON_STDERR)) - dup2 (so_fd[1], 1); + dup2 (so_fd[PIPE_WRITE], STDOUT_FILENO); else - dup2 (se_fd[1], 1); - dup2 (se_fd[1], 2); - close (so_fd[1]); - close (se_fd[1]); + dup2 (se_fd[PIPE_WRITE], STDOUT_FILENO); + dup2 (se_fd[PIPE_WRITE], STDERR_FILENO); + close (so_fd[PIPE_WRITE]); + close (se_fd[PIPE_WRITE]); execvp (argv[0], (void *...
2015 Dec 02
3
[PATCH] daemon: improve internal commandrvf
...if (open ("/dev/null", O_RDONLY) == -1) { + perror ("open(/dev/null)"); + _exit (EXIT_FAILURE); + } } close (so_fd[PIPE_READ]); close (se_fd[PIPE_READ]); - if (!(flags & COMMAND_FLAG_FOLD_STDOUT_ON_STDERR)) - dup2 (so_fd[PIPE_WRITE], STDOUT_FILENO); - else - dup2 (se_fd[PIPE_WRITE], STDOUT_FILENO); - dup2 (se_fd[PIPE_WRITE], STDERR_FILENO); + if (!(flags & COMMAND_FLAG_FOLD_STDOUT_ON_STDERR)) { + if (dup2 (so_fd[PIPE_WRITE], STDOUT_FILENO) == -1) { + perror ("dup2/so_fd[PIPE_WRITE]"); + _exit (E...
2020 Apr 14
0
[nbdkit PATCH v2 2/3] server: Sanitize stdin/out before running plugin code
...LY); - open ("/dev/null", O_WRONLY); - - /* If not verbose, set stderr to the same as stdout as well. */ + /* By this point, stdin/out have been redirected to /dev/null. + * If not verbose, set stderr to the same as stdout as well. + */ if (!verbose) - dup2 (1, 2); + dup2 (STDOUT_FILENO, STDERR_FILENO); forked_into_background = true; debug ("forked into background (new pid = %d)", getpid ()); diff --git a/server/captive.c b/server/captive.c index 0a243d2b..1ff10192 100644 --- a/server/captive.c +++ b/server/captive.c @@ -1,5 +1,5 @@ /* nbdkit - * Copyright (C) 20...
2015 Dec 02
0
Re: [PATCH] daemon: improve internal commandrvf
...Y) == -1) { > + perror ("open(/dev/null)"); > + _exit (EXIT_FAILURE); > + } > } > close (so_fd[PIPE_READ]); > close (se_fd[PIPE_READ]); > - if (!(flags & COMMAND_FLAG_FOLD_STDOUT_ON_STDERR)) > - dup2 (so_fd[PIPE_WRITE], STDOUT_FILENO); > - else > - dup2 (se_fd[PIPE_WRITE], STDOUT_FILENO); > - dup2 (se_fd[PIPE_WRITE], STDERR_FILENO); > + if (!(flags & COMMAND_FLAG_FOLD_STDOUT_ON_STDERR)) { > + if (dup2 (so_fd[PIPE_WRITE], STDOUT_FILENO) == -1) { > + perror ("dup2/so_fd[PIPE_WR...
2020 Apr 04
0
[nbdkit PATCH 2/2] server: Sanitize stdin/out before running plugin code
...ed provided that the following conditions are @@ -151,7 +151,13 @@ run_command (void) } if (pid > 0) { /* Parent process is the run command. */ - r = system (cmd); + /* Restore original stdin/out */ + if (dup2 (orig_in, STDIN_FILENO) == -1 || + dup2 (orig_out, STDOUT_FILENO) == -1) { + r = -1; + } + else + r = system (cmd); if (r == -1) { nbdkit_error ("failure to execute external command: %m"); r = EXIT_FAILURE; diff --git a/server/connections.c b/server/connections.c index c54c71c1..c7b55ca1 100644 --- a/server/connection...
2015 Jan 23
3
[LLVMdev] Behaviour of outs()?
I was just fixing a bug that was caused by `stdout` being closed before the runtime has done `fflush(stdout)` [or however this is implemented in the runtime]. The cause of this seems to be that `outs()` returns a static object created from `raw_fd_stream(STDOUT_FILENO, true)` - the `true` being the `shouldClose` parameter. Surely LLVM is not supposed to close `stdout` as part of its operations? -- Mats
2017 Oct 13
2
Why dup()?
On 13/10/17 16:22, Damien Miller wrote: > At a minimum, I think we'd have to dup2 a fd to /dev/null to > STDOUT_FILENO so writes to stdout (e.g. from ill-behaved > libraries) have somewhere to go. Would that really be useful?? Output from Ill-behaved libraries, written fd 1, already go to the same place.? Don't forget, dup does not create a new file, it creates a duplicate handle to the same file.? I'm...
2003 Jan 27
0
[Bug 477] New: progressmeter.c problem requires openbsd-compat/bsd-cray.h change
...rmal Priority: P2 Component: Build system AssignedTo: openssh-unix-dev at mindrot.org ReportedBy: wendyp at cray.com when foregroundproc() got put into progressmeter.c, the return line got changed from #ifdef HAVE_TCGETPGRP return ((ctty_pgrp = tcgetpgrp(STDOUT_FILENO)) != -1 && ctty_pgrp == pgrp); #else return ((ioctl(STDOUT_FILENO, TIOCGPGRP, &ctty_pgrp) != -1 && ctty_pgrp == pgrp)); #endif to return ((ioctl(STDOUT_FILENO, TIOCGPGRP, &ctty_pgrp) != -1 && ctty_p...
2013 Jan 31
0
File descriptors in pipe.c
...n inside the if statement"); if (dup2(to_child_pipe[0], STDIN_FILENO) < 0 || close(to_child_pipe[1]) < 0 || // fd 4 closed close(from_child_pipe[0]) < 0 || // fd 5 closed dup2(from_child_pipe[1], STDOUT_FILENO) < 0) { rsyserr(FERROR, errno, "Failed to dup/close"); exit_cleanup(RERR_IPC); } if (to_child_pipe[0] != STDIN_FILENO) close(to_child_pipe[0]); if (from_child_pipe[...
2015 Feb 26
4
Call for testing: OpenSSH 6.8
...union { struct cmsghdr hdr; char buf[CMSG_SPACE(sizeof(int))]; } cmsgbuf; struct cmsghdr *cmsg; - struct iovec iov; - char c = '\0'; - ssize_t r; +#endif + struct iovec vec; + char ch = '\0'; struct pollfd pfd; + ssize_t r; - /* Avoid obvious stupidity */ - if (isatty(STDOUT_FILENO)) - errx(1, "Cannot pass file descriptor to tty"); - - bzero(&mh, sizeof(mh)); - bzero(&cmsgbuf, sizeof(cmsgbuf)); - bzero(&iov, sizeof(iov)); - bzero(&pfd, sizeof(pfd)); - - mh.msg_control = (caddr_t)&cmsgbuf.buf; - mh.msg_controllen = sizeof(cmsgbuf.buf); - cmsg = C...
2015 Feb 25
2
Call for testing: OpenSSH 6.8
On 24/02/15 21:56, Tim Rice wrote: > On Wed, 25 Feb 2015, Damien Miller wrote: > > | On Tue, 24 Feb 2015, Tom G. Christensen wrote: > | > | > I've switched to HEAD in the git repo and it now builds on Solaris > | > 2.6, 7, 8 and 9 but the testsuite still cannot be built due to the > | > missing <err.h>. > > The err.h issue is fixes but there still
2006 Jan 03
2
Bug ? on ssh-agent
...related issue, I think it's may be a bug on the main openssh tree. Thus my posting here. I'm CC'ing to the public list for information. The part of code I'm refering to is : /* XXX might close listen socket */ (void)dup2(fd, STDIN_FILENO); (void)dup2(fd, STDOUT_FILENO); (void)dup2(fd, STDERR_FILENO); if (fd > 2) close(fd); I'm actually launching the ssh agent from a "run.exe" script launched at the start of my X server (Cygwin/X). Things used to work perfectly until my last update. Unfortunately, I don't know...
2012 Nov 29
2
[LLVMdev] Different behavoir when writing to stdout with 2 raw_fd_ostreams with or w/o redirection
...o be used like > this. > > >> #include "llvm/LLVMContext.h" >> #include "llvm/Module.h" >> #include "llvm/Support/raw_ostream.h" >> >> using namespace llvm; >> >> int main() >> { >> raw_fd_ostream S(STDOUT_FILENO, false); >> >> outs() << "Hello"; >> S << ", world!"; >> >> return 0; >> } >> >> With this layout everything is fine, it prints ", world!Hello" >> > > Yes. raw_ostream does...
2017 Oct 20
3
Why dup()?
...HANGE? This patch allows a program reading ssh's output to see an EOF from the remote session. Good for scripting. Author: David NewallPatch-Name: scriptable-ssh.patch --- diff -u a/ssh.c b/ssh.c --- a/ssh.c +++ b/ssh.c @@ -1837,11 +1837,11 @@ } else { in = dup(STDIN_FILENO); } - out = dup(STDOUT_FILENO); - err = dup(STDERR_FILENO); + out = STDOUT_FILENO; + err = STDERR_FILENO; - if (in < 0 || out < 0 || err < 0) - fatal("dup() in/out/err failed"); + if (in < 0) + fatal("dup() in failed"); /* enable nonblocking unless tty */ if (!isatty(in)) WHAT CAN I DO TO HEL...
2020 Apr 04
6
[nbdkit PATCH 0/2] stdin/out cleanups
This is what I've been playing with in response to my earlier question about what to do with 'nbdkit -s sh -' (https://www.redhat.com/archives/libguestfs/2020-April/msg00032.html) I'm still open to ideas on a better name, and/or whether adding <stdbool.h> to our public include files is a good idea (if not, returning int instead of bool is tolerable). Eric Blake (2):