summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornagai <nagai@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-07-23 16:07:35 +0000
committernagai <nagai@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-07-23 16:07:35 +0000
commitfd46a1da0a41b7939424bc5a393027be7940908e (patch)
treec77c6520287d10d2abab0f6e119d8eb5d7e36a80
parent528b6c3f6470cc24d6d5d39f0b573c76a74cc5c9 (diff)
process.c : unify indentation
configure.in : add --enable-setreuid option tcltklib.c : TclTkIp.new accepts 'ip-name' and 'options' ( e.g. TclTkIp.new('FOO', '-geometry 500x200 -use 0x2200009') ) tk.rb : support arguments of TclTkIp.new ( see TkCore::IP_NAME, TkCore::IP_OPTS ) tk*.rb : preparations for multi-Tk interpreter support git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@4127 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--configure.in7
-rw-r--r--ext/tcltklib/tcltklib.c27
-rw-r--r--ext/tk/lib/tk.rb347
-rw-r--r--ext/tk/lib/tkafter.rb22
-rw-r--r--ext/tk/lib/tkbgerror.rb2
-rw-r--r--ext/tk/lib/tkcanvas.rb45
-rw-r--r--ext/tk/lib/tkconsole.rb2
-rw-r--r--ext/tk/lib/tkdialog.rb2
-rw-r--r--ext/tk/lib/tkentry.rb2
-rw-r--r--ext/tk/lib/tkfont.rb17
-rw-r--r--ext/tk/lib/tkmacpkg.rb2
-rw-r--r--ext/tk/lib/tkmngfocus.rb6
-rw-r--r--ext/tk/lib/tkpalette.rb6
-rw-r--r--ext/tk/lib/tktext.rb29
-rw-r--r--ext/tk/lib/tkvirtevent.rb15
-rw-r--r--ext/tk/lib/tkwinpkg.rb4
-rw-r--r--process.c526
17 files changed, 612 insertions, 449 deletions
diff --git a/configure.in b/configure.in
index 0cfd147a5ad..96fabbf96d8 100644
--- a/configure.in
+++ b/configure.in
@@ -374,6 +374,13 @@ AC_CHECK_FUNCS(fmod killpg wait4 waitpid syscall chroot fsync\
getpgrp setpgrp getpgid setpgid initgroups getgroups setgroups\
getpriority getrlimit dlopen sigprocmask sigaction _setjmp\
setsid telldir seekdir fchmod mktime timegm cosh sinh tanh)
+AC_ARG_ENABLE(setreuid,
+ [ --enable-setreuid use setreuid()/setregid() according to need even if obsolete.],
+ [use_setreuid=$enableval])
+if test "$use_setreuid" = yes; then
+ AC_DEFINE(USE_SETREUID)
+ AC_DEFINE(USE_SETREGID)
+fi
AC_STRUCT_TIMEZONE
AC_CACHE_CHECK(for struct tm.tm_gmtoff, rb_cv_member_struct_tm_tm_gmtoff,
[AC_TRY_COMPILE([#include <time.h>],
diff --git a/ext/tcltklib/tcltklib.c b/ext/tcltklib/tcltklib.c
index 72ca933424f..9ebdbb31e72 100644
--- a/ext/tcltklib/tcltklib.c
+++ b/ext/tcltklib/tcltklib.c
@@ -530,7 +530,7 @@ ip_ruby(clientData, interp, argc, argv)
DUMP2("rb_eval_string(%s)", arg);
old_trapflg = rb_trap_immediate;
rb_trap_immediate = 0;
- res = rb_rescue2(rb_eval_string, (VALUE)arg,
+ res = rb_rescue2(rb_eval_string, (VALUE)arg,
ip_eval_rescue, (VALUE)&failed,
rb_eStandardError, rb_eScriptError, 0);
rb_trap_immediate = old_trapflg;
@@ -584,10 +584,14 @@ ip_alloc(self)
}
static VALUE
-ip_init(self)
+ip_init(argc, argv, self)
+ int argc;
+ VALUE *argv;
VALUE self;
{
struct tcltkip *ptr; /* tcltkip data struct */
+ VALUE argv0, opts, opt_n;
+ int cnt;
/* create object */
Data_Get_Struct(self, struct tcltkip, ptr);
@@ -605,6 +609,23 @@ ip_init(self)
if (Tcl_Init(ptr->ip) == TCL_ERROR) {
rb_raise(rb_eRuntimeError, "%s", ptr->ip->result);
}
+
+ /* set variables */
+ cnt = rb_scan_args(argc, argv, "02", &argv0, &opts);
+ switch(cnt) {
+ case 2:
+ /* options */
+ Tcl_SetVar(ptr->ip, "argv", StringValuePtr(opts), 0);
+ case 1:
+ /* argv0 */
+ if (argv0 != Qnil) {
+ Tcl_SetVar(ptr->ip, "argv0", StringValuePtr(argv0), 0);
+ }
+ case 0:
+ /* no args */
+ }
+
+ /* from Tcl_AppInit() */
DUMP1("Tk_Init");
if (Tk_Init(ptr->ip) == TCL_ERROR) {
rb_raise(rb_eRuntimeError, "%s", ptr->ip->result);
@@ -989,7 +1010,7 @@ Init_tcltklib()
get_eventloop_weight, 0);
rb_define_alloc_func(ip, ip_alloc);
- rb_define_method(ip, "initialize", ip_init, 0);
+ rb_define_method(ip, "initialize", ip_init, -1);
rb_define_method(ip, "_eval", ip_eval, 1);
rb_define_method(ip, "_toUTF8",ip_toUTF8,2);
rb_define_method(ip, "_fromUTF8",ip_fromUTF8,2);
diff --git a/ext/tk/lib/tk.rb b/ext/tk/lib/tk.rb
index ec69fb04cef..e0c11c1c0de 100644
--- a/ext/tk/lib/tk.rb
+++ b/ext/tk/lib/tk.rb
@@ -15,32 +15,18 @@ module TkComm
'None'
end
- Tk_CMDTBL = {}
- Tk_WINDOWS = {}
- Tk_IDs = [0, 0] # [0]-cmdid, [1]-winid
+ #Tk_CMDTBL = {}
+ #Tk_WINDOWS = {}
+ Tk_IDs = ["00000", "00000"] # [0]-cmdid, [1]-winid
- INITIALIZE_TARGETS = [self]
-
- def self.__init_tables__
- Tk_WINDOWS.clear
+ # for backward compatibility
+ Tk_CMDTBL = Object.new
+ def Tk_CMDTBL.method_missing(id, *args)
+ TkCore::INTERP.tk_cmd_tbl.send(id, *args)
end
-
- def self.__add_target_for_init__(target)
- INITIALIZE_TARGETS << target
-
- if target.const_defined? :TkINTERP_SETUP_SCRIPTS
- target::TkINTERP_SETUP_SCRIPTS.collect{|script|
- if script.kind_of? Proc
- script.call
- elsif script.kind_of? Array
- Tk.ip_invoke(*script)
- else
- Tk.ip_eval(script)
- end
- }
- else
- nil
- end
+ Tk_WINDOWS = Object.new
+ def Tk_WINDOWS.method_missing(id, *args)
+ TkCore::INTERP.tk_windows.send(id, *args)
end
def error_at
@@ -80,7 +66,8 @@ module TkComm
#{classname_def}
def initialize(path)
@path=path
- Tk_WINDOWS[@path] = self
+ #Tk_WINDOWS[@path] = self
+ TkCore::INTERP.tk_windows[@path] = self
end
end"
end
@@ -91,7 +78,8 @@ module TkComm
def tk_tcl2ruby(val)
if val =~ /^rb_out (c\d+)/
- return Tk_CMDTBL[$1]
+ #return Tk_CMDTBL[$1]
+ return TkCore::INTERP.tk_cmd_tbl[$1]
end
if val.include? ?\s
return val.split.collect{|v| tk_tcl2ruby(v)}
@@ -102,7 +90,9 @@ module TkComm
when /^-?\d+$/
val.to_i
when /^\./
- Tk_WINDOWS[val] ? Tk_WINDOWS[val] : _genobj_for_tkwidget(val)
+ #Tk_WINDOWS[val] ? Tk_WINDOWS[val] : _genobj_for_tkwidget(val)
+ TkCore::INTERP.tk_windows[val]?
+ TkCore::INTERP.tk_windows[val] : _genobj_for_tkwidget(val)
when /^i\d+$/
TkImage::Tk_IMGTBL[val]? TkImage::Tk_IMGTBL[val] : val
when / /
@@ -251,14 +241,17 @@ module TkComm
end
def window(val)
if val =~ /^\./
- Tk_WINDOWS[val]? Tk_WINDOWS[val] : _genobj_for_tkwidget(val)
+ #Tk_WINDOWS[val]? Tk_WINDOWS[val] : _genobj_for_tkwidget(val)
+ TkCore::INTERP.tk_windows[val]?
+ TkCore::INTERP.tk_windows[val] : _genobj_for_tkwidget(val)
else
nil
end
end
def procedure(val)
if val =~ /^rb_out (c\d+)/
- Tk_CMDTBL[$1]
+ #Tk_CMDTBL[$1]
+ TkCore::INTERP.tk_cmd_tbl[$1]
else
#nil
val
@@ -311,11 +304,13 @@ module TkComm
private :ruby2tcl
def _curr_cmd_id
- id = format("c%.4d", Tk_IDs[0])
+ #id = format("c%.4d", Tk_IDs[0])
+ id = "c" + Tk_IDs[0]
end
def _next_cmd_id
id = _curr_cmd_id
- Tk_IDs[0] += 1
+ #Tk_IDs[0] += 1
+ Tk_IDs[0].succ!
id
end
private :_curr_cmd_id, :_next_cmd_id
@@ -323,21 +318,25 @@ module TkComm
def install_cmd(cmd)
return '' if cmd == ''
id = _next_cmd_id
- Tk_CMDTBL[id] = cmd
+ #Tk_CMDTBL[id] = cmd
+ TkCore::INTERP.tk_cmd_tbl[id] = cmd
@cmdtbl = [] unless defined? @cmdtbl
@cmdtbl.push id
return format("rb_out %s", id);
end
def uninstall_cmd(id)
id = $1 if /rb_out (c\d+)/ =~ id
- Tk_CMDTBL.delete(id)
+ #Tk_CMDTBL.delete(id)
+ TkCore::INTERP.tk_cmd_tbl.delete(id)
end
private :install_cmd, :uninstall_cmd
def install_win(ppath,name=nil)
if !name or name == ''
- name = format("w%.4d", Tk_IDs[1])
- Tk_IDs[1] += 1
+ #name = format("w%.4d", Tk_IDs[1])
+ #Tk_IDs[1] += 1
+ name = "w" + Tk_IDs[1]
+ Tk_IDs[1].succ!
end
if name[0] == ?.
@path = name.dup
@@ -346,11 +345,13 @@ module TkComm
else
@path = format("%s.%s", ppath, name)
end
- Tk_WINDOWS[@path] = self
+ #Tk_WINDOWS[@path] = self
+ TkCore::INTERP.tk_windows[@path] = self
end
def uninstall_win()
- Tk_WINDOWS.delete(@path)
+ #Tk_WINDOWS.delete(@path)
+ TkCore::INTERP.tk_windows.delete(@path)
end
private :install_win, :uninstall_win
@@ -552,7 +553,8 @@ module TkComm
if context
tk_call(*what+["<#{tk_event_sequence(context)}>"]).collect {|cmdline|
if cmdline =~ /^rb_out (c\d+)\s+(.*)$/
- [Tk_CMDTBL[$1], $2]
+ #[Tk_CMDTBL[$1], $2]
+ [TkCore::INTERP.tk_cmd_tbl[$1], $2]
else
cmdline
end
@@ -636,9 +638,75 @@ module TkCore
include TkComm
extend TkComm
- INTERP = TclTkIp.new unless self.const_defined? :INTERP
+ unless self.const_defined? :INTERP
+ if self.const_defined? :IP_NAME
+ name = IP_NAME.to_s
+ else
+ name = nil
+ end
+ if self.const_defined? :IP_OPTS
+ if IP_OPTS.kind_of?(Hash)
+ opts = hash_kv(IP_OPTS).join(' ')
+ else
+ opts = IP_OPTS.to_s
+ end
+ else
+ opts = ''
+ end
+
+ INTERP = TclTkIp.new(name, opts)
+
+ def INTERP.__ip_id
+ nil
+ end
+
+ INTERP.instance_eval{
+ @tk_cmd_tbl = {}
+ @tk_windows = {}
+
+ @tk_table_list = []
+
+ @init_ip_env = [] # table of Procs
+ @add_tk_procs = [] # table of [name, body]
+ }
+ def INTERP.tk_cmd_tbl
+ @tk_cmd_tbl
+ end
+ def INTERP.tk_windows
+ @tk_windows
+ end
+
+ def INTERP.tk_object_table(id)
+ @tk_table_list[id]
+ end
+ def INTERP.create_table
+ id = @tk_table_list.size
+ @tk_table_list << {}
+ obj = Object.new
+ obj.instance_eval <<-EOD
+ def self.method_missing(m, *args)
+ TkCore::INTERP.tk_object_table(#{id}).send(m, *args)
+ end
+ EOD
+ return obj
+ end
+
+ def INTERP.init_ip_env(script = Proc.new)
+ @init_ip_env << script
+ script.call(self)
+ end
+ def INTERP.add_tk_procs(name, args, body)
+ @add_tk_procs << [name, args, body]
+ self._invoke('proc', name, args, body)
+ end
+ def INTERP.init_ip_internal
+ ip = self
+ @init_ip_env.each{|script| script.call(ip)}
+ @add_tk_procs.each{|name,args,body| ip._invoke('proc',name,args,body)}
+ end
+ end
- INTERP._invoke("proc", "rb_out", "args", <<-'EOL')
+ INTERP.add_tk_procs('rb_out', 'args', <<-'EOL')
regsub -all {!} $args {\\!} args
regsub -all "{" $args "\\{" args
if {[set st [catch {ruby [format "TkCore.callback %%Q!%s!" $args]} ret]] != 0} {
@@ -729,7 +797,9 @@ module TkCore
def TkCore.callback(arg)
# arg = tk_split_list(arg)
arg = tk_split_simplelist(arg)
- _get_eval_string(TkUtil.eval_cmd(Tk_CMDTBL[arg.shift], *arg))
+ #_get_eval_string(TkUtil.eval_cmd(Tk_CMDTBL[arg.shift], *arg))
+ _get_eval_string(TkUtil.eval_cmd(TkCore::INTERP.tk_cmd_tbl[arg.shift],
+ *arg))
end
def windowingsystem
@@ -824,13 +894,13 @@ module TkCore
TclTkLib.get_eventloop_weight
end
- def restart(app_name = nil, use = nil)
- TkComm::INITIALIZE_TARGETS.each{|m| m.__init_tables__ }
+ def restart(app_name = nil, keys = {})
+ TkCore::INTERP.init_ip_internal
tk_call('set', 'argv0', app_name) if app_name
- if use
- tk_call('set', 'argc', 2)
- tk_call('set', 'argv', "-use #{use}")
+ if keys.kind_of?(Hash) && keys.size > 0
+ # tk_call('set', 'argc', keys.size * 2)
+ tk_call('set', 'argv', hash_kv(keys).join(' '))
end
INTERP.restart
@@ -919,6 +989,8 @@ module TkPackage
include TkCore
extend TkPackage
+ TkCommandNames = ['package'.freeze].freeze
+
def add_path(path)
Tk::AUTO_PATH.value = Tk::AUTO_PATH.to_a << path
end
@@ -1136,6 +1208,9 @@ module Tk
module Wm
include TkComm
+
+ TkCommandNames = ['wm'.freeze].freeze
+
def aspect(*args)
w = tk_call('wm', 'aspect', path, *args)
if args.length == 0
@@ -1403,25 +1478,33 @@ if /^8\.[1-9]/ =~ Tk::TCL_VERSION && !Tk::JAPANIZED_TK
end
module Tk
- def encoding=(name)
- INTERP.encoding = name
- end
+ module Encoding
+ extend Encoding
- def encoding
- INTERP.encoding
- end
+ TkCommandNames = ['encoding'.freeze].freeze
- def encoding_names
- tk_split_simplelist(tk_call('encoding', 'names'))
- end
+ def encoding=(name)
+ INTERP.encoding = name
+ end
- def encoding_system
- tk_call('encoding', 'system')
- end
+ def encoding
+ INTERP.encoding
+ end
- def encoding_system=(enc)
- tk_call('encoding', 'system', enc)
+ def encoding_names
+ tk_split_simplelist(tk_call('encoding', 'names'))
+ end
+
+ def encoding_system
+ tk_call('encoding', 'system')
+ end
+
+ def encoding_system=(enc)
+ tk_call('encoding', 'system', enc)
+ end
end
+
+ extend Encoding
end
# estimate encoding
@@ -1443,21 +1526,27 @@ if /^8\.[1-9]/ =~ Tk::TCL_VERSION && !Tk::JAPANIZED_TK
else
# dummy methods
module Tk
- def encoding=(name)
- nil
- end
- def encoding
- nil
- end
- def encoding_names
- nil
- end
- def encoding_system
- nil
- end
- def encoding_system=(enc)
- nil
+ module Encoding
+ extend Encoding
+
+ def encoding=(name)
+ nil
+ end
+ def encoding
+ nil
+ end
+ def encoding_names
+ nil
+ end
+ def encoding_system
+ nil
+ end
+ def encoding_system=(enc)
+ nil
+ end
end
+
+ extend Encoding
end
end
@@ -1482,15 +1571,11 @@ end
class TkBindTag
include TkBindCore
- BTagID_TBL = {}
- Tk_BINDTAG_ID = ["btag00000"]
-
- TkComm.__add_target_for_init__(self)
+ #BTagID_TBL = {}
+ BTagID_TBL = TkCore::INTERP.create_table
+ Tk_BINDTAG_ID = ["btag".freeze, "00000"]
- def self.__init_tables__
- BTagID_TBL.clear
- Tk_BINDTAG_ID[0] = "btag00000"
- end
+ TkCore::INTERP.init_ip_env{ BTagID_TBL.clear }
def TkBindTag.id2obj(id)
BTagID_TBL[id]? BTagID_TBL[id]: id
@@ -1506,8 +1591,8 @@ class TkBindTag
end
def initialize(*args, &b)
- @id = Tk_BINDTAG_ID[0]
- Tk_BINDTAG_ID[0] = Tk_BINDTAG_ID[0].succ
+ @id = Tk_BINDTAG_ID.join
+ Tk_BINDTAG_ID[1].succ!
BTagID_TBL[@id] = self
bind(*args, &b) if args != []
end
@@ -1557,22 +1642,16 @@ class TkVariable
include Tk
extend TkCore
- TkVar_CB_TBL = {}
- TkVar_ID_TBL = {}
- Tk_VARIABLE_ID = ["v00000"]
+ TkCommandNames = ['tkwait'.freeze].freeze
- # this constant must be defined befor calling __add_target_for_init__
- TkINTERP_SETUP_SCRIPTS = [
- ["proc", "rb_var", "args",
- "ruby [format \"TkVariable.callback %%Q!%s!\" $args]"]
- ]
+ #TkVar_CB_TBL = {}
+ #TkVar_ID_TBL = {}
+ TkVar_CB_TBL = TkCore::INTERP.create_table
+ TkVar_ID_TBL = TkCore::INTERP.create_table
+ Tk_VARIABLE_ID = ["v".freeze, "00000"]
- TkComm.__add_target_for_init__(self)
-
- def self.__init_tables__
- # cannot clear
- # Tcl interpreter may keeps callbacks
- end
+ TkCore::INTERP.add_tk_procs('rb_var', 'args',
+ "ruby [format \"TkVariable.callback %%Q!%s!\" $args]")
def TkVariable.callback(args)
name1,name2,op = tk_split_list(args)
@@ -1584,8 +1663,8 @@ class TkVariable
end
def initialize(val="")
- @id = Tk_VARIABLE_ID[0]
- Tk_VARIABLE_ID[0] = Tk_VARIABLE_ID[0].succ
+ @id = Tk_VARIABLE_ID.join
+ Tk_VARIABLE_ID[1].succ!
TkVar_ID_TBL[@id] = self
if val == []
INTERP._eval(format('global %s; set %s(0) 0; unset %s(0)',
@@ -1885,6 +1964,8 @@ module TkSelection
include Tk
extend Tk
+ TkCommandNames = ['selection'.freeze].freeze
+
def self.clear(sel=nil)
if sel
tk_call 'selection', 'clear', '-selection', sel
@@ -1960,6 +2041,12 @@ module TkKinput
include Tk
extend Tk
+ TkCommandNames = [
+ 'kinput_start'.freeze,
+ 'kinput_send_spot'.freeze,
+ 'kanjiInput'.freeze
+ ].freeze
+
def TkKinput.start(window, style=None)
tk_call 'kinput_start', window.path, style
end
@@ -2022,6 +2109,8 @@ module TkXIM
include Tk
extend Tk
+ TkCommandNames = ['imconfigure'.freeze].freeze
+
def TkXIM.useinputmethods(window=nil, value=nil)
if window
if value
@@ -2107,6 +2196,8 @@ module TkWinfo
include Tk
extend Tk
+ TkCommandNames = ['winfo'.freeze].freeze
+
def TkWinfo.atom(name, win=nil)
if win
number(tk_call('winfo', 'atom', '-displayof', win, name))
@@ -2481,6 +2572,9 @@ end
module TkPack
include Tk
extend Tk
+
+ TkCommandNames = ['pack'.freeze].freeze
+
def configure(win, *args)
if args[-1].kind_of?(Hash)
keys = args.pop
@@ -2524,6 +2618,8 @@ module TkGrid
include Tk
extend Tk
+ TkCommandNames = ['grid'.freeze].freeze
+
def bbox(*args)
list(tk_call('grid', 'bbox', *args))
end
@@ -2619,6 +2715,8 @@ module TkPlace
include Tk
extend Tk
+ TkCommandNames = ['place'.freeze].freeze
+
def configure(win, slot, value=None)
if slot.kind_of? Hash
tk_call 'place', 'configure', win.epath, *hash_kv(slot)
@@ -2668,6 +2766,8 @@ module TkOptionDB
include Tk
extend Tk
+ TkCommandNames = ['option'.freeze].freeze
+
module Priority
WidgetDefault = 20
StartupFile = 40
@@ -2695,7 +2795,7 @@ module TkOptionDB
private :new
CARRIER = '.'.freeze
- METHOD_TBL = {}
+ METHOD_TBL = TkCore::INTERP.create_table
ADD_METHOD = false
SAFE_MODE = 4
@@ -2765,7 +2865,7 @@ module TkOptionDB
body = <<-"EOD"
class #{klass} < TkOptionDB.module_eval('@@resource_proc_class')
CARRIER = '#{carrier}'.freeze
- METHOD_TBL = {}
+ METHOD_TBL = TkCore::INTERP.create_table
ADD_METHOD = #{add}
SAFE_MODE = #{safe}
%w(#{func_str}).each{|f| METHOD_TBL[f.intern] = nil }
@@ -3654,6 +3754,8 @@ end
class TkRoot<TkWindow
include Wm
+
+=begin
ROOT = []
def TkRoot.new(keys=nil)
if ROOT[0]
@@ -3673,6 +3775,24 @@ class TkRoot<TkWindow
ROOT[0] = new
Tk_WINDOWS["."] = new
end
+=end
+ def TkRoot.new(keys=nil)
+ unless TkCore::INTERP.tk_windows['.']
+ TkCore::INTERP.tk_windows['.'] =
+ super(:without_creating=>true, :widgetname=>'.')
+ end
+ root = TkCore::INTERP.tk_windows['.']
+ if keys # wm commands
+ keys.each{|k,v|
+ if v.kind_of? Array
+ root.send(k,*v)
+ else
+ root.send(k,v)
+ end
+ }
+ end
+ return root
+ end
WidgetClassName = 'Tk'.freeze
WidgetClassNames[WidgetClassName] = self
@@ -3688,6 +3808,7 @@ end
class TkToplevel<TkWindow
include Wm
+ TkCommandNames = ['toplevel'.freeze].freeze
WidgetClassName = 'Toplevel'.freeze
WidgetClassNames[WidgetClassName] = self
@@ -3890,6 +4011,7 @@ class TkToplevel<TkWindow
end
class TkFrame<TkWindow
+ TkCommandNames = ['frame'.freeze].freeze
WidgetClassName = 'Frame'.freeze
WidgetClassNames[WidgetClassName] = self
@@ -4017,6 +4139,7 @@ class TkLabelFrame<TkFrame
end
class TkPanedWindow<TkWindow
+ TkCommandNames = ['panedwindow'.freeze].freeze
WidgetClassName = 'Panedwindow'.freeze
WidgetClassNames[WidgetClassName] = self
def create_self(keys)
@@ -4128,6 +4251,7 @@ end
TkPanedwindow = TkPanedWindow
class TkLabel<TkWindow
+ TkCommandNames = ['label'.freeze].freeze
WidgetClassName = 'Label'.freeze
WidgetClassNames[WidgetClassName] = self
def create_self(keys)
@@ -4143,6 +4267,7 @@ class TkLabel<TkWindow
end
class TkButton<TkLabel
+ TkCommandNames = ['button'.freeze].freeze
WidgetClassName = 'Button'.freeze
WidgetClassNames[WidgetClassName] = self
def create_self(keys)
@@ -4162,6 +4287,7 @@ class TkButton<TkLabel
end
class TkRadioButton<TkButton
+ TkCommandNames = ['radiobutton'.freeze].freeze
WidgetClassName = 'Radiobutton'.freeze
WidgetClassNames[WidgetClassName] = self
def create_self(keys)
@@ -4186,6 +4312,7 @@ end
TkRadiobutton = TkRadioButton
class TkCheckButton<TkRadioButton
+ TkCommandNames = ['checkbutton'.freeze].freeze
WidgetClassName = 'Checkbutton'.freeze
WidgetClassNames[WidgetClassName] = self
def create_self(keys)
@@ -4203,6 +4330,7 @@ end
TkCheckbutton = TkCheckButton
class TkMessage<TkLabel
+ TkCommandNames = ['message'.freeze].freeze
WidgetClassName = 'Message'.freeze
WidgetClassNames[WidgetClassName] = self
def create_self(keys)
@@ -4215,6 +4343,7 @@ class TkMessage<TkLabel
end
class TkScale<TkWindow
+ TkCommandNames = ['scale'.freeze].freeze
WidgetClassName = 'Scale'.freeze
WidgetClassNames[WidgetClassName] = self
@@ -4252,6 +4381,7 @@ class TkScale<TkWindow
end
class TkScrollbar<TkWindow
+ TkCommandNames = ['scrollbar'.freeze].freeze
WidgetClassName = 'Scrollbar'.freeze
WidgetClassNames[WidgetClassName] = self
@@ -4344,6 +4474,7 @@ class TkListbox<TkTextWin
include TkTreatListItemFont
include Scrollable
+ TkCommandNames = ['listbox'.freeze].freeze
WidgetClassName = 'Listbox'.freeze
WidgetClassNames[WidgetClassName] = self
@@ -4482,6 +4613,7 @@ end
class TkMenu<TkWindow
include TkTreatMenuEntryFont
+ TkCommandNames = ['menu'.freeze].freeze
WidgetClassName = 'Menu'.freeze
WidgetClassNames[WidgetClassName] = self
@@ -4657,7 +4789,8 @@ module TkSystemMenu
fail ArgumentError, "parent must be a TkMenu object"
end
@path = format("%s.%s", parent.path, self.class::SYSMENU_NAME)
- TkComm::Tk_WINDOWS[@path] = self
+ #TkComm::Tk_WINDOWS[@path] = self
+ TkCore::INTERP.tk_windows[@path] = self
if self.method(:create_self).arity == 0
p 'create_self has no arg' if $DEBUG
create_self
@@ -4688,6 +4821,7 @@ class TkSysMenu_Apple<TkMenu
end
class TkMenubutton<TkLabel
+ TkCommandNames = ['menubutton'.freeze].freeze
WidgetClassName = 'Menubutton'.freeze
WidgetClassNames[WidgetClassName] = self
def create_self(keys)
@@ -4700,10 +4834,13 @@ class TkMenubutton<TkLabel
end
class TkOptionMenubutton<TkMenubutton
+ TkCommandNames = ['tk_optionMenu'.freeze].freeze
+
class OptionMenu<TkMenu
def initialize(path) #==> return value of tk_optionMenu
@path = path
- TkComm::Tk_WINDOWS[@path] = self
+ #TkComm::Tk_WINDOWS[@path] = self
+ TkCore::INTERP.tk_windows[@path] = self
end
end
@@ -4843,6 +4980,8 @@ module TkClipboard
include Tk
extend Tk
+ TkCommandNames = ['clipboard'.freeze].freeze
+
def self.clear(win=nil)
if win
tk_call 'clipboard', 'clear', '-displayof', win
diff --git a/ext/tk/lib/tkafter.rb b/ext/tk/lib/tkafter.rb
index fec93a6a040..4401bce7197 100644
--- a/ext/tk/lib/tkafter.rb
+++ b/ext/tk/lib/tkafter.rb
@@ -9,21 +9,13 @@ class TkTimer
include TkCore
extend TkCore
- Tk_CBID = [0]
- Tk_CBTBL = {}
+ TkCommandNames = ['after'.freeze].freeze
- # this constant must be defined befor calling __add_target_for_init__
- TkINTERP_SETUP_SCRIPTS = [
- ["proc", "rb_after", "id",
- "ruby [format \"#{self.name}.callback %%Q!%s!\" $id]"]
- ]
+ Tk_CBID = ['a'.freeze, '00000']
+ Tk_CBTBL = TkCore::INTERP.create_table
- TkComm.__add_target_for_init__(self)
-
- def self.__init_tables__
- # cannot clear
- # Tcl interpreter may keep callbacks
- end
+ TkCore::INTERP.add_tk_procs('rb_after', 'id',
+ "ruby [format \"#{self.name}.callback %%Q!%s!\" $id]")
###############################
@@ -108,8 +100,8 @@ class TkTimer
end
def initialize(*args)
- @id = format("a%.4d", Tk_CBID[0])
- Tk_CBID[0] += 1
+ @id = Tk_CBID.join
+ Tk_CBID[1].succ!
@set_next = true
diff --git a/ext/tk/lib/tkbgerror.rb b/ext/tk/lib/tkbgerror.rb
index e068155b1c6..760a3901b3f 100644
--- a/ext/tk/lib/tkbgerror.rb
+++ b/ext/tk/lib/tkbgerror.rb
@@ -7,6 +7,8 @@ require 'tk'
module TkBgError
extend Tk
+ TkCommandNames = ['bgerror'.freeze].freeze
+
def bgerror(message)
tk_call 'bgerror', message
end
diff --git a/ext/tk/lib/tkcanvas.rb b/ext/tk/lib/tkcanvas.rb
index a98d770ccd5..cbe4f89043b 100644
--- a/ext/tk/lib/tkcanvas.rb
+++ b/ext/tk/lib/tkcanvas.rb
@@ -29,6 +29,7 @@ class TkCanvas<TkWindow
include TkTreatCItemFont
include Scrollable
+ TkCommandNames = ['canvas'.freeze].freeze
WidgetClassName = 'Canvas'.freeze
WidgetClassNames[WidgetClassName] = self
@@ -527,15 +528,10 @@ end
class TkcTag<TkObject
include TkcTagAccess
- CTagID_TBL = {}
- Tk_CanvasTag_ID = ['ctag0000']
+ CTagID_TBL = TkCore::INTERP.create_table
+ Tk_CanvasTag_ID = ['ctag', '00000']
- TkComm.__add_target_for_init__(self)
-
- def self.__init_tables__
- CTagID_TBL.clear
- Tk_CanvasTag_ID[0] = 'ctag0000'
- end
+ TkCore::INTERP.init_ip_env{ CTagID_TBL.clear }
def TkcTag.id2obj(canvas, id)
cpath = canvas.path
@@ -549,10 +545,10 @@ class TkcTag<TkObject
end
@c = parent
@cpath = parent.path
- @path = @id = Tk_CanvasTag_ID[0]
+ @path = @id = Tk_CanvasTag_ID.join
CTagID_TBL[@cpath] = {} unless CTagID_TBL[@cpath]
CTagID_TBL[@cpath][@id] = self
- Tk_CanvasTag_ID[0] = Tk_CanvasTag_ID[0].succ
+ Tk_CanvasTag_ID[1] = Tk_CanvasTag_ID[1].succ
if mode
tk_call @c.path, "addtag", @id, mode, *args
end
@@ -664,17 +660,17 @@ class TkcTagCurrent<TkcTag
end
class TkcGroup<TkcTag
- Tk_cGroup_ID = ['tkcg00000']
+ Tk_cGroup_ID = ['tkcg', '00000']
def create_self(parent, *args)
if not parent.kind_of?(TkCanvas)
fail format("%s need to be TkCanvas", parent.inspect)
end
@c = parent
@cpath = parent.path
- @path = @id = Tk_cGroup_ID[0]
+ @path = @id = Tk_cGroup_ID.join
CTagID_TBL[@cpath] = {} unless CTagID_TBL[@cpath]
CTagID_TBL[@cpath][@id] = self
- Tk_cGroup_ID[0] = Tk_cGroup_ID[0].succ
+ Tk_cGroup_ID[1] = Tk_cGroup_ID[1].succ
add(*args) if args != []
end
@@ -697,13 +693,9 @@ class TkcItem<TkObject
include TkcTagAccess
CItemTypeToClass = {}
- CItemID_TBL = {}
+ CItemID_TBL = TkCore::INTERP.create_table
- TkComm.__add_target_for_init__(self)
-
- def self.__init_tables__
- CItemID_TBL.clear
- end
+ TkCore::INTERP.init_ip_env{ CItemID_TBL.clear }
def TkcItem.type2class(type)
CItemTypeToClass[type]
@@ -828,19 +820,16 @@ end
class TkImage<TkObject
include Tk
- Tk_IMGTBL = {}
- Tk_Image_ID = ['i00000']
+ TkCommandNames = ['image'.freeze].freeze
- TkComm.__add_target_for_init__(self)
+ Tk_IMGTBL = TkCore::INTERP.create_table
+ Tk_Image_ID = ['i', '00000']
- def self.__init_tables__
- Tk_IMGTBL.clear
- Tk_Image_ID[0] = 'i00000'
- end
+ TkCore::INTERP.init_ip_env{ Tk_IMGTBL.clear }
def initialize(keys=nil)
- @path = Tk_Image_ID[0]
- Tk_Image_ID[0] = Tk_Image_ID[0].succ
+ @path = Tk_Image_ID.join
+ Tk_Image_ID[1] = Tk_Image_ID[1].succ
tk_call 'image', 'create', @type, @path, *hash_kv(keys)
Tk_IMGTBL[@path] = self
end
diff --git a/ext/tk/lib/tkconsole.rb b/ext/tk/lib/tkconsole.rb
index 0129501beed..d97df159fc7 100644
--- a/ext/tk/lib/tkconsole.rb
+++ b/ext/tk/lib/tkconsole.rb
@@ -7,6 +7,8 @@ module TkConsole
include Tk
extend Tk
+ TkCommandNames = ['console'.freeze].freeze
+
def self.title(str=None)
tk_call 'console', str
end
diff --git a/ext/tk/lib/tkdialog.rb b/ext/tk/lib/tkdialog.rb
index fd6e041576b..2c280d5618b 100644
--- a/ext/tk/lib/tkdialog.rb
+++ b/ext/tk/lib/tkdialog.rb
@@ -3,6 +3,8 @@ require "tk"
class TkDialog2 < TkWindow
extend Tk
+ TkCommandNames = ['tk_dialog'.freeze].freeze
+
def self.show(*args)
dlog = self.new(*args)
dlog.show
diff --git a/ext/tk/lib/tkentry.rb b/ext/tk/lib/tkentry.rb
index 20cca6bec7d..62b6535ef32 100644
--- a/ext/tk/lib/tkentry.rb
+++ b/ext/tk/lib/tkentry.rb
@@ -8,6 +8,7 @@ require 'tk.rb'
class TkEntry<TkLabel
include Scrollable
+ TkCommandNames = ['entry'.freeze].freeze
WidgetClassName = 'Entry'.freeze
WidgetClassNames[WidgetClassName] = self
@@ -221,6 +222,7 @@ class TkEntry<TkLabel
end
class TkSpinbox<TkEntry
+ TkCommandNames = ['spinbox'.freeze].freeze
WidgetClassName = 'Spinbox'.freeze
WidgetClassNames[WidgetClassName] = self
diff --git a/ext/tk/lib/tkfont.rb b/ext/tk/lib/tkfont.rb
index 4dfdd7a71ce..68eb91039b9 100644
--- a/ext/tk/lib/tkfont.rb
+++ b/ext/tk/lib/tkfont.rb
@@ -9,17 +9,16 @@ class TkFont
include Tk
extend TkCore
- Tk_FontID = [0]
- Tk_FontNameTBL = {}
- Tk_FontUseTBL = {}
+ TkCommandNames = ['font'.freeze].freeze
- TkComm.__add_target_for_init__(self)
+ Tk_FontID = ["@font".freeze, "00000"]
+ Tk_FontNameTBL = TkCore::INTERP.create_table
+ Tk_FontUseTBL = TkCore::INTERP.create_table
- def self.__init_tables__
+ TkCore::INTERP.init_ip_env{
Tk_FontNameTBL.clear
Tk_FontUseTBL.clear
- Tk_FontID[0] = 0
- end
+ }
# set default font
case Tk::TK_VERSION
@@ -222,8 +221,8 @@ class TkFont
private
###################################
def initialize(ltn=DEFAULT_LATIN_FONT_NAME, knj=nil, keys=nil)
- @id = format("@font%.4d", Tk_FontID[0])
- Tk_FontID[0] += 1
+ @id = Tk_FontID.join
+ Tk_FontID[1].succ!
Tk_FontNameTBL[@id] = self
knj = DEFAULT_KANJI_FONT_NAME if JAPANIZED_TK && !knj
create_compoundfont(ltn, knj, keys)
diff --git a/ext/tk/lib/tkmacpkg.rb b/ext/tk/lib/tkmacpkg.rb
index 1bd2d711b6b..3bac5e6c3ef 100644
--- a/ext/tk/lib/tkmacpkg.rb
+++ b/ext/tk/lib/tkmacpkg.rb
@@ -12,6 +12,8 @@ module TkMacResource
extend Tk
extend TkMacResource
+ TkCommandNames = ['resource'.freeze].freeze
+
tk_call('package', 'require', 'resource')
def close(rsrcRef)
diff --git a/ext/tk/lib/tkmngfocus.rb b/ext/tk/lib/tkmngfocus.rb
index f76855ed9fa..461525009fb 100644
--- a/ext/tk/lib/tkmngfocus.rb
+++ b/ext/tk/lib/tkmngfocus.rb
@@ -7,6 +7,12 @@ require 'tk'
module TkManageFocus
extend Tk
+ TkCommandNames = [
+ 'tk_focusFollowMouse'.freeze,
+ 'tk_focusNext'.freeze,
+ 'tk_focusPrev'.freeze
+ ].freeze
+
def TkManageFocus.followsMouse
tk_call 'tk_focusFollowsMouse'
end
diff --git a/ext/tk/lib/tkpalette.rb b/ext/tk/lib/tkpalette.rb
index a2dc7c87cb2..dc2fd47e5c5 100644
--- a/ext/tk/lib/tkpalette.rb
+++ b/ext/tk/lib/tkpalette.rb
@@ -8,6 +8,12 @@ module TkPalette
include Tk
extend Tk
+ TkCommandNames = [
+ 'tk_setPalette'.freeze,
+ 'tk_bisque'.freeze,
+ 'tkDarken'.freeze
+ ].freeze
+
def TkPalette.set(*args)
args = args.to_a.flatten if args.kind_of? Hash
tk_call 'tk_setPalette', *args
diff --git a/ext/tk/lib/tktext.rb b/ext/tk/lib/tktext.rb
index f23744af226..34663f35b41 100644
--- a/ext/tk/lib/tktext.rb
+++ b/ext/tk/lib/tktext.rb
@@ -28,6 +28,7 @@ class TkText<TkTextWin
include TkTreatTextTagFont
include Scrollable
+ TkCommandNames = ['text'.freeze].freeze
WidgetClassName = 'Text'.freeze
WidgetClassNames[WidgetClassName] = self
@@ -765,15 +766,10 @@ end
class TkTextTag<TkObject
include TkTreatTagFont
- TTagID_TBL = {}
- Tk_TextTag_ID = ['tag0000']
+ TTagID_TBL = TkCore::INTERP.create_table
+ Tk_TextTag_ID = ['tag', '00000']
- TkComm.__add_target_for_init__(self)
-
- def self.__init_tables__
- TTagID_TBL.clear
- Tk_TextTag_ID[0] = 'tag0000'
- end
+ TkCore::INTERP.init_ip_env{ TTagID_TBL.clear }
def TkTextTag.id2obj(text, id)
tpath = text.path
@@ -787,11 +783,11 @@ class TkTextTag<TkObject
end
@parent = @t = parent
@tpath = parent.path
- @path = @id = Tk_TextTag_ID[0]
+ @path = @id = Tk_TextTag_ID.join
TTagID_TBL[@id] = self
TTagID_TBL[@tpath] = {} unless TTagID_TBL[@tpath]
TTagID_TBL[@tpath][@id] = self
- Tk_TextTag_ID[0] = Tk_TextTag_ID[0].succ
+ Tk_TextTag_ID[1].succ!
#tk_call @t.path, "tag", "configure", @id, *hash_kv(keys)
if args != [] then
keys = args.pop
@@ -974,15 +970,10 @@ class TkTextTagSel<TkTextNamedTag
end
class TkTextMark<TkObject
- TMarkID_TBL = {}
- Tk_TextMark_ID = ['mark0000']
+ TMarkID_TBL = TkCore::INTERP.create_table
+ Tk_TextMark_ID = ['mark', '00000']
- TkComm.__add_target_for_init__(self)
-
- def self.__init_tables__
- TMarkID_TBL.clear
- Tk_TextMark_ID[0] = 'mark0000'
- end
+ TkCore::INTERP.init_ip_env{ TMarkID_TBL.clear }
def TkTextMark.id2obj(text, id)
tpath = text.path
@@ -996,7 +987,7 @@ class TkTextMark<TkObject
end
@parent = @t = parent
@tpath = parent.path
- @path = @id = Tk_TextMark_ID[0]
+ @path = @id = Tk_TextMark_ID.join
TMarkID_TBL[@id] = self
TMarkID_TBL[@tpath] = {} unless TMarkID_TBL[@tpath]
TMarkID_TBL[@tpath][@id] = self
diff --git a/ext/tk/lib/tkvirtevent.rb b/ext/tk/lib/tkvirtevent.rb
index aa37d626e70..c594d4716f4 100644
--- a/ext/tk/lib/tkvirtevent.rb
+++ b/ext/tk/lib/tkvirtevent.rb
@@ -7,15 +7,12 @@ require 'tk'
class TkVirtualEvent<TkObject
extend Tk
- TkVirtualEventID = [0]
- TkVirtualEventTBL = {}
+ TkCommandNames = ['event'.freeze].freeze
- TkComm.__add_target_for_init__(self)
+ TkVirtualEventID = ["<VirtEvent".freeze, "00000", ">".freeze]
+ TkVirtualEventTBL = TkCore::INTERP.create_table
- def self.__init_tables__
- TkVirtualEventTBL.clear
- TkVirtualEventID[0] = 0
- end
+ TkCore::INTERP.init_ip_env{ TkVirtualEventTBL.clear }
class PreDefVirtEvent<self
def initialize(event)
@@ -44,8 +41,8 @@ class TkVirtualEvent<TkObject
end
def initialize(*sequences)
- @path = @id = format("<VirtEvent%.4d>", TkVirtualEventID[0])
- TkVirtualEventID[0] += 1
+ @path = @id = TkVirtualEventID.join
+ TkVirtualEventID[1].succ!
add(*sequences)
end
diff --git a/ext/tk/lib/tkwinpkg.rb b/ext/tk/lib/tkwinpkg.rb
index a5ac5c7a1bd..7762b3a5962 100644
--- a/ext/tk/lib/tkwinpkg.rb
+++ b/ext/tk/lib/tkwinpkg.rb
@@ -12,6 +12,8 @@ module TkWinDDE
extend Tk
extend TkWinDDE
+ TkCommandNames = ['dde'.freeze].freeze
+
tk_call('package', 'require', 'dde')
def servername(topic=nil)
@@ -50,6 +52,8 @@ module TkWinRegistry
extend Tk
extend TkWinRegistry
+ TkCommandNames = ['registry'.freeze].freeze
+
tk_call('package', 'require', 'registry')
def delete(keynam, valnam=nil)
diff --git a/process.c b/process.c
index d80414a1f21..7e44e7a5015 100644
--- a/process.c
+++ b/process.c
@@ -1288,128 +1288,128 @@ p_uid_change_privilege(obj, id)
if (geteuid() == 0) { /* root-user */
#if defined(HAVE_SETRESUID)
- if (setresuid(uid, uid, uid) < 0) rb_sys_fail(0);
- SAVED_USER_ID = uid;
+ if (setresuid(uid, uid, uid) < 0) rb_sys_fail(0);
+ SAVED_USER_ID = uid;
#elif defined(HAVE_SETUID)
- if (setuid(uid) < 0) rb_sys_fail(0);
- SAVED_USER_ID = uid;
+ if (setuid(uid) < 0) rb_sys_fail(0);
+ SAVED_USER_ID = uid;
#elif defined(HAVE_SETREUID) && !defined(OBSOLETE_SETREUID)
- if (getuid() == uid) {
- if (SAVED_USER_ID == uid) {
- if (setreuid(-1, uid) < 0) rb_sys_fail(0);
+ if (getuid() == uid) {
+ if (SAVED_USER_ID == uid) {
+ if (setreuid(-1, uid) < 0) rb_sys_fail(0);
+ } else {
+ if (uid == 0) { /* (r,e,s) == (root, root, x) */
+ if (setreuid(-1, SAVED_USER_ID) < 0) rb_sys_fail(0);
+ if (setreuid(SAVED_USER_ID, 0) < 0) rb_sys_fail(0);
+ SAVED_USER_ID = 0; /* (r,e,s) == (x, root, root) */
+ if (setreuid(uid, uid) < 0) rb_sys_fail(0);
+ SAVED_USER_ID = uid;
+ } else {
+ if (setreuid(0, -1) < 0) rb_sys_fail(0);
+ SAVED_USER_ID = 0;
+ if (setreuid(uid, uid) < 0) rb_sys_fail(0);
+ SAVED_USER_ID = uid;
+ }
+ }
} else {
- if (uid == 0) { /* (r,e,s) == (root, root, x) */
- if (setreuid(-1, SAVED_USER_ID) < 0) rb_sys_fail(0);
- if (setreuid(SAVED_USER_ID, 0) < 0) rb_sys_fail(0);
- SAVED_USER_ID = 0; /* (r,e,s) == (x, root, root) */
- if (setreuid(uid, uid) < 0) rb_sys_fail(0);
- SAVED_USER_ID = uid;
- } else {
- if (setreuid(0, -1) < 0) rb_sys_fail(0);
- SAVED_USER_ID = 0;
if (setreuid(uid, uid) < 0) rb_sys_fail(0);
SAVED_USER_ID = uid;
- }
}
- } else {
- if (setreuid(uid, uid) < 0) rb_sys_fail(0);
- SAVED_USER_ID = uid;
- }
#elif defined(HAVE_SETRUID) && defined(HAVE_SETEUID)
- if (getuid() == uid) {
- if (SAVED_USER_ID == uid) {
- if (seteuid(uid) < 0) rb_sys_fail(0);
+ if (getuid() == uid) {
+ if (SAVED_USER_ID == uid) {
+ if (seteuid(uid) < 0) rb_sys_fail(0);
+ } else {
+ if (uid == 0) {
+ if (setruid(SAVED_USER_ID) < 0) rb_sys_fail(0);
+ SAVED_USER_ID = 0;
+ if (setruid(0) < 0) rb_sys_fail(0);
+ } else {
+ if (setruid(0) < 0) rb_sys_fail(0);
+ SAVED_USER_ID = 0;
+ if (seteuid(uid) < 0) rb_sys_fail(0);
+ if (setruid(uid) < 0) rb_sys_fail(0);
+ SAVED_USER_ID = uid;
+ }
+ }
} else {
- if (uid == 0) {
- if (setruid(SAVED_USER_ID) < 0) rb_sys_fail(0);
- SAVED_USER_ID = 0;
- if (setruid(0) < 0) rb_sys_fail(0);
- } else {
- if (setruid(0) < 0) rb_sys_fail(0);
- SAVED_USER_ID = 0;
if (seteuid(uid) < 0) rb_sys_fail(0);
if (setruid(uid) < 0) rb_sys_fail(0);
SAVED_USER_ID = uid;
- }
}
- } else {
- if (seteuid(uid) < 0) rb_sys_fail(0);
- if (setruid(uid) < 0) rb_sys_fail(0);
- SAVED_USER_ID = uid;
- }
#else
- rb_notimplement();
+ rb_notimplement();
#endif
} else { /* unprivileged user */
#if defined(HAVE_SETRESUID)
- if (setresuid((getuid() == uid)? -1: uid,
- (geteuid() == uid)? -1: uid,
- (SAVED_USER_ID == uid)? -1: uid) < 0) rb_sys_fail(0);
- SAVED_USER_ID = uid;
-#elif defined(HAVE_SETREUID) && !defined(OBSOLETE_SETREUID)
- if (SAVED_USER_ID == uid) {
- if (setreuid((getuid() == uid)? -1: uid,
- (geteuid() == uid)? -1: uid) < 0) rb_sys_fail(0);
- } else if (getuid() != uid) {
- if (setreuid(uid, (geteuid() == uid)? -1: uid) < 0) rb_sys_fail(0);
+ if (setresuid((getuid() == uid)? -1: uid,
+ (geteuid() == uid)? -1: uid,
+ (SAVED_USER_ID == uid)? -1: uid) < 0) rb_sys_fail(0);
SAVED_USER_ID = uid;
- } else if (/* getuid() == uid && */ geteuid() != uid) {
- if (setreuid(geteuid(), uid) < 0) rb_sys_fail(0);
- SAVED_USER_ID = uid;
- if (setreuid(uid, -1) < 0) rb_sys_fail(0);
- } else { /* getuid() == uid && geteuid() == uid */
- if (setreuid(-1, SAVED_USER_ID) < 0) rb_sys_fail(0);
- if (setreuid(SAVED_USER_ID, uid) < 0) rb_sys_fail(0);
- SAVED_USER_ID = uid;
- if (setreuid(uid, -1) < 0) rb_sys_fail(0);
- }
+#elif defined(HAVE_SETREUID) && !defined(OBSOLETE_SETREUID)
+ if (SAVED_USER_ID == uid) {
+ if (setreuid((getuid() == uid)? -1: uid,
+ (geteuid() == uid)? -1: uid) < 0) rb_sys_fail(0);
+ } else if (getuid() != uid) {
+ if (setreuid(uid, (geteuid() == uid)? -1: uid) < 0) rb_sys_fail(0);
+ SAVED_USER_ID = uid;
+ } else if (/* getuid() == uid && */ geteuid() != uid) {
+ if (setreuid(geteuid(), uid) < 0) rb_sys_fail(0);
+ SAVED_USER_ID = uid;
+ if (setreuid(uid, -1) < 0) rb_sys_fail(0);
+ } else { /* getuid() == uid && geteuid() == uid */
+ if (setreuid(-1, SAVED_USER_ID) < 0) rb_sys_fail(0);
+ if (setreuid(SAVED_USER_ID, uid) < 0) rb_sys_fail(0);
+ SAVED_USER_ID = uid;
+ if (setreuid(uid, -1) < 0) rb_sys_fail(0);
+ }
#elif defined(HAVE_SETRUID) && defined(HAVE_SETEUID)
- if (SAVED_USER_ID == uid) {
- if (geteuid() != uid && seteuid(uid) < 0) rb_sys_fail(0);
- if (getuid() != uid && setruid(uid) < 0) rb_sys_fail(0);
- } else if (/* SAVED_USER_ID != uid && */ geteuid() == uid) {
- if (getuid() != uid) {
- if (setruid(uid) < 0) rb_sys_fail(0);
- SAVED_USER_ID = uid;
+ if (SAVED_USER_ID == uid) {
+ if (geteuid() != uid && seteuid(uid) < 0) rb_sys_fail(0);
+ if (getuid() != uid && setruid(uid) < 0) rb_sys_fail(0);
+ } else if (/* SAVED_USER_ID != uid && */ geteuid() == uid) {
+ if (getuid() != uid) {
+ if (setruid(uid) < 0) rb_sys_fail(0);
+ SAVED_USER_ID = uid;
+ } else {
+ if (setruid(SAVED_USER_ID) < 0) rb_sys_fail(0);
+ SAVED_USER_ID = uid;
+ if (setruid(uid) < 0) rb_sys_fail(0);
+ }
+ } else if (/* geteuid() != uid && */ getuid() == uid) {
+ if (seteuid(uid) < 0) rb_sys_fail(0);
+ if (setruid(SAVED_USER_ID) < 0) rb_sys_fail(0);
+ SAVED_USER_ID = uid;
+ if (setruid(uid) < 0) rb_sys_fail(0);
} else {
- if (setruid(SAVED_USER_ID) < 0) rb_sys_fail(0);
- SAVED_USER_ID = uid;
- if (setruid(uid) < 0) rb_sys_fail(0);
+ errno = EPERM;
+ rb_sys_fail(0);
}
- } else if (/* geteuid() != uid && */ getuid() == uid) {
- if (seteuid(uid) < 0) rb_sys_fail(0);
- if (setruid(SAVED_USER_ID) < 0) rb_sys_fail(0);
- SAVED_USER_ID = uid;
- if (setruid(uid) < 0) rb_sys_fail(0);
- } else {
- errno = EPERM;
- rb_sys_fail(0);
- }
#elif defined HAVE_44BSD_SETUID
- if (getuid() == uid) {
- /* (r,e,s)==(uid,?,?) ==> (uid,uid,uid) */
- if (setuid(uid) < 0) rb_sys_fail(0);
- SAVED_USER_ID = uid;
- } else {
- errno = EPERM;
- rb_sys_fail(0);
- }
+ if (getuid() == uid) {
+ /* (r,e,s)==(uid,?,?) ==> (uid,uid,uid) */
+ if (setuid(uid) < 0) rb_sys_fail(0);
+ SAVED_USER_ID = uid;
+ } else {
+ errno = EPERM;
+ rb_sys_fail(0);
+ }
#elif defined HAVE_SETEUID
- if (getuid() == uid && SAVED_USER_ID == uid) {
- if (seteuid(uid) < 0) rb_sys_fail(0);
- } else {
- errno = EPERM;
- rb_sys_fail(0);
- }
+ if (getuid() == uid && SAVED_USER_ID == uid) {
+ if (seteuid(uid) < 0) rb_sys_fail(0);
+ } else {
+ errno = EPERM;
+ rb_sys_fail(0);
+ }
#elif defined HAVE_SETUID
- if (getuid() == uid && SAVED_USER_ID == uid) {
- if (setuid(uid) < 0) rb_sys_fail(0);
- } else {
- errno = EPERM;
- rb_sys_fail(0);
- }
+ if (getuid() == uid && SAVED_USER_ID == uid) {
+ if (setuid(uid) < 0) rb_sys_fail(0);
+ } else {
+ errno = EPERM;
+ rb_sys_fail(0);
+ }
#else
- rb_notimplement();
+ rb_notimplement();
#endif
}
return INT2FIX(uid);
@@ -1481,9 +1481,9 @@ p_sys_issetugid(obj)
{
#if defined HAVE_ISSETUGID
if (issetugid()) {
- return Qtrue;
+ return Qtrue;
} else {
- return Qfalse;
+ return Qfalse;
}
#else
rb_notimplement();
@@ -1586,7 +1586,8 @@ proc_setgroups(VALUE obj, VALUE ary)
else {
gr = getgrnam(RSTRING(g)->ptr);
if (gr == NULL)
- rb_raise(rb_eArgError, "can't find group for %s", RSTRING(g)->ptr);
+ rb_raise(rb_eArgError,
+ "can't find group for %s", RSTRING(g)->ptr);
groups[i] = gr->gr_gid;
}
}
@@ -1605,7 +1606,7 @@ proc_setgroups(VALUE obj, VALUE ary)
static VALUE
proc_initgroups(obj, uname, base_grp)
- VALUE obj, uname, base_grp;
+ VALUE obj, uname, base_grp;
{
#ifdef HAVE_INITGROUPS
if (initgroups(StringValuePtr(uname), (gid_t)NUM2INT(base_grp)) != 0) {
@@ -1632,7 +1633,7 @@ proc_setmaxgroups(obj, val)
size_t ngroups = FIX2INT(val);
if (ngroups > 4096)
- ngroups = 4096;
+ ngroups = 4096;
maxgroups = ngroups;
@@ -1652,129 +1653,129 @@ p_gid_change_privilege(obj, id)
if (geteuid() == 0) { /* root-user */
#if defined(HAVE_SETRESGID)
- if (setresgid(gid, gid, gid) < 0) rb_sys_fail(0);
- SAVED_GROUP_ID = gid;
+ if (setresgid(gid, gid, gid) < 0) rb_sys_fail(0);
+ SAVED_GROUP_ID = gid;
#elif defined HAVE_SETGID
- if (setgid(gid) < 0) rb_sys_fail(0);
- SAVED_GROUP_ID = gid;
+ if (setgid(gid) < 0) rb_sys_fail(0);
+ SAVED_GROUP_ID = gid;
#elif defined(HAVE_SETREGID) && !defined(OBSOLETE_SETREGID)
- if (getgid() == gid) {
- if (SAVED_GROUP_ID == gid) {
- if (setregid(-1, gid) < 0) rb_sys_fail(0);
+ if (getgid() == gid) {
+ if (SAVED_GROUP_ID == gid) {
+ if (setregid(-1, gid) < 0) rb_sys_fail(0);
+ } else {
+ if (gid == 0) { /* (r,e,s) == (root, y, x) */
+ if (setregid(-1, SAVED_GROUP_ID) < 0) rb_sys_fail(0);
+ if (setregid(SAVED_GROUP_ID, 0) < 0) rb_sys_fail(0);
+ SAVED_GROUP_ID = 0; /* (r,e,s) == (x, root, root) */
+ if (setregid(gid, gid) < 0) rb_sys_fail(0);
+ SAVED_GROUP_ID = gid;
+ } else { /* (r,e,s) == (z, y, x) */
+ if (setregid(0, 0) < 0) rb_sys_fail(0);
+ SAVED_GROUP_ID = 0;
+ if (setregid(gid, gid) < 0) rb_sys_fail(0);
+ SAVED_GROUP_ID = gid;
+ }
+ }
} else {
- if (gid == 0) { /* (r,e,s) == (root, y, x) */
- if (setregid(-1, SAVED_GROUP_ID) < 0) rb_sys_fail(0);
- if (setregid(SAVED_GROUP_ID, 0) < 0) rb_sys_fail(0);
- SAVED_GROUP_ID = 0; /* (r,e,s) == (x, root, root) */
- if (setregid(gid, gid) < 0) rb_sys_fail(0);
- SAVED_GROUP_ID = gid;
- } else { /* (r,e,s) == (z, y, x) */
- if (setregid(0, 0) < 0) rb_sys_fail(0);
- SAVED_GROUP_ID = 0;
if (setregid(gid, gid) < 0) rb_sys_fail(0);
SAVED_GROUP_ID = gid;
- }
}
- } else {
- if (setregid(gid, gid) < 0) rb_sys_fail(0);
- SAVED_GROUP_ID = gid;
- }
#elif defined(HAVE_SETRGID) && defined (HAVE_SETEGID)
- if (getgid() == gid) {
- if (SAVED_GROUP_ID == gid) {
- if (setegid(gid) < 0) rb_sys_fail(0);
+ if (getgid() == gid) {
+ if (SAVED_GROUP_ID == gid) {
+ if (setegid(gid) < 0) rb_sys_fail(0);
+ } else {
+ if (gid == 0) {
+ if (setegid(gid) < 0) rb_sys_fail(0);
+ if (setrgid(SAVED_GROUP_ID) < 0) rb_sys_fail(0);
+ SAVED_GROUP_ID = 0;
+ if (setrgid(0) < 0) rb_sys_fail(0);
+ } else {
+ if (setrgid(0) < 0) rb_sys_fail(0);
+ SAVED_GROUP_ID = 0;
+ if (setegid(gid) < 0) rb_sys_fail(0);
+ if (setrgid(gid) < 0) rb_sys_fail(0);
+ SAVED_GROUP_ID = gid;
+ }
+ }
} else {
- if (gid == 0) {
- if (setegid(gid) < 0) rb_sys_fail(0);
- if (setrgid(SAVED_GROUP_ID) < 0) rb_sys_fail(0);
- SAVED_GROUP_ID = 0;
- if (setrgid(0) < 0) rb_sys_fail(0);
- } else {
- if (setrgid(0) < 0) rb_sys_fail(0);
- SAVED_GROUP_ID = 0;
if (setegid(gid) < 0) rb_sys_fail(0);
if (setrgid(gid) < 0) rb_sys_fail(0);
SAVED_GROUP_ID = gid;
- }
}
- } else {
- if (setegid(gid) < 0) rb_sys_fail(0);
- if (setrgid(gid) < 0) rb_sys_fail(0);
- SAVED_GROUP_ID = gid;
- }
#else
- rb_notimplement();
+ rb_notimplement();
#endif
} else { /* unprivileged user */
#if defined(HAVE_SETRESGID)
- if (setresgid((getgid() == gid)? -1: gid,
- (getegid() == gid)? -1: gid,
- (SAVED_GROUP_ID == gid)? -1: gid) < 0) rb_sys_fail(0);
- SAVED_GROUP_ID = gid;
-#elif defined(HAVE_SETREGID) && !defined(OBSOLETE_SETREGID)
- if (SAVED_GROUP_ID == gid) {
- if (setregid((getgid() == gid)? -1: gid,
- (getegid() == gid)? -1: gid) < 0) rb_sys_fail(0);
- } else if (getgid() != gid) {
- if (setregid(gid, (getegid() == gid)? -1: gid) < 0) rb_sys_fail(0);
- SAVED_GROUP_ID = gid;
- } else if (/* getgid() == gid && */ getegid() != gid) {
- if (setregid(getegid(), gid) < 0) rb_sys_fail(0);
+ if (setresgid((getgid() == gid)? -1: gid,
+ (getegid() == gid)? -1: gid,
+ (SAVED_GROUP_ID == gid)? -1: gid) < 0) rb_sys_fail(0);
SAVED_GROUP_ID = gid;
- if (setregid(gid, -1) < 0) rb_sys_fail(0);
- } else { /* getgid() == gid && getegid() == gid */
- if (setregid(-1, SAVED_GROUP_ID) < 0) rb_sys_fail(0);
- if (setregid(SAVED_GROUP_ID, gid) < 0) rb_sys_fail(0);
- SAVED_GROUP_ID = gid;
- if (setregid(gid, -1) < 0) rb_sys_fail(0);
- }
+#elif defined(HAVE_SETREGID) && !defined(OBSOLETE_SETREGID)
+ if (SAVED_GROUP_ID == gid) {
+ if (setregid((getgid() == gid)? -1: gid,
+ (getegid() == gid)? -1: gid) < 0) rb_sys_fail(0);
+ } else if (getgid() != gid) {
+ if (setregid(gid, (getegid() == gid)? -1: gid) < 0) rb_sys_fail(0);
+ SAVED_GROUP_ID = gid;
+ } else if (/* getgid() == gid && */ getegid() != gid) {
+ if (setregid(getegid(), gid) < 0) rb_sys_fail(0);
+ SAVED_GROUP_ID = gid;
+ if (setregid(gid, -1) < 0) rb_sys_fail(0);
+ } else { /* getgid() == gid && getegid() == gid */
+ if (setregid(-1, SAVED_GROUP_ID) < 0) rb_sys_fail(0);
+ if (setregid(SAVED_GROUP_ID, gid) < 0) rb_sys_fail(0);
+ SAVED_GROUP_ID = gid;
+ if (setregid(gid, -1) < 0) rb_sys_fail(0);
+ }
#elif defined(HAVE_SETRGID) && defined(HAVE_SETEGID)
- if (SAVED_GROUP_ID == gid) {
- if (getegid() != gid && setegid(gid) < 0) rb_sys_fail(0);
- if (getgid() != gid && setrgid(gid) < 0) rb_sys_fail(0);
- } else if (/* SAVED_GROUP_ID != gid && */ getegid() == gid) {
- if (getgid() != gid) {
- if (setrgid(gid) < 0) rb_sys_fail(0);
- SAVED_GROUP_ID = gid;
+ if (SAVED_GROUP_ID == gid) {
+ if (getegid() != gid && setegid(gid) < 0) rb_sys_fail(0);
+ if (getgid() != gid && setrgid(gid) < 0) rb_sys_fail(0);
+ } else if (/* SAVED_GROUP_ID != gid && */ getegid() == gid) {
+ if (getgid() != gid) {
+ if (setrgid(gid) < 0) rb_sys_fail(0);
+ SAVED_GROUP_ID = gid;
+ } else {
+ if (setrgid(SAVED_GROUP_ID) < 0) rb_sys_fail(0);
+ SAVED_GROUP_ID = gid;
+ if (setrgid(gid) < 0) rb_sys_fail(0);
+ }
+ } else if (/* getegid() != gid && */ getgid() == gid) {
+ if (setegid(gid) < 0) rb_sys_fail(0);
+ if (setrgid(SAVED_GROUP_ID) < 0) rb_sys_fail(0);
+ SAVED_GROUP_ID = gid;
+ if (setrgid(gid) < 0) rb_sys_fail(0);
} else {
- if (setrgid(SAVED_GROUP_ID) < 0) rb_sys_fail(0);
- SAVED_GROUP_ID = gid;
- if (setrgid(gid) < 0) rb_sys_fail(0);
+ errno = EPERM;
+ rb_sys_fail(0);
}
- } else if (/* getegid() != gid && */ getgid() == gid) {
- if (setegid(gid) < 0) rb_sys_fail(0);
- if (setrgid(SAVED_GROUP_ID) < 0) rb_sys_fail(0);
- SAVED_GROUP_ID = gid;
- if (setrgid(gid) < 0) rb_sys_fail(0);
- } else {
- errno = EPERM;
- rb_sys_fail(0);
- }
#elif defined HAVE_44BSD_SETGID
- if (getgid() == gid) {
- /* (r,e,s)==(gid,?,?) ==> (gid,gid,gid) */
- if (setgid(gid) < 0) rb_sys_fail(0);
- SAVED_GROUP_ID = gid;
- } else {
- errno = EPERM;
- rb_sys_fail(0);
- }
+ if (getgid() == gid) {
+ /* (r,e,s)==(gid,?,?) ==> (gid,gid,gid) */
+ if (setgid(gid) < 0) rb_sys_fail(0);
+ SAVED_GROUP_ID = gid;
+ } else {
+ errno = EPERM;
+ rb_sys_fail(0);
+ }
#elif defined HAVE_SETEGID
- if (getgid() == gid && SAVED_GROUP_ID == gid) {
- if (setegid(gid) < 0) rb_sys_fail(0);
- } else {
- errno = EPERM;
- rb_sys_fail(0);
- }
+ if (getgid() == gid && SAVED_GROUP_ID == gid) {
+ if (setegid(gid) < 0) rb_sys_fail(0);
+ } else {
+ errno = EPERM;
+ rb_sys_fail(0);
+ }
#elif defined HAVE_SETGID
- if (getgid() == gid && SAVED_GROUP_ID == gid) {
- if (setgid(gid) < 0) rb_sys_fail(0);
- } else {
- errno = EPERM;
- rb_sys_fail(0);
- }
+ if (getgid() == gid && SAVED_GROUP_ID == gid) {
+ if (setgid(gid) < 0) rb_sys_fail(0);
+ } else {
+ errno = EPERM;
+ rb_sys_fail(0);
+ }
#else
- rb_notimplement();
+ rb_notimplement();
#endif
}
return INT2FIX(gid);
@@ -1822,17 +1823,17 @@ rb_seteuid_core(euid)
#if defined(HAVE_SETRESUID) && !defined(__CHECKER__)
if (uid != euid) {
- if (setresuid(-1,euid,euid) < 0) rb_sys_fail(0);
- SAVED_USER_ID = euid;
+ if (setresuid(-1,euid,euid) < 0) rb_sys_fail(0);
+ SAVED_USER_ID = euid;
} else {
- if (setresuid(-1,euid,-1) < 0) rb_sys_fail(0);
+ if (setresuid(-1,euid,-1) < 0) rb_sys_fail(0);
}
#elif defined(HAVE_SETREUID) && !defined(OBSOLETE_SETREUID)
if (setreuid(-1, euid) < 0) rb_sys_fail(0);
if (uid != euid) {
- if (setreuid(euid,uid) < 0) rb_sys_fail(0);
- if (setreuid(uid,euid) < 0) rb_sys_fail(0);
- SAVED_USER_ID = euid;
+ if (setreuid(euid,uid) < 0) rb_sys_fail(0);
+ if (setreuid(uid,euid) < 0) rb_sys_fail(0);
+ SAVED_USER_ID = euid;
}
#elif defined HAVE_SETEUID
if (seteuid(euid) < 0) rb_sys_fail(0);
@@ -1849,7 +1850,7 @@ static VALUE
p_uid_grant_privilege(obj, id)
VALUE obj, id;
{
- return rb_seteuid_core(NUM2INT(id));
+ return rb_seteuid_core(NUM2INT(id));
}
static VALUE
@@ -1896,17 +1897,17 @@ rb_setegid_core(egid)
#if defined(HAVE_SETRESGID) && !defined(__CHECKER__)
if (gid != egid) {
- if (setresgid(-1,egid,egid) < 0) rb_sys_fail(0);
- SAVED_GROUP_ID = egid;
+ if (setresgid(-1,egid,egid) < 0) rb_sys_fail(0);
+ SAVED_GROUP_ID = egid;
} else {
- if (setresgid(-1,egid,-1) < 0) rb_sys_fail(0);
+ if (setresgid(-1,egid,-1) < 0) rb_sys_fail(0);
}
#elif defined(HAVE_SETREGID) && !defined(OBSOLETE_SETREGID)
if (setregid(-1, egid) < 0) rb_sys_fail(0);
if (gid != egid) {
- if (setregid(egid,gid) < 0) rb_sys_fail(0);
- if (setregid(gid,egid) < 0) rb_sys_fail(0);
- SAVED_GROUP_ID = egid;
+ if (setregid(egid,gid) < 0) rb_sys_fail(0);
+ if (setregid(gid,egid) < 0) rb_sys_fail(0);
+ SAVED_GROUP_ID = egid;
}
#elif defined HAVE_SETEGID
if (setegid(egid) < 0) rb_sys_fail(0);
@@ -1923,18 +1924,18 @@ static VALUE
p_gid_grant_privilege(obj, id)
VALUE obj, id;
{
- return rb_setegid_core(NUM2INT(id));
+ return rb_setegid_core(NUM2INT(id));
}
static VALUE
p_uid_exchangeable()
{
#if defined(HAVE_SETRESUID) && !defined(__CHECKER__)
- return Qtrue;
+ return Qtrue;
#elif defined(HAVE_SETREUID) && !defined(OBSOLETE_SETREUID)
- return Qtrue;
+ return Qtrue;
#else
- return Qfalse;
+ return Qfalse;
#endif
}
@@ -1963,11 +1964,11 @@ static VALUE
p_gid_exchangeable()
{
#if defined(HAVE_SETRESGID) && !defined(__CHECKER__)
- return Qtrue;
+ return Qtrue;
#elif defined(HAVE_SETREGID) && !defined(OBSOLETE_SETREGID)
- return Qtrue;
+ return Qtrue;
#else
- return Qfalse;
+ return Qfalse;
#endif
}
@@ -1996,9 +1997,9 @@ static VALUE
p_uid_have_saved_id()
{
#if defined(HAVE_SETRESUID) || defined(HAVE_SETEUID) || _POSIX_SAVED_IDS
- return Qtrue;
+ return Qtrue;
#else
- return Qfalse;
+ return Qfalse;
#endif
}
@@ -2014,33 +2015,33 @@ p_uid_switch(obj)
#if defined(HAVE_SETRESUID) || defined(HAVE_SETEUID) || _POSIX_SAVED_IDS
if (uid != euid) {
- proc_seteuid(obj, INT2FIX(uid));
- if (rb_block_given_p()) {
- return rb_ensure(rb_yield, Qnil, rb_seteuid_core, SAVED_USER_ID);
- } else {
- return INT2FIX(euid);
- }
+ proc_seteuid(obj, INT2FIX(uid));
+ if (rb_block_given_p()) {
+ return rb_ensure(rb_yield, Qnil, rb_seteuid_core, SAVED_USER_ID);
+ } else {
+ return INT2FIX(euid);
+ }
} else if (euid != SAVED_USER_ID) {
- proc_seteuid(obj, INT2FIX(SAVED_USER_ID));
- if (rb_block_given_p()) {
- return rb_ensure(rb_yield, Qnil, rb_seteuid_core, euid);
- } else {
- return INT2FIX(uid);
- }
+ proc_seteuid(obj, INT2FIX(SAVED_USER_ID));
+ if (rb_block_given_p()) {
+ return rb_ensure(rb_yield, Qnil, rb_seteuid_core, euid);
+ } else {
+ return INT2FIX(uid);
+ }
} else {
- errno = EPERM;
- rb_sys_fail(0);
+ errno = EPERM;
+ rb_sys_fail(0);
}
#else
if (uid == euid) {
- errno = EPERM;
- rb_sys_fail(0);
+ errno = EPERM;
+ rb_sys_fail(0);
}
p_uid_switch(obj);
if (rb_block_given_p()) {
- return rb_ensure(rb_yield, Qnil, p_uid_switch, obj);
+ return rb_ensure(rb_yield, Qnil, p_uid_switch, obj);
} else {
- return INT2FIX(euid);
+ return INT2FIX(euid);
}
#endif
}
@@ -2049,9 +2050,9 @@ static VALUE
p_gid_have_saved_id()
{
#if defined(HAVE_SETRESGID) || defined(HAVE_SETEGID) || _POSIX_SAVED_IDS
- return Qtrue;
+ return Qtrue;
#else
- return Qfalse;
+ return Qfalse;
#endif
}
@@ -2067,33 +2068,34 @@ p_gid_switch(obj)
#if defined(HAVE_SETRESGID) || defined(HAVE_SETEGID) || _POSIX_SAVED_IDS
if (gid != egid) {
- proc_setegid(obj, INT2FIX(gid));
- if (rb_block_given_p()) {
- return rb_ensure(rb_yield, Qnil, proc_setegid, INT2FIX(SAVED_GROUP_ID));
- } else {
- return INT2FIX(egid);
- }
+ proc_setegid(obj, INT2FIX(gid));
+ if (rb_block_given_p()) {
+ return rb_ensure(rb_yield, Qnil, proc_setegid,
+ INT2FIX(SAVED_GROUP_ID));
+ } else {
+ return INT2FIX(egid);
+ }
} else if (egid != SAVED_GROUP_ID) {
- proc_setegid(obj, INT2FIX(SAVED_GROUP_ID));
- if (rb_block_given_p()) {
- return rb_ensure(rb_yield, Qnil, proc_setegid, INT2FIX(egid));
- } else {
- return INT2FIX(gid);
- }
+ proc_setegid(obj, INT2FIX(SAVED_GROUP_ID));
+ if (rb_block_given_p()) {
+ return rb_ensure(rb_yield, Qnil, proc_setegid, INT2FIX(egid));
+ } else {
+ return INT2FIX(gid);
+ }
} else {
- errno = EPERM;
- rb_sys_fail(0);
+ errno = EPERM;
+ rb_sys_fail(0);
}
#else
if (gid == egid) {
- errno = EPERM;
- rb_sys_fail(0);
+ errno = EPERM;
+ rb_sys_fail(0);
}
p_gid_switch(obj);
if (rb_block_given_p()) {
- return rb_ensure(rb_yield, Qnil, p_gid_switch, obj);
+ return rb_ensure(rb_yield, Qnil, p_gid_switch, obj);
} else {
- return INT2FIX(egid);
+ return INT2FIX(egid);
}
#endif
}