Skip to content

Commit

Permalink
fix building libproc cython extension with gcc 14
Browse files Browse the repository at this point in the history
  • Loading branch information
totaam committed Jan 31, 2024
1 parent 8273e18 commit ffb5abf
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 28 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2190,7 +2190,7 @@ def bundle_tests():
#platform:
tace(sd_listen_ENABLED, "xpra.platform.posix.sd_listen", "libsystemd")
tace(proc_ENABLED and proc_use_procps, "xpra.platform.posix.proc_procps", "libprocps", extra_compile_args = "-Wno-error")
tace(proc_ENABLED and proc_use_libproc, "xpra.platform.posix.proc_libproc", "libproc2", extra_compile_args = "-Wno-error")
tace(proc_ENABLED and proc_use_libproc, "xpra.platform.posix.proc_libproc", "libproc2", language="c++")

#codecs:
toggle_packages(enc_proxy_ENABLED, "xpra.codecs.proxy")
Expand Down
44 changes: 17 additions & 27 deletions xpra/platform/posix/proc_libproc.pyx
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
# This file is part of Xpra.
# Copyright (C) 2022 Antoine Martin <[email protected]>
# Copyright (C) 2022-2024 Antoine Martin <[email protected]>
# Xpra is released under the terms of the GNU GPL v2, or, at your option, any
# later version. See the file COPYING for details.

from libc.string cimport memset

from xpra.log import Logger

log = Logger("util", "exec")
Expand All @@ -14,6 +12,9 @@ DEF PROC_PID = 0x1000 #process id numbers ( 0 terminated )


cdef extern from "libproc2/pids.h":
ctypedef enum pids_item:
PIDS_ID_PPID

# Opaque handle used by procps to store its buffers
struct pids_info:
pass
Expand All @@ -38,36 +39,25 @@ cdef extern from "libproc2/pids.h":
pids_counts *counts
pids_stack **stacks

# Flag used to query the parent process, part of the pids_item enum
int PIDS_ID_PPID

# Flag used to return one value per process, part of pids_select_type enum.
# All we care about here is PPID which is the same for each thread within a
# process.
int PIDS_SELECT_PID
ctypedef enum pids_select_type:
PIDS_SELECT_PID
PIDS_SELECT_PID_THREADS
PIDS_SELECT_UID
PIDS_SELECT_UID_THREADS

int procps_pids_new(pids_info **info, int *items, int numitems)
int procps_pids_new(pids_info **info, pids_item *items, int numitems)
int procps_pids_unref(pids_info **info)
pids_fetch *procps_pids_select(pids_info *info, unsigned int *pids, int pidcount, int select_type)
pids_fetch *procps_pids_select(pids_info *info, unsigned*pids, int pidcount, int select_type)

def get_parent_pid(int pid) -> int:
cdef pids_info *handle
cdef int selector

handle = NULL
selector = PIDS_ID_PPID
def get_parent_pid(unsigned int pid) -> int:
cdef pids_info *handle = NULL
cdef pids_item selector = PIDS_ID_PPID
if procps_pids_new(&handle, &selector, 1) != 0:
return 0

cdef unsigned int upid
cdef pids_fetch *query
cdef int retval

upid = pid
query = procps_pids_select(handle, &upid, 1, PIDS_SELECT_PID)
if query == NULL or query.counts.total != 1 or query.stacks[0].head.item != PIDS_ID_PPID:
retval = 0
else:
cdef pids_fetch *query = procps_pids_select(handle, &pid, 1, PIDS_SELECT_PID)
cdef int retval = 0
if query != NULL and query.counts.total == 1 and query.stacks[0].head.item == PIDS_ID_PPID:
retval = query.stacks[0].head.result.s_int

procps_pids_unref(&handle)
Expand Down

0 comments on commit ffb5abf

Please sign in to comment.