> On 18. Jun 2019, at 15:32, Ludovic Courtès <l...@gnu.org> wrote:
> 
> Hi,
> 
> Danny Milosavljevic <dan...@scratchpost.org> skribis:
> 
>> I think it could be made part of shepherd and be exported there, then 
>> everyone
>> could use it.  Logging to syslog isn't exactly an obscure requirement :)
> 
> +1!
> 
>> Although shepherd already has its own /dev/log (syslog) client 
>> implementation,
>> the external "logger" executable (or similar) is still necessary, because
>> /dev/log is a UNIX domain socket and one can't write to UNIX domain sockets
>> the same way one does pipes.  Although it might be possible (and not
>> advisable) to connect() the socket and then dup it to 1 and 2 for the child 
>> :P
> 
> Yes, that should be enough.
> 
> Robert, would you like to give it a go?

I’d rather not get too deep into shepherd at this point.

Here’s the wrapper updated in response to Danny’s comments, in case you want to
reuse that inside shepherd:

(define* (logger-wrapper name exec . args)
  "Return a derivation that builds a script to start a process with
standard output and error redirected to syslog via logger."
  (define exp
    #~(begin
        (use-modules (ice-9 popen))
        (let* ((pid    (number->string (getpid)))
               (logger #$(file-append inetutils "/bin/logger"))
               (args   (list "-t" #$name (string-append "--id=" pid)))
               (pipe   (apply open-pipe* OPEN_WRITE logger args)))
          (dup pipe 1)
          (dup pipe 2)
          (execl #$exec #$exec #$@args))))
  (program-file (string-append name "-logger") exp))

Cheers
Robert


Reply via email to