]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
logger: use SCM_CREDENTIALS on LINUX only
authorRuediger Meier <ruediger.meier@ga-group.nl>
Fri, 19 Feb 2016 00:44:14 +0000 (01:44 +0100)
committerRuediger Meier <ruediger.meier@ga-group.nl>
Fri, 26 Feb 2016 02:29:41 +0000 (03:29 +0100)
This is a build fix of FreeBSD and OSX. Basically we revert
the following commit for non-linux systems:
27a9eb53 "use --id as local socket credentials"

Note I could also compile it like this:

  #ifdef HAVE_SYS_UCRED_H
  # define _WANT_UCRED
  # include <sys/param.h>
  # include <sys/ucred.h>
  # define SCM_CREDENTIALS SCM_CREDS
  #endif

  [...]
  #ifdef _linux_
  cred->pid = ctl->pid;
  #endif
  [...]

... but don't know how to test whether it does what it
should.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
misc-utils/logger.c

index 4201e4335a23352e998de1d0be7efdf0cfa3de35..d9aee0eb9c5af4edf69b42aed37c4665c75d1e28 100644 (file)
@@ -446,12 +446,14 @@ static void write_output(const struct logger_ctl *ctl, const char *const msg)
 
        if (!ctl->noact) {
                struct msghdr message = { 0 };
+#ifdef SCM_CREDENTIALS
                struct cmsghdr *cmhp;
                struct ucred *cred;
                union {
                        struct cmsghdr cmh;
                        char   control[CMSG_SPACE(sizeof(struct ucred))];
                } cbuf;
+#endif
 
                /* 4) add extra \n to make sure message is terminated */
                if ((ctl->socket_type == TYPE_TCP) && !ctl->octet_count)
@@ -460,6 +462,7 @@ static void write_output(const struct logger_ctl *ctl, const char *const msg)
                message.msg_iov = iov;
                message.msg_iovlen = iovlen;
 
+#ifdef SCM_CREDENTIALS
                /* syslog/journald may follow local socket credentials rather
                 * than in the message PID. If we use --id as root than we can
                 * force kernel to accept another valid PID than the real logger(1)
@@ -479,6 +482,7 @@ static void write_output(const struct logger_ctl *ctl, const char *const msg)
 
                        cred->pid = ctl->pid;
                }
+#endif
 
                if (sendmsg(ctl->fd, &message, 0) < 0)
                        warn(_("send message failed"));