[#35446] [Ruby 1.9 - Bug #4477][Open] Kernel:exec and backtick (`) don't work for certain system commands — Joachim Wuttke <j.wuttke@...>

10 messages 2011/03/07

[#35476] [Ruby 1.9 - Bug #4489][Open] [PATCH] Encodings with /-(unix|dos|mac)\Z/ — "James M. Lawrence" <quixoticsycophant@...>

20 messages 2011/03/10

[#35552] [Ruby 1.9 - Feature #4523][Open] Kernel#require to return the path of the loaded file — Alex Young <alex@...>

14 messages 2011/03/24

[#35565] [Ruby 1.9 - Feature #4531][Open] [PATCH 0/7] use poll() instead of select() in certain cases — Eric Wong <normalperson@...>

33 messages 2011/03/28

[#35566] [Ruby 1.9 - Feature #4532][Open] [PATCH] add IO#pread and IO#pwrite methods — Eric Wong <normalperson@...>

12 messages 2011/03/28

[#35586] [Ruby 1.9 - Feature #4538][Open] [PATCH (cleanup)] avoid unnecessary select() calls before doing I/O — Eric Wong <normalperson@...>

9 messages 2011/03/29

[ruby-core:35496] Re: /proc/$PID/environ in Linux

From: Eric Wong <normalperson@...>
Date: 2011-03-14 19:39:17 UTC
List: ruby-core #35496
KOSAKI Motohiro <kosaki.motohiro@gmail.com> wrote:
> > @@ -1810,6 +1822,14 @@ set_arg0(VALUE val, ID id)
> >     setproctitle("%.*s", (int)i, s);
> >  #else
> >
> > +# ifdef USE_ENVSPACE_FOR_ARG0
> > +    if (envspace_capa > 0 && (size_t)i > origarg.len - origarg.argc) {
> > +       move_environ();
> > +       origarg.len += envspace_capa;
> > +       envspace_capa = 0;
> > +    }
> > +# endif
> 
> No. this is thread unsafe. therefore it is MVM unsafe.
> I don't want to increase MVM unsafe code anymore.
> 
> Please simply do lazy zero fill, not environemt moving itself.

Checking origarg.len/envspace_capa and modifying them wouldn't be
thread-safe without a lock, either, wouldn't it?

I think the entire hunk that cares for origarg.len will need
a lock around it for MVM.

Here's an updated patch without locks for now:

From 3074f19907648e25fd5d3a6162e355a5b7073d84 Mon Sep 17 00:00:00 2001
From: Eric Wong <normalperson@yhbt.net>
Date: Sun, 13 Mar 2011 08:39:15 +0000
Subject: [PATCH] ruby.c: avoid clobbering environ for $0 changes

This allows /proc/<pid>/environ on Linux to remain useful
for minor $0 modifications.  This is especially useful for
Ruby because argv storage space is inflated from shebang
usage so there's less need for environ space.

I've only tested this on Linux 2.6
---
 ruby.c |   11 +++++++++++
 1 files changed, 11 insertions(+), 0 deletions(-)

diff --git a/ruby.c b/ruby.c
index c5d46ed..16640b6 100644
--- a/ruby.c
+++ b/ruby.c
@@ -1733,6 +1733,7 @@ rb_load_file(const char *fname)
 
 #ifdef USE_ENVSPACE_FOR_ARG0
 extern char **environ;
+static size_t envspace_capa;
 #endif
 
 static size_t
@@ -1755,6 +1756,7 @@ get_arglen(int argc, char **argv)
     }
 #if defined(USE_ENVSPACE_FOR_ARG0)
     if (environ && (s+1 == environ[0])) {
+	char *pre_env = s;
 	s++;
 	s += strlen(s);
 	for (i = 1; environ[i]; i++) {
@@ -1776,6 +1778,8 @@ get_arglen(int argc, char **argv)
 # else
 	ruby_setenv("", NULL); /* duplicate environ vars */
 # endif
+	envspace_capa = s - pre_env;
+	s = pre_env;
     }
 #endif
     return s - argv[0];
@@ -1810,6 +1814,13 @@ set_arg0(VALUE val, ID id)
     setproctitle("%.*s", (int)i, s);
 #else
 
+# ifdef USE_ENVSPACE_FOR_ARG0
+    if (envspace_capa > 0 && (size_t)i > origarg.len - origarg.argc) {
+	origarg.len += envspace_capa;
+	envspace_capa = 0;
+    }
+# endif
+
     if ((size_t)i > origarg.len - origarg.argc) {
 	i = (long)(origarg.len - origarg.argc);
     }
-- 
Eric Wong

In This Thread

Prev Next