From: Han Pingtian <hanpt@linux.vnet.ibm.com>
To: zsh-workers <zsh-workers@zsh.org>
Cc: zsh-user <zsh-users@zsh.org>
Subject: [PATCH] use prctl() if available with jobs -Z
Date: Sat, 17 Nov 2012 20:38:17 +0800 [thread overview]
Message-ID: <20121117123817.GA20447@localhost.localdomain> (raw)
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 <sys/prctl.h>
+ 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
next reply other threads:[~2012-11-17 12:48 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-11-17 12:38 Han Pingtian [this message]
2012-11-18 1:28 ` Bart Schaefer
2012-11-18 2:16 ` Han Pingtian
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=20121117123817.GA20447@localhost.localdomain \
--to=hanpt@linux.vnet.ibm.com \
--cc=zsh-users@zsh.org \
--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).