summaryrefslogtreecommitdiff
path: root/src/os
Commit message (Collapse)AuthorAgeFilesLines
* Win32: non-ASCII names in ngx_fs_bsize(), ngx_fs_available().Maxim Dounin2023-02-231-4/+42
| | | | | This fixes potentially incorrect cache size calculations and non-working "min_free" when using cache in directories with non-ASCII names.
* Win32: removed attempt to use a drive letter in ngx_fs_bsize().Maxim Dounin2023-02-231-6/+0
| | | | | | | | | | Just a drive letter might not correctly represent file system being used, notably when using symlinks (as created by "mklink /d"). As such, instead of trying to call GetDiskFreeSpace() with just a drive letter, we now always use GetDiskFreeSpace() with full path. Further, it looks like the code to use just a drive letter never worked, since it tried to test name[2] instead of name[1] to be ':'.
* Win32: non-ASCII names support in ngx_open_tempfile().Maxim Dounin2023-02-232-10/+37
| | | | | This makes it possible to use temporary directories with non-ASCII characters, either explicitly or via a prefix with non-ASCII characters in it.
* Win32: non-ASCII names support in ngx_rename_file().Maxim Dounin2023-02-232-1/+56
| | | | | This makes it possible to upload files with non-ASCII characters when using the dav module (ticket #1433).
* Win32: non-ASCII names support in ngx_delete_file().Maxim Dounin2023-02-232-1/+37
| | | | | This makes it possible to delete files with non-ASCII characters when using the dav module (ticket #1433).
* Win32: reworked ngx_win32_rename_file() to use nginx wrappers.Maxim Dounin2023-02-231-3/+3
| | | | | | | | This ensures that ngx_win32_rename_file() will support non-ASCII names when supported by the wrappers. Notably, this is used by PUT requests in the dav module when overwriting existing files with non-ASCII names (ticket #1433).
* Win32: reworked ngx_win32_rename_file() to check errors.Maxim Dounin2023-02-231-2/+10
| | | | | | | | Previously, ngx_win32_rename_file() retried on all errors returned by MoveFile() to a temporary name. It only make sense, however, to retry when the destination file already exists, similarly to the condition when ngx_win32_rename_file() is called. Retrying on other errors is meaningless and might result in an infinite loop.
* Win32: non-ASCII directory names support in ngx_delete_dir().Maxim Dounin2023-02-232-1/+37
| | | | | This makes it possible to delete directories with non-ASCII characters when using the dav module (ticket #1433).
* Win32: non-ASCII directory names support in ngx_create_dir().Maxim Dounin2023-02-232-10/+72
| | | | | | | | | | | | This makes it possible to create directories under prefix with non-ASCII characters, as well as makes it possible to create directories with non-ASCII characters when using the dav module (ticket #1433). To ensure that the dav module operations are restricted similarly to other file operations (in particular, short names are not allowed), the ngx_win32_check_filename() function is used. It improved to support checking of just dirname, and now can be used to check paths when creating files or directories.
* Win32: non-ASCII directory names support in ngx_getcwd().Maxim Dounin2023-02-232-1/+39
| | | | | This makes it possible to start nginx without a prefix explicitly set in a directory with non-ASCII characters in it.
* Win32: non-ASCII names support in "include" with wildcards.Maxim Dounin2023-02-232-34/+64
| | | | | Notably, ngx_open_glob() now supports opening directories with non-ASCII characters, and pathnames returned by ngx_read_glob() are converted to UTF-8.
* Win32: non-ASCII names support in autoindex (ticket #458).Maxim Dounin2023-02-232-21/+244
| | | | | | Notably, ngx_open_dir() now supports opening directories with non-ASCII characters, and directory entries returned by ngx_read_dir() are properly converted to UTF-8.
* Style.BullerDu2022-12-161-1/+1
|
* Win32: event flags handling edge cases in ngx_wsarecv().Maxim Dounin2022-12-012-0/+4
| | | | | | | Fixed event flags handling edge cases in ngx_wsarecv() and ngx_wsarecv_chain(), notably to always reset rev->ready in case of errors (which wasn't the case after ngx_socket_nread() errors), and after EOF (rev->ready was not cleared if due to a misconfiguration a zero-sized buffer was used for reading).
* Fixed segfault when switching off master process during upgrade.Maxim Dounin2022-11-231-10/+0
| | | | | | | | | | | | | | | | | | | | Binary upgrades are not supported without master process, but it is, however, possible, that nginx running with master process is asked to upgrade binary, and the configuration file as available on disk at this time includes "master_process off;". If this happens, listening sockets inherited from the previous binary will have ls[i].previous set. But the old cycle on initial process startup, including startup after binary upgrade, is destroyed by ngx_init_cycle() once configuration parsing is complete. As a result, an attempt to dereference ls[i].previous in ngx_event_process_init() accesses already freed memory. Fix is to avoid looking into ls[i].previous if the old cycle is already freed. With this change it is also no longer needed to clear ls[i].previous in worker processes, so the relevant code was removed.
* Process events posted by ngx_close_idle_connections() immediately.Roman Arutyunyan2022-11-182-0/+2
| | | | | | Previously, if an event was posted by a read event handler, called by ngx_close_idle_connections(), that event was not processed until the next event loop iteration, which could happen after a timeout.
* Win32: disabled C4306 warnings with MSVC.Maxim Dounin2022-09-071-0/+3
| | | | | | | | | Multiple C4306 warnings (conversion from 'type1' to 'type2' of greater size) appear during 64-bit compilation with MSVC 2010 (and older) due to extensively used constructs like "(void *) -1", so they were disabled. In newer MSVC versions C4306 warnings were replaced with C4312 ones, and these are not generated for such trivial type casts.
* Win32: removed misleading comment about warnings being disabled.Maxim Dounin2022-09-071-2/+0
| | | | Warnings being disabled are not only from the "-W4" level since e4590dfd97ff.
* Events: fixed EPOLLRDHUP with FIONREAD (ticket #2367).Maxim Dounin2022-07-151-0/+2
| | | | | | | | | | | | | | | | | | | When reading exactly rev->available bytes, rev->available might become 0 after FIONREAD usage introduction in efd71d49bde0. On the next call of ngx_readv_chain() on systems with EPOLLRDHUP this resulted in return without any actions, that is, with rev->ready set, and this in turn resulted in no timers set in event pipe, leading to socket leaks. Fix is to reset rev->ready in ngx_readv_chain() when returning due to rev->available being 0 with EPOLLRDHUP, much like it is already done in ngx_unix_recv(). This ensures that if rev->available will become 0, on systems with EPOLLRDHUP support appropriate EPOLLRDHUP-specific handling will happen on the next ngx_readv_chain() call. While here, also synced ngx_readv_chain() to match ngx_unix_recv() and reset rev->ready when returning due to rev->available being 0 with kqueue. This is mostly cosmetic change, as rev->ready is anyway reset when rev->available is set to 0.
* Fixed runtime handling of systems without EPOLLRDHUP support.Marcus Ball2022-05-302-2/+6
| | | | | | | | | | | | | | | | | | | | | | In 7583:efd71d49bde0 (nginx 1.17.5) along with introduction of the ioctl(FIONREAD) support proper handling of systems without EPOLLRDHUP support in the kernel (but with EPOLLRDHUP in headers) was broken. Before the change, rev->available was never set to 0 unless ngx_use_epoll_rdhup was also set (that is, runtime test for EPOLLRDHUP introduced in 6536:f7849bfb6d21 succeeded). After the change, rev->available might reach 0 on systems without runtime EPOLLRDHUP support, stopping further reading in ngx_readv_chain() and ngx_unix_recv(). And, if EOF happened to be already reported along with the last event, it is not reported again by epoll_wait(), leading to connection hangs and timeouts on such systems. This affects Linux kernels before 2.6.17 if nginx was compiled with newer headers, and, more importantly, emulation layers, such as DigitalOcean's App Platform's / gVisor's epoll emulation layer. Fix is to explicitly check ngx_use_epoll_rdhup before the corresponding rev->pending_eof tests in ngx_readv_chain() and ngx_unix_recv().
* Core: added autotest for UDP segmentation offloading.Vladimir Homutov2022-01-261-0/+4
|
* Core: added function for local source address cmsg.Vladimir Homutov2022-01-251-0/+65
|
* Core: made the ngx_sendmsg() function non-static.Vladimir Homutov2022-01-251-70/+95
| | | | | The NGX_HAVE_ADDRINFO_CMSG macro is defined when at least one of methods to deal with corresponding control message is available.
* Support for sendfile(SF_NOCACHE).Maxim Dounin2021-12-271-0/+6
| | | | | | The SF_NOCACHE flag, introduced in FreeBSD 11 along with the new non-blocking sendfile() implementation by glebius@, makes it possible to use sendfile() along with the "directio" directive.
* Simplified sendfile(SF_NODISKIO) usage.Maxim Dounin2021-12-271-46/+28
| | | | | | | | | | | | | | | | | | | Starting with FreeBSD 11, there is no need to use AIO operations to preload data into cache for sendfile(SF_NODISKIO) to work. Instead, sendfile() handles non-blocking loading data from disk by itself. It still can, however, return EBUSY if a page is already being loaded (for example, by a different process). If this happens, we now post an event for the next event loop iteration, so sendfile() is retried "after a short period", as manpage recommends. The limit of the number of EBUSY tolerated without any progress is preserved, but now it does not result in an alert, since on an idle system event loop iteration might be very short and EBUSY can happen many times in a row. Instead, SF_NODISKIO is simply disabled for one call once the limit is reached. With this change, sendfile(SF_NODISKIO) is now used automatically as long as sendfile() is enabled, and no longer requires "aio on;".
* HTTP/2: fixed "task already active" with sendfile in threads.Maxim Dounin2021-11-252-22/+0
| | | | | | | | | | | | | | | | | | | With sendfile in threads, "task already active" alerts might appear in logs if a write event happens on the main HTTP/2 connection, triggering a sendfile in threads while another thread operation is already running. Observed with "aio threads; aio_write on; sendfile on;" and with thread event handlers modified to post a write event to the main HTTP/2 connection (though can happen without any modifications). Similarly, sendfile() with AIO preloading on FreeBSD can trigger duplicate aio operation, resulting in "second aio post" alerts. This is, however, harder to reproduce, especially on modern FreeBSD systems, since sendfile() usually does not return EBUSY. Fix is to avoid starting a sendfile operation if other thread operation is active by checking r->aio in the thread handler (and, similarly, in aio preload handler). The added check also makes duplicate calls protection redundant, so it is removed.
* Fixed sendfile() limit handling on Linux.Maxim Dounin2021-10-291-1/+3
| | | | | | | | | | | On Linux starting with 2.6.16, sendfile() silently limits all operations to MAX_RW_COUNT, defined as (INT_MAX & PAGE_MASK). This incorrectly triggered the interrupt check, and resulted in 0-sized writev() on the next loop iteration. Fix is to make sure the limit is always checked, so we will return from the loop if the limit is already reached even if number of bytes sent is not exactly equal to the number of bytes we've tried to send.
* Give GCC atomics precedence over deprecated Darwin atomic(3).Sergey Kandaurov2021-08-301-33/+33
| | | | This allows to build nginx on macOS with -Wdeprecated-declarations.
* Win32: use only preallocated memory in send/recv chain functions.Ruslan Ermilov2021-07-052-12/+20
| | | | | | The ngx_wsasend_chain() and ngx_wsarecv_chain() functions were modified to use only preallocated memory, and the number of preallocated wsabufs was increased to 64.
* Use only preallocated memory in ngx_readv_chain() (ticket #1408).Ruslan Ermilov2021-07-051-1/+1
| | | | | | | | | | In d1bde5c3c5d2, the number of preallocated iovec's for ngx_readv_chain() was increased. Still, in some setups, the function might allocate memory for iovec's from a connection pool, which is only freed when closing the connection. The ngx_readv_chain() function was modified to use only preallocated memory, similarly to the ngx_writev_chain() change in 8e903522c17a.
* Fixed format strings for ngx_win32_version.Maxim Dounin2021-06-181-3/+3
|
* Restored zeroing of ngx_channel_t in ngx_pass_open_channel().Ruslan Ermilov2021-04-221-0/+2
| | | | | | | | | Due to structure's alignment, some uninitialized memory contents may have been passed between processes. Zeroing was removed in 0215ec9aaa8a. Reported by Johnny Wang.
* Removed "ch" argument from ngx_pass_open_channel().Ruslan Ermilov2021-03-111-39/+18
|
* Introduced strerrordesc_np() support.Maxim Dounin2021-03-011-1/+45
| | | | | | The strerrordesc_np() function, introduced in glibc 2.32, provides an async-signal-safe way to obtain error messages. This makes it possible to avoid copying error messages.
* Improved maximum errno detection.Maxim Dounin2021-03-011-6/+85
| | | | | | | | | | | | | | | | Previously, systems without sys_nerr (or _sys_nerr) were handled with an assumption that errors start at 0 and continuous. This is, however, not something POSIX requires, and not true on some platforms. Notably, on Linux, where sys_nerr is no longer available for newly linked binaries starting with glibc 2.32, there are gaps in error list, which used to stop us from properly detecting maximum errno. Further, on GNU/Hurd errors start at 0x40000001. With this change, maximum errno detection is moved to the runtime code, now able to ignore gaps, and also detects the first error if needed. This fixes observed "Unknown error" messages as seen on Linux with glibc 2.32 and on GNU/Hurd.
* Cache: introduced min_free cache clearing.Maxim Dounin2020-06-224-0/+48
| | | | | | | | | | | Clearing cache based on free space left on a file system is expected to allow better disk utilization in some cases, notably when disk space might be also used for something other than nginx cache (including nginx own temporary files) and while loading cache (when cache size might be inaccurate for a while, effectively disabling max_size cache clearing). Based on a patch by Adam Bambuch.
* Too large st_blocks values are now ignored (ticket #157).Maxim Dounin2020-06-221-1/+4
| | | | | | | | | | | | | | With XFS, using "allocsize=64m" mount option results in large preallocation being reported in the st_blocks as returned by fstat() till the file is closed. This in turn results in incorrect cache size calculations and wrong clearing based on max_size. To avoid too aggressive cache clearing on such volumes, st_blocks values which result in sizes larger than st_size and eight blocks (an arbitrary limit) are no longer trusted, and we use st_size instead. The ngx_de_fs_size() counterpart is intentionally not modified, as it is used on closed files and hence not affected by this problem.
* Large block sizes on Linux are now ignored (ticket #1168).Maxim Dounin2020-06-221-0/+12
| | | | | | | | | | | | | | | | | | NFS on Linux is known to report wsize as a block size (in both f_bsize and f_frsize, both in statfs() and statvfs()). On the other hand, typical file system block sizes on Linux (ext2/ext3/ext4, XFS) are limited to pagesize. (With FAT, block sizes can be at least up to 512k in extreme cases, but this doesn't really matter, see below.) To avoid too aggressive cache clearing on NFS volumes on Linux, block sizes larger than pagesize are now ignored. Note that it is safe to ignore large block sizes. Since 3899:e7cd13b7f759 (1.0.1) cache size is calculated based on fstat() st_blocks, and rounding to file system block size is preserved mostly for Windows. Note well that on other OSes valid block sizes seen are at least up to 65536. In particular, UFS on FreeBSD is known to work well with block and fragment sizes set to 65536.
* Stream: fixed processing of zero length UDP packets (ticket #1982).Vladimir Homutov2020-06-081-0/+7
|
* Fixed SIGQUIT not removing listening UNIX sockets (closes #753).Ruslan Ermilov2020-06-011-12/+2
| | | | | | Listening UNIX sockets were not removed on graceful shutdown, preventing the next runs. The fix is to replace the custom socket closing code in ngx_master_process_cycle() by the ngx_close_listening_sockets() call.
* Win32: silenced -Wcast-function-type GCC warning (ticket #1865).Maxim Dounin2019-10-211-1/+1
| | | | | | | With MinGW-w64, building 64-bit nginx binary with GCC 8 and above results in warning due to cast of GetProcAddress() result to ngx_wsapoll_pt, which GCC thinks is incorrect. Added intermediate cast to "void *" to silence the warning.
* Win32: improved fallback on FormatMessage() errors.Maxim Dounin2019-10-211-1/+1
| | | | | | | | | | | | FormatMessage() seems to return many errors which essentially indicate that the language in question is not available. At least the following were observed in the wild and during testing: ERROR_MUI_FILE_NOT_FOUND (15100) (ticket #1868), ERROR_RESOURCE_TYPE_NOT_FOUND (1813). While documentation says it should be ERROR_RESOURCE_LANG_NOT_FOUND (1815), this doesn't seem to be the case. As such, checking error code was removed, and as long as FormatMessage() returns an error, we now always try the default language.
* Events: available bytes calculation via ioctl(FIONREAD).Maxim Dounin2019-10-178-2/+173
| | | | | | | | | | | | | | | | | | | | | This makes it possible to avoid looping for a long time while working with a fast enough peer when data are added to the socket buffer faster than we are able to read and process them (ticket #1431). This is basically what we already do on FreeBSD with kqueue, where information about the number of bytes in the socket buffer is returned by the kevent() call. With other event methods rev->available is now set to -1 when the socket is ready for reading. Later in ngx_recv() and ngx_recv_chain(), if full buffer is received, real number of bytes in the socket buffer is retrieved using ioctl(FIONREAD). Reading more than this number of bytes ensures that even with edge-triggered event methods the event will be triggered again, so it is safe to stop processing of the socket and switch to other connections. Using ioctl(FIONREAD) only after reading a full buffer is an optimization. With this approach we only call ioctl(FIONREAD) when there are at least two recv()/readv() calls.
* Fixed portability issues with union sigval.Sergey Kandaurov2019-01-282-1/+7
| | | | | | | | | | | | | | | | | | AIO support in nginx was originally developed against FreeBSD versions 4-6, where the sival_ptr field was named as sigval_ptr (seemingly by mistake[1]), which made nginx use the only name available then. The standard-complaint name was restored in 2005 (first appeared in FreeBSD 7.0, 2008), retaining compatibility with previous versions[2][3]. In DragonFly, similar changes were committed in 2009[4], with backward compatibility recently removed[5]. The change switches to the standard name, retaining compatibility with old FreeBSD versions. [1] https://svnweb.freebsd.org/changeset/base/48621 [2] https://svnweb.freebsd.org/changeset/base/152029 [3] https://svnweb.freebsd.org/changeset/base/174003 [4] https://gitweb.dragonflybsd.org/dragonfly.git/commit/3693401 [5] https://gitweb.dragonflybsd.org/dragonfly.git/commit/7875042
* Win32: added WSAPoll() support.Maxim Dounin2019-01-242-0/+75
| | | | | | | | | | | | WSAPoll() is only available with Windows Vista and newer (and only available during compilation if _WIN32_WINNT >= 0x0600). To make sure the code works with Windows XP, we do not redefine _WIN32_WINNT, but instead load WSAPoll() dynamically if it is not available during compilation. Also, sockets are not guaranteed to be small integers on Windows. So an index array is used instead of NGX_USE_FD_EVENT to map events to connections.
* Win32: removed NGX_DIR_MASK concept.Maxim Dounin2018-12-243-9/+18
| | | | | | | | | | | | Previous interface of ngx_open_dir() assumed that passed directory name has a room for NGX_DIR_MASK at the end (NGX_DIR_MASK_LEN bytes). While all direct users of ngx_dir_open() followed this interface, this also implied similar requirements for indirect uses - in particular, via ngx_walk_tree(). Currently none of ngx_walk_tree() uses provides appropriate space, and fixing this does not look like a right way to go. Instead, ngx_dir_open() interface was changed to not require any additional space and use appropriate allocations instead.
* Fixed NGX_TID_T_FMT format specification for uint64_t.Maxim Dounin2018-07-221-2/+2
| | | | | | Previously, "%uA" was used, which corresponds to ngx_atomic_uint_t. Size of ngx_atomic_uint_t can be easily different from uint64_t, leading to undefined results.
* Win32: fixed comment in ngx_gettimeofday() calculations.Ruslan Ermilov2018-05-291-1/+1
|
* Removed glibc crypt_r() bug workaround (ticket #1469).Maxim Dounin2018-05-231-4/+0
| | | | | | | | | The bug in question was fixed in glibc 2.3.2 and is no longer expected to manifest itself on real servers. On the other hand, the workaround causes compilation problems on various systems. Previously, we've already fixed the code to compile with musl libc (fd6fd02f6a4d), and now it is broken on Fedora 28 where glibc's crypt library was replaced by libxcrypt. So the workaround was removed.
* Fixed checking ngx_tcp_push() and ngx_tcp_nopush() return values.Ruslan Ermilov2018-03-192-2/+2
| | | | No functional changes.