mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* 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
This commit is contained in:
parent
86afcfe402
commit
4264ca9436
6 changed files with 56 additions and 19 deletions
|
@ -1,3 +1,11 @@
|
||||||
|
Thu May 8 06:43:52 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
|
* 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 <nobu@ruby-lang.org>
|
Thu May 8 06:27:33 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
* thread.c (rb_thread_key_p): thread local storage stores ID.
|
* thread.c (rb_thread_key_p): thread local storage stores ID.
|
||||||
|
|
29
dln.c
29
dln.c
|
@ -1568,10 +1568,10 @@ dln_load(const char *file)
|
||||||
return 0; /* dummy return */
|
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 *
|
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) {
|
if (!path) {
|
||||||
path = getenv(PATH_ENV);
|
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:.";
|
path = "/usr/local/bin:/usr/ucb:/usr/bin:/bin:.";
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
return dln_find_1(fname, path, 1);
|
return dln_find_1(fname, path, buf, size, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
char *
|
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__
|
#ifndef __MACOS__
|
||||||
if (!path) path = ".";
|
if (!path) path = ".";
|
||||||
return dln_find_1(fname, path, 0);
|
return dln_find_1(fname, path, buf, size, 0);
|
||||||
#else
|
#else
|
||||||
if (!path) path = ".";
|
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
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static char fbuf[MAXPATHLEN];
|
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 *
|
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 *dp;
|
||||||
register const char *ep;
|
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 */
|
/* find the length of that component */
|
||||||
l = ep - dp;
|
l = ep - dp;
|
||||||
bp = fbuf;
|
bp = fbuf;
|
||||||
fspace = sizeof fbuf - 2;
|
fspace = size - 2;
|
||||||
if (l > 0) {
|
if (l > 0) {
|
||||||
/*
|
/*
|
||||||
** If the length of the component is zero length,
|
** If the length of the component is zero length,
|
||||||
|
|
2
dln.h
2
dln.h
|
@ -30,6 +30,8 @@
|
||||||
|
|
||||||
char *dln_find_exe(const char*,const char*);
|
char *dln_find_exe(const char*,const char*);
|
||||||
char *dln_find_file(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
|
#ifdef USE_DLN_A_OUT
|
||||||
extern char *dln_argv0;
|
extern char *dln_argv0;
|
||||||
|
|
6
file.c
6
file.c
|
@ -4334,11 +4334,12 @@ rb_find_file_ext(VALUE *filep, const char *const *ext)
|
||||||
OBJ_FREEZE(fname);
|
OBJ_FREEZE(fname);
|
||||||
for (i = 0; i < RARRAY_LEN(load_path); i++) {
|
for (i = 0; i < RARRAY_LEN(load_path); i++) {
|
||||||
VALUE str = RARRAY_PTR(load_path)[i];
|
VALUE str = RARRAY_PTR(load_path)[i];
|
||||||
|
char fbuf[MAXPATHLEN];
|
||||||
|
|
||||||
FilePathValue(str);
|
FilePathValue(str);
|
||||||
if (RSTRING_LEN(str) == 0) continue;
|
if (RSTRING_LEN(str) == 0) continue;
|
||||||
path = RSTRING_PTR(str);
|
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)) {
|
if (found && file_load_ok(found)) {
|
||||||
*filep = rb_str_new2(found);
|
*filep = rb_str_new2(found);
|
||||||
return j+1;
|
return j+1;
|
||||||
|
@ -4354,6 +4355,7 @@ rb_find_file(VALUE path)
|
||||||
VALUE tmp, load_path;
|
VALUE tmp, load_path;
|
||||||
char *f = StringValueCStr(path);
|
char *f = StringValueCStr(path);
|
||||||
char *lpath;
|
char *lpath;
|
||||||
|
char fbuf[MAXPATHLEN];
|
||||||
|
|
||||||
if (f[0] == '~') {
|
if (f[0] == '~') {
|
||||||
path = rb_file_expand_path(path, Qnil);
|
path = rb_file_expand_path(path, Qnil);
|
||||||
|
@ -4411,7 +4413,7 @@ rb_find_file(VALUE path)
|
||||||
if (!lpath) {
|
if (!lpath) {
|
||||||
return 0; /* no path, no load */
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
if (rb_safe_level() >= 1 && !fpath_check(f)) {
|
if (rb_safe_level() >= 1 && !fpath_check(f)) {
|
||||||
|
|
25
process.c
25
process.c
|
@ -51,6 +51,12 @@ struct timeval rb_time_interval(VALUE);
|
||||||
#ifdef HAVE_SYS_RESOURCE_H
|
#ifdef HAVE_SYS_RESOURCE_H
|
||||||
# include <sys/resource.h>
|
# include <sys/resource.h>
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef HAVE_SYS_PARAM_H
|
||||||
|
# include <sys/param.h>
|
||||||
|
#endif
|
||||||
|
#ifndef MAXPATHLEN
|
||||||
|
# define MAXPATHLEN 1024
|
||||||
|
#endif
|
||||||
#include "ruby/st.h"
|
#include "ruby/st.h"
|
||||||
|
|
||||||
#ifdef __EMX__
|
#ifdef __EMX__
|
||||||
|
@ -963,7 +969,7 @@ void rb_thread_reset_timer_thread(void);
|
||||||
#define after_exec() \
|
#define after_exec() \
|
||||||
(rb_thread_start_timer_thread(), rb_disable_interrupt())
|
(rb_thread_start_timer_thread(), rb_disable_interrupt())
|
||||||
|
|
||||||
extern char *dln_find_exe(const char *fname, const char *path);
|
#include "dln.h"
|
||||||
|
|
||||||
static void
|
static void
|
||||||
security(const char *str)
|
security(const char *str)
|
||||||
|
@ -978,9 +984,11 @@ security(const char *str)
|
||||||
static int
|
static int
|
||||||
proc_exec_v(char **argv, const char *prog)
|
proc_exec_v(char **argv, const char *prog)
|
||||||
{
|
{
|
||||||
|
char fbuf[MAXPATHLEN];
|
||||||
|
|
||||||
if (!prog)
|
if (!prog)
|
||||||
prog = argv[0];
|
prog = argv[0];
|
||||||
prog = dln_find_exe(prog, 0);
|
prog = dln_find_exe_r(prog, 0, fbuf, sizeof(fbuf));
|
||||||
if (!prog) {
|
if (!prog) {
|
||||||
errno = ENOENT;
|
errno = ENOENT;
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -1015,7 +1023,7 @@ proc_exec_v(char **argv, const char *prog)
|
||||||
*p = '\\';
|
*p = '\\';
|
||||||
new_argv[0] = COMMAND;
|
new_argv[0] = COMMAND;
|
||||||
argv = new_argv;
|
argv = new_argv;
|
||||||
prog = dln_find_exe(argv[0], 0);
|
prog = dln_find_exe_r(argv[0], 0, fbuf, sizeof(fbuf));
|
||||||
if (!prog) {
|
if (!prog) {
|
||||||
errno = ENOENT;
|
errno = ENOENT;
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -1081,7 +1089,8 @@ rb_proc_exec(const char *str)
|
||||||
if (status != -1)
|
if (status != -1)
|
||||||
exit(status);
|
exit(status);
|
||||||
#elif defined(__human68k__) || defined(__CYGWIN32__) || defined(__EMX__)
|
#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;
|
int status = -1;
|
||||||
before_exec();
|
before_exec();
|
||||||
if (shell)
|
if (shell)
|
||||||
|
@ -1128,13 +1137,14 @@ rb_proc_exec(const char *str)
|
||||||
static rb_pid_t
|
static rb_pid_t
|
||||||
proc_spawn_v(char **argv, char *prog)
|
proc_spawn_v(char **argv, char *prog)
|
||||||
{
|
{
|
||||||
|
char fbuf[MAXPATHLEN];
|
||||||
char *extension;
|
char *extension;
|
||||||
rb_pid_t status;
|
rb_pid_t status;
|
||||||
|
|
||||||
if (!prog)
|
if (!prog)
|
||||||
prog = argv[0];
|
prog = argv[0];
|
||||||
security(prog);
|
security(prog);
|
||||||
prog = dln_find_exe(prog, 0);
|
prog = dln_find_exe_r(prog, 0, fbuf, sizeof(fbuf));
|
||||||
if (!prog)
|
if (!prog)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
|
@ -1155,7 +1165,7 @@ proc_spawn_v(char **argv, char *prog)
|
||||||
*p = '\\';
|
*p = '\\';
|
||||||
new_argv[0] = COMMAND;
|
new_argv[0] = COMMAND;
|
||||||
argv = new_argv;
|
argv = new_argv;
|
||||||
prog = dln_find_exe(argv[0], 0);
|
prog = dln_find_exe_r(argv[0], 0, fbuf, sizeof(fbuf));
|
||||||
if (!prog) {
|
if (!prog) {
|
||||||
errno = ENOENT;
|
errno = ENOENT;
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -1192,13 +1202,14 @@ proc_spawn_n(int argc, VALUE *argv, VALUE prog)
|
||||||
static rb_pid_t
|
static rb_pid_t
|
||||||
proc_spawn(char *str)
|
proc_spawn(char *str)
|
||||||
{
|
{
|
||||||
|
char fbuf[MAXPATHLEN];
|
||||||
char *s, *t;
|
char *s, *t;
|
||||||
char **argv, **a;
|
char **argv, **a;
|
||||||
rb_pid_t status;
|
rb_pid_t status;
|
||||||
|
|
||||||
for (s = str; *s; s++) {
|
for (s = str; *s; s++) {
|
||||||
if (*s != ' ' && !ISALPHA(*s) && strchr("*?{}[]<>()~&|\\$;'`\"\n",*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();
|
before_exec();
|
||||||
status = shell?spawnl(P_WAIT,shell,"sh","-c",str,(char*)NULL):system(str);
|
status = shell?spawnl(P_WAIT,shell,"sh","-c",str,(char*)NULL):system(str);
|
||||||
rb_last_status_set(status == -1 ? 127 : status, 0);
|
rb_last_status_set(status == -1 ? 127 : status, 0);
|
||||||
|
|
5
ruby.c
5
ruby.c
|
@ -953,6 +953,7 @@ process_options(VALUE arg)
|
||||||
VALUE parser;
|
VALUE parser;
|
||||||
rb_encoding *enc, *lenc;
|
rb_encoding *enc, *lenc;
|
||||||
const char *s;
|
const char *s;
|
||||||
|
char fbuf[MAXPATHLEN];
|
||||||
int i = proc_options(argc, argv, opt);
|
int i = proc_options(argc, argv, opt);
|
||||||
int safe;
|
int safe;
|
||||||
|
|
||||||
|
@ -1033,10 +1034,10 @@ process_options(VALUE arg)
|
||||||
|
|
||||||
opt->script = 0;
|
opt->script = 0;
|
||||||
if (path) {
|
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) {
|
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)
|
if (!opt->script)
|
||||||
opt->script = argv[0];
|
opt->script = argv[0];
|
||||||
|
|
Loading…
Add table
Reference in a new issue