Hide command line arguments from ps, for forked children like getty

The built-in gety in Finit forks but does not execv().  To prevent
confusion on the part of the user, this patch hides all command line
arguments to PID 1 so it won't show up in ps listings of children.

Finit currently reads its arguments from the kernel /proc/cmdline,
it has hard-coded paths to /etc/finit.conf etc.  A future version
of Finit may take command line params, in which case this patch
should be moved after any getopt() handling.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
Joachim Nilsson
2020-01-06 18:49:14 +01:00
parent 85fe613b30
commit c391e04983
+14 -1
View File
@@ -305,7 +305,7 @@ static void final_worker(void *work)
finalize();
}
int main(int argc, char* argv[])
int main(int argc, char *argv[])
{
struct wq crank = {
.cb = crank_worker
@@ -325,6 +325,19 @@ int main(int argc, char* argv[])
if (getpid() != 1)
return client(argc, argv);
/*
* Hide command line arguments from ps (in particular for
* forked children that don't execv()). This is an ugly
* hack that only works on Linux.
* https://web.archive.org/web/20110227041321/http://netsplit.com/2007/01/10/hiding-arguments-from-ps/
*/
if (argc > 1) {
char *arg_end;
arg_end = argv[argc-1] + strlen (argv[argc-1]);
*arg_end = ' ';
}
/*
* Initalize event context.
*/