diff options
author | NIIBE Yutaka <[email protected]> | 2025-06-23 05:03:09 +0000 |
---|---|---|
committer | NIIBE Yutaka <[email protected]> | 2025-06-23 05:03:09 +0000 |
commit | 8caa7cc517ebf61c5e47c9b571169740a9301acb (patch) | |
tree | c4164f93ab3cc015014583f4e6e3bb694b6fac3d | |
parent | Fix debug output of posix-io.c. (diff) | |
download | gpgme-8caa7cc517ebf61c5e47c9b571169740a9301acb.tar.gz gpgme-8caa7cc517ebf61c5e47c9b571169740a9301acb.zip |
Use sysconf as a fallback mechanism in the initialization.
* src/posix-io.c (max_fds_fallback): New.
[_SC_OPEN_MAX] (_gpgme_io_subsystem_init): Set max_fds_fallback.
(get_max_fds): Use max_fds_fallback.
--
GnuPG-bug-id: 7694
Fixes-commit: e8e5434cc4f5cc3c322659792cc1850a5c5b26b8
Signed-off-by: NIIBE Yutaka <[email protected]>
-rw-r--r-- | src/posix-io.c | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/src/posix-io.c b/src/posix-io.c index 00b89007..aa69bfc9 100644 --- a/src/posix-io.c +++ b/src/posix-io.c @@ -134,6 +134,10 @@ _gpgme_is_fd_valid (int fd) #endif /*0*/ +/* Fallback value for max_fds for some systems. It can be used later + in get_max_fds function. */ +static int max_fds_fallback; + void _gpgme_io_subsystem_init (void) { @@ -147,6 +151,23 @@ _gpgme_io_subsystem_init (void) act.sa_flags = 0; sigaction (SIGPIPE, &act, NULL); } + + max_fds_fallback = -1; + +#ifdef _SC_OPEN_MAX + if (max_fds_fallback == -1) + { + /* For multithread application, sysconf cannot be used in the + * forked child process (in get_max_fds function), since it is + * not async-signal-safe function. Here, we can assume it's + * only a single thread. + */ + long scres = sysconf (_SC_OPEN_MAX); + + if (scres >= 0) + max_fds_fallback = scres; + } +#endif } @@ -444,6 +465,13 @@ get_max_fds (void) } } #endif + + if (fds == -1 && max_fds_fallback >= 0) + { + source = "fallback"; + return max_fds_fallback; + } + #ifdef OPEN_MAX if (fds == -1) { @@ -453,7 +481,7 @@ get_max_fds (void) #endif #if !defined(RLIMIT_NOFILE) && !defined(RLIMIT_OFILE) \ - && !defined(OPEN_MAX) + && !defined(_SC_OPEN_MAX) && !defined(OPEN_MAX) #warning "No known way to get the maximum number of file descriptors." #endif if (fds == -1) |