Bug 1096067 - sd-journal: Undocumented behaviour of sd_journal_send
Summary: sd-journal: Undocumented behaviour of sd_journal_send
Keywords:
Status: CLOSED CURRENTRELEASE
Alias: None
Product: Fedora
Classification: Fedora
Component: systemd
Version: rawhide
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified
Target Milestone: ---
Assignee: systemd-maint
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2014-05-09 07:57 UTC by Lukas Slebodnik
Modified: 2014-07-20 00:00 UTC (History)
8 users (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2014-07-20 00:00:35 UTC


Attachments (Terms of Use)
simple program with function sd_journal_send (633 bytes, text/x-csrc)
2014-05-09 07:57 UTC, Lukas Slebodnik
no flags Details

Description Lukas Slebodnik 2014-05-09 07:57:11 UTC
Created attachment 893874 [details]
simple program with function sd_journal_send

Description of problem:
I tried to use some program in docker container, which is able to log messages into the journald and fall back to logging into standard error output.
I could not see any log message in journald from this program and there was nothing printed to the stderr. After debugging, I found out that
the function sd_journal_sendv silently fails if the journal is not available

bash-4.3# cd /usr/src/debug/systemd-212/
bash-4.3# grep -C5 ENOENT src/journal/journal-send.c
        k = sendmsg(fd, &mh, MSG_NOSIGNAL);
        if (k >= 0)
                return 0;

        /* Fail silently if the journal is not available */
        if (errno == ENOENT)
                return 0;

        if (errno != EMSGSIZE && errno != ENOBUFS)
                return -errno;

The problem is that the message isn't written into journald and disable possibility logging into files or standard error output.
This behaviour limits the recovery and message is lost.

*It should be* at least documented in manual page sd_journal_send

bash-4.3# man sd_journal_send | grep RETURN -A 8
RETURN VALUE
       The four calls return 0 on success or a negative errno-style error code. 

ASYNC SIGNAL SAFETY
       sd_journal_sendv() is "async signal safe" in the meaning of signal(7).
       sd_journal_print, sd_journal_printv, sd_journal_send, and sd_journal_perr



Version-Release number of selected component (if applicable):
bash-4.3# rpm -q systemd-libs
systemd-libs-212-4.fc21.x86_64

How reproducible:
Deterministic

Steps to Reproduce:
1. compile attached file
  host$ cc `pkg-config --cflags --libs libsystemd-journal` -o jd_simple jd_simple.c
2. run docker container
  host$ docker run -t -i --rm -v=`pwd`:/example fedora:rawhide /bin/bash
3. ensure journald is not running
  docker# ls -l /run/systemd/journal/socket
  ls: cannot access /run/systemd/journal/socket: No such file or directory
4. execute compiled program
  docker# /example/jd_simple
  return value from log: [0]
  
  host$ journalctl -n 1000 | grep "starting program"
  host$ echo $?
  1

Actual results:
The message "starting program" is lost

Additional info:
The workaround is to mount bind socket from host machine to the docker container
host$ docker run -t -i --rm -v=.:/example -v=/run/systemd/journal/:/run/systemd/journal/ fedora /bin/bash

Comment 1 Zbigniew Jędrzejewski-Szmek 2014-05-09 12:41:48 UTC
http://cgit.freedesktop.org/systemd/systemd/commit/?id=bdf9fc1a

Comment 2 Fedora Update System 2014-06-19 13:19:27 UTC
systemd-208-18.fc20 has been submitted as an update for Fedora 20.
https://admin.fedoraproject.org/updates/systemd-208-18.fc20

Comment 3 Fedora Update System 2014-06-19 22:56:10 UTC
Package systemd-208-18.fc20:
* should fix your issue,
* was pushed to the Fedora 20 testing repository,
* should be available at your local mirror within two days.
Update it with:
# su -c 'yum update --enablerepo=updates-testing systemd-208-18.fc20'
as soon as you are able to.
Please go to the following url:
https://admin.fedoraproject.org/updates/FEDORA-2014-7512/systemd-208-18.fc20
then log in and leave karma (feedback).

Comment 4 Fedora Update System 2014-06-22 23:55:31 UTC
Package systemd-208-19.fc20:
* should fix your issue,
* was pushed to the Fedora 20 testing repository,
* should be available at your local mirror within two days.
Update it with:
# su -c 'yum update --enablerepo=updates-testing systemd-208-19.fc20'
as soon as you are able to.
Please go to the following url:
https://admin.fedoraproject.org/updates/FEDORA-2014-7512/systemd-208-19.fc20
then log in and leave karma (feedback).


Note You need to log in before you can comment on or make changes to this bug.