From c391e049832b051e5304eaf4386502b41aabfdd9 Mon Sep 17 00:00:00 2001 From: Joachim Nilsson Date: Mon, 6 Jan 2020 18:48:53 +0100 Subject: [PATCH] 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 --- src/finit.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/finit.c b/src/finit.c index d4a710d8..aa57d658 100644 --- a/src/finit.c +++ b/src/finit.c @@ -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. */