207 Commits

Author SHA1 Message Date
Benoit Chesneau
bbae34b951
Fix setproctitle initialization with systemd socket activation (#3465)
Force early setproctitle initialization by calling getproctitle()
immediately after import. This ensures setproctitle captures the
argv/environ memory layout before systemd.listen_fds() modifies
the environment by removing LISTEN_FDS and LISTEN_PID.

Without this fix, if LISTEN_FDS is the first environment variable,
setproctitle fails to detect argv correctly and silently fails.

Fixes #3430
2026-01-25 15:18:04 +01:00
Benoit Chesneau
be6f3b97ab Disable setproctitle on macOS to prevent segfaults
setproctitle causes segfaults on macOS due to fork() safety issues
introduced in newer macOS versions. The mere import of setproctitle
can trigger crashes in forked worker processes.

Fixes #3021
2026-01-25 09:57:20 +01:00
benoitc
7268a61099 fix util.set_owner_process
Python 2.x is not supported anymore, let's remove this extra feature.

fix #3212
2024-08-11 09:52:51 +02:00
Paul J. Dorn
4f7766585d Python 3.3+: replace deprecated aliases
since 3.3: EnvironmentError, IOError, socket.error and select.error are merged into IOError.
They may now return a more specific subclass - which this commit does not utilize yet.
2024-04-22 03:33:31 +02:00
Paul J. Dorn
4323027b1e drop long-default - coding: utf-8 2024-04-22 03:33:14 +02:00
benoitc
f628dd9730 fix import error 2023-07-17 22:40:52 +02:00
unknown
48d670f087 update pylint version, and fix linter issues 2023-05-17 18:45:59 +03:00
Benoit Chesneau
59bbcdc2d5
Merge pull request #2963 from gotmax23/load_entry
replace pkg_resources.load_entry_point
2023-05-13 20:59:25 +02:00
Maxwell G
7f480daf07
replace pkg_resources.load_entry_point
pkg_resources is deprecated. Use the corresponding importlib.metadata
interface instead. Use the stdlib version on python >= 3.8 and use the
importlib_metadata backport on older versions.
2023-05-12 21:29:54 +00:00
Benoit Chesneau
f19e31fec5
utils.py: fix code reference
fix #2632
2023-05-07 19:46:02 +02:00
samypr100
2ea4699fe7
Fixing errors reported by pycodestyle 2023-01-22 21:20:11 -05:00
DwarfMaster
cc3238c6ff Prevent unnecessary setuid call 2022-03-13 17:16:32 +01:00
Brett Randall
0b6939de86
Undo changes that make -R branch logic behave the same as non -R branch,
that is, to close(0) and open /dev/null as fd=0 instead of fd=3.

(Partially) Revert "Ensure fd 0 stdin </dev/null is always inheritable."

This partially reverts commit 7946678f271e25473618929d6f2725c8c375563e.
2022-02-07 07:39:46 +11:00
Brett Randall
e9c4f7443e
Revert "Refactoring: common stdin </dev/null."
This reverts commit a4f286769858ecfef14080f815adce26c260b2a9.
2022-02-07 07:39:46 +11:00
Brett Randall
eedc3a38b6
Refactoring: common stdin </dev/null. 2022-02-07 07:39:46 +11:00
Brett Randall
835a4fc420
Ensure fd 0 stdin </dev/null is always inheritable.
When gunicorn --daemon daemonizes the process, prior to this change it was
noted that in the general case (without -R / --enable-stdio-inheritance), when fd 0
was replaced with /dev/null, the dup2 copy is skipped, and per PEP 446
"Make newly created file descriptors non-inheritable", the result was a stdio
fd </dev/null which was non-inheritable.  As a result, any launched subprocess
did not have an open 0/stdin fd, which can cause problems in some applications.

This change retains the behaviour of opening /dev/null with fd 0, but adds a call
to os.set_inheritable(..) to ensure the fd is inheritable.

The -R branch had different logic but has now been standardised with the general
case.  It was previously opening /dev/null as fd 3 and the dup2() copy made it
inheritable as fd 0.  This branch now applies the same logic: open as fd 0
(i.e. after close(0)), then set_inheritable.  As a result, an extra fd 3 </dev/null
previously left open is no longer left open.

Signed-off-by: Brett Randall <javabrett@gmail.com>
2022-02-07 07:39:46 +11:00
Kevin Michel
287916a5d4 Remove dead code: find_library and _findWalk_ldpath 2020-01-29 16:14:33 +01:00
Takuya Noguchi
ed901637ff Enable pycodestyle 2019-11-28 19:30:38 +09:00
ThePrez
4d3ec28046 fix IBM i 'missing libc' failure (#2195)
allow gunicorn on IBM i (and AIX) platform with Python 3.6 and earlier
2019-11-22 22:14:35 +01:00
Benoit Chesneau
e150ca4ff8
add "*.so.*" case to util.find_lib
The actual libc name in musl is: libc.musl-x86_64.so.1 this case should handle it.
2019-11-21 11:53:13 +01:00
benoitc
d55c7cb015 fix lib discovery
LD_LIBRARY_PATH is sometimes empty, this change fix it.
Also test suffix with the "." as it seems to be an issue
2019-11-20 21:41:05 +01:00
benoitc
b8860ef615 fix gunicorn when used with musl libc
find_library('c') doesn't work in Alpine Linux. This happen because musl has a simpler implementation of libc.

This patch fix it by extending ctypes.util.find_library to search the libs using LD_LIBRARY_PATH.

Patch is based on e3f67780aa

See also https://bugs.python.org/issue21622

fix #2160
2019-11-20 21:40:58 +01:00
David Lord
19cb68f4c3 load application from factory function (#2178)
* load application from factory function

Use `ast.parse` to validate that the string passed to the CLI is either
an attribute name or a function call. Use `ast.literal_eval` to parse
any positional and keyword arguments to the function. Call the function
to get the real application.

Co-authored-by: Connor Brinton <connor.brinton@gmail.com>

* test coverage for util.import_app

* document app factory pattern
2019-11-19 23:09:53 +01:00
Hasan Ramezani
e7890d8d1b
Fix lint errors (#2123) 2019-10-27 11:57:16 +01:00
c-bata
6df58a99b5 Remove util.import_module 2019-05-28 16:07:31 +03:00
Masashi SHIBATA
3701ad9f26 Use importlib instead of __import__ and eval (#2043) 2019-05-22 22:07:02 +03:00
c-bata
d4ff4b419c Fix typo: peform to perform 2019-05-20 12:56:18 +03:00
Randall Leeds
cc8e67ea83 Fix new pylint errors 2019-03-16 16:11:23 -07:00
Hasan Ramezani
2b07f2be28 Rewrite parse_address util and add one test 2019-03-16 15:07:53 -07:00
Florian Apolloner
ee7af1247b Added support to --bind to open file descriptors (#1809)
Fixes #1107
2018-11-16 20:21:13 +03:00
Hugo
e974f30517 Drop support for Python 2
Co-Authored-By: Dustin Ingram <di@users.noreply.github.com>
Co-Authored-By: Berker Peksag <berker.peksag@gmail.com>
2018-08-01 15:31:17 +03:00
7
7d0787cd1a Fix linting for Pylint 2.0 (#1833)
Closes #1832
2018-07-18 19:33:09 +03:00
Edward Betts
fc64a43ec6 Correct spelling mistakes. 2018-02-19 22:00:41 +03:00
Berker Peksag
76eaa0805b Fix various warnings and errors reported by pylint 2018-01-11 09:59:31 +03:00
Andy Wilcox
32992a88f9 Avoid needlessly triggering non-false return from issetugid on MacOSX 2018-01-03 08:15:17 -08:00
YuppY
5953148573 Do not strip leading slash from path (#1511)
Fixes #1512
2017-12-28 11:32:47 +03:00
Juan Julián Merelo Guervós
6ba2ebe545 Make "failed to find application" more informative (#1648)
Co-Authored-By: Luis Liñán Villafranca <luislivilla@gmail.com>

Fixes #1647
2017-11-24 10:42:03 +03:00
Hasan Ramezani
81efa40da7 Improve parsing of 'unix://' addresses in parse_address (#1623) 2017-10-16 09:44:00 +03:00
Berker Peksag
f00fb441ca Remove unused variables 2017-07-12 18:07:16 +03:00
Benno Rice
72dd0199d7 Deal fully with deprecated functions.
If possible use a function based on inspect.signature to calculate the
arity.  If inspect.signature is not available fall back to getargspec. The
version based on inspect.signature looks like more code but is actually a
subset of what inspect.getfullargspec does.

html.escape is preferred over cgi.escape primarily because it defaults quote
to True. For this reason pass quote=True to cgi.escape when used.
2017-07-12 16:14:09 +03:00
Ed Morley
fbd151e984 Remove dead code found using vulture (#1469)
https://pypi.python.org/pypi/vulture

In particular the removal of `get_maxfd()` means the `resource` module
is no longer required (which is not available on Windows) and so helps
with #524.
2017-03-13 13:33:11 -07:00
Berker Peksag
31b8e48a78 Silence prospector warnings 2017-02-07 09:05:43 +03:00
Saeed Gharedaghi
ab444eed50 change __dict__ to vars function
Back gunicorn/argparse_compat.py gunicorn/six.py files changes

Back run_gunicorn.py file changes
2017-01-11 23:07:20 +03:00
Randall Leeds
bc5ae5d457 format boot tracebacks properly with reloader (#1415)
fix #1408
2016-12-23 10:56:07 -08:00
Patrick Browne
915c534eab feat(import_app): print original exception on AppImportError (#1334)
* feat(import_app): print original exception on AppImportError
2016-10-03 12:52:20 -07:00
benoitc
cb84e6ed11 initialize the group access list for a worker when initgroups is set
Allows the possibility to initialise the group access list when needed to separate privileges

fix #1287
2016-05-31 18:26:41 +02:00
benoitc
4d845f2ae4 fix pep8 warnings 2016-05-31 15:48:39 +02:00
benoitc
418f140445 remove file locking
This changes improve the binary upgrade behaviour using USR2:

- only one binary upgrade can happen at a time: the old arbiter needs to be
  killed to promote the new arbiter.
- if a new arbiter is already spawned, until one is killed USR2 has no action
- if a new arbiter has been spawned, the unix socket won't be unlinked
- until the old arbiter have been killed the newly created pidfile has the name
  <pidfile>.2 and the name Master.2 .

Note: there is no dialog between both arbiters to handle this features.
Instead they will supervise each others until one is killed. So isolation is
still guaranted.

fix #1267
2016-05-20 15:42:55 +02:00
benoitc
8a6748ee65 fix unix socket locking
This change add proper file locking to gunicorn. By default "gunicorn.lock" is created in the temporary directory when a unix socket is bound.  In case someone want to fix the lock file path or use multiple gunicorn instance the "--lock-file" setting can be used to set the path of this file.

fix #1259
2016-05-14 22:03:40 +02:00
benoitc
5bc13be79e rename util.is_fileobject to util.has_fileno
be more descriptive
2015-12-31 15:32:08 +01:00