[前][次][番号順一覧][スレッド一覧]

ruby-changes:35770

From: odaira <ko1@a...>
Date: Thu, 9 Oct 2014 07:32:08 +0900 (JST)
Subject: [ruby-changes:35770] odaira:r47852 (trunk): missing/setproctitle.c: Avoid invalidating argv[1], argv[2], etc. until the first call to Process.setproctitle, because the ps command of AIX refers to the argv array. [Bug #10090]

odaira	2014-10-09 07:31:53 +0900 (Thu, 09 Oct 2014)

  New Revision: 47852

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=47852

  Log:
    missing/setproctitle.c: Avoid invalidating argv[1], argv[2], etc. until the first call to Process.setproctitle, because the ps command of AIX refers to the argv array. [Bug #10090]

  Modified files:
    trunk/ChangeLog
    trunk/missing/setproctitle.c
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 47851)
+++ ChangeLog	(revision 47852)
@@ -1,3 +1,10 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Thu Oct  9 07:20:30 2014  Rei Odaira  <Rei.Odaira@g...>
+
+	* missing/setproctitle.c: Avoid invalidating argv[1], argv[2],
+	  etc. until the first call to Process.setproctitle, because
+	  the ps command of AIX refers to the argv array.
+	  [Bug #10090]
+
 Thu Oct  9 00:53:15 2014  Nobuyoshi Nakada  <nobu@r...>
 
 	* dir.c (dir_s_aref): fix rdoc.  `Dir.glob` allows an array but
Index: missing/setproctitle.c
===================================================================
--- missing/setproctitle.c	(revision 47851)
+++ missing/setproctitle.c	(revision 47852)
@@ -74,6 +74,7 @@ https://github.com/ruby/ruby/blob/trunk/missing/setproctitle.c#L74
 static char *argv_start = NULL;
 static size_t argv_env_len = 0;
 static size_t argv_len = 0;
+static char **argv1_addr = NULL;
 #endif
 
 #endif /* HAVE_SETPROCTITLE */
@@ -119,7 +120,9 @@ compat_init_setproctitle(int argc, char https://github.com/ruby/ruby/blob/trunk/missing/setproctitle.c#L120
 			lastenvp = envp[i] + strlen(envp[i]);
 	}
 
-	argv[1] = NULL;
+	/* We keep argv[1], argv[2], etc. at this moment,
+	   because the ps command of AIX refers to them. */
+	argv1_addr = &argv[1];
 	argv_start = argv[0];
 	argv_len = lastargv - argv[0];
 	argv_env_len = lastenvp - argv[0];
@@ -162,6 +165,8 @@ setproctitle(const char *fmt, ...) https://github.com/ruby/ruby/blob/trunk/missing/setproctitle.c#L165
 	argvlen = len > argv_len ? argv_env_len : argv_len;
 	for(; len < argvlen; len++)
 		argv_start[len] = SPT_PADCHAR;
+	/* argv[1], argv[2], etc. are no longer valid. */
+	*argv1_addr = NULL;
 #endif
 
 #endif /* SPT_NONE */

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]