diff options
-rw-r--r-- | ChangeLog | 4 | ||||
-rw-r--r-- | cygwin/GNUmakefile.in | 17 | ||||
-rw-r--r-- | defs/gmake.mk | 33 | ||||
-rw-r--r-- | missing/setproctitle.c | 1 | ||||
-rw-r--r-- | rubystub.c | 57 | ||||
-rw-r--r-- | win32/Makefile.sub | 5 | ||||
-rw-r--r-- | win32/stub.c | 48 |
7 files changed, 99 insertions, 66 deletions
@@ -1,3 +1,7 @@ +Sat Aug 20 11:20:32 2016 Nobuyoshi Nakada <nobu@ruby-lang.org> + + * rubystub.c: generalize win32/stub.c. + Fri Aug 19 11:39:06 2016 Nobuyoshi Nakada <nobu@ruby-lang.org> * parse.y (primary): allow parenthesised statement as a method diff --git a/cygwin/GNUmakefile.in b/cygwin/GNUmakefile.in index e0d727e303..2f93102efe 100644 --- a/cygwin/GNUmakefile.in +++ b/cygwin/GNUmakefile.in @@ -13,9 +13,6 @@ else DLL_BASE_NAME := $(RUBY_SO_NAME) DLLWRAP += -mno-cygwin VPATH := $(VPATH):$(srcdir)/win32 - STUBPROGRAM = rubystub$(EXEEXT) - IGNOREDPATTERNS = %~ .% %.orig %.rej \#%\# - SCRIPTPROGRAMS = $(addsuffix $(EXEEXT),$(filter-out $(IGNOREDPATTERNS),$(notdir $(wildcard $(srcdir)/bin/*)))) endif ifneq ($(ENABLE_SHARED),yes) @@ -44,13 +41,6 @@ RUBYDEF = $(DLL_BASE_NAME).def ruby: $(PROGRAM) rubyw: $(WPROGRAM) -stub: $(STUBPROGRAM) -scriptbin: $(SCRIPTPROGRAMS) - -%$(EXEEXT): bin/% $(STUBPROGRAM) - $(ECHO) generating $@ - $(Q) { cat $(STUBPROGRAM); echo; sed -e '1{' -e '/^#!.*ruby/!i\' -e '#!/bin/ruby' -e '}' $<; } > $@ - $(Q) chmod +x $@ $(LIBRUBY): $(RUBY_EXP) $(LIBRUBY_SO) $(RUBY_EXP) $(LIBRUBY_SO): $(DLL_BASE_NAME).res.@OBJEXT@ @@ -72,12 +62,7 @@ $(WPROGRAM): $(RUBYW_INSTALL_NAME).res.@OBJEXT@ $(ECHO) linking $@ $(Q) $(PURIFY) $(CC) -mwindows -e $(SYMBOL_PREFIX)mainCRTStartup $(LDFLAGS) $(XLDFLAGS) \ $(MAINOBJ) $(EXTOBJS) $(LIBRUBYARG) $(LIBS) -o $@ -$(STUBPROGRAM): $(RUBY_INSTALL_NAME).res.@OBJEXT@ win32/stub.@OBJEXT@ - @rm -f $@ - $(ECHO) linking $@ - $(Q) $(PURIFY) $(CC) $(LDFLAGS) $(XLDFLAGS) \ - win32/stub.@OBJEXT@ $(EXTOBJS) $(LIBRUBYARG) $(LIBS) -o $@ - $(if $(STRIP),$(Q) $(STRIP) $@) +$(STUBPROGRAM): $(RUBY_INSTALL_NAME).res.@OBJEXT@ $(RUBY_EXP): $(LIBRUBY_A) $(ECHO) creating $@ diff --git a/defs/gmake.mk b/defs/gmake.mk index 5220eb3583..2233627f8c 100644 --- a/defs/gmake.mk +++ b/defs/gmake.mk @@ -92,3 +92,36 @@ else $(Q) mv $@.new $@ $(Q) $(RMALL) make_des_table* endif + +STUBPROGRAM = rubystub$(EXEEXT) +IGNOREDPATTERNS = %~ .% %.orig %.rej \#%\# +SCRIPTBINDIR := $(if $(EXEEXT),,exec/) +SCRIPTPROGRAMS = $(addprefix $(SCRIPTBINDIR),$(addsuffix $(EXEEXT),$(filter-out $(IGNOREDPATTERNS),$(notdir $(wildcard $(srcdir)/bin/*))))) + +stub: $(STUBPROGRAM) +scriptbin: $(SCRIPTPROGRAMS) +ifneq ($(STUBPROGRAM),rubystub) +rubystub: $(STUBPROGRAM) +endif + +$(SCRIPTPROGRAMS): $(STUBPROGRAM) + +$(STUBPROGRAM): rubystub.$(OBJEXT) $(LIBRUBY) $(MAINOBJ) $(OBJS) $(EXTOBJS) $(SETUP) $(PREP) + +rubystub$(EXEEXT): + @rm -f $@ + $(ECHO) linking $@ + $(Q) $(PURIFY) $(CC) $(LDFLAGS) $(XLDFLAGS) rubystub.$(OBJEXT) $(EXTOBJS) $(LIBRUBYARG) $(MAINLIBS) $(LIBS) $(EXTLIBS) $(OUTFLAG)$@ + $(Q) $(POSTLINK) + $(if $(STRIP),$(Q) $(STRIP) $@) + +$(SCRIPTBINDIR)%$(EXEEXT): bin/% $(STUBPROGRAM) \ + $(if $(SCRIPTBINDIR),$(TIMESTAMPDIR)/.exec.time) + $(ECHO) generating $@ + $(Q) { cat $(STUBPROGRAM); echo; sed -e '1{' -e '/^#!.*ruby/!i\' -e '#!/bin/ruby' -e '}' $<; } > $@ + $(Q) chmod +x $@ + $(Q) $(POSTLINK) + +$(TIMESTAMPDIR)/.exec.time: + $(Q) mkdir exec + $(Q) exit > $@ diff --git a/missing/setproctitle.c b/missing/setproctitle.c index 602ddf105c..9fceeee52b 100644 --- a/missing/setproctitle.c +++ b/missing/setproctitle.c @@ -35,6 +35,7 @@ #include "ruby.h" #include "ruby/util.h" #define compat_init_setproctitle ruby_init_setproctitle +RUBY_FUNC_EXPORTED void ruby_init_setproctitle(int argc, char *argv[]); #ifndef HAVE_SETPROCTITLE diff --git a/rubystub.c b/rubystub.c new file mode 100644 index 0000000000..80b04d4b27 --- /dev/null +++ b/rubystub.c @@ -0,0 +1,57 @@ +#include "internal.h" +#if defined HAVE_DLADDR +#include <dlfcn.h> +#endif +static void* stub_options(int argc, char **argv); +#define ruby_options stub_options +#include <main.c> +#undef ruby_options + +void * +stub_options(int argc, char **argv) +{ + char xflag[] = "-x"; + char *xargv[4] = {NULL, xflag}; + char *cmd = argv[0]; + void *ret; + +#if defined __CYGWIN__ || defined _WIN32 + /* GetCommandLineW should contain the accessible path, + * use argv[0] as is */ +#elif defined __linux__ + { + char selfexe[MAXPATHLEN]; + ssize_t len = readlink("/proc/self/exe", selfexe, sizeof(selfexe)); + if (len < 0) { + perror("readlink(\"/proc/self/exe\")"); + return NULL; + } + selfexe[len] = '\0'; + cmd = selfexe; + } +#elif defined HAVE_DLADDR + { + Dl_info dli; + if (!dladdr(stub_options, &dli)) { + perror("dladdr"); + return NULL; + } + cmd = (char *)dli.dli_fname; + } +#endif + +#ifndef HAVE_SETPROCTITLE + /* argc and argv must be the original */ + ruby_init_setproctitle(argc, argv); +#endif + + /* set script with -x option */ + /* xargv[0] is NULL not to re-initialize setproctitle again */ + xargv[2] = cmd; + ret = ruby_options(3, xargv); + + /* set all arguments to ARGV */ + ruby_set_argv(argc - 1, argv + 1); + + return ret; +} diff --git a/win32/Makefile.sub b/win32/Makefile.sub index abe65997df..e3fae91c65 100644 --- a/win32/Makefile.sub +++ b/win32/Makefile.sub @@ -418,6 +418,7 @@ prog: config ruby: $(PROGRAM) rubyw: $(WPROGRAM) stub: $(STUBPROGRAM) +rubystub: $(STUBPROGRAM) !if !exist(enc/trans/newline.c) && exist($(srcdir)/enc/trans/newline.c) NEWLINE_C = $(srcdir)/enc/trans/newline.c @@ -1005,9 +1006,9 @@ $(WPROGRAM): $(MAINOBJ) $(WINMAINOBJ) $(LIBRUBY_SO) $(RUBYW_INSTALL_NAME).res !endif !if "$(STUBPROGRAM)" != "" -$(STUBPROGRAM): win32/stub.$(OBJEXT) $(LIBRUBY) $(LIBRUBY_SO) $(RUBY_INSTALL_NAME).res +$(STUBPROGRAM): rubystub.$(OBJEXT) $(LIBRUBY) $(LIBRUBY_SO) $(RUBY_INSTALL_NAME).res $(ECHO) linking $(@:\=/) - $(Q) $(PURIFY) $(CC) win32/stub.$(OBJEXT) $(RUBY_INSTALL_NAME).res \ + $(Q) $(PURIFY) $(CC) rubystub.$(OBJEXT) $(RUBY_INSTALL_NAME).res \ $(OUTFLAG)$@ $(LIBRUBYARG) -link $(LDFLAGS) $(XLDFLAGS) $(Q) $(LDSHARED_0) $(Q) $(LDSHARED_1) diff --git a/win32/stub.c b/win32/stub.c deleted file mode 100644 index 39bdcd9b05..0000000000 --- a/win32/stub.c +++ /dev/null @@ -1,48 +0,0 @@ -#include <ruby.h> -static void stub_sysinit(int *argc, char ***argv); -#define ruby_sysinit stub_sysinit -#include <main.c> -#undef ruby_sysinit - -void -stub_sysinit(int *argc, char ***argv) -{ - WCHAR exename[4096]; - size_t wlenexe, len0, lenall; - int lenexe; - int i, ac; - char **av, *p; - - wlenexe = (size_t)GetModuleFileNameW(NULL, exename, sizeof(exename) / sizeof(*exename)); - lenexe = WideCharToMultiByte(CP_UTF8, 0, exename, wlenexe, NULL, 0, NULL, NULL); - ruby_sysinit(argc, argv); - ac = *argc; - av = *argv; - len0 = strlen(av[0]) + 1; - lenall = 0; - for (i = 1; i < ac; ++i) { - lenall += strlen(av[i]) + 1; - } - av = realloc(av, lenall + len0 + (lenexe + 1) + sizeof(char *) * (i + 2)); - if (!av) { - perror("realloc command line"); - exit(-1); - } - *argv = av; - *argc = ++ac; - p = (char *)(av + i + 2); - memmove(p + len0 + lenexe + 1, (char *)(av + ac) + len0, lenall); - memmove(p, (char *)(av + ac), len0); - *av++ = p; - p += len0; - WideCharToMultiByte(CP_UTF8, 0, exename, wlenexe, p, lenexe, NULL, NULL); - p[lenexe] = '\0'; - *av++ = p; - p += lenexe + 1; - while (--i) { - *av++ = p; - p += strlen(p) + 1; - } - *av = NULL; -} - |