Commit 4ab5349c authored by Niels Möller's avatar Niels Möller
Browse files

* src/werror.c (error_fd): Made static.

(dup_error_stream): New function.
(set_error_ignore, set_error_syslog): Set error_fd to -1.

Rev: src/werror.c:1.44
Rev: src/werror.h:1.25
parent 1b56a36c
...@@ -95,7 +95,7 @@ const struct argp werror_argp = ...@@ -95,7 +95,7 @@ const struct argp werror_argp =
NULL, NULL, NULL, NULL, NULL NULL, NULL, NULL, NULL, NULL
}; };
int error_fd = STDERR_FILENO; static int error_fd = STDERR_FILENO;
#define BUF_SIZE 500 #define BUF_SIZE 500
static UINT8 error_buffer[BUF_SIZE]; static UINT8 error_buffer[BUF_SIZE];
...@@ -141,9 +141,33 @@ void set_error_stream(int fd, int with_poll) ...@@ -141,9 +141,33 @@ void set_error_stream(int fd, int with_poll)
error_write = with_poll ? write_raw_with_poll : write_raw; error_write = with_poll ? write_raw_with_poll : write_raw;
} }
int dup_error_stream(void)
{
if (error_fd < 0)
/* We're not writing error messages on any file; there's no
* problem. */
return 1;
else
{
int fd = dup(error_fd);
if (fd > STDERR_FILENO)
{
io_set_close_on_exec(fd);
error_fd = fd;
return 1;
}
if (fd >= 0)
close(fd);
return 0;
}
}
void set_error_ignore(void) void set_error_ignore(void)
{ {
error_write = write_ignore; error_write = write_ignore;
error_fd = -1;
} }
#define WERROR(l, d) (error_write(error_fd, (l), (d))) #define WERROR(l, d) (error_write(error_fd, (l), (d)))
......
...@@ -42,6 +42,11 @@ extern const struct argp werror_argp; ...@@ -42,6 +42,11 @@ extern const struct argp werror_argp;
void set_error_stream(int fd, int with_poll); void set_error_stream(int fd, int with_poll);
void set_error_ignore(void); void set_error_ignore(void);
/* Tries to dup any error fd to something higher than STDERR_FILENO.
* Used to be able to print any error messages while forking a child
* process. */
int dup_error_stream(void);
#ifdef HAVE_SYSLOG #ifdef HAVE_SYSLOG
void set_error_syslog(const char *id); void set_error_syslog(const char *id);
#endif #endif
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment