systemu 1.1.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README +18 -7
- data/README.tmpl +11 -1
- data/a.rb +2 -11
- data/lib/systemu.rb +39 -29
- data/samples/f.rb +2 -2
- metadata +3 -4
- data/systemu-1.1.0.gem +0 -0
data/README
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
NAME
|
2
2
|
|
3
|
-
systemu
|
3
|
+
systemu
|
4
4
|
|
5
5
|
SYNOPSIS
|
6
6
|
|
@@ -10,11 +10,21 @@ URIS
|
|
10
10
|
|
11
11
|
http://rubyforge.org/projects/codeforpeople/
|
12
12
|
http://codeforpeople.com/lib/ruby/
|
13
|
+
http://codeforpeople.rubyforge.org/svn/
|
13
14
|
|
14
15
|
INSTALL
|
15
16
|
|
16
17
|
gem install systemu
|
17
18
|
|
19
|
+
HISTORY
|
20
|
+
|
21
|
+
1.2.0
|
22
|
+
|
23
|
+
- fixed handling of background thread management - needed
|
24
|
+
Thread.current.abort_on_exception = true
|
25
|
+
|
26
|
+
- fixed reporting of child pid, it was reported as the parent's pid before
|
27
|
+
|
18
28
|
SAMPLES
|
19
29
|
|
20
30
|
<========< samples/a.rb >========>
|
@@ -35,7 +45,7 @@ SAMPLES
|
|
35
45
|
|
36
46
|
~ > ruby samples/a.rb
|
37
47
|
|
38
|
-
[#<Process::Status: pid=
|
48
|
+
[#<Process::Status: pid=987,exited(0)>, "Thu Dec 06 16:01:59 -0700 2007\n", "Thu Dec 06 16:01:59 -0700 2007\n"]
|
39
49
|
|
40
50
|
|
41
51
|
<========< samples/b.rb >========>
|
@@ -57,7 +67,7 @@ SAMPLES
|
|
57
67
|
|
58
68
|
~ > ruby samples/b.rb
|
59
69
|
|
60
|
-
[#<Process::Status: pid=
|
70
|
+
[#<Process::Status: pid=992,exited(0)>, "Thu Dec 06 16:01:59 -0700 2007\n", "Thu Dec 06 16:01:59 -0700 2007\n"]
|
61
71
|
|
62
72
|
|
63
73
|
<========< samples/c.rb >========>
|
@@ -98,7 +108,7 @@ SAMPLES
|
|
98
108
|
|
99
109
|
~ > ruby samples/d.rb
|
100
110
|
|
101
|
-
/tmp
|
111
|
+
/private/tmp
|
102
112
|
|
103
113
|
|
104
114
|
<========< samples/e.rb >========>
|
@@ -140,10 +150,11 @@ SAMPLES
|
|
140
150
|
Process.kill 9, cid
|
141
151
|
end
|
142
152
|
|
143
|
-
p
|
144
|
-
|
153
|
+
p status
|
154
|
+
p stderr
|
145
155
|
|
146
156
|
~ > ruby samples/f.rb
|
147
157
|
|
148
|
-
|
158
|
+
#<Process::Status: pid=1012,signaled(SIGKILL=9)>
|
159
|
+
"1196982119\n1196982120\n1196982121\n"
|
149
160
|
|
data/README.tmpl
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
NAME
|
2
2
|
|
3
|
-
systemu
|
3
|
+
systemu
|
4
4
|
|
5
5
|
SYNOPSIS
|
6
6
|
|
@@ -10,11 +10,21 @@ URIS
|
|
10
10
|
|
11
11
|
http://rubyforge.org/projects/codeforpeople/
|
12
12
|
http://codeforpeople.com/lib/ruby/
|
13
|
+
http://codeforpeople.rubyforge.org/svn/
|
13
14
|
|
14
15
|
INSTALL
|
15
16
|
|
16
17
|
gem install systemu
|
17
18
|
|
19
|
+
HISTORY
|
20
|
+
|
21
|
+
1.2.0
|
22
|
+
|
23
|
+
- fixed handling of background thread management - needed
|
24
|
+
Thread.current.abort_on_exception = true
|
25
|
+
|
26
|
+
- fixed reporting of child pid, it was reported as the parent's pid before
|
27
|
+
|
18
28
|
SAMPLES
|
19
29
|
|
20
30
|
@samples
|
data/a.rb
CHANGED
@@ -1,15 +1,6 @@
|
|
1
|
-
require 'rubygems'
|
2
1
|
require 'systemu'
|
3
2
|
|
4
|
-
threads = []
|
5
3
|
|
6
|
-
|
7
|
-
|
8
|
-
status, stdout, stderr = systemu 'cat', :stdin => ('42' * 1024)
|
9
|
-
[status, stdout[0..15]]
|
10
|
-
end
|
11
|
-
threads << t
|
4
|
+
systemu 'date' do |cid|
|
5
|
+
p cid
|
12
6
|
end
|
13
|
-
|
14
|
-
threads.map{|t| p t.value}
|
15
|
-
|
data/lib/systemu.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# vim: ts=2:sw=2:sts=2:et:fdm=marker
|
1
2
|
require 'tmpdir'
|
2
3
|
require 'socket'
|
3
4
|
require 'fileutils'
|
@@ -10,12 +11,11 @@ class Object
|
|
10
11
|
end
|
11
12
|
|
12
13
|
class SystemUniversal
|
13
|
-
#--{{{
|
14
14
|
#
|
15
15
|
# constants
|
16
16
|
#
|
17
|
-
SystemUniversal::VERSION = '1.
|
18
|
-
def version() VERSION end
|
17
|
+
SystemUniversal::VERSION = '1.2.0' unless defined? SystemUniversal::VERSION
|
18
|
+
def version() SystemUniversal::VERSION end
|
19
19
|
#
|
20
20
|
# class methods
|
21
21
|
#
|
@@ -42,7 +42,6 @@ class SystemUniversal
|
|
42
42
|
#
|
43
43
|
|
44
44
|
def initialize argv, opts = {}, &block
|
45
|
-
#--{{{
|
46
45
|
getopt = getopts opts
|
47
46
|
|
48
47
|
@argv = argv
|
@@ -58,21 +57,16 @@ class SystemUniversal
|
|
58
57
|
@ppid = getopt[ 'ppid', self.class.ppid ]
|
59
58
|
@pid = getopt[ 'pid', self.class.pid ]
|
60
59
|
@ruby = getopt[ 'ruby', self.class.ruby ]
|
61
|
-
#--}}}
|
62
60
|
end
|
63
61
|
|
64
62
|
def systemu
|
65
|
-
#--{{{
|
66
63
|
tmpdir do |tmp|
|
67
64
|
c = child_setup tmp
|
68
65
|
status = nil
|
69
66
|
|
70
|
-
if @block
|
71
|
-
q = Queue.new
|
72
|
-
t = Thread.new{ Thread.current_abort_on_exception = true; @block[ q.pop ] }
|
73
|
-
end
|
74
|
-
|
75
67
|
begin
|
68
|
+
thread = nil
|
69
|
+
|
76
70
|
quietly{
|
77
71
|
IO.popen "#{ @ruby } #{ c['program'] }", 'r+' do |pipe|
|
78
72
|
line = pipe.gets
|
@@ -90,14 +84,22 @@ class SystemUniversal
|
|
90
84
|
raise "wtf?\n#{ buf }\n"
|
91
85
|
end
|
92
86
|
end
|
93
|
-
|
94
|
-
q.push cid if @block
|
87
|
+
thread = new_thread cid, @block if @block
|
95
88
|
pipe.read rescue nil
|
96
89
|
end
|
97
90
|
}
|
98
91
|
status = $?
|
99
92
|
ensure
|
100
|
-
|
93
|
+
if thread
|
94
|
+
begin
|
95
|
+
class << status
|
96
|
+
attr 'thread'
|
97
|
+
end
|
98
|
+
status.instance_eval{ @thread = thread }
|
99
|
+
rescue
|
100
|
+
42
|
101
|
+
end
|
102
|
+
end
|
101
103
|
end
|
102
104
|
|
103
105
|
if @stdout or @stderr
|
@@ -108,11 +110,20 @@ class SystemUniversal
|
|
108
110
|
[status, IO.read(c['stdout']), IO.read(c['stderr'])]
|
109
111
|
end
|
110
112
|
end
|
111
|
-
|
113
|
+
end
|
114
|
+
|
115
|
+
def new_thread cid, block
|
116
|
+
q = Queue.new
|
117
|
+
Thread.new(cid) do |cid|
|
118
|
+
current = Thread.current
|
119
|
+
current.abort_on_exception = true
|
120
|
+
q.push current
|
121
|
+
block.call cid
|
122
|
+
end
|
123
|
+
q.pop
|
112
124
|
end
|
113
125
|
|
114
126
|
def child_setup tmp
|
115
|
-
#--{{{
|
116
127
|
stdin = File.expand_path(File.join(tmp, 'stdin'))
|
117
128
|
stdout = File.expand_path(File.join(tmp, 'stdout'))
|
118
129
|
stderr = File.expand_path(File.join(tmp, 'stderr'))
|
@@ -140,21 +151,17 @@ class SystemUniversal
|
|
140
151
|
open(program, 'w'){|f| f.write child_program(config)}
|
141
152
|
|
142
153
|
c
|
143
|
-
#--}}}
|
144
154
|
end
|
145
155
|
|
146
156
|
def quietly
|
147
|
-
#--{{{
|
148
157
|
v = $VERBOSE
|
149
158
|
$VERBOSE = nil
|
150
159
|
yield
|
151
160
|
ensure
|
152
161
|
$VERBOSE = v
|
153
|
-
#--}}}
|
154
162
|
end
|
155
163
|
|
156
164
|
def child_program config
|
157
|
-
#--{{{
|
158
165
|
<<-program
|
159
166
|
PIPE = STDOUT.dup
|
160
167
|
begin
|
@@ -176,7 +183,7 @@ class SystemUniversal
|
|
176
183
|
STDOUT.reopen stdout
|
177
184
|
STDERR.reopen stderr
|
178
185
|
|
179
|
-
PIPE.puts "pid:
|
186
|
+
PIPE.puts "pid: \#{ Process.pid }"
|
180
187
|
PIPE.flush ### the process is ready yo!
|
181
188
|
PIPE.close
|
182
189
|
|
@@ -186,22 +193,18 @@ class SystemUniversal
|
|
186
193
|
exit 42
|
187
194
|
end
|
188
195
|
program
|
189
|
-
#--}}}
|
190
196
|
end
|
191
197
|
|
192
198
|
def relay srcdst
|
193
|
-
#--{{{
|
194
199
|
src, dst, ignored = srcdst.to_a.first
|
195
200
|
if src.respond_to? 'read'
|
196
201
|
while((buf = src.read(8192))); dst << buf; end
|
197
202
|
else
|
198
203
|
src.each{|buf| dst << buf}
|
199
204
|
end
|
200
|
-
#--}}}
|
201
205
|
end
|
202
206
|
|
203
207
|
def tmpdir d = Dir.tmpdir, max = 42, &b
|
204
|
-
#--{{{
|
205
208
|
i = -1 and loop{
|
206
209
|
i += 1
|
207
210
|
|
@@ -226,11 +229,9 @@ class SystemUniversal
|
|
226
229
|
end
|
227
230
|
)
|
228
231
|
}
|
229
|
-
#--}}}
|
230
232
|
end
|
231
233
|
|
232
234
|
def getopts opts = {}
|
233
|
-
#--{{{
|
234
235
|
lambda do |*args|
|
235
236
|
keys, default, ignored = args
|
236
237
|
catch('opt') do
|
@@ -242,14 +243,23 @@ class SystemUniversal
|
|
242
243
|
default
|
243
244
|
end
|
244
245
|
end
|
245
|
-
#--}}}
|
246
246
|
end
|
247
|
-
#--}}}
|
248
247
|
end
|
249
248
|
|
250
249
|
SystemU = SystemUniversal unless defined? SystemU
|
251
250
|
|
252
251
|
|
252
|
+
|
253
|
+
|
254
|
+
|
255
|
+
|
256
|
+
|
257
|
+
|
258
|
+
|
259
|
+
|
260
|
+
|
261
|
+
|
262
|
+
|
253
263
|
if $0 == __FILE__
|
254
264
|
#
|
255
265
|
# date
|
data/samples/f.rb
CHANGED
metadata
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
|
-
rubygems_version: 0.9.
|
2
|
+
rubygems_version: 0.9.4
|
3
3
|
specification_version: 1
|
4
4
|
name: systemu
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 1.
|
7
|
-
date: 2007-
|
6
|
+
version: 1.2.0
|
7
|
+
date: 2007-12-06 00:00:00 -07:00
|
8
8
|
summary: systemu
|
9
9
|
require_paths:
|
10
10
|
- lib
|
@@ -44,7 +44,6 @@ files:
|
|
44
44
|
- samples/d.rb
|
45
45
|
- samples/e.rb
|
46
46
|
- samples/f.rb
|
47
|
-
- systemu-1.1.0.gem
|
48
47
|
test_files: []
|
49
48
|
|
50
49
|
rdoc_options: []
|
data/systemu-1.1.0.gem
DELETED
File without changes
|