aboutsummaryrefslogtreecommitdiffstats
path: root/pseudo_util.c
diff options
context:
space:
mode:
authorPeter Seebach <peter.seebach@windriver.com>2016-02-23 15:47:32 -0600
committerPeter Seebach <peter.seebach@windriver.com>2016-02-23 15:47:32 -0600
commit6b14fe133eea0148ad232e41bc12cc2e6e9c969f (patch)
tree5c17763d017014c3fc98a0737fd6373ed89937a5 /pseudo_util.c
parent786c6d3813622d18e12d36c4aa722af6a417c8fa (diff)
downloadpseudo-6b14fe133eea0148ad232e41bc12cc2e6e9c969f.tar.gz
pseudo-6b14fe133eea0148ad232e41bc12cc2e6e9c969f.tar.bz2
pseudo-6b14fe133eea0148ad232e41bc12cc2e6e9c969f.zip
Improve logfile handling
For sound reasons, the server wants to be sure no client is on fd 2. However, the client shouldn't force the pseudo log file to be fd 2; it should leave stderr alone when a log file is specified.
Diffstat (limited to 'pseudo_util.c')
-rw-r--r--pseudo_util.c13
1 files changed, 7 insertions, 6 deletions
diff --git a/pseudo_util.c b/pseudo_util.c
index c81df5a..9d24362 100644
--- a/pseudo_util.c
+++ b/pseudo_util.c
@@ -1313,7 +1313,7 @@ pseudo_etc_file(const char *file, char *realname, int flags, const char **search
/* set up a log file */
int
-pseudo_logfile(char *defname) {
+pseudo_logfile(char *defname, int prefer_fd) {
char *pseudo_path;
char *filename = pseudo_get_value("PSEUDO_DEBUG_FILE");
char *s;
@@ -1401,15 +1401,16 @@ pseudo_logfile(char *defname) {
if (fd == -1) {
pseudo_diag("help: can't open log file %s: %s\n", pseudo_path, strerror(errno));
} else {
- /* try to force fd to 2. We do this because glibc's malloc
+ /* try to force fd to prefer_fd. We do this because glibc's malloc
* debug unconditionally writes to fd 2, and we don't want
* a client process ending op on fd 2, or server debugging
- * becomes a nightmare.
+ * becomes a nightmare. So, server sets prefer_fd to 2. Client
+ * leaves it at -1.
*/
- if (fd != 2) {
+ if (prefer_fd >= 0 && fd != prefer_fd) {
int newfd;
- close(2);
- newfd = dup2(fd, 2);
+ close(prefer_fd);
+ newfd = dup2(fd, prefer_fd);
if (newfd != -1) {
fd = newfd;
}