proc-wait3 1.5.1 → 1.5.2
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +9 -0
- data/README +5 -2
- data/doc/wait3.txt +53 -4
- data/extconf.rb +19 -0
- data/lib/proc/wait3.c +50 -18
- data/test/tc_wait3.rb +40 -16
- metadata +4 -4
data/CHANGES
CHANGED
@@ -1,3 +1,12 @@
|
|
1
|
+
== 1.5.2 - 24-Jul-2006
|
2
|
+
* Fixed the way I was handling whether or not Ruby already defined the various
|
3
|
+
RLIMIT constants within wait3.c.
|
4
|
+
* Fixed the way in which certain RLIM constants were being converted. I
|
5
|
+
shamelessly plagiarized from process.c for this.
|
6
|
+
* Adds the RLIMIT_MEMLOCK constant if found and not already defined.
|
7
|
+
* Added the WAIT3_VERSION constant.
|
8
|
+
* The getrlimit and setrlimit tests are now skipped for Ruby 1.8.5 or later.
|
9
|
+
|
1
10
|
== 1.5.1 - 13-Jul-2006
|
2
11
|
* Fixed bugs with improper values being set for some of the rlimit constants.
|
3
12
|
* Cleaned up a few warnings related to signed-ness for the RLIM_xxx constants.
|
data/README
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
== Description
|
2
2
|
Adds the wait3, wait4, waitid, pause, sigsend, and getrusage methods to
|
3
|
-
the Process module.
|
3
|
+
the Process module. For Ruby 1.8.4 or earlier, it also adds the getrlimit
|
4
|
+
and setrlimit methods.
|
4
5
|
|
5
6
|
== Installation
|
6
7
|
ruby extconf.rb
|
@@ -29,7 +30,9 @@ threads for more information. Also available as ruby-Patches-1486 on the
|
|
29
30
|
RubyForge project page for Ruby.
|
30
31
|
|
31
32
|
To apply the patch, simply run "ruby patch.rb". Note that you may need to be
|
32
|
-
root to apply the patch.
|
33
|
+
root to apply the patch. This may fail in Ruby 1.8.5 or later. Since there's
|
34
|
+
no good way to make a compatible diff, you will just have to edit the mkmf.rb
|
35
|
+
file manually.
|
33
36
|
|
34
37
|
== Integration with Ruby's process.c
|
35
38
|
I considered simply providing a patch to the core process.c file, but I
|
data/doc/wait3.txt
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
== Description
|
2
2
|
Adds the wait3, wait4, waitid, pause, sigsend, and getrusage methods to
|
3
|
-
the Process module.
|
3
|
+
the Process module. For Ruby 1.8.4 or earlier, it also adds the getrlimit
|
4
|
+
and setrlimit methods.
|
4
5
|
|
5
6
|
== Synopsis
|
6
7
|
require "proc/wait3"
|
@@ -71,7 +72,20 @@ Proc.waitid(id_type, id_num=nil, options=nil)
|
|
71
72
|
|
72
73
|
Not supported on all platforms.
|
73
74
|
|
75
|
+
== Ruby 1.8.4 or earlier.
|
76
|
+
Process.getrlimit(resource) => [cur_limit, max_limit]
|
77
|
+
Returns a two element array consisting of the hard and soft limit
|
78
|
+
for the current process for the given +resource+. The array consists of
|
79
|
+
either numeric values or the word "infinite".
|
80
|
+
|
81
|
+
Process.setrlimit(resource, current, max=nil) => nil
|
82
|
+
Sets the resource limit for +resource+ to +current+ for the soft limit and
|
83
|
+
+max+ for the hard limit, or to +current+ if +max+ is nil.
|
84
|
+
|
74
85
|
== Constants
|
86
|
+
=== Standard
|
87
|
+
Process::WAIT3_VERSION
|
88
|
+
Returns the version of this package as a string.
|
75
89
|
|
76
90
|
=== Process type constants
|
77
91
|
==== All platforms
|
@@ -123,15 +137,50 @@ Process::WTRAPPED
|
|
123
137
|
Wait for traced process(es) to become trapped or reach a breakpoint.
|
124
138
|
|
125
139
|
Not supported on all platforms.
|
140
|
+
|
141
|
+
=== RLIMIT constants
|
142
|
+
Process::RLIMIT_AS
|
143
|
+
A synonym for RLIMIT_VMEM
|
144
|
+
|
145
|
+
Process::RLIMIT_CORE
|
146
|
+
The maximum size of a core file, in bytes, that may be created.
|
147
|
+
|
148
|
+
Process::RLIMIT_CPU
|
149
|
+
The maximum amount of CPU time, in seconds, the process is allowed to use.
|
150
|
+
|
151
|
+
Process::RLIMIT_DATA
|
152
|
+
The maximum size of the process' heap size, in bytes.
|
153
|
+
|
154
|
+
Process::RLIMIT_FSIZE
|
155
|
+
The maximum size of a file, in bytes, that the process may create.
|
156
|
+
|
157
|
+
Process::RLIMIT_NOFILE
|
158
|
+
The maximum value that the kernel may assign to a file descriptor,
|
159
|
+
effectively limiting the number of open files for the calling process.
|
160
|
+
|
161
|
+
Process::RLIMIT_STACK
|
162
|
+
The maximum size of the process' stack in bytes.
|
163
|
+
|
164
|
+
Process::RLIMIT_VMEM
|
165
|
+
The maximum size of the process' mapped address space.
|
166
|
+
|
167
|
+
Process::RLIM_INFINITY
|
168
|
+
A infinite limit.
|
169
|
+
|
170
|
+
Process::RLIM_SAVED_CUR
|
171
|
+
Current soft limit.
|
172
|
+
|
173
|
+
Process::RLIM_SAVED_MAX
|
174
|
+
Current hard limit.
|
126
175
|
|
127
176
|
== Notes
|
128
|
-
The wait3 and wait4 methods are similar to the wait2
|
177
|
+
The wait3 and wait4 methods are similar to the wait2 and waitpid2
|
129
178
|
methods, except that they return much more information via the rusage
|
130
179
|
struct.
|
131
180
|
|
132
181
|
== Known Bugs
|
133
|
-
None that I'm aware of. Please log any bugs on the
|
134
|
-
page at http://
|
182
|
+
None that I'm aware of. Please log any bugs on the RubyForge project
|
183
|
+
page at http://www.rubyforge.org/projects/shards.
|
135
184
|
|
136
185
|
== License
|
137
186
|
Ruby's
|
data/extconf.rb
CHANGED
@@ -7,6 +7,25 @@ require "ftools"
|
|
7
7
|
|
8
8
|
File.copy("lib/proc/wait3.c",".")
|
9
9
|
|
10
|
+
# Check to see if Ruby has already defined the various RLIMIT constants
|
11
|
+
# and set an appropriate macro in the source.
|
12
|
+
begin
|
13
|
+
Process::RLIMIT_AS
|
14
|
+
rescue
|
15
|
+
check_sizeof("int")
|
16
|
+
check_sizeof("long")
|
17
|
+
check_sizeof("long long")
|
18
|
+
unless check_sizeof("rlim_t", "sys/resource.h")
|
19
|
+
if (2**33).is_a?(Fixnum)
|
20
|
+
$defs.push("-DSIZEOF_RLIM_T 8") # 64 bit
|
21
|
+
else
|
22
|
+
$defs.push("-DSIZEOF_RLIM_T 4") # 32 bit
|
23
|
+
end
|
24
|
+
end
|
25
|
+
else
|
26
|
+
$defs.push("-DRUBY_HAS_RLIMIT") # Used within wait.c
|
27
|
+
end
|
28
|
+
|
10
29
|
have_header("wait.h")
|
11
30
|
|
12
31
|
# wait3 is mandatory.
|
data/lib/proc/wait3.c
CHANGED
@@ -17,6 +17,20 @@
|
|
17
17
|
#define SIG2STR_MAX 32
|
18
18
|
#endif
|
19
19
|
|
20
|
+
/* Copied from process.c in Ruby 1.8.5 */
|
21
|
+
#ifndef RUBY_HAS_RLIMIT
|
22
|
+
#if SIZEOF_RLIM_T == SIZEOF_INT
|
23
|
+
# define RLIM2NUM(v) UINT2NUM(v)
|
24
|
+
# define NUM2RLIM(v) NUM2UINT(v)
|
25
|
+
#elif SIZEOF_RLIM_T == SIZEOF_LONG
|
26
|
+
# define RLIM2NUM(v) ULONG2NUM(v)
|
27
|
+
# define NUM2RLIM(v) NUM2ULONG(v)
|
28
|
+
#elif SIZEOF_RLIM_T == SIZEOF_LONG_LONG
|
29
|
+
# define RLIM2NUM(v) ULL2NUM(v)
|
30
|
+
# define NUM2RLIM(v) NUM2ULL(v)
|
31
|
+
#endif
|
32
|
+
#endif
|
33
|
+
|
20
34
|
VALUE v_last_status;
|
21
35
|
VALUE v_procstat_struct, v_siginfo_struct, v_usage_struct;
|
22
36
|
|
@@ -295,6 +309,7 @@ static VALUE proc_waitid(int argc, VALUE* argv, VALUE mod){
|
|
295
309
|
idtype_t idtype;
|
296
310
|
id_t id = 0;
|
297
311
|
int options = 0;
|
312
|
+
int i = 0;
|
298
313
|
|
299
314
|
rb_scan_args(argc, argv, "12", &v_type, &v_id, &v_options);
|
300
315
|
|
@@ -430,7 +445,6 @@ static VALUE proc_waitid(int argc, VALUE* argv, VALUE mod){
|
|
430
445
|
}
|
431
446
|
|
432
447
|
if(sig == SIGPROF){
|
433
|
-
int i = 0;
|
434
448
|
#ifdef HAVE_ST_SI_SYSARG
|
435
449
|
int ssize = sizeof(infop.si_sysarg) / sizeof(infop.si_sysarg[0]);
|
436
450
|
rbSysarg = rb_ary_new();
|
@@ -701,21 +715,22 @@ static VALUE proc_getrusage(int argc, VALUE* argv, VALUE mod){
|
|
701
715
|
}
|
702
716
|
#endif
|
703
717
|
|
718
|
+
#ifndef RUBY_HAS_RLIMIT
|
704
719
|
/*
|
705
720
|
* call-seq:
|
706
|
-
* Process.getrlimit(resource)
|
721
|
+
* Process.getrlimit(resource) => [cur_limit, max_limit]
|
707
722
|
*
|
708
723
|
* Returns a two element array consisting of the hard and soft limit
|
709
724
|
* for the current process for the given +resource+. The array consists of
|
710
725
|
* either numeric values or the word "infinite".
|
711
726
|
*/
|
712
|
-
static VALUE proc_getrlimit(VALUE mod, VALUE
|
727
|
+
static VALUE proc_getrlimit(VALUE mod, VALUE v_resource){
|
713
728
|
struct rlimit limits;
|
714
729
|
VALUE v_array = rb_ary_new();
|
715
730
|
|
716
731
|
rb_secure(2);
|
717
732
|
|
718
|
-
if(getrlimit(NUM2INT(
|
733
|
+
if(getrlimit(NUM2INT(v_resource), &limits) < 0)
|
719
734
|
rb_sys_fail("getrlimit");
|
720
735
|
|
721
736
|
if(limits.rlim_cur == RLIM_INFINITY)
|
@@ -733,24 +748,32 @@ static VALUE proc_getrlimit(VALUE mod, VALUE rbResource){
|
|
733
748
|
|
734
749
|
/*
|
735
750
|
* call-seq;
|
736
|
-
* Process.setrlimit(resource, current, max)
|
751
|
+
* Process.setrlimit(resource, current, max=nil) => nil
|
737
752
|
*
|
738
|
-
* Sets the current (soft) and max (hard) limit for the given +resource+
|
739
|
-
* the current process.
|
753
|
+
* Sets the +current+ (soft) and +max+ (hard) limit for the given +resource+
|
754
|
+
* for the current process. If +max+ is nil it is set to the same value as
|
755
|
+
* +current+.
|
740
756
|
*/
|
741
|
-
static VALUE proc_setrlimit(
|
757
|
+
static VALUE proc_setrlimit(int argc, VALUE* argv, VALUE mod){
|
758
|
+
VALUE v_res, v_cur, v_max;
|
742
759
|
struct rlimit limits;
|
743
760
|
|
744
761
|
rb_secure(2);
|
745
762
|
|
746
|
-
|
747
|
-
limits.rlim_max = NUM2INT(rbMax);
|
763
|
+
rb_scan_args(argc, argv, "21", &v_res, &v_cur, &v_max);
|
748
764
|
|
749
|
-
if(
|
765
|
+
if(NIL_P(v_max))
|
766
|
+
v_max = v_cur;
|
767
|
+
|
768
|
+
limits.rlim_cur = RLIM2NUM(v_cur);
|
769
|
+
limits.rlim_max = RLIM2NUM(v_max);
|
770
|
+
|
771
|
+
if(setrlimit(NUM2UINT(v_res), &limits) < 0)
|
750
772
|
rb_sys_fail("setrlimit");
|
751
773
|
|
752
774
|
return Qnil;
|
753
775
|
}
|
776
|
+
#endif
|
754
777
|
|
755
778
|
/*
|
756
779
|
* Adds the wait3, wait4, waitid, pause, sigsend, and getrusage methods to the
|
@@ -768,8 +791,11 @@ void Init_wait3()
|
|
768
791
|
|
769
792
|
rb_define_module_function(rb_mProcess, "wait3", proc_wait3, -1);
|
770
793
|
rb_define_module_function(rb_mProcess, "pause", proc_pause, -1);
|
794
|
+
|
795
|
+
#ifndef RUBY_HAS_RLIMIT
|
771
796
|
rb_define_module_function(rb_mProcess, "getrlimit", proc_getrlimit, 1);
|
772
|
-
rb_define_module_function(rb_mProcess, "setrlimit", proc_setrlimit,
|
797
|
+
rb_define_module_function(rb_mProcess, "setrlimit", proc_setrlimit, -1);
|
798
|
+
#endif
|
773
799
|
|
774
800
|
#ifdef HAVE_SIGSEND
|
775
801
|
rb_define_module_function(rb_mProcess, "sigsend", proc_sigsend, -1);
|
@@ -883,10 +909,10 @@ void Init_wait3()
|
|
883
909
|
#endif
|
884
910
|
|
885
911
|
/* Constants for getrlimit, setrlimit. It appears that these are defined
|
886
|
-
* by Ruby as of 1.8.5.
|
887
|
-
*
|
912
|
+
* by Ruby as of 1.8.5. We'll only set the RLIMIT constants for Ruby 1.8.4
|
913
|
+
* or earlier.
|
888
914
|
*/
|
889
|
-
#ifndef
|
915
|
+
#ifndef RUBY_HAS_RLIMIT
|
890
916
|
rb_define_const(rb_mProcess, "RLIMIT_AS", INT2FIX(RLIMIT_AS));
|
891
917
|
rb_define_const(rb_mProcess, "RLIMIT_CORE", INT2FIX(RLIMIT_CORE));
|
892
918
|
rb_define_const(rb_mProcess, "RLIMIT_CPU", INT2FIX(RLIMIT_CPU));
|
@@ -894,14 +920,20 @@ void Init_wait3()
|
|
894
920
|
rb_define_const(rb_mProcess, "RLIMIT_FSIZE", INT2FIX(RLIMIT_FSIZE));
|
895
921
|
rb_define_const(rb_mProcess, "RLIMIT_NOFILE", INT2FIX(RLIMIT_NOFILE));
|
896
922
|
rb_define_const(rb_mProcess, "RLIMIT_STACK", INT2FIX(RLIMIT_STACK));
|
897
|
-
rb_define_const(rb_mProcess, "RLIM_INFINITY",
|
898
|
-
rb_define_const(rb_mProcess, "RLIM_SAVED_MAX",
|
899
|
-
rb_define_const(rb_mProcess, "RLIM_SAVED_CUR",
|
923
|
+
rb_define_const(rb_mProcess, "RLIM_INFINITY", RLIM2NUM(RLIM_INFINITY));
|
924
|
+
rb_define_const(rb_mProcess, "RLIM_SAVED_MAX", RLIM2NUM(RLIM_SAVED_MAX));
|
925
|
+
rb_define_const(rb_mProcess, "RLIM_SAVED_CUR", RLIM2NUM(RLIM_SAVED_CUR));
|
926
|
+
|
927
|
+
#ifdef RLIMIT_MEMLOCK
|
928
|
+
rb_define_const(rb_mProcess, "RLIMIT_MEMLOCK", INT2FIX(RLIMIT_MEMLOCK));
|
900
929
|
#endif
|
901
930
|
|
902
931
|
#ifdef RLIMIT_VMEM
|
903
932
|
rb_define_const(rb_mProcess, "RLIMIT_VMEM", INT2FIX(RLIMIT_VMEM));
|
904
933
|
#endif
|
934
|
+
#endif
|
935
|
+
|
936
|
+
rb_define_const(rb_mProcess, "WAIT3_VERSION", rb_str_new2("1.5.2"));
|
905
937
|
|
906
938
|
/* Define this last in our Init_wait3 function */
|
907
939
|
rb_define_readonly_variable("$?", &v_last_status);
|
data/test/tc_wait3.rb
CHANGED
@@ -31,6 +31,10 @@ class TC_Wait3 < Test::Unit::TestCase
|
|
31
31
|
"termsig", "stopsig"]
|
32
32
|
end
|
33
33
|
|
34
|
+
def test_wait3_version
|
35
|
+
assert_equal('1.5.2', Process::WAIT3_VERSION)
|
36
|
+
end
|
37
|
+
|
34
38
|
def test_wait3_basic
|
35
39
|
assert_respond_to(Process,:wait3)
|
36
40
|
end
|
@@ -126,7 +130,7 @@ end
|
|
126
130
|
pid = fork{ sleep 1 }
|
127
131
|
assert_nothing_raised{ Process.getrusage }
|
128
132
|
assert_nothing_raised{ Process.getrusage(true) }
|
129
|
-
assert_kind_of(Struct::RUsage,Process.getrusage)
|
133
|
+
assert_kind_of(Struct::RUsage, Process.getrusage)
|
130
134
|
end
|
131
135
|
|
132
136
|
def test_wait_constants
|
@@ -140,22 +144,32 @@ end
|
|
140
144
|
assert_not_nil(Process::WTRAPPED, msg) unless RUBY_PLATFORM.match("linux")
|
141
145
|
end
|
142
146
|
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
147
|
+
# Skip these tests on Ruby 1.8.5 or later
|
148
|
+
#
|
149
|
+
if RUBY_VERSION.split('.').last.to_i <= 4
|
150
|
+
def test_getrlimit
|
151
|
+
assert_respond_to(Process, :getrlimit)
|
152
|
+
assert_nothing_raised{ Process.getrlimit(Process::RLIMIT_CPU) }
|
153
|
+
assert_kind_of(Array, Process.getrlimit(Process::RLIMIT_CPU))
|
154
|
+
assert_equal(2, Process.getrlimit(Process::RLIMIT_CPU).length)
|
155
|
+
end
|
149
156
|
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
157
|
+
def test_setrlimit
|
158
|
+
assert_respond_to(Process, :setrlimit)
|
159
|
+
assert_nothing_raised{
|
160
|
+
Process.setrlimit(
|
161
|
+
Process::RLIMIT_CPU,
|
162
|
+
Process::RLIM_SAVED_CUR,
|
163
|
+
Process::RLIM_SAVED_MAX
|
164
|
+
)
|
165
|
+
}
|
166
|
+
assert_nothing_raised{
|
167
|
+
Process.setrlimit(Process::RLIMIT_CPU, Process::RLIM_SAVED_CUR)
|
168
|
+
}
|
169
|
+
end
|
170
|
+
else
|
171
|
+
STDOUT.puts('Process.getrlimit test skipped for Ruby 1.8.5 or later')
|
172
|
+
STDOUT.puts('Process.setrlimit test skipped for Ruby 1.8.5 or later')
|
159
173
|
end
|
160
174
|
|
161
175
|
# Test to ensure that the various rlimit constants are defined. Note that
|
@@ -175,6 +189,16 @@ end
|
|
175
189
|
assert_not_nil(Process::RLIM_SAVED_CUR)
|
176
190
|
end
|
177
191
|
|
192
|
+
# This test was added to ensure that these three constants are being
|
193
|
+
# defined properly after an issue appeared on Linux with regards to
|
194
|
+
# the value accidentally being assigned a negative value.
|
195
|
+
#
|
196
|
+
def test_rlimit_constants_valid
|
197
|
+
assert(Process::RLIM_INFINITY > 0)
|
198
|
+
assert(Process::RLIM_SAVED_MAX > 0)
|
199
|
+
assert(Process::RLIM_SAVED_CUR > 0)
|
200
|
+
end
|
201
|
+
|
178
202
|
def test_process_type_flags
|
179
203
|
unless RUBY_PLATFORM.match("linux")
|
180
204
|
assert_not_nil(Process::P_ALL)
|
metadata
CHANGED
@@ -3,15 +3,15 @@ rubygems_version: 0.9.0
|
|
3
3
|
specification_version: 1
|
4
4
|
name: proc-wait3
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 1.5.
|
7
|
-
date: 2006-07-
|
8
|
-
summary: Adds the wait3, wait4, waitid, pause, sigsend, and getrusage methods to the Process module
|
6
|
+
version: 1.5.2
|
7
|
+
date: 2006-07-24 00:00:00 -06:00
|
8
|
+
summary: Adds the wait3, wait4, waitid, pause, sigsend, and getrusage methods to the Process module. It also adds the getrlimit and setrlimit methods for Ruby 1.8.4 or earlier.
|
9
9
|
require_paths:
|
10
10
|
- lib
|
11
11
|
email: djberg96@gmail.com
|
12
12
|
homepage: http://www.rubyforge.org/projects/shards
|
13
13
|
rubyforge_project: shards
|
14
|
-
description: Adds the wait3, wait4, waitid, pause, sigsend, and getrusage methods to the Process module
|
14
|
+
description: Adds the wait3, wait4, waitid, pause, sigsend, and getrusage methods to the Process module. It also adds the getrlimit and setrlimit methods for Ruby 1.8.4 or earlier.
|
15
15
|
autorequire:
|
16
16
|
default_executable:
|
17
17
|
bindir: bin
|