From: Sami Kerola <kerolasa@iki.fi>
To: util-linux@vger.kernel.org
Cc: kerolasa@iki.fi, Karel Zak <kzak@redhat.com>
Subject: [PATCH 13/13] logger: make local sockets to try both stream and datagram
Date: Tue, 2 Apr 2013 20:42:57 +0100 [thread overview]
Message-ID: <1364931777-2645-14-git-send-email-kerolasa@iki.fi> (raw)
In-Reply-To: <1364931777-2645-1-git-send-email-kerolasa@iki.fi>
When journald, from systemd, is in use logger gave following error.
$ logger --socket /dev/log test logger: connect /dev/log: Protocol wrong
type for socket
The journald supports only AF_DGRAM, and nothing else. Support for
AF_STREAM sockets was dropped because it messed up message ordering.
>From an users point of view necessity to add --udp (UNIX(TM) Datagram
Protocol?) option when talking to syslog via unix socket felt confusing
and wrong. The command should know what is the socket type, and silently
use the correct one, unless the type is explicitely defined.
CC: Karel Zak <kzak@redhat.com>
Adviced-by: Lennart Poettering <lennart@poettering.net>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
misc-utils/logger.c | 42 +++++++++++++++++++++++++-----------------
1 file changed, 25 insertions(+), 17 deletions(-)
diff --git a/misc-utils/logger.c b/misc-utils/logger.c
index 30e8fa4..a6fafc1 100644
--- a/misc-utils/logger.c
+++ b/misc-utils/logger.c
@@ -58,8 +58,6 @@
#define SYSLOG_NAMES
#include <syslog.h>
-static int optd = 0;
-
static int decode(char *name, CODE *codetab)
{
register CODE *c;
@@ -98,23 +96,33 @@ static int pencode(char *s)
}
static int
-myopenlog(const char *sock) {
- int fd;
- static struct sockaddr_un s_addr; /* AF_UNIX address of local logger */
-
- if (strlen(sock) >= sizeof(s_addr.sun_path))
- errx(EXIT_FAILURE, _("openlog %s: pathname too long"), sock);
+myopenlog(const char *sock, int optd)
+{
+ int fd;
+ static struct sockaddr_un s_addr; /* AF_UNIX address of local logger */
- s_addr.sun_family = AF_UNIX;
- (void)strcpy(s_addr.sun_path, sock);
+ if (strlen(sock) >= sizeof(s_addr.sun_path))
+ errx(EXIT_FAILURE, _("openlog %s: pathname too long"), sock);
- if ((fd = socket(AF_UNIX, optd ? SOCK_DGRAM : SOCK_STREAM, 0)) == -1)
- err(EXIT_FAILURE, _("socket %s"), sock);
+ s_addr.sun_family = AF_UNIX;
+ (void)strcpy(s_addr.sun_path, sock);
- if (connect(fd, (struct sockaddr *) &s_addr, sizeof(s_addr)) == -1)
- err(EXIT_FAILURE, _("connect %s"), sock);
+ if (optd == 0) {
+ if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) == -1)
+ goto udp_socket;
+ if (connect(fd, (struct sockaddr *)&s_addr, sizeof(s_addr)) == -1) {
+ close(fd);
+ goto udp_socket;
+ }
+ } else {
+ udp_socket:
+ if ((fd = socket(AF_UNIX, SOCK_DGRAM, 0)) == -1)
+ err(EXIT_FAILURE, _("socket %s"), sock);
+ if (connect(fd, (struct sockaddr *)&s_addr, sizeof(s_addr)) == -1)
+ err(EXIT_FAILURE, _("connect %s"), sock);
+ }
- return fd;
+ return fd;
}
static int
@@ -202,7 +210,7 @@ main(int argc, char **argv) {
char *usock = NULL;
char *udpserver = NULL;
char *udpport = NULL;
- int LogSock = -1;
+ int LogSock = -1, optd = 0;
static const struct option longopts[] = {
{ "id", no_argument, 0, 'i' },
@@ -279,7 +287,7 @@ main(int argc, char **argv) {
else if (udpserver)
LogSock = udpopenlog(udpserver,udpport);
else
- LogSock = myopenlog(usock);
+ LogSock = myopenlog(usock, optd);
/* log input line if appropriate */
if (argc > 0) {
--
1.8.2
next prev parent reply other threads:[~2013-04-02 19:43 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-04-02 19:42 [PATCH 00/13] pull: fixes in preparation to v2.23 release Sami Kerola
2013-04-02 19:42 ` [PATCH 01/13] docs: fix type in mkfs.8 Sami Kerola
2013-04-02 19:42 ` [PATCH 02/13] newgrp: use xstrdup to check allocation succeeded Sami Kerola
2013-04-02 19:42 ` [PATCH 03/13] agetty: the command does not have -h and -V options Sami Kerola
2013-04-02 19:42 ` [PATCH 04/13] dmesg: fix usage() output consistancy Sami Kerola
2013-04-02 19:42 ` [PATCH 05/13] fsfreeze: tell user when mandatory option is not specified Sami Kerola
2013-04-02 19:42 ` [PATCH 06/13] losetup: allow -j option argument to be relative path Sami Kerola
2013-04-02 19:42 ` [PATCH 07/13] lscpu: fix error message Sami Kerola
2013-04-02 19:42 ` [PATCH 08/13] partx: remove deprecated option from usage() Sami Kerola
2013-04-02 19:42 ` [PATCH 09/13] setarch: add option to list settable architectures Sami Kerola
2013-04-05 12:04 ` Karel Zak
2013-04-02 19:42 ` [PATCH 10/13] setterm: fix various color option argument lists Sami Kerola
2013-04-02 19:42 ` [PATCH 11/13] vipw: add usage() function Sami Kerola
2013-04-02 19:42 ` [PATCH 12/13] chrt: make command syntax easier to understand in usage() Sami Kerola
2013-04-02 19:42 ` Sami Kerola [this message]
2013-04-05 12:10 ` [PATCH 00/13] pull: fixes in preparation to v2.23 release Karel Zak
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1364931777-2645-14-git-send-email-kerolasa@iki.fi \
--to=kerolasa@iki.fi \
--cc=kzak@redhat.com \
--cc=util-linux@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox