logger: ensure program writes everything to syslog file descriptor

It is fair assumption messages an user is asking to be wrote will be
attempted to be wrote as hard as possible.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
logger: fix indentation issues

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
logger: do not rely only getlogin(3) telling who ran the command

The getlogin(3) is known not to always work, and when that happens it is
reasonable to try determine user of name by looking process owner and
passwd information.

Reference: http://man7.org/linux/man-pages/man3/getlogin.3.html
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
logger: refactor long if clause

When if clause that continues throughout whole function it usually can be
shorten to immediate action, e.g., in this case return on the spot not at
end of the function.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
docs: make logger.1 facilities and levels easier to read

Most people read vertical list a lot quicker than horizontal.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
logger: add function pointer to choose how logging is done

This change paves way to adding support for both RFC 3164 and RFC 5424
syslog protocols.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
logger: tidy up main() by adding small functions and ctl data

Add logger_open(), logger_command_line(), logger_stdin(), and
logger_close() functions, and move all remaining option argument
assignments to control structure.

Proposed-by: Karel Zak <kzak@redhat.com>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
logger: add rfc5424 support

Add support the more recent syslog protocol and make it default.  The
older BSD syslog protocol can still be used with option --rfc3164.
Protocols are meaningful only when messages are sent to remote syslog
server.

Requested-by: Kodiak Firesmith <ksf@sei.cmu.edu>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
docs: add logger protocol notes to manual page

Inform about rfc5424 support, how to control what it includes to
submission, and that it is the new default when sending syslog messages
to remote server without specifying protocol.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
logger: add process --id=parent optional argument

When scripts send several messages they will be easier to group together
when parent process id is printed rather than id of the each logger
process.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
logger: make --stderr print remote server messages

Users wish to see the message should include also remote messages, not
only the one sent to locally via libc function.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
logger: improve readablity of pencode() function

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
logger: warn when --file and command line message are combined

When --file is combined with command line arguments the later has
silently been ignored.  This commit makes user to be aware the logger
will not use command line arguments when --file is specified.

Reported-by: "Daniel 'DaB.' Baur" <debian@daniel.baur4.info>
Bug-Debian: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=467244
CC: Andreas Henriksson <andreas@fatal.se>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
logger: add hostname to rfc3164 message

This makes the obsolete protocol a little bit more compliant with the
internet standard, but few should care now when we have rfc5424 support,
and rfc3164 feels broken.  For example it requires hostname to be not
fully qualified, which is hard to understand, and should make users to
prefer the new protocol.

Reported-by: Frank Thilo <thilo@unix-ag.org>
Bug-Debian: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=705217
CC: Andreas Henriksson <andreas@fatal.se>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
wall: wrap message header when it exceeds 79 characters

Header truncation started to happen more often after commit
d81c30553f4fb49173d38f69edff4b0b67a18b65 that made the header to be
longer.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Merge branch 'logger' of git://github.com/kerolasa/lelux-utiliteetit

* 'logger' of git://github.com/kerolasa/lelux-utiliteetit:
  wall: wrap message header when it exceeds 79 characters
  logger: add hostname to rfc3164 message
  logger: warn when --file and command line message are combined
  logger: improve readablity of pencode() function
  logger: make --stderr print remote server messages
  logger: add process --id=parent optional argument
  docs: add logger protocol notes to manual page
  logger: add rfc5424 support
  logger: tidy up main() by adding small functions and ctl data
  logger: add function pointer to choose how logging is done
  docs: make logger.1 facilities and levels easier to read
  logger: refactor long if clause
  logger: do not rely only getlogin(3) telling who ran the command
  logger: fix indentation issues
  logger: ensure program writes everything to syslog file descriptor
logger: clean up strings usage

 - use allocated buffers to compose the final messages

 - initialize static buffers to zero

 - remove strlen-after-sprintf

Signed-off-by: Karel Zak <kzak@redhat.com>
logger: fix -i=ppid

For short options (-i) the optional argument contains '='.

Signed-off-by: Karel Zak <kzak@redhat.com>