Currently all samba processes are shown under the same process name in linux ps. Since linux libc currently does not offer a setproctitle call, it might be useful to provide and use a replacement function. The function code may be derived from the ps_status code in postgresql.
Created attachment 7837 [details] patch adding a setproctitle function for use in process_standard.c patch adding a trimmed down version of the postgresql setproctitle code, adjusted to match the BSD API. The patch makes the new replacement function available to process_standard.c. With the patch, the process list looks like this: 18627 ? Ss 0:00 /usr/sbin/samba -D 18640 ? S 0:00 /usr/sbin/samba: task[s3fs_parent] 18641 ? S 0:00 /usr/sbin/samba: task[dcesrv] 18642 ? S 0:00 /usr/sbin/samba: task[nbtd] 18643 ? S 0:00 /usr/sbin/samba: task[wreplsrv] 18644 ? S 0:02 /usr/sbin/samba: task[ldapsrv] 18645 ? Ss 0:00 /usr/sbin/smbd --configfile /var/lib/samba/private/smbd.tmp/fileserver.conf --foreground 18646 ? S 0:00 /usr/sbin/samba: task[cldapd] 18647 ? S 0:00 /usr/sbin/samba: task[kdc] 18648 ? S 0:00 /usr/sbin/samba: task[dreplsrv] 18649 ? S 0:00 /usr/sbin/samba: task[winbind] 18650 ? S 0:00 /usr/sbin/samba: task[ntp_signd] 18651 ? S 0:00 /usr/sbin/samba: task[kccsrv] 18652 ? S 0:00 /usr/sbin/samba: task[dnsupdate] Mimicking BSD setproctitle behaviour, the binary name is picked up from argv[0].
I said in a private mail: > I have to say, I'm afraid of this patch. It is large, complex and the > idea of messing about with that memory scares me. Additionally, from > memory we had weird issues when we last used even system-provided > setproctitle libraries. > > We would need to dig into that history before we even started, and try > and assure ourselves that this really is safe across multiple platforms. > (Starting with postgres code is a good start, but it still scares me). I understand the need for a way to identify processes, so I wonder if we should instead have a tool based on the registered server names for the IPC messaging system?
Just as an update: Since this bug was filed, we have changed the code to find setproctitle via libbsd if installed. However, the libbsd implementation is a no-op, so we haven't actually made any real progress here. My proposal is to write an extension to samba-tool to use the registered messaging endpoints for our datagram-based IPC as process names. It is far from ideal (ps on FreeBSD is a dream to work with, with this info just where we want it!), but I don't see any other good, safe solutions right now.
(In reply to comment #3) > Just as an update: > > Since this bug was filed, we have changed the code to find setproctitle via > libbsd if installed. However, the libbsd implementation is a no-op, so we > haven't actually made any real progress here. Note that we also support using libsetproctitle if libbsd is not available. libsetproctitle *does* provide a full implementation of setproctitle(). However, it is not packaged on Debian/Ubuntu. The best way forward I think would be to submit a patch to libbsd to provide a setproctitle implementation, or get libsetproctitle packaged. Cheers, Jelmer
Arvid pointed out these links: (an attempt to get this into glibc) http://permalink.gmane.org/gmane.comp.lib.glibc.alpha/14686 (an attempt to get the kernel to help) http://lkml.org/lkml/2009/12/23/358 What worries me is that this libsetproctitle creates a new environ pointer with malloc, but can't work around the original issue of the environment size.
Created attachment 8029 [details] Patches for v4-0-test Backports from master, they just make use of libbsd. We still want to improve this by providing a replacement...
(In reply to comment #6) > Created attachment 8029 [details] > Patches for v4-0-test > > Backports from master, they just make use of libbsd. > We still want to improve this by providing a replacement... Pushed to autobuild-v4-0-test.
(In reply to comment #6) > Created attachment 8029 [details] > Patches for v4-0-test > > Backports from master, they just make use of libbsd. > We still want to improve this by providing a replacement... We also support using libsetproctitle, which does provide an appropriate replacement (and is a bit of a hack). Mostly, this requires some help from the kernel.
Created attachment 8248 [details] samba-tool processes patches for v4-0-test "samba-tool processes" makes it possible to debug on systems without setproctitle
Comment on attachment 8248 [details] samba-tool processes patches for v4-0-test ACK
==> Karolin for 4.0
Pushed to autobuild-v4-0-test.
Pushed to v4-0-test. Closing out bug report. Thanks!