Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: jobs -Z example?



On Mar 15,  9:07pm, Dan Nelson wrote:
}
} In case it stops working later, all of the *BSDs provide a setproctitle()

I see there's been some discussion about adding setproctitle() to glibc.

Let's try this.


diff -ru -x CVS zsh-forge/current/configure.ac zsh-4.0/configure.ac
--- zsh-forge/current/configure.ac	2009-03-08 14:01:12.000000000 -0700
+++ zsh-4.0/configure.ac	2009-03-15 20:59:52.000000000 -0700
@@ -1885,6 +1885,11 @@
   AC_DEFINE(USE_GETCWD)
 fi
 
+dnl CHECK FOR setproctitle() FOR jobs -Z / ARGV0
+AH_TEMPLATE([HAVE_SETPROCTITLE],
+[Define to 1 if the system supports this call to change process name])
+AC_SEARCH_LIBS(setproctitle, util, AC_DEFINE(HAVE_SETPROCTITLE))
+
 dnl -------------
 dnl CHECK FOR NIS
 dnl -------------
diff -ru -x CVS zsh-forge/current/Src/jobs.c zsh-4.0/Src/jobs.c
--- zsh-forge/current/Src/jobs.c	2009-03-14 23:22:20.000000000 -0700
+++ zsh-4.0/Src/jobs.c	2009-03-15 21:03:13.000000000 -0700
@@ -1572,12 +1572,14 @@
     return returnval;
 }
 
+#ifndef HAVE_SETPROCTITLE
 /* 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. */
 
 static char *hackzero;
 static int hackspace;
+#endif
 
 
 /* Initialise job handling. */
@@ -1600,6 +1602,7 @@
     jobtabsize = MAXJOBS_ALLOC;
     memset(jobtab, 0, init_bytes);
 
+#ifndef HAVE_SETPROCTITLE
     /*
      * Initialise the jobs -Z system.  The technique is borrowed from
      * perl: check through the argument and environment space, to see
@@ -1622,6 +1625,7 @@
     }
     done:
     hackspace = p - hackzero;
+#endif
 }
 
 
@@ -1718,10 +1722,14 @@
 	}
 	queue_signals();
 	unmetafy(*argv, &len);
+#ifdef HAVE_SETPROCTITLE
+	setproctitle("%s", *argv);
+#else
 	if(len > hackspace)
 	    len = hackspace;
 	memcpy(hackzero, *argv, len);
 	memset(hackzero + len, 0, hackspace - len);
+#endif
 	unqueue_signals();
 	return 0;
     }



Messages sorted by: Reverse Date, Date, Thread, Author