Article View: pl.comp.lang.ruby
Article #1296Problem with ruby-dbus and subprocesses
From: Marcin Lewandowski
Date: Wed, 01 Sep 2010 20:46
Date: Wed, 01 Sep 2010 20:46
95 lines
3836 bytes
3836 bytes
Hi,
I am writing a system, where there are a few small, slave ruby scripts
doing something, spawned by master one.
I encountered propably a bug, and I don't know, how to solve it, so
please give me some help...
Please consider following script:
#!/usr/bin/ruby
require 'glib2'
require 'dbus'
bus = DBus::SessionBus.instance
bus.glibize
service = bus.request_service("dummy.test")
class DummyDBUS < DBus::Object
dbus_interface "dummy.Test" do
dbus_method :Shutdown do
$mainloop.quit
end
dbus_method :Spawn do
system("/bin/sh -c 'while [ 1 ]; do echo . >> /tmp/dot; sleep 1;
done &'")
end
end
end
$mainloop = GLib::MainLoop.new
dbus_object = DummyDBUS.new "Application"
service.export dbus_object
$mainloop.run
The idea is that I spawn a some subprocesses after receiving a command
via DBus. Later they communicate via DBus after slave subprocesses had
performed their tasks.
Unfortunately, Shutdown() command does not work if you previously
spawn any subprocesses using Spawn() command. It kills the master
process, but DBus does not release service name until it
I've check that it does not matter if they are spawned like
system("/bin/sh -c 'while [ 1 ]; do echo . >> /tmp/dot; sleep 1; done
&'")
or
exec("while [ 1 ]; do echo . >> /tmp/dot; sleep 1; done &") if
fork.nil?
or any other way to daemonize subprocess (I've tried also
Daemons.daemonize).
So the first test case is:
1. Spawn master script mentioned above.
2. Call Shutdown() method via DBus.
3. Works perfectly - master process is killed and removed from DBus'
service list.
Second test case is:
1. Spawn master script mentioned above.
2. Call Spawn() method via DBus.
3. Check, for sure, if subprocess works (tailf /tmp/dot) and if it's
separated from master process (e.g. pstree)
4. Call Shutdown() method via DBus.
5. Bug! Master process gets killed (mainloop is stopped) but service
name is not released in DBus until subprocess is killed.
Why?
It seems that some DBus messages are waiting until subprocess is
killed - it's easy to see with dbus-monitor. But how it's possible
that spawning a subprocess causes buffering those data? Is it a ruby
internal bug? Maybe ruby-dbus bug? dbus itself?
PS. I've checked that also without calling bus.glibize, with normal
loop - the same effect.
PS2. I use ubuntu 10.04, ruby 1.8.7 (2010-01-10 patchlevel 249),
libdbus-ruby 0.4.0, libglib2-ruby1.8 0.19.3-1ubuntu3
I appreciate any help or directions,
thank you in advance,
--
Marcin
Technical Details
Message-ID:
<e6cb137e-afd5-492e-82cd-1a5bce746ecd@x42g2000yqx.googlegroups.com>Path:
mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.icm.edu.pl!news.nask.pl!news.nask.org.pl!plix.pl!newsfeed1.plix.pl!news-out2.kabelfoon.nl!newsfeed.kabelfoon.nl!xindi.nntp.kabelfoon.nl!198.186.194.249.MISMATCH!news-out.readnews.com!transit3.readnews.com!postnews.google.com!x42g2000yqx.googlegroups.com!not-for-mailShow Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.icm.edu.pl!news.nask.pl!news.nask.org.pl!plix.pl!newsfeed1.plix.pl!news-out2.kabelfoon.nl!newsfeed.kabelfoon.nl!xindi.nntp.kabelfoon.nl!198.186.194.249.MISMATCH!news-out.readnews.com!transit3.readnews.com!postnews.google.com!x42g2000yqx.googlegroups.com!not-for-mail From: Marcin Lewandowski <marcin@mediaspoleczne.pl> Newsgroups: pl.comp.lang.ruby Subject: Problem with ruby-dbus and subprocesses Date: Wed, 1 Sep 2010 13:46:18 -0700 (PDT) Organization: http://groups.google.com Lines: 95 Message-ID: <e6cb137e-afd5-492e-82cd-1a5bce746ecd@x42g2000yqx.googlegroups.com> NNTP-Posting-Host: 77.255.112.91 Mime-Version: 1.0 X-Trace: posting.google.com 1283373978 21097 127.0.0.1 (1 Sep 2010 20:46:18 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Wed, 1 Sep 2010 20:46:18 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: x42g2000yqx.googlegroups.com; posting-host=77.255.112.91; posting-account=JsKv7AoAAADdpcOTkMG4K8ogbnWjiZkG User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (X11; U; Linux x86_64; en-US) AppleWebKit/533.4 (KHTML, like Gecko) Chrome/5.0.375.127 Safari/533.4,gzip(gfe) Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit