From 4264ca9436a7b1496dbd6c9ca6e2e043f0c48630 Mon Sep 17 00:00:00 2001 From: nobu Date: Wed, 7 May 2008 21:43:54 +0000 Subject: * dln.c (dln_find_exe_r, dln_find_file_r): reentrant versions. * file.c (rb_find_file_ext, rb_find_file), process.c (proc_exec_v), (rb_proc_exec, proc_spawn_v, proc_spawn), ruby.c (process_options): use reentrant versions. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@16319 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 8 ++++++++ dln.c | 29 +++++++++++++++++++++-------- dln.h | 2 ++ file.c | 6 ++++-- process.c | 25 ++++++++++++++++++------- ruby.c | 5 +++-- 6 files changed, 56 insertions(+), 19 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9912afe81e..b379ee0bec 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +Thu May 8 06:43:52 2008 Nobuyoshi Nakada + + * dln.c (dln_find_exe_r, dln_find_file_r): reentrant versions. + + * file.c (rb_find_file_ext, rb_find_file), process.c (proc_exec_v), + (rb_proc_exec, proc_spawn_v, proc_spawn), ruby.c (process_options): + use reentrant versions. + Thu May 8 06:27:33 2008 Nobuyoshi Nakada * thread.c (rb_thread_key_p): thread local storage stores ID. diff --git a/dln.c b/dln.c index 33b912d384..13f6e29e61 100644 --- a/dln.c +++ b/dln.c @@ -1568,10 +1568,10 @@ dln_load(const char *file) return 0; /* dummy return */ } -static char *dln_find_1(const char *fname, const char *path, int exe_flag); +static char *dln_find_1(const char *fname, const char *path, char *buf, int size, int exe_flag); char * -dln_find_exe(const char *fname, const char *path) +dln_find_exe_r(const char *fname, const char *path, char *buf, int size) { if (!path) { path = getenv(PATH_ENV); @@ -1584,25 +1584,38 @@ dln_find_exe(const char *fname, const char *path) path = "/usr/local/bin:/usr/ucb:/usr/bin:/bin:."; #endif } - return dln_find_1(fname, path, 1); + return dln_find_1(fname, path, buf, size, 1); } char * -dln_find_file(const char *fname, const char *path) +dln_find_file_r(const char *fname, const char *path, char *buf, int size) { #ifndef __MACOS__ if (!path) path = "."; - return dln_find_1(fname, path, 0); + return dln_find_1(fname, path, buf, size, 0); #else if (!path) path = "."; - return _macruby_path_conv_posix_to_macos(dln_find_1(fname, path, 0)); + return _macruby_path_conv_posix_to_macos(dln_find_1(fname, path, buf, size, 0)); #endif } static char fbuf[MAXPATHLEN]; +char * +dln_find_exe(const char *fname, const char *path) +{ + return dln_find_exe_r(fname, path, fbuf, sizeof(fbuf)); +} + +char * +dln_find_file(const char *fname, const char *path) +{ + return dln_find_file_r(fname, path, fbuf, sizeof(fbuf)); +} + static char * -dln_find_1(const char *fname, const char *path, int exe_flag /* non 0 if looking for executable. */) +dln_find_1(const char *fname, const char *path, char *fbuf, int size, + int exe_flag /* non 0 if looking for executable. */) { register const char *dp; register const char *ep; @@ -1642,7 +1655,7 @@ dln_find_1(const char *fname, const char *path, int exe_flag /* non 0 if looking /* find the length of that component */ l = ep - dp; bp = fbuf; - fspace = sizeof fbuf - 2; + fspace = size - 2; if (l > 0) { /* ** If the length of the component is zero length, diff --git a/dln.h b/dln.h index 90d76aa90a..aee4c8fe43 100644 --- a/dln.h +++ b/dln.h @@ -30,6 +30,8 @@ char *dln_find_exe(const char*,const char*); char *dln_find_file(const char*,const char*); +char *dln_find_exe_r(const char*,const char*,char*,int); +char *dln_find_file_r(const char*,const char*,char*,int); #ifdef USE_DLN_A_OUT extern char *dln_argv0; diff --git a/file.c b/file.c index 4c51c171e8..c614a7e380 100644 --- a/file.c +++ b/file.c @@ -4334,11 +4334,12 @@ rb_find_file_ext(VALUE *filep, const char *const *ext) OBJ_FREEZE(fname); for (i = 0; i < RARRAY_LEN(load_path); i++) { VALUE str = RARRAY_PTR(load_path)[i]; + char fbuf[MAXPATHLEN]; FilePathValue(str); if (RSTRING_LEN(str) == 0) continue; path = RSTRING_PTR(str); - found = dln_find_file(StringValueCStr(fname), path); + found = dln_find_file_r(StringValueCStr(fname), path, fbuf, sizeof(fbuf)); if (found && file_load_ok(found)) { *filep = rb_str_new2(found); return j+1; @@ -4354,6 +4355,7 @@ rb_find_file(VALUE path) VALUE tmp, load_path; char *f = StringValueCStr(path); char *lpath; + char fbuf[MAXPATHLEN]; if (f[0] == '~') { path = rb_file_expand_path(path, Qnil); @@ -4411,7 +4413,7 @@ rb_find_file(VALUE path) if (!lpath) { return 0; /* no path, no load */ } - if (!(f = dln_find_file(f, lpath))) { + if (!(f = dln_find_file_r(f, lpath, fbuf, sizeof(fbuf)))) { return 0; } if (rb_safe_level() >= 1 && !fpath_check(f)) { diff --git a/process.c b/process.c index 0958eeba6e..58bd08b81f 100644 --- a/process.c +++ b/process.c @@ -51,6 +51,12 @@ struct timeval rb_time_interval(VALUE); #ifdef HAVE_SYS_RESOURCE_H # include #endif +#ifdef HAVE_SYS_PARAM_H +# include +#endif +#ifndef MAXPATHLEN +# define MAXPATHLEN 1024 +#endif #include "ruby/st.h" #ifdef __EMX__ @@ -963,7 +969,7 @@ void rb_thread_reset_timer_thread(void); #define after_exec() \ (rb_thread_start_timer_thread(), rb_disable_interrupt()) -extern char *dln_find_exe(const char *fname, const char *path); +#include "dln.h" static void security(const char *str) @@ -978,9 +984,11 @@ security(const char *str) static int proc_exec_v(char **argv, const char *prog) { + char fbuf[MAXPATHLEN]; + if (!prog) prog = argv[0]; - prog = dln_find_exe(prog, 0); + prog = dln_find_exe_r(prog, 0, fbuf, sizeof(fbuf)); if (!prog) { errno = ENOENT; return -1; @@ -1015,7 +1023,7 @@ proc_exec_v(char **argv, const char *prog) *p = '\\'; new_argv[0] = COMMAND; argv = new_argv; - prog = dln_find_exe(argv[0], 0); + prog = dln_find_exe_r(argv[0], 0, fbuf, sizeof(fbuf)); if (!prog) { errno = ENOENT; return -1; @@ -1081,7 +1089,8 @@ rb_proc_exec(const char *str) if (status != -1) exit(status); #elif defined(__human68k__) || defined(__CYGWIN32__) || defined(__EMX__) - char *shell = dln_find_exe("sh", 0); + char fbuf[MAXPATHLEN]; + char *shell = dln_find_exe_r("sh", 0, fbuf, sizeof(fbuf)); int status = -1; before_exec(); if (shell) @@ -1128,13 +1137,14 @@ rb_proc_exec(const char *str) static rb_pid_t proc_spawn_v(char **argv, char *prog) { + char fbuf[MAXPATHLEN]; char *extension; rb_pid_t status; if (!prog) prog = argv[0]; security(prog); - prog = dln_find_exe(prog, 0); + prog = dln_find_exe_r(prog, 0, fbuf, sizeof(fbuf)); if (!prog) return -1; @@ -1155,7 +1165,7 @@ proc_spawn_v(char **argv, char *prog) *p = '\\'; new_argv[0] = COMMAND; argv = new_argv; - prog = dln_find_exe(argv[0], 0); + prog = dln_find_exe_r(argv[0], 0, fbuf, sizeof(fbuf)); if (!prog) { errno = ENOENT; return -1; @@ -1192,13 +1202,14 @@ proc_spawn_n(int argc, VALUE *argv, VALUE prog) static rb_pid_t proc_spawn(char *str) { + char fbuf[MAXPATHLEN]; char *s, *t; char **argv, **a; rb_pid_t status; for (s = str; *s; s++) { if (*s != ' ' && !ISALPHA(*s) && strchr("*?{}[]<>()~&|\\$;'`\"\n",*s)) { - char *shell = dln_find_exe("sh", 0); + char *shell = dln_find_exe_r("sh", 0, fbuf, sizeof(fbuf)); before_exec(); status = shell?spawnl(P_WAIT,shell,"sh","-c",str,(char*)NULL):system(str); rb_last_status_set(status == -1 ? 127 : status, 0); diff --git a/ruby.c b/ruby.c index a0636e3ca7..be0af70aa5 100644 --- a/ruby.c +++ b/ruby.c @@ -953,6 +953,7 @@ process_options(VALUE arg) VALUE parser; rb_encoding *enc, *lenc; const char *s; + char fbuf[MAXPATHLEN]; int i = proc_options(argc, argv, opt); int safe; @@ -1033,10 +1034,10 @@ process_options(VALUE arg) opt->script = 0; if (path) { - opt->script = dln_find_file(argv[0], path); + opt->script = dln_find_file_r(argv[0], path, fbuf, sizeof(fbuf)); } if (!opt->script) { - opt->script = dln_find_file(argv[0], getenv(PATH_ENV)); + opt->script = dln_find_file_r(argv[0], getenv(PATH_ENV), fbuf, sizeof(fbuf)); } if (!opt->script) opt->script = argv[0]; -- cgit v1.2.1