proc-wait3 1.5.2 → 1.5.3
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +13 -0
- data/extconf.rb +6 -1
- data/lib/proc/wait3.c +109 -67
- data/test/tc_wait3.rb +16 -2
- metadata +2 -2
data/CHANGES
CHANGED
@@ -1,3 +1,16 @@
|
|
1
|
+
== 1.5.3 - 25-Oct-2006
|
2
|
+
* Because not all platforms support automatically converting signal names
|
3
|
+
into their equivalent numbers, the Process.pause method now accepts names
|
4
|
+
or numbers. It will raise an ArgumentError if you try to use a signal name
|
5
|
+
on a platform that doesn't support the str2sig() function (such as Linux).
|
6
|
+
* Fixed a bug where fractional seconds for utime/stime were not reported in
|
7
|
+
the Process.getrusage method. Thanks go to Eric Hodel for the spot and
|
8
|
+
the patch.
|
9
|
+
* Fixed potential bigint overflow issues in the Process.getrusage method.
|
10
|
+
Thanks go again to Eric Hodel.
|
11
|
+
* Internal fixes for platforms that don't support the strlcpy() function.
|
12
|
+
* Minor update for the test_pause.rb example program.
|
13
|
+
|
1
14
|
== 1.5.2 - 24-Jul-2006
|
2
15
|
* Fixed the way I was handling whether or not Ruby already defined the various
|
3
16
|
RLIMIT constants within wait3.c.
|
data/extconf.rb
CHANGED
@@ -34,11 +34,16 @@ unless have_func("wait3")
|
|
34
34
|
exit
|
35
35
|
end
|
36
36
|
|
37
|
-
#
|
37
|
+
# Yay, Linux
|
38
|
+
have_func("str2sig")
|
39
|
+
have_func("strlcpy")
|
40
|
+
|
41
|
+
# wait4, waitid, etc, are optional (HPUX, et al)
|
38
42
|
have_func("wait4")
|
39
43
|
have_func("waitid")
|
40
44
|
have_func("sigsend")
|
41
45
|
have_func("getrusage")
|
46
|
+
have_func("getdtablesize")
|
42
47
|
|
43
48
|
have_struct_member("struct siginfo", "si_trapno", "signal.h")
|
44
49
|
have_struct_member("struct siginfo", "si_pc", "signal.h")
|
data/lib/proc/wait3.c
CHANGED
@@ -384,35 +384,35 @@ static VALUE proc_waitid(int argc, VALUE* argv, VALUE mod){
|
|
384
384
|
);
|
385
385
|
}
|
386
386
|
else{
|
387
|
-
VALUE
|
387
|
+
VALUE v_utime = Qnil, v_status = Qnil, v_stime = Qnil, v_fd = Qnil;
|
388
388
|
#ifdef HAVE_ST_SI_TRAPNO
|
389
|
-
VALUE
|
389
|
+
VALUE v_trapno = Qnil;
|
390
390
|
#endif
|
391
391
|
#ifdef HAVE_ST_SI_PC
|
392
|
-
VALUE
|
392
|
+
VALUE v_pc = Qnil;
|
393
393
|
#endif
|
394
394
|
#ifdef HAVE_ST_SI_FADDR
|
395
|
-
VALUE
|
395
|
+
VALUE v_addr = Qnil;
|
396
396
|
#endif
|
397
397
|
#ifdef HAVE_ST_SI_TSTAMP
|
398
|
-
VALUE
|
398
|
+
VALUE v_time = Qnil;
|
399
399
|
#endif
|
400
400
|
#ifdef HAVE_ST_SI_SYSCALL
|
401
|
-
VALUE
|
401
|
+
VALUE v_syscall = Qnil;
|
402
402
|
#endif
|
403
403
|
#ifdef HAVE_ST_SI_NSYSARG
|
404
|
-
VALUE
|
404
|
+
VALUE v_nsysarg = Qnil;
|
405
405
|
#endif
|
406
406
|
#ifdef HAVE_ST_SI_FAULT
|
407
|
-
VALUE
|
407
|
+
VALUE v_fault = Qnil;
|
408
408
|
#endif
|
409
409
|
#ifdef HAVE_ST_SI_SYSARG
|
410
|
-
VALUE
|
410
|
+
VALUE v_sysarg = Qnil;
|
411
411
|
#endif
|
412
412
|
#ifdef HAVE_ST_SI_MSTATE
|
413
|
-
VALUE
|
413
|
+
VALUE v_state = Qnil;
|
414
414
|
#endif
|
415
|
-
VALUE
|
415
|
+
VALUE v_band = Qnil, v_entity = Qnil;
|
416
416
|
int sig = infop.si_signo;
|
417
417
|
int code = infop.si_code;
|
418
418
|
|
@@ -421,64 +421,64 @@ static VALUE proc_waitid(int argc, VALUE* argv, VALUE mod){
|
|
421
421
|
* the si_signo struct member will always be SIGCHLD.
|
422
422
|
*/
|
423
423
|
if(sig == SIGCHLD){
|
424
|
-
|
425
|
-
|
426
|
-
|
424
|
+
v_utime = ULL2NUM(infop.si_utime);
|
425
|
+
v_status = ULL2NUM(infop.si_status);
|
426
|
+
v_stime = ULL2NUM(infop.si_stime);
|
427
427
|
}
|
428
428
|
|
429
429
|
if(sig == SIGBUS || sig == SIGFPE || sig == SIGILL || sig == SIGSEGV ||
|
430
430
|
sig == SIGTRAP)
|
431
431
|
{
|
432
432
|
#ifdef HAVE_ST_SI_TRAPNO
|
433
|
-
|
433
|
+
v_trapno = INT2FIX(infop.si_trapno);
|
434
434
|
#endif
|
435
435
|
#ifdef HAVE_ST_SI_PC
|
436
|
-
|
436
|
+
v_pc = INT2FIX(infop.si_pc);
|
437
437
|
#endif
|
438
438
|
}
|
439
439
|
|
440
440
|
if(sig == SIGXFSZ){
|
441
|
-
|
441
|
+
v_fd = INT2FIX(infop.si_fd);
|
442
442
|
if(code == POLL_IN || code == POLL_OUT || code == POLL_MSG){
|
443
|
-
|
443
|
+
v_band = LONG2FIX(infop.si_band);
|
444
444
|
}
|
445
445
|
}
|
446
446
|
|
447
447
|
if(sig == SIGPROF){
|
448
448
|
#ifdef HAVE_ST_SI_SYSARG
|
449
449
|
int ssize = sizeof(infop.si_sysarg) / sizeof(infop.si_sysarg[0]);
|
450
|
-
|
450
|
+
v_sysarg = rb_ary_new();
|
451
451
|
|
452
452
|
for(i = 0; i < ssize; i++)
|
453
|
-
rb_ary_push(
|
453
|
+
rb_ary_push(v_sysarg, LONG2FIX(infop.si_sysarg[i]));
|
454
454
|
#endif
|
455
455
|
#ifdef HAVE_ST_SI_MSTATE
|
456
456
|
int msize = sizeof(infop.si_mstate) / sizeof(infop.si_mstate[0]);
|
457
|
-
|
457
|
+
v_state = rb_ary_new();
|
458
458
|
|
459
459
|
for(i = 0; i < msize; i++)
|
460
|
-
rb_ary_push(
|
460
|
+
rb_ary_push(v_state, INT2FIX(infop.si_mstate[i]));
|
461
461
|
#endif
|
462
462
|
#ifdef HAVE_ST_SI_FADDR
|
463
|
-
|
463
|
+
v_addr = INT2FIX(infop.si_faddr);
|
464
464
|
#endif
|
465
465
|
#ifdef HAVE_ST_SI_SYSCALL
|
466
|
-
|
466
|
+
v_syscall = INT2FIX(infop.si_syscall);
|
467
467
|
#endif
|
468
468
|
#ifdef HAVE_ST_SI_NSYSARG
|
469
|
-
|
469
|
+
v_nsysarg = INT2FIX(infop.si_nsysarg);
|
470
470
|
#endif
|
471
471
|
#ifdef HAVE_ST_SI_FAULT
|
472
|
-
|
472
|
+
v_fault = INT2FIX(infop.si_fault);
|
473
473
|
#endif
|
474
474
|
#ifdef HAVE_ST_SI_TSTAMP
|
475
|
-
|
475
|
+
v_time = rb_time_new(infop.si_tstamp.tv_sec,infop.si_tstamp.tv_nsec);
|
476
476
|
#endif
|
477
477
|
}
|
478
478
|
|
479
479
|
#ifdef SIGXRES
|
480
480
|
if(sig == SIGXRES){
|
481
|
-
|
481
|
+
v_entity = INT2FIX(infop.si_entity);
|
482
482
|
}
|
483
483
|
#endif
|
484
484
|
|
@@ -488,39 +488,39 @@ static VALUE proc_waitid(int argc, VALUE* argv, VALUE mod){
|
|
488
488
|
INT2FIX(infop.si_code), /* Should be anything but SI_NOINFO */
|
489
489
|
INT2FIX(infop.si_pid), /* Real PID that sent the signal */
|
490
490
|
INT2FIX(infop.si_uid), /* Real UID of process that sent signal */
|
491
|
-
|
492
|
-
|
493
|
-
|
491
|
+
v_utime,
|
492
|
+
v_status,
|
493
|
+
v_stime,
|
494
494
|
#ifdef HAVE_ST_SI_TRAPNO
|
495
|
-
|
495
|
+
v_trapno,
|
496
496
|
#endif
|
497
497
|
#ifdef HAVE_ST_SI_PC
|
498
|
-
|
498
|
+
v_pc,
|
499
499
|
#endif
|
500
|
-
|
501
|
-
|
500
|
+
v_fd,
|
501
|
+
v_band,
|
502
502
|
#ifdef HAVE_ST_SI_FADDR
|
503
|
-
|
503
|
+
v_addr,
|
504
504
|
#endif
|
505
505
|
#ifdef HAVE_ST_SI_TSTAMP
|
506
|
-
|
506
|
+
v_time,
|
507
507
|
#endif
|
508
508
|
#ifdef HAVE_ST_SI_SYSCALL
|
509
|
-
|
509
|
+
v_syscall,
|
510
510
|
#endif
|
511
511
|
#ifdef HAVE_ST_SI_NSYSARG
|
512
|
-
|
512
|
+
v_nsysarg,
|
513
513
|
#endif
|
514
514
|
#ifdef HAVE_ST_SI_FAULT
|
515
|
-
|
515
|
+
v_fault,
|
516
516
|
#endif
|
517
517
|
#ifdef HAVE_ST_SI_SYSARG
|
518
|
-
|
518
|
+
v_sysarg,
|
519
519
|
#endif
|
520
520
|
#ifdef HAVE_ST_SI_MSTATE
|
521
|
-
|
521
|
+
v_state,
|
522
522
|
#endif
|
523
|
-
|
523
|
+
v_entity
|
524
524
|
);
|
525
525
|
}
|
526
526
|
|
@@ -536,8 +536,14 @@ static VALUE proc_waitid(int argc, VALUE* argv, VALUE mod){
|
|
536
536
|
* you pass as arguments it will return from the pause and continue with
|
537
537
|
* the execution of your code. Otherwise, it will exit.
|
538
538
|
*
|
539
|
-
*
|
540
|
-
*
|
539
|
+
* The +signals+ argument can be an array of integers or strings (or a mix
|
540
|
+
* of each) which correspond to signals on your system. If a string is used,
|
541
|
+
* be sure to leave off the leading 'SIG' substring, e.g. use 'INT' instead
|
542
|
+
* of 'SIGINT'.
|
543
|
+
*
|
544
|
+
* Note that not all platforms (notably Linux) do not support automatically
|
545
|
+
* converting strings to their corresponding signal values, so it is
|
546
|
+
* recommended that you always use an array of numeric values.
|
541
547
|
*
|
542
548
|
* Returns the result of the pause() function, which should always be -1.
|
543
549
|
*/
|
@@ -558,11 +564,29 @@ static VALUE proc_pause(int argc, VALUE* argv, VALUE mod){
|
|
558
564
|
for(i = 0; i < len; i++){
|
559
565
|
v_val = rb_ary_shift(v_signals);
|
560
566
|
|
561
|
-
if(
|
562
|
-
|
567
|
+
if(TYPE(v_val) == T_STRING){
|
568
|
+
#ifdef HAVE_STRLCPY
|
569
|
+
if(strlcpy(signame, StringValuePtr(v_val), max) >= max)
|
570
|
+
rb_raise(rb_eArgError, "string too large");
|
571
|
+
#else
|
572
|
+
if(RSTRING(v_val)->len > max)
|
573
|
+
rb_raise(rb_eArgError, "string too large");
|
574
|
+
else
|
575
|
+
strncpy(signame, RSTRING(v_val)->ptr, max);
|
576
|
+
#endif
|
563
577
|
|
564
|
-
|
565
|
-
|
578
|
+
#ifdef HAVE_STR2SIG
|
579
|
+
if(str2sig(signame, &signum) != 0)
|
580
|
+
rb_sys_fail("pause");
|
581
|
+
#else
|
582
|
+
rb_raise(rb_eArgError,
|
583
|
+
"platform does not support signal names - use numbers instead"
|
584
|
+
);
|
585
|
+
#endif
|
586
|
+
}
|
587
|
+
else{
|
588
|
+
signum = NUM2INT(v_val);
|
589
|
+
}
|
566
590
|
|
567
591
|
sigset(signum, sigproc);
|
568
592
|
}
|
@@ -688,29 +712,29 @@ static VALUE proc_getrusage(int argc, VALUE* argv, VALUE mod){
|
|
688
712
|
|
689
713
|
rb_scan_args(argc, argv, "01", &v_children);
|
690
714
|
|
691
|
-
if(
|
715
|
+
if(RTEST(v_children))
|
692
716
|
who = RUSAGE_CHILDREN;
|
693
717
|
|
694
718
|
if(getrusage(who,&r) == -1)
|
695
719
|
rb_sys_fail("getrusage");
|
696
720
|
|
697
721
|
return rb_struct_new(v_usage_struct,
|
698
|
-
|
699
|
-
|
700
|
-
|
701
|
-
|
702
|
-
|
703
|
-
|
704
|
-
|
705
|
-
|
706
|
-
|
707
|
-
|
708
|
-
|
709
|
-
|
710
|
-
|
711
|
-
|
712
|
-
|
713
|
-
|
722
|
+
rb_float_new((double)r.ru_utime.tv_sec+(double)r.ru_utime.tv_usec/1e6),
|
723
|
+
rb_float_new((double)r.ru_stime.tv_sec+(double)r.ru_stime.tv_usec/1e6),
|
724
|
+
LONG2NUM(r.ru_maxrss),
|
725
|
+
LONG2NUM(r.ru_ixrss),
|
726
|
+
LONG2NUM(r.ru_idrss),
|
727
|
+
LONG2NUM(r.ru_isrss),
|
728
|
+
LONG2NUM(r.ru_minflt),
|
729
|
+
LONG2NUM(r.ru_majflt),
|
730
|
+
LONG2NUM(r.ru_nswap),
|
731
|
+
LONG2NUM(r.ru_inblock),
|
732
|
+
LONG2NUM(r.ru_oublock),
|
733
|
+
LONG2NUM(r.ru_msgsnd),
|
734
|
+
LONG2NUM(r.ru_msgrcv),
|
735
|
+
LONG2NUM(r.ru_nsignals),
|
736
|
+
LONG2NUM(r.ru_nvcsw),
|
737
|
+
LONG2NUM(r.ru_nivcsw)
|
714
738
|
);
|
715
739
|
}
|
716
740
|
#endif
|
@@ -775,6 +799,20 @@ static VALUE proc_setrlimit(int argc, VALUE* argv, VALUE mod){
|
|
775
799
|
}
|
776
800
|
#endif
|
777
801
|
|
802
|
+
#ifdef HAVE_GETDTABLESIZE
|
803
|
+
/*
|
804
|
+
* call-seq:
|
805
|
+
* Process.getdtablesize
|
806
|
+
*
|
807
|
+
* Returns the current soft limit of the maximum file descriptor number. This
|
808
|
+
* is effectively the same as calling Process.getrlimit with RLIMIT_NOFILE
|
809
|
+
* as the resource identifier.
|
810
|
+
*/
|
811
|
+
static VALUE proc_getdtablesize(VALUE mod){
|
812
|
+
return INT2FIX(getdtablesize());
|
813
|
+
}
|
814
|
+
#endif
|
815
|
+
|
778
816
|
/*
|
779
817
|
* Adds the wait3, wait4, waitid, pause, sigsend, and getrusage methods to the
|
780
818
|
* Process module.
|
@@ -797,6 +835,10 @@ void Init_wait3()
|
|
797
835
|
rb_define_module_function(rb_mProcess, "setrlimit", proc_setrlimit, -1);
|
798
836
|
#endif
|
799
837
|
|
838
|
+
#ifdef HAVE_GETDTABLESIZE
|
839
|
+
rb_define_module_function(rb_mProcess,"getdtablesize",proc_getdtablesize,0);
|
840
|
+
#endif
|
841
|
+
|
800
842
|
#ifdef HAVE_SIGSEND
|
801
843
|
rb_define_module_function(rb_mProcess, "sigsend", proc_sigsend, -1);
|
802
844
|
#endif
|
@@ -933,7 +975,7 @@ void Init_wait3()
|
|
933
975
|
#endif
|
934
976
|
#endif
|
935
977
|
|
936
|
-
rb_define_const(rb_mProcess, "WAIT3_VERSION", rb_str_new2("1.5.
|
978
|
+
rb_define_const(rb_mProcess, "WAIT3_VERSION", rb_str_new2("1.5.3"));
|
937
979
|
|
938
980
|
/* Define this last in our Init_wait3 function */
|
939
981
|
rb_define_readonly_variable("$?", &v_last_status);
|
data/test/tc_wait3.rb
CHANGED
@@ -32,11 +32,11 @@ class TC_Wait3 < Test::Unit::TestCase
|
|
32
32
|
end
|
33
33
|
|
34
34
|
def test_wait3_version
|
35
|
-
assert_equal('1.5.
|
35
|
+
assert_equal('1.5.3', Process::WAIT3_VERSION)
|
36
36
|
end
|
37
37
|
|
38
38
|
def test_wait3_basic
|
39
|
-
assert_respond_to(Process
|
39
|
+
assert_respond_to(Process, :wait3)
|
40
40
|
end
|
41
41
|
|
42
42
|
def test_wait3_no_args
|
@@ -55,6 +55,14 @@ class TC_Wait3 < Test::Unit::TestCase
|
|
55
55
|
assert_nothing_raised{ Process.wait3(Process::WNOHANG) }
|
56
56
|
end
|
57
57
|
|
58
|
+
if RUBY_PLATFORM =~ /solaris|sunos/i
|
59
|
+
def test_getdtablesize
|
60
|
+
assert_respond_to(Process, :getdtablesize)
|
61
|
+
assert_kind_of(Fixnum, Process.getdtablesize)
|
62
|
+
assert(Process.getdtablesize > 0)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
58
66
|
unless RUBY_PLATFORM =~ /hpux/i
|
59
67
|
def test_wait4_basic
|
60
68
|
assert_respond_to(Process,:wait4)
|
@@ -131,6 +139,12 @@ end
|
|
131
139
|
assert_nothing_raised{ Process.getrusage }
|
132
140
|
assert_nothing_raised{ Process.getrusage(true) }
|
133
141
|
assert_kind_of(Struct::RUsage, Process.getrusage)
|
142
|
+
assert_kind_of(Float, Process.getrusage.stime)
|
143
|
+
assert_kind_of(Float, Process.getrusage.utime)
|
144
|
+
end
|
145
|
+
|
146
|
+
def test_pause
|
147
|
+
assert_respond_to(Process, :pause)
|
134
148
|
end
|
135
149
|
|
136
150
|
def test_wait_constants
|
metadata
CHANGED
@@ -3,8 +3,8 @@ 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-
|
6
|
+
version: 1.5.3
|
7
|
+
date: 2006-10-25 00:00:00 -06:00
|
8
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
|