|
56 | 56 | esac |
57 | 57 |
|
58 | 58 | case "$postgres_main_pid" in |
59 | | - ''|*[!0-9]*|0|1) |
| 59 | + ''|*[!0-9]*|0) |
60 | 60 | echo "cannot resolve the parent of PostgreSQL backend PID $backend_pid" >&2 |
61 | 61 | exit 43 |
62 | 62 | ;; |
63 | 63 | esac |
64 | 64 |
|
65 | 65 | postgres_main_status=/proc/$postgres_main_pid/status |
| 66 | +# In a container the postmaster can be PID 1. Validate its process name below |
| 67 | +# just as for any other parent, rather than rejecting the namespace init PID. |
66 | 68 | if [ ! -r "$postgres_main_status" ]; then |
67 | 69 | echo "parent PID $postgres_main_pid of PostgreSQL backend PID $backend_pid is not visible" >&2 |
68 | 70 | exit 43 |
|
89 | 91 | esac |
90 | 92 |
|
91 | 93 | postgres_executable=$(readlink "/proc/$postgres_main_pid/exe" 2>/dev/null || true) |
| 94 | +postgres_owner= |
| 95 | +runuser_bin=$(command -v runuser 2>/dev/null || true) |
| 96 | +if [ -z "$postgres_executable" ] && [ "$(id -u)" = 0 ] && [ -n "$runuser_bin" ]; then |
| 97 | + # Container root may lack CAP_SYS_PTRACE. The actual process owner can still |
| 98 | + # inspect its executable; use that identity only for readlink and ldd. |
| 99 | + postgres_owner=$(stat -c %U "$postgres_main_status" 2>/dev/null || true) |
| 100 | + if [ -n "$postgres_owner" ]; then |
| 101 | + postgres_executable=$("$runuser_bin" -u "$postgres_owner" -- readlink "/proc/$postgres_main_pid/exe" 2>/dev/null || true) |
| 102 | + fi |
| 103 | +fi |
92 | 104 | if [ -z "$postgres_executable" ]; then |
93 | 105 | echo "cannot resolve /proc/$postgres_main_pid/exe for PostgreSQL backend PID $backend_pid" >&2 |
94 | 106 | exit 45 |
|
105 | 117 | printf 'PGDIAG_POSTGRES_EXECUTABLE=%s\n' "$postgres_executable" |
106 | 118 | printf 'PGDIAG_LDD_PATH=%s\n' "$ldd_bin" |
107 | 119 | printf '%s\n' 'PGDIAG_LDD_BEGIN' |
108 | | -"$ldd_bin" "/proc/$postgres_main_pid/exe" |
| 120 | +if [ -n "$postgres_owner" ]; then |
| 121 | + "$runuser_bin" -u "$postgres_owner" -- "$ldd_bin" "/proc/$postgres_main_pid/exe" |
| 122 | +else |
| 123 | + "$ldd_bin" "/proc/$postgres_main_pid/exe" |
| 124 | +fi |
109 | 125 | """ |
110 | 126 |
|
111 | 127 | _RESOLVED_RE = re.compile( |
|
0 commit comments