Bug 9121 - provide and use setproctitle replacement function for samba4 processes on linux
Summary: provide and use setproctitle replacement function for samba4 processes on linux
Status: RESOLVED FIXED
Alias: None
Product: Samba 4.0
Classification: Unclassified
Component: Other (show other bugs)
Version: 4.0 beta4
Hardware: All All
: P5 normal (vote)
Target Milestone: ---
Assignee: Karolin Seeger
QA Contact: samba4-qa@samba.org
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-08-28 12:03 UTC by Arvid Requate
Modified: 2012-12-03 19:33 UTC (History)
4 users (show)

See Also:


Attachments
patch adding a setproctitle function for use in process_standard.c (13.84 KB, patch)
2012-08-28 12:11 UTC, Arvid Requate
no flags Details
Patches for v4-0-test (6.33 KB, patch)
2012-10-10 06:22 UTC, Stefan Metzmacher
kseeger: review+
Details
samba-tool processes patches for v4-0-test (20.72 KB, patch)
2012-12-03 08:04 UTC, Stefan Metzmacher
obnox: review+
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Arvid Requate 2012-08-28 12:03:55 UTC
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.
Comment 1 Arvid Requate 2012-08-28 12:11:04 UTC
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].
Comment 2 Andrew Bartlett 2012-09-24 08:40:30 UTC
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?
Comment 3 Andrew Bartlett 2012-10-02 06:22:38 UTC
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.
Comment 4 Jelmer Vernooij 2012-10-03 19:51:58 UTC
(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
Comment 5 Andrew Bartlett 2012-10-04 02:10:17 UTC
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.
Comment 6 Stefan Metzmacher 2012-10-10 06:22:46 UTC
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...
Comment 7 Karolin Seeger 2012-10-10 06:52:22 UTC
(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.
Comment 8 Jelmer Vernooij 2012-10-10 09:01:26 UTC
(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.
Comment 9 Stefan Metzmacher 2012-12-03 08:04:03 UTC
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 10 Michael Adam 2012-12-03 11:40:31 UTC
Comment on attachment 8248 [details]
samba-tool processes patches for v4-0-test

ACK
Comment 11 Michael Adam 2012-12-03 11:42:08 UTC
==> Karolin for 4.0
Comment 12 Karolin Seeger 2012-12-03 12:19:15 UTC
Pushed to autobuild-v4-0-test.
Comment 13 Karolin Seeger 2012-12-03 19:33:50 UTC
Pushed to v4-0-test.
Closing out bug report.

Thanks!