Re: [GitHub] Add option to btpd to run a hook script on certain actions [btpd/btpd GH-24]

5 views
Skip to first unread message

Nicholas Marriott

unread,
Oct 22, 2010, 1:19:25 PM10/22/10
to ajd...@connectical.com, queu...@gmail.com, btpd-...@googlegroups.com
This is a nice idea but it looks like it blocks the entire btpd process,
so what happens if someone wants to call btcli from their script (very
likely)?


On Fri, Oct 22, 2010 at 07:10:21AM -0700, GitHub wrote:
> ajdiaz wants someone to pull from ajdiaz:master:
>
> With these patches, btpd allows a --hook-script option, which receives any executable path. This file will be called when a leech start or stop and also when download is finished.
>
> The hook script will be called with two arguments, the first one is a character which indicates the action:
>
> 'S': Start
> 'T': Stop
> 'F': Finished
>
> And the second one is the torrent name. It's useful, for example, to display a desktop notification, or unpack the downloaded file or anything else.
>
>
> View Pull Request: http://github.com/btpd/btpd/pull/24

Nicholas Marriott

unread,
Oct 22, 2010, 2:28:25 PM10/22/10
to Andrés J. Díaz, queu...@gmail.com, btpd-...@googlegroups.com
You could just fire off the process with fork/exec as you do now but
instead of waiting for it with waitpid() immediately, install a SIGCHLD
handler and wait for children there with waitpid WNOHANG.

It may require some fiddling if you want to report the exit status,
you'll have to keep a list of outstanding children then cause the signal
handler to trigger an event to report the status. This is easy with
libevent but I don't know how easy with btpd's customised thing.


On Fri, Oct 22, 2010 at 08:09:39PM +0200, Andr�s J. D�az wrote:
>
> Yes, you are right, btpd process still blocking while script working, I
> my case it's not a problem (I use btpd to deploy applications, usually
> one tarball per hour), but it seems to be a problem in a lot of cases...
>
> I would try to exec the script in a child process (fork). It would be
> fine for you?

> --
> Regards,
> Andr�s J. D�az


Reply all
Reply to author
Forward
0 new messages