void server_process_syslog_message(
                Server *s,
                const char *buf,
                size_t raw_len,
                const struct ucred *ucred,
                const struct timeval *tv,
                const char *label,
                size_t label_len) {

        char *t, syslog_priority[sizeof("PRIORITY=") + DECIMAL_STR_MAX(int)],
                 syslog_facility[sizeof("SYSLOG_FACILITY=") + DECIMAL_STR_MAX(int)];
        const char *msg, *syslog_ts, *a;
        _cleanup_free_ char *identifier = NULL, *pid = NULL,
                *dummy = NULL, *msg_msg = NULL, *msg_raw = NULL;
        int priority = LOG_USER | LOG_INFO, r;
        ClientContext *context = NULL;
        struct iovec *iovec;
        size_t n = 0, m, i, leading_ws, syslog_ts_len;
        bool store_raw;

        assert(s);
        assert(buf);
        /* The message cannot be empty. */
        assert(raw_len > 0);
        /* The buffer NUL-terminated and can be used a string. raw_len is the length
         * without the terminating NUL byte, the buffer is actually one bigger. */
        assert(buf[raw_len] == '\0');

        if (ucred && pid_is_valid(ucred->pid)) {
                r = client_context_get(s, ucred->pid, ucred, label, label_len, NULL, &context);
                if (r < 0)
                        log_warning_errno(r, "Failed to retrieve credentials for PID " PID_FMT ", ignoring: %m", ucred->pid);
        }

        /* We are creating a copy of the message because we want to forward the original message
           verbatim to the legacy syslog implementation */
        for (i = raw_len; i > 0; i--)
                if (!strchr(WHITESPACE, buf[i-1]))
                        break;

        leading_ws = strspn(buf, WHITESPACE);

        if (i == 0)
                /* The message contains only whitespaces */
                msg = buf + raw_len;
        else if (i == raw_len)
                /* Nice! No need to strip anything on the end, let's optimize this a bit */
                msg = buf + leading_ws;
        else {
                msg = dummy = new(char, i - leading_ws + 1);
                if (!dummy) {
                        log_oom();
                        return;
                }

                memcpy(dummy, buf + leading_ws, i - leading_ws);
                dummy[i - leading_ws] = 0;
        }

        /* We will add the SYSLOG_RAW= field when we stripped anything
         * _or_ if the input message contained NUL bytes. */
        store_raw = msg != buf || strlen(msg) != raw_len;

        syslog_parse_priority(&msg, &priority, true);

        if (!client_context_test_priority(context, priority))
                return;

        syslog_ts = msg;
        syslog_ts_len = syslog_skip_timestamp(&msg);
        if (syslog_ts_len == 0)
                /* We failed to parse the full timestamp, store the raw message too */
                store_raw = true;

        syslog_parse_identifier(&msg, &identifier, &pid);

        if (s->forward_to_syslog)
                forward_syslog_raw(s, priority, buf, raw_len, ucred, tv);

        if (s->forward_to_kmsg)
                server_forward_kmsg(s, priority, identifier, msg, ucred);

        if (s->forward_to_console)
                server_forward_console(s, priority, identifier, msg, ucred);

        if (s->forward_to_wall)
                server_forward_wall(s, priority, identifier, msg, ucred);

        m = N_IOVEC_META_FIELDS + 8 + client_context_extra_fields_n_iovec(context);
        iovec = newa(struct iovec, m);

        iovec[n++] = IOVEC_MAKE_STRING("_TRANSPORT=syslog");

        xsprintf(syslog_priority, "PRIORITY=%i", priority & LOG_PRIMASK);
        iovec[n++] = IOVEC_MAKE_STRING(syslog_priority);

        if (priority & LOG_FACMASK) {
                xsprintf(syslog_facility, "SYSLOG_FACILITY=%i", LOG_FAC(priority));
                iovec[n++] = IOVEC_MAKE_STRING(syslog_facility);
        }

        if (identifier) {
                a = strjoina("SYSLOG_IDENTIFIER=", identifier);
                iovec[n++] = IOVEC_MAKE_STRING(a);
        }

        if (pid) {
                a = strjoina("SYSLOG_PID=", pid);
                iovec[n++] = IOVEC_MAKE_STRING(a);
        }

        if (syslog_ts_len > 0) {
                const size_t hlen = strlen("SYSLOG_TIMESTAMP=");

                t = newa(char, hlen + raw_len);
                memcpy(t, "SYSLOG_TIMESTAMP=", hlen);
                memcpy(t + hlen, syslog_ts, syslog_ts_len);

                iovec[n++] = IOVEC_MAKE(t, hlen + syslog_ts_len);
        }

        msg_msg = strjoin("MESSAGE=", msg);
        if (!msg_msg) {
                log_oom();
                return;
        }
        iovec[n++] = IOVEC_MAKE_STRING(msg_msg);

        if (store_raw) {
                const size_t hlen = strlen("SYSLOG_RAW=");

                msg_raw = new(char, hlen + raw_len);
                if (!msg_raw) {
                        log_oom();
                        return;
                }

                memcpy(msg_raw, "SYSLOG_RAW=", hlen);
                memcpy(msg_raw + hlen, buf, raw_len);

                iovec[n++] = IOVEC_MAKE(msg_raw, hlen + raw_len);
        }

        server_dispatch_message(s, iovec, n, m, context, tv, priority, 0);
}