Re: 2.4 setproctitle breakage (was reiserfs marathon thread)

From: Khimenko Victor (khim@sch57.msk.ru)
Date: Tue Jun 13 2000 - 18:41:02 EST


In <20000613223733.986BA7D2B@bagpuss.pyrites.org.uk> Nick Holloway (Nick.Holloway@pyrites.org.uk) wrote:
NH> khim@sch57.msk.ru (Khimenko Victor) wrote:
>> Alan Cox (alan@lxorguk.ukuu.org.uk) wrote:
>> >> wu-ftpd's ftpwho works on Irix, HP-UX, Solaris and more (perhaps even more
>> >> then PostgreSQL). It does not work with Linux 2.3.x ...
>>
>> AC> It works on 2.2.x but not 2.3.x - can you tell me more ? I dont like things
>> AC> stopping working.
>>
>> General reaction was "sendmail, ftpd and bunch of other daemons using
>> setproctitle(3) and hack used in 2.2 does not work anymore but we do not
>> bother at all since setproctitle(3) is not POSIX anyway [...]

NH> The problem is that /proc/$$/cmdline only returns the number of bytes
NH> initially set up for it.

Exactly.

NH> I posted a patch in March which changes the behaviour of /proc/$$/cmdline
NH> to be compatable with that of 2.2 -- so an application can use the
NH> environment space in addition to the command line for the purpose of
NH> setproctitle.

It's just plain wrong thing to do. Adding hack to make other hack working
is bad thing(tm). Using environment space in addition to command line can
lead to strange results (enviroment was NOT added to make setproctitle(3)
happy - there are can be some interesting bits, you know).

NH> The patch is against 2.3.99-pre1, but a) I'm too tired to do anything to
NH> check it is up to date right now, and b) I don't believe that anything
NH> has changed in this area of /proc.

Basically most kernel developers do not bother it seems. If it's not in POSIX
it does not exist - bunch of broken programs (rare ones - like wu-ftpd,
sendmail and utils-linux :-) do not count unless it can crash system badly...

NH> ===========================================================================

NH> --cNdxnHkX5QqsyA0e
NH> Content-Type: text/plain; charset=us-ascii

NH> Here is a change to proc_pid_cmdline so that applications that attempt to
NH> present their current state to ps(1) using some variant of setproctitle(3)
NH> work in the same manner under 2.3 as they do under 2.2.

NH> Whereas 2.2 would look into the environment area to return the full
NH> information available from setproctitle(3), 2.3 only looks the area set
NH> aside for the arguments.

NH> This patch uses the following heuristic. If the nul byte at the end
NH> of the argument area has been overwritten, then setproctitle(3) is
NH> being used. If there is no nul in the argument area, then the contents
NH> of environment area up to the first nul is also included.

NH> If the argument area is not modified, then the only overhead is checking
NH> a byte in the buffer to be returned to the user. It is not possible to
NH> get /proc/$$/cmdline to look outside the argument and environment space,
NH> nor to return more than 1 page of data. I've left /proc/$$/environ
NH> to return random garbage if setproctitle(3) is being used -- behaviour
NH> compatable with 2.2.

NH> I've given this a quick workout using assignments to $0 in Perl. I'd like
NH> others to have a look at this and try it out, and see how it works with
NH> their favorite applications.

NH> --
NH> `O O' | Nick.Holloway@alfie.demon.co.uk
NH> // ^ \\ | http://www.alfie.demon.co.uk/

NH> --cNdxnHkX5QqsyA0e
NH> Content-Type: text/plain; charset=us-ascii
NH> Content-Disposition: attachment; filename="setproctitle.diff"

NH> --- linux-2.3/fs/proc/base.c Mon Mar 20 21:06:55 2000
NH> +++ linux-2.3-hacked/fs/proc/base.c Mon Mar 20 20:42:02 2000
NH> @@ -123,6 +123,24 @@
NH> if (len > PAGE_SIZE)
NH> len = PAGE_SIZE;
NH> res = access_process_vm(task, mm->arg_start, buffer, len, 0);
NH> + // If the nul at the end of args has been overwritten, then
NH> + // assume application is using setproctitle(3).
NH> + if ( res > 0 && buffer[res-1] != '\0' )
NH> + {
NH> + len = strnlen( buffer, res );
NH> + if ( len < res )
NH> + {
NH> + res = len;
NH> + }
NH> + else
NH> + {
NH> + len = mm->env_end - mm->env_start;
NH> + if (len > PAGE_SIZE - res)
NH> + len = PAGE_SIZE - res;
NH> + res += access_process_vm(task, mm->env_start, buffer+res, len, 0);
NH> + res = strnlen( buffer, res );
NH> + }
NH> + }
NH> }
NH> return res;
NH> }

NH> --cNdxnHkX5QqsyA0e--

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/



This archive was generated by hypermail 2b29 : Thu Jun 15 2000 - 21:00:29 EST