zsh-workers
 help / color / mirror / code / Atom feed
From: Han Pingtian <hanpt@linux.vnet.ibm.com>
To: zsh-workers@zsh.org
Subject: [PATCH] Re: cannot hide command name from ps -e
Date: Tue, 14 Oct 2014 15:50:35 +0800	[thread overview]
Message-ID: <20141014075035.GB2994@localhost.localdomain> (raw)
In-Reply-To: <20141014062710.GA2994@localhost.localdomain>

On Tue, Oct 14, 2014 at 02:27:10PM +0800, Han Pingtian wrote:
> On Mon, Oct 13, 2014 at 10:27:31AM -0700, Bart Schaefer wrote:
> > 
> > Maybe the right thing is to use all possible such mechanisms at the same
> > time, rather than attempt to choose just one at configure time.
> Thanks. I'll try to figure out a patch.
I have figured out a patch, it works fine on Fedora 20. Please review.
Thanks!


>From c2385d70b06cfc70fa523c1406c01bb6379fa7cb Mon Sep 17 00:00:00 2001
From: Han Pingtian <hanpt@linux.vnet.ibm.com>
Date: Tue, 14 Oct 2014 15:31:28 +0800
Subject: [PATCH] 33457: hide command name when checking with "ps -e"
Status: RO
Content-Length: 1324
Lines: 46

"ps -e" on linux will check /proc/$$/comm, which can be changed by
calling prctl().

Signed-off-by: Han Pingtian <hanpt@linux.vnet.ibm.com>
---
 Src/jobs.c   | 7 +++++++
 configure.ac | 6 ++++++
 2 files changed, 13 insertions(+)

diff --git a/Src/jobs.c b/Src/jobs.c
index bd95afb..2db5a31 100644
--- a/Src/jobs.c
+++ b/Src/jobs.c
@@ -1972,6 +1972,13 @@ bin_fg(char *name, char **argv, Options ops, int func)
 	memcpy(hackzero, *argv, len);
 	memset(hackzero + len, 0, hackspace - len);
 #endif
+
+#ifdef HAVE_PRCTL
+	/* try to change /proc/$$/comm which will *
+	 * be used when checking with "ps -e"  */
+#include <sys/prctl.h>
+	prctl(PR_SET_NAME, *argv);
+#endif
 	unqueue_signals();
 	return 0;
     }
diff --git a/configure.ac b/configure.ac
index 306a005..8e5e2c5 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2083,6 +2083,12 @@ AH_TEMPLATE([HAVE_SETPROCTITLE],
 AC_CHECK_FUNC(setproctitle,AC_DEFINE(HAVE_SETPROCTITLE),
 AC_SEARCH_LIBS(setproctitle,util,AC_DEFINE(HAVE_SETPROCTITLE)))
 
+dnl CHECK FOR prctl() FOR jobs -Z / ARGV0 when checking with ps -e
+AH_TEMPLATE([HAVE_PRCTL],
+[Define to 1 if the system supports `prctl' to change process name])
+AC_CHECK_FUNC(prctl,AC_DEFINE(HAVE_PRCTL),
+AC_SEARCH_LIBS(prctl,c,AC_DEFINE(HAVE_PRCTL)))
+
 dnl -------------
 dnl CHECK FOR NIS
 dnl -------------
-- 
1.9.3


      reply	other threads:[~2014-10-14  8:00 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-10-13  8:29 Han Pingtian
2014-10-13 17:27 ` Bart Schaefer
2014-10-14  6:27   ` Han Pingtian
2014-10-14  7:50     ` Han Pingtian [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20141014075035.GB2994@localhost.localdomain \
    --to=hanpt@linux.vnet.ibm.com \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).