Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
[PATCH] use prctl() if available with jobs -Z
- X-seq: zsh-users 17401
- From: Han Pingtian <hanpt@xxxxxxxxxxxxxxxxxx>
- To: zsh-workers <zsh-workers@xxxxxxx>
- Subject: [PATCH] use prctl() if available with jobs -Z
- Date: Sat, 17 Nov 2012 20:38:17 +0800
- Cc: zsh-user <zsh-users@xxxxxxx>
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
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
Messages sorted by:
Reverse Date,
Date,
Thread,
Author