aboutsummaryrefslogtreecommitdiffstats
path: root/ruby-runner.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-05-29 06:39:41 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-05-29 06:39:41 +0000
commitcfca9553c5b108e47a3af2b93bb6e4f3f2b852ff (patch)
tree76a1d998a945ad696f9196058d79b358cb59e5f8 /ruby-runner.c
parent311a552c1d8914066a530cd6ca883689361eab59 (diff)
downloadruby-cfca9553c5b108e47a3af2b93bb6e4f3f2b852ff.tar.gz
ruby-runner.c: replace argv[0]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58950 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ruby-runner.c')
-rw-r--r--ruby-runner.c26
1 files changed, 21 insertions, 5 deletions
diff --git a/ruby-runner.c b/ruby-runner.c
index c16e7c6829..f44a02bcc7 100644
--- a/ruby-runner.c
+++ b/ruby-runner.c
@@ -12,6 +12,11 @@ int
main(int argc, char **argv)
{
static const char builddir[] = BUILDDIR;
+ static const char rubypath[] = BUILDDIR"/"STRINGIZE(RUBY_INSTALL_NAME);
+ const size_t dirsize = sizeof(builddir);
+ const size_t namesize = sizeof(rubypath) - dirsize;
+ const char *rubyname = rubypath + dirsize;
+ char *arg0 = argv[0], *p;
const char *libpath = getenv(LIBPATHENV);
char c = 0;
@@ -20,16 +25,27 @@ main(int argc, char **argv)
}
if (c) {
size_t n = strlen(libpath);
- char *e = malloc(sizeof(builddir)+n+1);
- memcpy(e, builddir, sizeof(builddir)-1);
- e[sizeof(builddir)-1] = PATH_SEP;
- memcpy(e+sizeof(builddir), libpath, n+1);
+ char *e = malloc(dirsize+n+1);
+ memcpy(e, builddir, dirsize-1);
+ e[dirsize-1] = PATH_SEP;
+ memcpy(e+dirsize, libpath, n+1);
libpath = e;
}
else {
libpath = builddir;
}
setenv(LIBPATHENV, libpath, 1);
- execv(BUILDDIR"/"STRINGIZE(RUBY_INSTALL_NAME), argv);
+
+ if (!(p = strrchr(arg0, '/'))) p = arg0; else p++;
+ if (strlen(p) < namesize - 1) {
+ argv[0] = malloc(p - arg0 + namesize);
+ memcpy(argv[0], arg0, p - arg0);
+ memcpy(argv[0] + (p - arg0), rubypath + dirsize, namesize);
+ }
+ else {
+ memcpy(p, rubyname, namesize);
+ }
+
+ execv(rubypath, argv);
return -1;
}