Bug 9816 - support setproctitle on linux via prset(PR_SET_NAME
Summary: support setproctitle on linux via prset(PR_SET_NAME
Status: RESOLVED FIXED
Alias: None
Product: Samba 4.0
Classification: Unclassified
Component: Other (show other bugs)
Version: 4.0.5
Hardware: All Linux
: P5 normal (vote)
Target Milestone: ---
Assignee: Andrew Bartlett
QA Contact: Samba QA Contact
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-04-19 10:10 UTC by Samjam
Modified: 2019-06-11 20:55 UTC (History)
3 users (show)

See Also:


Attachments
patch to provide setproctitle support in lib/replace.c for linux (1.46 KB, patch)
2013-04-19 10:10 UTC, Samjam
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Samjam 2013-04-19 10:10:15 UTC
Created attachment 8790 [details]
patch to provide setproctitle support in lib/replace.c for linux

Samba does not set process titles on Linux systems because GNU/Linux systems do not provide the setproctitle library function.

However on Linux systems the library call prset allows the process title to be set up to 16 characters.

As long as samba calls to setproctitle put the more relevant information first, this should be a adequate replacement.

Attached is a patch to a recent samba 4.0.5 release that adds this support to lib/replace.c if prset is available and PR_SET_NAME is defined
Comment 1 Arkadiusz Miskiewicz 2013-05-06 16:00:04 UTC
There is setproctitle library that can be detected and used by samba:

http://sisyphus.ru/srpm/Sisyphus/setproctitle/get

Now prctl way should be always preffered over external setproctitle (less dependencies etc) and currently samba with your patch will preffer external setproctitle.
Comment 2 Samjam 2013-05-06 20:37:53 UTC
I would think that if a package builder has installed a setproctitle library and also chooses to link samba to it, that they would know what they are doing.

prctl only allows 16 character process names; if someone has a library that can overcome this limitation they should be allowed to use it.

it seems reasonable for libreplace to provide the alternative implementation as a fallback because it has this length restriction.
Comment 3 Andrew Bartlett 2013-05-06 21:12:34 UTC
That library seems magic, but the blunt reality is that it isn't used because it does all the dangerous things (as I understand it) that prevent us implementing that this way in libreplace.  See bug 9121.
Comment 4 Andrew Bartlett 2013-05-06 21:39:32 UTC
Andreas,

In our previous discussion on setproctitle you said this prctl needed a static string.  Can you work out with Sam if his patch is mistaken (using a malloc'ed buffer later free'ed) or if it is actually fine?  I would like to include this patch, even with the limitations.        

man prctl makes no such assertion:
PR_SET_NAME (since Linux 2.6.9)
              Set  the process name for the calling process, using the value in the location pointed to by (char *) arg2.  The name can be up to 16 bytes long, and should be null-termi‐
              nated if it contains fewer bytes.
Comment 5 Andreas Schneider 2013-05-07 14:04:59 UTC
It's still on my todo list but I haven't had time to work on it. All I have at the moment is:

https://git.samba.org/?p=asn/samba.git;a=commitdiff;h=6eb0b7a3551a896f2fd2ecd7c73c7cef8c4b581e
Comment 6 Samjam 2013-05-08 14:07:30 UTC
There is some argument to abstract this in a modified standard_set_title() and modifying the signature of the model_ops.set_title function on the grounds that more care is needed in constructing a meaningful title with only 16 characters.
Comment 7 Andrew Bartlett 2015-03-06 10:40:57 UTC
setproctitle is supported via libbsd.  The remaining task is to link our binaries to libbsd-ctor or call the magic init routine in our popt code (provided we know we never call that popt code from libraries - need to check DLZ_BIND9).
Comment 8 Samjam 2015-03-06 12:18:18 UTC
I note that since this bug was filed, there have been other bugs filed over the same issue, and that an alternative resolution still does not exist.

Can I propose this patch for when libbsd is not available or desirable?

It has the benefit of delivering value now, and simply, without dependancy on libbsd's convoluted immplementation and all the attendant difficulties and risks.

It also seems very legitimate that lib_replace should be able to provide a replacement to setproctitle when libbsd is not present.

And therefore this patch has value independant of any libbsd solution whenever it might arrive
Comment 9 Andrew Bartlett 2019-06-11 20:55:55 UTC
We use setproctitle via libbsd these days, and even call the correct setproctitle_init() now.