FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
jruby/src/org/jruby/RubyProcess.java at parallel_boot · MSNexploder/jruby · GitHub
MSNexploder
/
jruby
Public
forked from
jruby/jruby
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
jruby
/
src
/
org
/
jruby
/
RubyProcess.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
1126 lines (977 loc) · 45.2 KB
Breadcrumbs
jruby
/
src
/
org
/
jruby
/
RubyProcess.java
Copy path
File metadata and controls
1126 lines (977 loc) · 45.2 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
**** BEGIN LICENSE BLOCK *****
* Version: EPL 1.0/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Eclipse Public
* License Version 1.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.eclipse.org/legal/epl-v10.html
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* Copyright (C) 2004 Thomas E Enebo <enebo@acm.org>
* Copyright (C) 2004 Jan Arne Petersen <jpetersen@uni-bonn.de>
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the EPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the EPL, the GPL or the LGPL.
***** END LICENSE BLOCK *****/
package
org
.
jruby
;
import
jnr
.
ffi
.*;
import
jnr
.
constants
.
platform
.
Signal
;
import
jnr
.
constants
.
platform
.
Sysconf
;
import
jnr
.
posix
.
Times
;
import
org
.
jruby
.
anno
.
JRubyClass
;
import
org
.
jruby
.
anno
.
JRubyMethod
;
import
org
.
jruby
.
anno
.
JRubyModule
;
import
jnr
.
posix
.
POSIX
;
import
org
.
jruby
.
platform
.
Platform
;
import
org
.
jruby
.
runtime
.
Arity
;
import
org
.
jruby
.
runtime
.
Block
;
import
org
.
jruby
.
runtime
.
BlockCallback
;
import
org
.
jruby
.
runtime
.
CallBlock
;
import
org
.
jruby
.
runtime
.
ObjectAllocator
;
import
org
.
jruby
.
runtime
.
ThreadContext
;
import
static
org
.
jruby
.
runtime
.
Visibility
.*;
import
org
.
jruby
.
runtime
.
builtin
.
IRubyObject
;
import
org
.
jruby
.
util
.
ShellLauncher
;
import
static
org
.
jruby
.
CompatVersion
.*;
import
static
org
.
jruby
.
runtime
.
Helpers
.
invokedynamic
;
import
static
org
.
jruby
.
runtime
.
invokedynamic
.
MethodNames
.
OP_EQUAL
;
/**
*/
@
JRubyModule
(
name
=
"Process"
)
public
class
RubyProcess
{
public
static
RubyModule
createProcessModule
(
Ruby
runtime
) {
RubyModule
process
=
runtime
.
defineModule
(
"Process"
);
runtime
.
setProcess
(
process
);
// TODO: NOT_ALLOCATABLE_ALLOCATOR is probably ok here. Confirm. JRUBY-415
RubyClass
process_status
=
process
.
defineClassUnder
(
"Status"
,
runtime
.
getObject
(),
ObjectAllocator
.
NOT_ALLOCATABLE_ALLOCATOR
);
runtime
.
setProcStatus
(
process_status
);
RubyModule
process_uid
=
process
.
defineModuleUnder
(
"UID"
);
runtime
.
setProcUID
(
process_uid
);
RubyModule
process_gid
=
process
.
defineModuleUnder
(
"GID"
);
runtime
.
setProcGID
(
process_gid
);
RubyModule
process_sys
=
process
.
defineModuleUnder
(
"Sys"
);
runtime
.
setProcSys
(
process_sys
);
process
.
defineAnnotatedMethods
(
RubyProcess
.
class
);
process_status
.
defineAnnotatedMethods
(
RubyStatus
.
class
);
process_uid
.
defineAnnotatedMethods
(
UserID
.
class
);
process_gid
.
defineAnnotatedMethods
(
GroupID
.
class
);
process_sys
.
defineAnnotatedMethods
(
Sys
.
class
);
runtime
.
loadConstantSet
(
process
,
jnr
.
constants
.
platform
.
PRIO
.
class
);
runtime
.
loadConstantSet
(
process
,
jnr
.
constants
.
platform
.
RLIM
.
class
);
runtime
.
loadConstantSet
(
process
,
jnr
.
constants
.
platform
.
RLIMIT
.
class
);
process
.
defineConstant
(
"WNOHANG"
,
runtime
.
newFixnum
(
1
));
process
.
defineConstant
(
"WUNTRACED"
,
runtime
.
newFixnum
(
2
));
return
process
;
}
@
JRubyClass
(
name
=
"Process::Status"
)
public
static
class
RubyStatus
extends
RubyObject
{
private
final
long
status
;
private
final
long
pid
;
private
static
final
long
EXIT_SUCCESS
=
0L
;
public
RubyStatus
(
Ruby
runtime
,
RubyClass
metaClass
,
long
status
,
long
pid
) {
super
(
runtime
,
metaClass
);
this
.
status
=
status
;
this
.
pid
=
pid
;
}
public
static
RubyStatus
newProcessStatus
(
Ruby
runtime
,
long
status
,
long
pid
) {
return
new
RubyStatus
(
runtime
,
runtime
.
getProcStatus
(),
status
,
pid
);
}
// Bunch of methods still not implemented
@
JRubyMethod
(
name
=
"to_int"
)
public
IRubyObject
not_implemented
() {
String
error
=
"Process::Status#to_int not implemented"
;
throw
getRuntime
().
newNotImplementedError
(
error
);
}
@
JRubyMethod
(
name
=
"stopped?"
)
public
IRubyObject
not_implemented0
() {
String
error
=
"Process::Status#stopped? not implemented"
;
throw
getRuntime
().
newNotImplementedError
(
error
);
}
@
JRubyMethod
(
name
= {
"&"
})
public
IRubyObject
not_implemented1
(
IRubyObject
arg
) {
String
error
=
"Process::Status#& not implemented"
;
throw
getRuntime
().
newNotImplementedError
(
error
);
}
@
JRubyMethod
public
IRubyObject
exitstatus
() {
return
getRuntime
().
newFixnum
(
status
);
}
@
JRubyMethod
(
name
= {
"exited?"
})
public
IRubyObject
exited
() {
return
RubyBoolean
.
newBoolean
(
getRuntime
(), (
status
==
0
));
}
@
JRubyMethod
(
name
= {
"signaled?"
})
public
IRubyObject
signaled
() {
return
RubyBoolean
.
newBoolean
(
getRuntime
(), (
status
>
0
));
}
@
JRubyMethod
(
name
= {
"termsig"
})
public
IRubyObject
termsig
() {
return
RubyFixnum
.
newFixnum
(
getRuntime
(),
status
&
0x7f
);
}
@
JRubyMethod
(
name
= {
"stopsig"
})
public
IRubyObject
stopsig
() {
return
RubyFixnum
.
newFixnum
(
getRuntime
(),
status
);
}
@
Deprecated
public
IRubyObject
op_rshift
(
IRubyObject
other
) {
return
op_rshift
(
getRuntime
(),
other
);
}
@
JRubyMethod
(
name
=
">>"
)
public
IRubyObject
op_rshift
(
ThreadContext
context
,
IRubyObject
other
) {
return
op_rshift
(
context
.
runtime
,
other
);
}
public
IRubyObject
op_rshift
(
Ruby
runtime
,
IRubyObject
other
) {
long
shiftValue
=
other
.
convertToInteger
().
getLongValue
();
return
runtime
.
newFixnum
(
status
>>
shiftValue
);
}
@
Override
@
JRubyMethod
(
name
=
"=="
)
public
IRubyObject
op_equal
(
ThreadContext
context
,
IRubyObject
other
) {
return
invokedynamic
(
context
,
other
,
OP_EQUAL
,
this
.
to_i
(
context
.
runtime
));
}
@
Deprecated
public
IRubyObject
to_i
() {
return
to_i
(
getRuntime
());
}
@
JRubyMethod
public
IRubyObject
to_i
(
ThreadContext
context
) {
return
to_i
(
context
.
runtime
);
}
public
IRubyObject
to_i
(
Ruby
runtime
) {
return
runtime
.
newFixnum
(
shiftedValue
());
}
@
Override
public
IRubyObject
to_s
() {
return
to_s
(
getRuntime
());
}
@
JRubyMethod
public
IRubyObject
to_s
(
ThreadContext
context
) {
return
to_s
(
context
.
runtime
);
}
public
IRubyObject
to_s
(
Ruby
runtime
) {
return
runtime
.
newString
(
String
.
valueOf
(
shiftedValue
()));
}
@
Override
public
IRubyObject
inspect
() {
return
inspect
(
getRuntime
());
}
@
JRubyMethod
public
IRubyObject
inspect
(
ThreadContext
context
) {
return
inspect
(
context
.
runtime
);
}
public
IRubyObject
inspect
(
Ruby
runtime
) {
return
runtime
.
newString
(
"#<Process::Status: pid="
+
pid
+
",exited("
+
String
.
valueOf
(
status
) +
")>"
);
}
@
JRubyMethod
(
name
=
"success?"
)
public
IRubyObject
success_p
(
ThreadContext
context
) {
return
context
.
runtime
.
newBoolean
(
status
==
EXIT_SUCCESS
);
}
@
JRubyMethod
(
name
=
"coredump?"
)
public
IRubyObject
coredump_p
(
ThreadContext
context
) {
// Temporarily return false until a backend can be implemented
// to copy the CRuby behavior (checking WCOREDUMP)
return
context
.
runtime
.
getFalse
();
}
@
JRubyMethod
public
IRubyObject
pid
(
ThreadContext
context
) {
return
context
.
runtime
.
newFixnum
(
pid
);
}
private
long
shiftedValue
() {
return
status
<<
8
;
}
}
@
JRubyModule
(
name
=
"Process::UID"
)
public
static
class
UserID
{
@
JRubyMethod
(
name
=
"change_privilege"
,
module
=
true
)
public
static
IRubyObject
change_privilege
(
IRubyObject
self
,
IRubyObject
arg
) {
throw
self
.
getRuntime
().
newNotImplementedError
(
"Process::UID::change_privilege not implemented yet"
);
}
@
Deprecated
public
static
IRubyObject
eid
(
IRubyObject
self
) {
return
euid
(
self
.
getRuntime
());
}
@
JRubyMethod
(
name
=
"eid"
,
module
=
true
)
public
static
IRubyObject
eid
(
ThreadContext
context
,
IRubyObject
self
) {
return
euid
(
context
.
runtime
);
}
@
Deprecated
public
static
IRubyObject
eid
(
IRubyObject
self
,
IRubyObject
arg
) {
return
eid
(
self
.
getRuntime
(),
arg
);
}
@
JRubyMethod
(
name
=
"eid="
,
module
=
true
)
public
static
IRubyObject
eid
(
ThreadContext
context
,
IRubyObject
self
,
IRubyObject
arg
) {
return
eid
(
context
.
runtime
,
arg
);
}
public
static
IRubyObject
eid
(
Ruby
runtime
,
IRubyObject
arg
) {
return
euid_set
(
runtime
,
arg
);
}
@
JRubyMethod
(
name
=
"grant_privilege"
,
module
=
true
)
public
static
IRubyObject
grant_privilege
(
IRubyObject
self
,
IRubyObject
arg
) {
throw
self
.
getRuntime
().
newNotImplementedError
(
"Process::UID::grant_privilege not implemented yet"
);
}
@
JRubyMethod
(
name
=
"re_exchange"
,
module
=
true
)
public
static
IRubyObject
re_exchange
(
ThreadContext
context
,
IRubyObject
self
) {
return
switch_rb
(
context
,
self
,
Block
.
NULL_BLOCK
);
}
@
JRubyMethod
(
name
=
"re_exchangeable?"
,
module
=
true
)
public
static
IRubyObject
re_exchangeable_p
(
IRubyObject
self
) {
throw
self
.
getRuntime
().
newNotImplementedError
(
"Process::UID::re_exchangeable? not implemented yet"
);
}
@
Deprecated
public
static
IRubyObject
rid
(
IRubyObject
self
) {
return
rid
(
self
.
getRuntime
());
}
@
JRubyMethod
(
name
=
"rid"
,
module
=
true
)
public
static
IRubyObject
rid
(
ThreadContext
context
,
IRubyObject
self
) {
return
rid
(
context
.
runtime
);
}
public
static
IRubyObject
rid
(
Ruby
runtime
) {
return
uid
(
runtime
);
}
@
JRubyMethod
(
name
=
"sid_available?"
,
module
=
true
)
public
static
IRubyObject
sid_available_p
(
IRubyObject
self
) {
throw
self
.
getRuntime
().
newNotImplementedError
(
"Process::UID::sid_available not implemented yet"
);
}
@
JRubyMethod
(
name
=
"switch"
,
module
=
true
,
visibility
=
PRIVATE
)
public
static
IRubyObject
switch_rb
(
ThreadContext
context
,
IRubyObject
self
,
Block
block
) {
Ruby
runtime
=
context
.
runtime
;
int
uid
=
checkErrno
(
runtime
,
runtime
.
getPosix
().
getuid
());
int
euid
=
checkErrno
(
runtime
,
runtime
.
getPosix
().
geteuid
());
if
(
block
.
isGiven
()) {
try
{
checkErrno
(
runtime
,
runtime
.
getPosix
().
seteuid
(
uid
));
checkErrno
(
runtime
,
runtime
.
getPosix
().
setuid
(
euid
));
return
block
.
yield
(
context
,
runtime
.
getNil
());
}
finally
{
checkErrno
(
runtime
,
runtime
.
getPosix
().
seteuid
(
euid
));
checkErrno
(
runtime
,
runtime
.
getPosix
().
setuid
(
uid
));
}
}
else
{
checkErrno
(
runtime
,
runtime
.
getPosix
().
seteuid
(
uid
));
checkErrno
(
runtime
,
runtime
.
getPosix
().
setuid
(
euid
));
return
RubyFixnum
.
zero
(
runtime
);
}
}
}
@
JRubyModule
(
name
=
"Process::GID"
)
public
static
class
GroupID
{
@
JRubyMethod
(
name
=
"change_privilege"
,
module
=
true
)
public
static
IRubyObject
change_privilege
(
IRubyObject
self
,
IRubyObject
arg
) {
throw
self
.
getRuntime
().
newNotImplementedError
(
"Process::GID::change_privilege not implemented yet"
);
}
@
Deprecated
public
static
IRubyObject
eid
(
IRubyObject
self
) {
return
eid
(
self
.
getRuntime
());
}
@
JRubyMethod
(
name
=
"eid"
,
module
=
true
)
public
static
IRubyObject
eid
(
ThreadContext
context
,
IRubyObject
self
) {
return
eid
(
context
.
runtime
);
}
public
static
IRubyObject
eid
(
Ruby
runtime
) {
return
egid
(
runtime
);
}
@
Deprecated
public
static
IRubyObject
eid
(
IRubyObject
self
,
IRubyObject
arg
) {
return
eid
(
self
.
getRuntime
(),
arg
);
}
@
JRubyMethod
(
name
=
"eid="
,
module
=
true
)
public
static
IRubyObject
eid
(
ThreadContext
context
,
IRubyObject
self
,
IRubyObject
arg
) {
return
eid
(
context
.
runtime
,
arg
);
}
public
static
IRubyObject
eid
(
Ruby
runtime
,
IRubyObject
arg
) {
return
RubyProcess
.
egid_set
(
runtime
,
arg
);
}
@
JRubyMethod
(
name
=
"grant_privilege"
,
module
=
true
)
public
static
IRubyObject
grant_privilege
(
IRubyObject
self
,
IRubyObject
arg
) {
throw
self
.
getRuntime
().
newNotImplementedError
(
"Process::GID::grant_privilege not implemented yet"
);
}
@
JRubyMethod
(
name
=
"re_exchange"
,
module
=
true
)
public
static
IRubyObject
re_exchange
(
ThreadContext
context
,
IRubyObject
self
) {
return
switch_rb
(
context
,
self
,
Block
.
NULL_BLOCK
);
}
@
JRubyMethod
(
name
=
"re_exchangeable?"
,
module
=
true
)
public
static
IRubyObject
re_exchangeable_p
(
IRubyObject
self
) {
throw
self
.
getRuntime
().
newNotImplementedError
(
"Process::GID::re_exchangeable? not implemented yet"
);
}
@
Deprecated
public
static
IRubyObject
rid
(
IRubyObject
self
) {
return
rid
(
self
.
getRuntime
());
}
@
JRubyMethod
(
name
=
"rid"
,
module
=
true
)
public
static
IRubyObject
rid
(
ThreadContext
context
,
IRubyObject
self
) {
return
rid
(
context
.
runtime
);
}
public
static
IRubyObject
rid
(
Ruby
runtime
) {
return
gid
(
runtime
);
}
@
JRubyMethod
(
name
=
"sid_available?"
,
module
=
true
)
public
static
IRubyObject
sid_available_p
(
IRubyObject
self
) {
throw
self
.
getRuntime
().
newNotImplementedError
(
"Process::GID::sid_available not implemented yet"
);
}
@
JRubyMethod
(
name
=
"switch"
,
module
=
true
,
visibility
=
PRIVATE
)
public
static
IRubyObject
switch_rb
(
ThreadContext
context
,
IRubyObject
self
,
Block
block
) {
Ruby
runtime
=
context
.
runtime
;
int
gid
=
checkErrno
(
runtime
,
runtime
.
getPosix
().
getgid
());
int
egid
=
checkErrno
(
runtime
,
runtime
.
getPosix
().
getegid
());
if
(
block
.
isGiven
()) {
try
{
checkErrno
(
runtime
,
runtime
.
getPosix
().
setegid
(
gid
));
checkErrno
(
runtime
,
runtime
.
getPosix
().
setgid
(
egid
));
return
block
.
yield
(
context
,
runtime
.
getNil
());
}
finally
{
checkErrno
(
runtime
,
runtime
.
getPosix
().
setegid
(
egid
));
checkErrno
(
runtime
,
runtime
.
getPosix
().
setgid
(
gid
));
}
}
else
{
checkErrno
(
runtime
,
runtime
.
getPosix
().
setegid
(
gid
));
checkErrno
(
runtime
,
runtime
.
getPosix
().
setgid
(
egid
));
return
RubyFixnum
.
zero
(
runtime
);
}
}
}
@
JRubyModule
(
name
=
"Process::Sys"
)
public
static
class
Sys
{
@
Deprecated
public
static
IRubyObject
getegid
(
IRubyObject
self
) {
return
egid
(
self
.
getRuntime
());
}
@
JRubyMethod
(
name
=
"getegid"
,
module
=
true
,
visibility
=
PRIVATE
)
public
static
IRubyObject
getegid
(
ThreadContext
context
,
IRubyObject
self
) {
return
egid
(
context
.
runtime
);
}
@
Deprecated
public
static
IRubyObject
geteuid
(
IRubyObject
self
) {
return
euid
(
self
.
getRuntime
());
}
@
JRubyMethod
(
name
=
"geteuid"
,
module
=
true
,
visibility
=
PRIVATE
)
public
static
IRubyObject
geteuid
(
ThreadContext
context
,
IRubyObject
self
) {
return
euid
(
context
.
runtime
);
}
@
Deprecated
public
static
IRubyObject
getgid
(
IRubyObject
self
) {
return
gid
(
self
.
getRuntime
());
}
@
JRubyMethod
(
name
=
"getgid"
,
module
=
true
,
visibility
=
PRIVATE
)
public
static
IRubyObject
getgid
(
ThreadContext
context
,
IRubyObject
self
) {
return
gid
(
context
.
runtime
);
}
@
Deprecated
public
static
IRubyObject
getuid
(
IRubyObject
self
) {
return
uid
(
self
.
getRuntime
());
}
@
JRubyMethod
(
name
=
"getuid"
,
module
=
true
,
visibility
=
PRIVATE
)
public
static
IRubyObject
getuid
(
ThreadContext
context
,
IRubyObject
self
) {
return
uid
(
context
.
runtime
);
}
@
Deprecated
public
static
IRubyObject
setegid
(
IRubyObject
recv
,
IRubyObject
arg
) {
return
egid_set
(
recv
.
getRuntime
(),
arg
);
}
@
JRubyMethod
(
name
=
"setegid"
,
module
=
true
,
visibility
=
PRIVATE
)
public
static
IRubyObject
setegid
(
ThreadContext
context
,
IRubyObject
recv
,
IRubyObject
arg
) {
return
egid_set
(
context
.
runtime
,
arg
);
}
@
Deprecated
public
static
IRubyObject
seteuid
(
IRubyObject
recv
,
IRubyObject
arg
) {
return
euid_set
(
recv
.
getRuntime
(),
arg
);
}
@
JRubyMethod
(
name
=
"seteuid"
,
module
=
true
,
visibility
=
PRIVATE
)
public
static
IRubyObject
seteuid
(
ThreadContext
context
,
IRubyObject
recv
,
IRubyObject
arg
) {
return
euid_set
(
context
.
runtime
,
arg
);
}
@
Deprecated
public
static
IRubyObject
setgid
(
IRubyObject
recv
,
IRubyObject
arg
) {
return
gid_set
(
recv
.
getRuntime
(),
arg
);
}
@
JRubyMethod
(
name
=
"setgid"
,
module
=
true
,
visibility
=
PRIVATE
)
public
static
IRubyObject
setgid
(
ThreadContext
context
,
IRubyObject
recv
,
IRubyObject
arg
) {
return
gid_set
(
context
.
runtime
,
arg
);
}
@
Deprecated
public
static
IRubyObject
setuid
(
IRubyObject
recv
,
IRubyObject
arg
) {
return
uid_set
(
recv
.
getRuntime
(),
arg
);
}
@
JRubyMethod
(
name
=
"setuid"
,
module
=
true
,
visibility
=
PRIVATE
)
public
static
IRubyObject
setuid
(
ThreadContext
context
,
IRubyObject
recv
,
IRubyObject
arg
) {
return
uid_set
(
context
.
runtime
,
arg
);
}
}
@
JRubyMethod
(
name
=
"abort"
,
optional
=
1
,
module
=
true
,
visibility
=
PRIVATE
)
public
static
IRubyObject
abort
(
ThreadContext
context
,
IRubyObject
recv
,
IRubyObject
[]
args
) {
return
RubyKernel
.
abort
(
context
,
recv
,
args
);
}
@
JRubyMethod
(
name
=
"exit!"
,
optional
=
1
,
module
=
true
,
visibility
=
PRIVATE
)
public
static
IRubyObject
exit_bang
(
IRubyObject
recv
,
IRubyObject
[]
args
) {
return
RubyKernel
.
exit_bang
(
recv
,
args
);
}
@
JRubyMethod
(
name
=
"groups"
,
module
=
true
,
visibility
=
PRIVATE
)
public
static
IRubyObject
groups
(
IRubyObject
recv
) {
throw
recv
.
getRuntime
().
newNotImplementedError
(
"Process#groups not yet implemented"
);
}
@
JRubyMethod
(
name
=
"setrlimit"
,
rest
=
true
,
module
=
true
,
visibility
=
PRIVATE
)
public
static
IRubyObject
setrlimit
(
IRubyObject
recv
,
IRubyObject
[]
args
) {
throw
recv
.
getRuntime
().
newNotImplementedError
(
"Process#setrlimit not yet implemented"
);
}
@
Deprecated
public
static
IRubyObject
getpgrp
(
IRubyObject
recv
) {
return
getpgrp
(
recv
.
getRuntime
());
}
@
JRubyMethod
(
name
=
"getpgrp"
,
module
=
true
,
visibility
=
PRIVATE
)
public
static
IRubyObject
getpgrp
(
ThreadContext
context
,
IRubyObject
recv
) {
return
getpgrp
(
context
.
runtime
);
}
public
static
IRubyObject
getpgrp
(
Ruby
runtime
) {
return
runtime
.
newFixnum
(
runtime
.
getPosix
().
getpgrp
());
}
@
JRubyMethod
(
name
=
"groups="
,
required
=
1
,
module
=
true
,
visibility
=
PRIVATE
)
public
static
IRubyObject
groups_set
(
IRubyObject
recv
,
IRubyObject
arg
) {
throw
recv
.
getRuntime
().
newNotImplementedError
(
"Process#groups not yet implemented"
);
}
@
Deprecated
public
static
IRubyObject
waitpid
(
IRubyObject
recv
,
IRubyObject
[]
args
) {
return
waitpid
(
recv
.
getRuntime
(),
args
);
}
@
JRubyMethod
(
name
=
"waitpid"
,
rest
=
true
,
module
=
true
,
visibility
=
PRIVATE
)
public
static
IRubyObject
waitpid
(
ThreadContext
context
,
IRubyObject
recv
,
IRubyObject
[]
args
) {
return
waitpid
(
context
.
runtime
,
args
);
}
public
static
IRubyObject
waitpid
(
Ruby
runtime
,
IRubyObject
[]
args
) {
int
pid
= -
1
;
int
flags
=
0
;
if
(
args
.
length
>
0
) {
pid
= (
int
)
args
[
0
].
convertToInteger
().
getLongValue
();
}
if
(
args
.
length
>
1
) {
flags
= (
int
)
args
[
1
].
convertToInteger
().
getLongValue
();
}
int
[]
status
=
new
int
[
1
];
runtime
.
getPosix
().
errno
(
0
);
pid
=
runtime
.
getPosix
().
waitpid
(
pid
,
status
,
flags
);
raiseErrnoIfSet
(
runtime
,
ECHILD
);
runtime
.
getCurrentContext
().
setLastExitStatus
(
RubyProcess
.
RubyStatus
.
newProcessStatus
(
runtime
, (
status
[
0
] >>
8
) &
0xff
,
pid
));
return
runtime
.
newFixnum
(
pid
);
}
private
interface
NonNativeErrno
{
public
int
handle
(
Ruby
runtime
,
int
result
);
}
private
static
final
NonNativeErrno
ECHILD
=
new
NonNativeErrno
() {
public
int
handle
(
Ruby
runtime
,
int
result
) {
throw
runtime
.
newErrnoECHILDError
();
}
};
@
Deprecated
public
static
IRubyObject
wait
(
IRubyObject
recv
,
IRubyObject
[]
args
) {
return
wait
(
recv
.
getRuntime
(),
args
);
}
@
JRubyMethod
(
name
=
"wait"
,
rest
=
true
,
module
=
true
,
visibility
=
PRIVATE
)
public
static
IRubyObject
wait
(
ThreadContext
context
,
IRubyObject
recv
,
IRubyObject
[]
args
) {
return
wait
(
context
.
runtime
,
args
);
}
public
static
IRubyObject
wait
(
Ruby
runtime
,
IRubyObject
[]
args
) {
if
(
args
.
length
>
0
) {
return
waitpid
(
runtime
,
args
);
}
int
[]
status
=
new
int
[
1
];
runtime
.
getPosix
().
errno
(
0
);
int
pid
=
runtime
.
getPosix
().
wait
(
status
);
raiseErrnoIfSet
(
runtime
,
ECHILD
);
runtime
.
getCurrentContext
().
setLastExitStatus
(
RubyProcess
.
RubyStatus
.
newProcessStatus
(
runtime
, (
status
[
0
] >>
8
) &
0xff
,
pid
));
return
runtime
.
newFixnum
(
pid
);
}
@
Deprecated
public
static
IRubyObject
waitall
(
IRubyObject
recv
) {
return
waitall
(
recv
.
getRuntime
());
}
@
JRubyMethod
(
name
=
"waitall"
,
module
=
true
,
visibility
=
PRIVATE
)
public
static
IRubyObject
waitall
(
ThreadContext
context
,
IRubyObject
recv
) {
return
waitall
(
context
.
runtime
);
}
public
static
IRubyObject
waitall
(
Ruby
runtime
) {
POSIX
posix
=
runtime
.
getPosix
();
RubyArray
results
=
runtime
.
newArray
();
int
[]
status
=
new
int
[
1
];
int
result
=
posix
.
wait
(
status
);
while
(
result
!= -
1
) {
results
.
append
(
runtime
.
newArray
(
runtime
.
newFixnum
(
result
),
RubyProcess
.
RubyStatus
.
newProcessStatus
(
runtime
, (
status
[
0
] >>
8
) &
0xff
,
result
)));
result
=
posix
.
wait
(
status
);
}
return
results
;
}
@
Deprecated
public
static
IRubyObject
setsid
(
IRubyObject
recv
) {
return
setsid
(
recv
.
getRuntime
());
}
@
JRubyMethod
(
name
=
"setsid"
,
module
=
true
,
visibility
=
PRIVATE
)
public
static
IRubyObject
setsid
(
ThreadContext
context
,
IRubyObject
recv
) {
return
setsid
(
context
.
runtime
);
}
public
static
IRubyObject
setsid
(
Ruby
runtime
) {
return
runtime
.
newFixnum
(
checkErrno
(
runtime
,
runtime
.
getPosix
().
setsid
()));
}
@
Deprecated
public
static
IRubyObject
setpgrp
(
IRubyObject
recv
) {
return
setpgrp
(
recv
.
getRuntime
());
}
@
JRubyMethod
(
name
=
"setpgrp"
,
module
=
true
,
visibility
=
PRIVATE
)
public
static
IRubyObject
setpgrp
(
ThreadContext
context
,
IRubyObject
recv
) {
return
setpgrp
(
context
.
runtime
);
}
public
static
IRubyObject
setpgrp
(
Ruby
runtime
) {
return
runtime
.
newFixnum
(
checkErrno
(
runtime
,
runtime
.
getPosix
().
setpgid
(
0
,
0
)));
}
@
Deprecated
public
static
IRubyObject
egid_set
(
IRubyObject
recv
,
IRubyObject
arg
) {
return
egid_set
(
recv
.
getRuntime
(),
arg
);
}
@
JRubyMethod
(
name
=
"egid="
,
required
=
1
,
module
=
true
,
visibility
=
PRIVATE
)
public
static
IRubyObject
egid_set
(
ThreadContext
context
,
IRubyObject
recv
,
IRubyObject
arg
) {
return
egid_set
(
context
.
runtime
,
arg
);
}
public
static
IRubyObject
egid_set
(
Ruby
runtime
,
IRubyObject
arg
) {
checkErrno
(
runtime
,
runtime
.
getPosix
().
setegid
((
int
)
arg
.
convertToInteger
().
getLongValue
()));
return
RubyFixnum
.
zero
(
runtime
);
}
@
Deprecated
public
static
IRubyObject
euid
(
IRubyObject
recv
) {
return
euid
(
recv
.
getRuntime
());
}
@
JRubyMethod
(
name
=
"euid"
,
module
=
true
,
visibility
=
PRIVATE
)
public
static
IRubyObject
euid
(
ThreadContext
context
,
IRubyObject
recv
) {
return
euid
(
context
.
runtime
);
}
public
static
IRubyObject
euid
(
Ruby
runtime
) {
return
runtime
.
newFixnum
(
checkErrno
(
runtime
,
runtime
.
getPosix
().
geteuid
()));
}
@
Deprecated
public
static
IRubyObject
uid_set
(
IRubyObject
recv
,
IRubyObject
arg
) {
return
uid_set
(
recv
.
getRuntime
(),
arg
);
}
@
JRubyMethod
(
name
=
"uid="
,
required
=
1
,
module
=
true
,
visibility
=
PRIVATE
)
public
static
IRubyObject
uid_set
(
ThreadContext
context
,
IRubyObject
recv
,
IRubyObject
arg
) {
return
uid_set
(
context
.
runtime
,
arg
);
}
public
static
IRubyObject
uid_set
(
Ruby
runtime
,
IRubyObject
arg
) {
checkErrno
(
runtime
,
runtime
.
getPosix
().
setuid
((
int
)
arg
.
convertToInteger
().
getLongValue
()));
return
RubyFixnum
.
zero
(
runtime
);
}
@
Deprecated
public
static
IRubyObject
gid
(
IRubyObject
recv
) {
return
gid
(
recv
.
getRuntime
());
}
@
JRubyMethod
(
name
=
"gid"
,
module
=
true
,
visibility
=
PRIVATE
)
public
static
IRubyObject
gid
(
ThreadContext
context
,
IRubyObject
recv
) {
return
gid
(
context
.
runtime
);
}
public
static
IRubyObject
gid
(
Ruby
runtime
) {
if
(
Platform
.
IS_WINDOWS
) {
// MRI behavior on Windows
return
RubyFixnum
.
zero
(
runtime
);
}
return
runtime
.
newFixnum
(
checkErrno
(
runtime
,
runtime
.
getPosix
().
getgid
()));
}
@
JRubyMethod
(
name
=
"maxgroups"
,
module
=
true
,
visibility
=
PRIVATE
)
public
static
IRubyObject
maxgroups
(
IRubyObject
recv
) {
throw
recv
.
getRuntime
().
newNotImplementedError
(
"Process#maxgroups not yet implemented"
);
}
@
Deprecated
public
static
IRubyObject
getpriority
(
IRubyObject
recv
,
IRubyObject
arg1
,
IRubyObject
arg2
) {
return
getpriority
(
recv
.
getRuntime
(),
arg1
,
arg2
);
}
@
JRubyMethod
(
name
=
"getpriority"
,
required
=
2
,
module
=
true
,
visibility
=
PRIVATE
)
public
static
IRubyObject
getpriority
(
ThreadContext
context
,
IRubyObject
recv
,
IRubyObject
arg1
,
IRubyObject
arg2
) {
return
getpriority
(
context
.
runtime
,
arg1
,
arg2
);
}
public
static
IRubyObject
getpriority
(
Ruby
runtime
,
IRubyObject
arg1
,
IRubyObject
arg2
) {
int
which
= (
int
)
arg1
.
convertToInteger
().
getLongValue
();
int
who
= (
int
)
arg2
.
convertToInteger
().
getLongValue
();
int
result
=
checkErrno
(
runtime
,
runtime
.
getPosix
().
getpriority
(
which
,
who
));
return
runtime
.
newFixnum
(
result
);
}
@
Deprecated
public
static
IRubyObject
uid
(
IRubyObject
recv
) {
return
uid
(
recv
.
getRuntime
());
}
@
JRubyMethod
(
name
=
"uid"
,
module
=
true
,
visibility
=
PRIVATE
)
public
static
IRubyObject
uid
(
ThreadContext
context
,
IRubyObject
recv
) {
return
uid
(
context
.
runtime
);
}
public
static
IRubyObject
uid
(
Ruby
runtime
) {
return
runtime
.
newFixnum
(
checkErrno
(
runtime
,
runtime
.
getPosix
().
getuid
()));
}
@
Deprecated
public
static
IRubyObject
waitpid2
(
IRubyObject
recv
,
IRubyObject
[]
args
) {
return
waitpid2
(
recv
.
getRuntime
(),
args
);
}
@
JRubyMethod
(
name
=
"waitpid2"
,
rest
=
true
,
module
=
true
,
visibility
=
PRIVATE
)
public
static
IRubyObject
waitpid2
(
ThreadContext
context
,
IRubyObject
recv
,
IRubyObject
[]
args
) {
return
waitpid2
(
context
.
runtime
,
args
);
}
public
static
IRubyObject
waitpid2
(
Ruby
runtime
,
IRubyObject
[]
args
) {
int
pid
= -
1
;
int
flags
=
0
;
if
(
args
.
length
>
0
) {
pid
= (
int
)
args
[
0
].
convertToInteger
().
getLongValue
();
}
if
(
args
.
length
>
1
) {
flags
= (
int
)
args
[
1
].
convertToInteger
().
getLongValue
();
}
int
[]
status
=
new
int
[
1
];
pid
=
checkErrno
(
runtime
,
runtime
.
getPosix
().
waitpid
(
pid
,
status
,
flags
),
ECHILD
);
return
runtime
.
newArray
(
runtime
.
newFixnum
(
pid
),
RubyProcess
.
RubyStatus
.
newProcessStatus
(
runtime
, (
status
[
0
] >>
8
) &
0xff
,
pid
));
}
@
JRubyMethod
(
name
=
"initgroups"
,
required
=
2
,
module
=
true
,
visibility
=
PRIVATE
)
public
static
IRubyObject
initgroups
(
IRubyObject
recv
,
IRubyObject
arg1
,
IRubyObject
arg2
) {
throw
recv
.
getRuntime
().
newNotImplementedError
(
"Process#initgroups not yet implemented"
);
}
@
JRubyMethod
(
name
=
"maxgroups="
,
required
=
1
,
module
=
true
,
visibility
=
PRIVATE
)
public
static
IRubyObject
maxgroups_set
(
IRubyObject
recv
,
IRubyObject
arg
) {
throw
recv
.
getRuntime
().
newNotImplementedError
(
"Process#maxgroups_set not yet implemented"
);
}
@
Deprecated
public
static
IRubyObject
ppid
(
IRubyObject
recv
) {
return
ppid
(
recv
.
getRuntime
());
}
@
JRubyMethod
(
name
=
"ppid"
,
module
=
true
,
visibility
=
PRIVATE
)
public
static
IRubyObject
ppid
(
ThreadContext
context
,
IRubyObject
recv
) {
return
ppid
(
context
.
runtime
);
}
public
static
IRubyObject
ppid
(
Ruby
runtime
) {
int
result
=
checkErrno
(
runtime
,
runtime
.
getPosix
().
getppid
());
return
runtime
.
newFixnum
(
result
);
}
@
Deprecated
public
static
IRubyObject
gid_set
(
IRubyObject
recv
,
IRubyObject
arg
) {
return
gid_set
(
recv
.
getRuntime
(),
arg
);
}
@
JRubyMethod
(
name
=
"gid="
,
required
=
1
,
module
=
true
,
visibility
=
PRIVATE
)
public
static
IRubyObject
gid_set
(
ThreadContext
context
,
IRubyObject
recv
,
IRubyObject
arg
) {
return
gid_set
(
context
.
runtime
,
arg
);
}
public
static
IRubyObject
gid_set
(
Ruby
runtime
,
IRubyObject
arg
) {
int
result
=
checkErrno
(
runtime
,
runtime
.
getPosix
().
setgid
((
int
)
arg
.
convertToInteger
().
getLongValue
()));
return
runtime
.
newFixnum
(
result
);
}
@
Deprecated
public
static
IRubyObject
wait2
(
IRubyObject
recv
,
IRubyObject
[]
args
) {
return
waitpid2
(
recv
.
getRuntime
(),
args
);
}
@
JRubyMethod
(
name
=
"wait2"
,
rest
=
true
,
module
=
true
,
visibility
=
PRIVATE
)
public
static
IRubyObject
wait2
(
ThreadContext
context
,
IRubyObject
recv
,
IRubyObject
[]
args
) {
return
waitpid2
(
context
.
runtime
,
args
);
}
@
Deprecated
public
static
IRubyObject
euid_set
(
IRubyObject
recv
,
IRubyObject
arg
) {
return
euid_set
(
recv
.
getRuntime
(),
arg
);
}
@
JRubyMethod
(
name
=
"euid="
,
required
=
1
,
module
=
true
,
visibility
=
PRIVATE
)
public
static
IRubyObject
euid_set
(
ThreadContext
context
,
IRubyObject
recv
,
IRubyObject
arg
) {
return
euid_set
(
context
.
runtime
,
arg
);
}
public
static
IRubyObject
euid_set
(
Ruby
runtime
,
IRubyObject
arg
) {
checkErrno
(
runtime
,
runtime
.
getPosix
().
seteuid
((
int
)
arg
.
convertToInteger
().
getLongValue
()));
return
RubyFixnum
.
zero
(
runtime
);
}
@
Deprecated
public
static
IRubyObject
setpriority
(
IRubyObject
recv
,
IRubyObject
arg1
,
IRubyObject
arg2
,
IRubyObject
arg3
) {
return
setpriority
(
recv
.
getRuntime
(),
arg1
,
arg2
,
arg3
);
}
@
JRubyMethod
(
name
=
"setpriority"
,
required
=
3
,
module
=
true
,
visibility
=
PRIVATE
)
public
static
IRubyObject
setpriority
(
ThreadContext
context
,
IRubyObject
recv
,
IRubyObject
arg1
,
IRubyObject
arg2
,
IRubyObject
arg3
) {
return
setpriority
(
context
.
runtime
,
arg1
,
arg2
,
arg3
);
}
public
static
IRubyObject
setpriority
(
Ruby
runtime
,
IRubyObject
arg1
,
IRubyObject
arg2
,
IRubyObject
arg3
) {
int
which
= (
int
)
arg1
.
convertToInteger
().
getLongValue
();
int
who
= (
int
)
arg2
.
convertToInteger
().
getLongValue
();
int
prio
= (
int
)
arg3
.
convertToInteger
().
getLongValue
();
runtime
.
getPosix
().
errno
(
0
);
int
result
=
checkErrno
(
runtime
,
runtime
.
getPosix
().
setpriority
(
which
,
who
,
prio
));
return
runtime
.
newFixnum
(
result
);
}
@
Deprecated
public
static
IRubyObject
setpgid
(
IRubyObject
recv
,
IRubyObject
arg1
,
IRubyObject
arg2
) {
return
setpgid
(
recv
.
getRuntime
(),
arg1
,
arg2
);
}
@
JRubyMethod
(
name
=
"setpgid"
,
required
=
2
,
module
=
true
,
visibility
=
PRIVATE
)
public
static
IRubyObject
setpgid
(
ThreadContext
context
,
IRubyObject
recv
,
IRubyObject
arg1
,
IRubyObject
arg2
) {
return
setpgid
(
context
.
runtime
,
arg1
,
arg2
);
}
public
static
IRubyObject
setpgid
(
Ruby
runtime
,
IRubyObject
arg1
,
IRubyObject
arg2
) {
int
pid
= (
int
)
arg1
.
convertToInteger
().
getLongValue
();
int
gid
= (
int
)
arg2
.
convertToInteger
().
getLongValue
();
return
runtime
.
newFixnum
(
checkErrno
(
runtime
,
runtime
.
getPosix
().
setpgid
(
pid
,
gid
)));
}
@
Deprecated
public
static
IRubyObject
getpgid
(
IRubyObject
recv
,
IRubyObject
arg
) {
return
getpgid
(
recv
.
getRuntime
(),
arg
);
}
@
JRubyMethod
(
name
=
"getpgid"
,
required
=
1
,
module
=
true
,
visibility
=
PRIVATE
)
public
static
IRubyObject
getpgid
(
ThreadContext
context
,
IRubyObject
recv
,
IRubyObject
arg
) {
return
getpgid
(
context
.
runtime
,
arg
);
}
public
static
IRubyObject
getpgid
(
Ruby
runtime
,
IRubyObject
arg
) {
return
runtime
.
newFixnum
(
checkErrno
(
runtime
,
runtime
.
getPosix
().
getpgid
((
int
)
arg
.
convertToInteger
().
getLongValue
())));
}
@
Deprecated
public
static
IRubyObject
getrlimit
(
IRubyObject
recv
,
IRubyObject
arg
) {
return
getrlimit
(
recv
.
getRuntime
(),
arg
);
}
@
JRubyMethod
(
name
=
"getrlimit"
,
required
=
1
,
module
=
true
,
visibility
=
PRIVATE
)
public
static
IRubyObject
getrlimit
(
ThreadContext
context
,
IRubyObject
recv
,
IRubyObject
arg
) {
return
getrlimit
(
context
.
runtime
,
arg
);
}
public
static
IRubyObject
getrlimit
(
Ruby
runtime
,
IRubyObject
arg
) {
throw
runtime
.
newNotImplementedError
(
"Process#getrlimit not yet implemented"
);
}
@
Deprecated
public
static
IRubyObject
egid
(
IRubyObject
recv
) {
return
egid
(
recv
.
getRuntime
());
}
@
JRubyMethod
(
name
=
"egid"
,
module
=
true
,
visibility
=
PRIVATE
)
public
static
IRubyObject
egid
(
ThreadContext
context
,
IRubyObject
recv
) {
return
egid
(
context
.
runtime
);
}
public
static
IRubyObject
egid
(
Ruby
runtime
) {
if
(
Platform
.
IS_WINDOWS
) {
// MRI behavior on Windows
return
RubyFixnum
.
zero
(
runtime
);
}
return
runtime
.
newFixnum
(
checkErrno
(
runtime
,
runtime
.
getPosix
().
getegid
()));
}
private
static
int
parseSignalString
(
Ruby
runtime
,
String
value
) {
boolean
negative
=
value
.
startsWith
(
"-"
);
// Gets rid of the - if there is one present.
if
(
negative
)
value
=
value
.
substring
(
1
);
// We need the SIG for sure.
String
signalName
=
value
.
startsWith
(
"SIG"
) ?
value
:
"SIG"
+
value
;
try
{
int
signalValue
=
Signal
.
valueOf
(
signalName
).
intValue
();
return
negative
? -
signalValue
:
signalValue
;
}
catch
(
IllegalArgumentException
ex
) {
throw
runtime
.
newArgumentError
(
"unsupported name `"
+
signalName
+
"'"
);
}
}
public
static
interface
Kernel32
{
jnr
.
ffi
.
Pointer
OpenProcess
(
int
dwDesiredAccess
,
int
bInheritHandle
,
int
dwProcessId
);
int
CloseHandle
(
jnr
.
ffi
.
Pointer
handle
);
int
GetLastError
();
int
GetExitCodeProcess
(
jnr
.
ffi
.
Pointer
hProcess
,
jnr
.
ffi
.
Pointer
pointerToExitCodeDword
);
int
TerminateProcess
(
jnr
.
ffi
.
Pointer
hProcess
,
int
uExitCode
);
}
private
static
class
Kernel32Holder
{
static
Kernel32
kernel32Instance
=
Library
.
loadLibrary
(
"kernel32"
,
Kernel32
.
class
);
// instantiated lazily
}
static
Kernel32
kernel32
() {
return
Kernel32Holder
.
kernel32Instance
;
}
@
Deprecated
public
static
IRubyObject
kill
(
IRubyObject
recv
,
IRubyObject
[]
args
) {
return
kill
(
recv
.
getRuntime
(),
args
);
}
@
JRubyMethod
(
name
=
"kill"
,
rest
=
true
,
module
=
true
,
visibility
=
PRIVATE
)
public
static
IRubyObject
kill
(
ThreadContext
context
,
IRubyObject
recv
,
IRubyObject
[]
args
) {
return
kill
(
context
.
runtime
,
args
);
}
public
static
IRubyObject
kill
(
Ruby
runtime
,
IRubyObject
[]
args
) {
if
(
args
.
length
<
2
) {
throw
runtime
.
newArgumentError
(
"wrong number of arguments -- kill(sig, pid...)"
);
}
int
signal
;
if
(
args
[
0
]
instanceof
RubyFixnum
) {
signal
= (
int
) ((
RubyFixnum
)
args
[
0
]).
getLongValue
();
}
else
if
(
args
[
0
]
instanceof
RubySymbol
) {
signal
=
parseSignalString
(
runtime
,
args
[
0
].
toString
());
}
else
if
(
args
[
0
]
instanceof
RubyString
) {
signal
=
parseSignalString
(
runtime
,
args
[
0
].
toString
());
}
else
{
signal
=
parseSignalString
(
runtime
,
args
[
0
].
checkStringType
().
toString
());
}
boolean
processGroupKill
=
signal
<
0
;
if
(
processGroupKill
) {
if
(
Platform
.
IS_WINDOWS
) {
throw
runtime
.
newErrnoEINVALError
(
"group signals not implemented in windows"
);
}
signal
= -
signal
;
}
if
(
Platform
.
IS_WINDOWS
) {
int
PROCESS_QUERY_INFORMATION
=
0x0400
;
int
ERROR_INVALID_PARAMETER
=
0x57
;
int
PROCESS_TERMINATE
=
0x0001
;
int
STILL_ACTIVE
=
259
;
jnr
.
ffi
.
Pointer
status
=
Memory
.
allocate
(
Library
.
getRuntime
(
kernel32
()),
4
);
for
(
int
i
=
1
;
i
<
args
.
length
;
i
++) {
int
pid
=
RubyNumeric
.
num2int
(
args
[
i
]);
if
(
signal
==
0
) {
jnr
.
ffi
.
Pointer
ptr
=
kernel32
().
OpenProcess
(
PROCESS_QUERY_INFORMATION
,
0
,
pid
);
if
(
ptr
!=
null
&&
ptr
.
address
() != -
1
) {
try
{
if
(
kernel32
().
GetExitCodeProcess
(
ptr
,
status
) ==
0
) {
throw
runtime
.
newErrnoEPERMError
(
"unable to call GetExitCodeProcess "
+
pid
);
}
else
{
if
(
status
.
getInt
(
0
) !=
STILL_ACTIVE
) {
throw
runtime
.
newErrnoEPERMError
(
"Process exists but is not alive anymore "
+
pid
);
}
}
}
finally
{
kernel32
().
CloseHandle
(
ptr
);
}
}
else
{
if
(
kernel32
().
GetLastError
() ==
ERROR_INVALID_PARAMETER
) {
throw
runtime
.
newErrnoESRCHError
();
}
else
{
throw
runtime
.
newErrnoEPERMError
(
"Process does not exist "
+
pid
);
}
}
}
else
if
(
signal
==
9
) {
//SIGKILL
jnr
.
ffi
.
Pointer
ptr
=
kernel32
().
OpenProcess
(
PROCESS_TERMINATE
|
PROCESS_QUERY_INFORMATION
,
0
,
pid
);
if
(
ptr
!=
null
&&
ptr
.
address
() != -
1
) {
try
{
if
(
kernel32
().
GetExitCodeProcess
(
ptr
,
status
) ==
0
) {
throw
runtime
.
newErrnoEPERMError
(
"unable to call GetExitCodeProcess "
+
pid
);
// todo better error messages
}
else
{
if
(
status
.
getInt
(
0
) ==
STILL_ACTIVE
) {
if
(
kernel32
().
TerminateProcess
(
ptr
,
0
) ==
0
) {
throw
runtime
.
newErrnoEPERMError
(
"unable to call TerminateProcess "
+
pid
);
}
// success
}
}
}
finally
{
kernel32
().
CloseHandle
(
ptr
);
}
}
else
{
if
(
kernel32
().
GetLastError
() ==
ERROR_INVALID_PARAMETER
) {
throw
runtime
.
newErrnoESRCHError
();
}
else
{
throw
runtime
.
newErrnoEPERMError
(
"Process does not exist "
+
pid
);
}
}
}
else
{
throw
runtime
.
newNotImplementedError
(
"this signal not yet implemented in windows"
);
}
}
}
else
{
POSIX
posix
=
runtime
.
getPosix
();
for
(
int
i
=
1
;
i
<
args
.
length
;
i
++) {
int
pid
=
RubyNumeric
.
num2int
(
args
[
i
]);
// FIXME: It may be possible to killpg on systems which support it. POSIX library
// needs to tell whether a particular method works or not
if
(
pid
==
0
)
pid
=
runtime
.
getPosix
().
getpid
();
checkErrno
(
runtime
,
posix
.
kill
(
processGroupKill
? -
pid
:
pid
,
signal
));
View remainder of file in raw view
Back
|
FazBrowse Home
|
New Git URL