mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* io.c (rb_io_reopen): should clear allocated OpenFile. pointed
out by Guy Decoux. [ruby-core:03288] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6781 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
4af25f5813
commit
67232b2151
6 changed files with 66 additions and 8 deletions
|
@ -418,7 +418,7 @@ AC_CHECK_FUNCS(fmod killpg wait4 waitpid fork spawnv syscall chroot fsync getcwd
|
|||
getpgrp setpgrp getpgid setpgid initgroups getgroups setgroups\
|
||||
getpriority getrlimit dlopen sigprocmask sigaction _setjmp\
|
||||
setsid telldir seekdir fchmod mktime timegm cosh sinh tanh\
|
||||
setuid setgid)
|
||||
setuid setgid daemon)
|
||||
AC_ARG_ENABLE(setreuid,
|
||||
[ --enable-setreuid use setreuid()/setregid() according to need even if obsolete.],
|
||||
[use_setreuid=$enableval])
|
||||
|
|
2
io.c
2
io.c
|
@ -3369,6 +3369,7 @@ rb_io_reopen(argc, argv, file)
|
|||
fptr = RFILE(file)->fptr;
|
||||
if (!fptr) {
|
||||
fptr = RFILE(file)->fptr = ALLOC(OpenFile);
|
||||
MEMZERO(fptr, OpenFile, 1);
|
||||
}
|
||||
|
||||
if (!NIL_P(nmode)) {
|
||||
|
@ -3392,7 +3393,6 @@ rb_io_reopen(argc, argv, file)
|
|||
fclose(fptr->f2);
|
||||
fptr->f2 = 0;
|
||||
}
|
||||
|
||||
return file;
|
||||
}
|
||||
|
||||
|
|
|
@ -871,6 +871,7 @@ r_bytes0(len, arg)
|
|||
{
|
||||
VALUE str;
|
||||
|
||||
if (len == 0) return rb_str_new(0, 0);
|
||||
if (!arg->end) {
|
||||
VALUE src = (VALUE)arg->ptr;
|
||||
VALUE n = LONG2NUM(len);
|
||||
|
|
|
@ -779,7 +779,7 @@ An end of a defun is found by moving forward from the beginning of one."
|
|||
(if done
|
||||
(save-excursion
|
||||
(back-to-indentation)
|
||||
(if (looking-at (concat ("\\<\\(" ruby-block-mid-re "\\)\\>")))
|
||||
(if (looking-at (concat "\\<\\(" ruby-block-mid-re "\\)\\>"))
|
||||
(setq done nil))))))
|
||||
(back-to-indentation))
|
||||
|
||||
|
|
56
process.c
56
process.c
|
@ -2663,6 +2663,60 @@ proc_setmaxgroups(obj, val)
|
|||
return INT2FIX(maxgroups);
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* Process.daemon() => fixnum
|
||||
* Process.daemon(nochdir=0,noclose=0) => fixnum
|
||||
*
|
||||
* Detach the process from controlling terminal and run in
|
||||
* the background as system daemon. Unless the argument
|
||||
* nochdir is true (i.e. non false), it changes the current
|
||||
* working directory to the root ("/"). Unless the argument
|
||||
* noclose is true, daemon() will redirect standard input,
|
||||
* standard output and standard error to /dev/null.
|
||||
*/
|
||||
|
||||
static VALUE
|
||||
proc_daemon(argc, argv)
|
||||
int argc;
|
||||
VALUE *argv;
|
||||
{
|
||||
VALUE nochdir, noclose;
|
||||
int n;
|
||||
|
||||
rb_scan_args(argc, argv, "02", &nochdir, &noclose);
|
||||
|
||||
#if defined(HAVE_DAEMON)
|
||||
n = daemon(RTEST(nochdir), RTEST(noclose));
|
||||
if (n < 0) rb_sys_fail("daemon");
|
||||
return INT2FIX(n);
|
||||
#elif defined(HAVE_FORK)
|
||||
switch (rb_fork(0, 0, 0)) {
|
||||
case -1:
|
||||
return (-1);
|
||||
case 0:
|
||||
break;
|
||||
default:
|
||||
_exit(0);
|
||||
}
|
||||
|
||||
proc_setsid();
|
||||
|
||||
if (!RTEST(nochdir))
|
||||
(void)chdir("/");
|
||||
|
||||
if (!RTEST(noclose) && (n = open("/dev/null", O_RDWR, 0)) != -1) {
|
||||
(void)dup2(n, 0);
|
||||
(void)dup2(n, 1);
|
||||
(void)dup2(n, 2);
|
||||
if (n > 2)
|
||||
(void)close (n);
|
||||
}
|
||||
return INT2FIX(0);
|
||||
#else
|
||||
rb_notimplement();
|
||||
#endif
|
||||
}
|
||||
|
||||
/********************************************************************
|
||||
*
|
||||
|
@ -3543,6 +3597,8 @@ Init_process()
|
|||
rb_define_module_function(rb_mProcess, "maxgroups", proc_getmaxgroups, 0);
|
||||
rb_define_module_function(rb_mProcess, "maxgroups=", proc_setmaxgroups, 1);
|
||||
|
||||
rb_define_module_function(rb_mProcess, "daemon", proc_daemon, -1);
|
||||
|
||||
rb_define_module_function(rb_mProcess, "times", rb_proc_times, 0);
|
||||
|
||||
#if defined(HAVE_TIMES) || defined(_WIN32)
|
||||
|
|
11
string.c
11
string.c
|
@ -1079,10 +1079,10 @@ rb_str_index_m(argc, argv, str)
|
|||
{
|
||||
int c = FIX2INT(sub);
|
||||
long len = RSTRING(str)->len;
|
||||
unsigned char *p = RSTRING(str)->ptr;
|
||||
char *p = RSTRING(str)->ptr;
|
||||
|
||||
for (;pos<len;pos++) {
|
||||
if (p[pos] == c) return LONG2NUM(pos);
|
||||
if ((unsigned char)p[pos] == c) return LONG2NUM(pos);
|
||||
}
|
||||
return Qnil;
|
||||
}
|
||||
|
@ -1201,15 +1201,16 @@ rb_str_rindex_m(argc, argv, str)
|
|||
case T_FIXNUM:
|
||||
{
|
||||
int c = FIX2INT(sub);
|
||||
unsigned char *p = RSTRING(str)->ptr + pos;
|
||||
unsigned char *pbeg = RSTRING(str)->ptr;
|
||||
char *p = RSTRING(str)->ptr + pos;
|
||||
char *pbeg = RSTRING(str)->ptr;
|
||||
|
||||
if (pos == RSTRING(str)->len) {
|
||||
if (pos == 0) return Qnil;
|
||||
--p;
|
||||
}
|
||||
while (pbeg <= p) {
|
||||
if (*p == c) return LONG2NUM((char*)p - RSTRING(str)->ptr);
|
||||
if ((unsigned char)*p == c)
|
||||
return LONG2NUM((char*)p - RSTRING(str)->ptr);
|
||||
p--;
|
||||
}
|
||||
return Qnil;
|
||||
|
|
Loading…
Reference in a new issue