diff options
Diffstat (limited to 'common')
-rw-r--r-- | common/logging.c | 3 | ||||
-rw-r--r-- | common/sysutils.c | 11 | ||||
-rw-r--r-- | common/sysutils.h | 1 |
3 files changed, 15 insertions, 0 deletions
diff --git a/common/logging.c b/common/logging.c index 8c70742cc..ac130535c 100644 --- a/common/logging.c +++ b/common/logging.c @@ -570,6 +570,9 @@ log_set_file (const char *name) void log_set_fd (int fd) { + if (! gnupg_fd_valid (fd)) + log_fatal ("logger-fd is invalid: %s\n", strerror (errno)); + set_file_fd (NULL, fd); } diff --git a/common/sysutils.c b/common/sysutils.c index e67420f18..a796677ba 100644 --- a/common/sysutils.c +++ b/common/sysutils.c @@ -1281,3 +1281,14 @@ gnupg_get_socket_name (int fd) return name; } #endif /*!HAVE_W32_SYSTEM*/ + +/* Check whether FD is valid. */ +int +gnupg_fd_valid (int fd) +{ + int d = dup (fd); + if (d < 0) + return 0; + close (d); + return 1; +} diff --git a/common/sysutils.h b/common/sysutils.h index a9316d7ce..ecd9f846e 100644 --- a/common/sysutils.h +++ b/common/sysutils.h @@ -72,6 +72,7 @@ int gnupg_setenv (const char *name, const char *value, int overwrite); int gnupg_unsetenv (const char *name); char *gnupg_getcwd (void); char *gnupg_get_socket_name (int fd); +int gnupg_fd_valid (int fd); gpg_error_t gnupg_inotify_watch_socket (int *r_fd, const char *socket_name); int gnupg_inotify_has_name (int fd, const char *name); |