From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 20340 invoked by alias); 17 Nov 2012 12:48:50 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 30804 Received: (qmail 28926 invoked from network); 17 Nov 2012 12:48:38 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.2 Received-SPF: none (ns1.primenet.com.au: domain at linux.vnet.ibm.com does not designate permitted sender hosts) Date: Sat, 17 Nov 2012 20:38:17 +0800 From: Han Pingtian To: zsh-workers Cc: zsh-user Subject: [PATCH] use prctl() if available with jobs -Z Message-ID: <20121117123817.GA20447@localhost.localdomain> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) X-Content-Scanned: Fidelis XPS MAILER x-cbid: 12111712-7182-0000-0000-000003432378 Use prctl() to change argv[0]. It is more safe than modifying argv[0] directly. After the changing, new name can be seen by 'ps -p $$'. --- Src/jobs.c | 9 ++++++--- configure.ac | 6 ++++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/Src/jobs.c b/Src/jobs.c index 0464d18..1c16671 100644 --- a/Src/jobs.c +++ b/Src/jobs.c @@ -1698,7 +1698,7 @@ getjob(const char *s, const char *prog) return returnval; } -#ifndef HAVE_SETPROCTITLE +#if !defined(HAVE_SETPROCTITLE) && !defined(HAVE_PRCTL) /* For jobs -Z (which modifies the shell's name as seen in ps listings). * * hackzero is the start of the safely writable space, and hackspace is * * its length, excluding a final NUL terminator that will always be left. */ @@ -1714,7 +1714,6 @@ static int hackspace; void init_jobs(char **argv, char **envp) { - char *p, *q; size_t init_bytes = MAXJOBS_ALLOC*sizeof(struct job); /* @@ -1728,13 +1727,14 @@ init_jobs(char **argv, char **envp) jobtabsize = MAXJOBS_ALLOC; memset(jobtab, 0, init_bytes); -#ifndef HAVE_SETPROCTITLE +#if !defined(HAVE_SETPROCTITLE) && !defined(HAVE_PRCTL) /* * Initialise the jobs -Z system. The technique is borrowed from * perl: check through the argument and environment space, to see * how many of the strings are in contiguous space. This determines * the value of hackspace. */ + char *p, *q; hackzero = *argv; p = strchr(hackzero, 0); while(*++argv) { @@ -1850,6 +1850,9 @@ bin_fg(char *name, char **argv, Options ops, int func) unmetafy(*argv, &len); #ifdef HAVE_SETPROCTITLE setproctitle("%s", *argv); +#elif defined(HAVE_PRCTL) +#include + prctl(PR_SET_NAME, *argv); #else if(len > hackspace) len = hackspace; diff --git a/configure.ac b/configure.ac index 5528597..4c6d15f 100644 --- a/configure.ac +++ b/configure.ac @@ -2018,6 +2018,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 +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.7.7.6