util: Ensure debugger can be attached to process
commit05a1ca2f4c771d1e249a6d756488cb5e1e3312dd
authorJoseph Sutton <josephsutton@catalyst.net.nz>
Mon, 29 Mar 2021 02:04:53 +0000 (29 15:04 +1300)
committerAndreas Schneider <asn@cryptomilk.org>
Tue, 20 Apr 2021 11:42:37 +0000 (20 11:42 +0000)
treea6361cef3074e15d128a8d7bd6b1241ffd7f602c
parentc50475487274cc8f524b28aac9825e35e9407c8d
util: Ensure debugger can be attached to process

samba_start_debugger() attempts to start a debugger attached to the
calling process by calling system() to start a background process.
However, if the spawned shell exits before the debugger has had a chance
to attach, the debugger process will no longer be a child of the parent
process (as it will have been reparented).

If the system does not allow tracing by non-child processes, attachment
may fail as a result.

This commit replaces the system() call and the implicit shell around
xterm with an explicit fork()/exec() so that the debugger remains a
child of the calling process, ensuring the attachment succeeds unless
tracing is disabled completely.

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Andrew Bartlet <abartlet@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
lib/util/util.c