get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

GET /api/patches/138870/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 138870,
    "url": "http://patches.dpdk.org/api/patches/138870/?format=api",
    "web_url": "http://patches.dpdk.org/project/dpdk/patch/20240327164726.68732-15-stephen@networkplumber.org/",
    "project": {
        "id": 1,
        "url": "http://patches.dpdk.org/api/projects/1/?format=api",
        "name": "DPDK",
        "link_name": "dpdk",
        "list_id": "dev.dpdk.org",
        "list_email": "dev@dpdk.org",
        "web_url": "http://core.dpdk.org",
        "scm_url": "git://dpdk.org/dpdk",
        "webscm_url": "http://git.dpdk.org/dpdk",
        "list_archive_url": "https://inbox.dpdk.org/dev",
        "list_archive_url_format": "https://inbox.dpdk.org/dev/{}",
        "commit_url_format": ""
    },
    "msgid": "<20240327164726.68732-15-stephen@networkplumber.org>",
    "list_archive_url": "https://inbox.dpdk.org/dev/20240327164726.68732-15-stephen@networkplumber.org",
    "date": "2024-03-27T16:45:32",
    "name": "[v16,14/15] log: add support for systemd journal",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": true,
    "hash": "f3ba0bf13e78a8ffcd3d4d250ac8f6309ec43086",
    "submitter": {
        "id": 27,
        "url": "http://patches.dpdk.org/api/people/27/?format=api",
        "name": "Stephen Hemminger",
        "email": "stephen@networkplumber.org"
    },
    "delegate": {
        "id": 1,
        "url": "http://patches.dpdk.org/api/users/1/?format=api",
        "username": "tmonjalo",
        "first_name": "Thomas",
        "last_name": "Monjalon",
        "email": "thomas@monjalon.net"
    },
    "mbox": "http://patches.dpdk.org/project/dpdk/patch/20240327164726.68732-15-stephen@networkplumber.org/mbox/",
    "series": [
        {
            "id": 31630,
            "url": "http://patches.dpdk.org/api/series/31630/?format=api",
            "web_url": "http://patches.dpdk.org/project/dpdk/list/?series=31630",
            "date": "2024-03-27T16:45:18",
            "name": "Logging unification and improvements",
            "version": 16,
            "mbox": "http://patches.dpdk.org/series/31630/mbox/"
        }
    ],
    "comments": "http://patches.dpdk.org/api/patches/138870/comments/",
    "check": "success",
    "checks": "http://patches.dpdk.org/api/patches/138870/checks/",
    "tags": {},
    "related": [],
    "headers": {
        "Return-Path": "<dev-bounces@dpdk.org>",
        "X-Original-To": "patchwork@inbox.dpdk.org",
        "Delivered-To": "patchwork@inbox.dpdk.org",
        "Received": [
            "from mails.dpdk.org (mails.dpdk.org [217.70.189.124])\n\tby inbox.dpdk.org (Postfix) with ESMTP id E703743D55;\n\tWed, 27 Mar 2024 17:49:16 +0100 (CET)",
            "from mails.dpdk.org (localhost [127.0.0.1])\n\tby mails.dpdk.org (Postfix) with ESMTP id 179E642DC0;\n\tWed, 27 Mar 2024 17:47:57 +0100 (CET)",
            "from mail-pf1-f172.google.com (mail-pf1-f172.google.com\n [209.85.210.172])\n by mails.dpdk.org (Postfix) with ESMTP id 25DC942B71\n for <dev@dpdk.org>; Wed, 27 Mar 2024 17:47:48 +0100 (CET)",
            "by mail-pf1-f172.google.com with SMTP id\n d2e1a72fcca58-6e6b6f86975so48302b3a.1\n for <dev@dpdk.org>; Wed, 27 Mar 2024 09:47:48 -0700 (PDT)",
            "from hermes.local (204-195-123-203.wavecable.com. [204.195.123.203])\n by smtp.gmail.com with ESMTPSA id\n a33-20020a056a0011e100b006e580678dfbsm5160873pfu.193.2024.03.27.09.47.46\n (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n Wed, 27 Mar 2024 09:47:46 -0700 (PDT)"
        ],
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1711558067;\n x=1712162867; darn=dpdk.org;\n h=content-transfer-encoding:mime-version:references:in-reply-to\n :message-id:date:subject:cc:to:from:from:to:cc:subject:date\n :message-id:reply-to;\n bh=46SG9RLhZSJQXgtr6/M3XC3YSSvsoh/NwdGR6vHqARE=;\n b=ezMsyKAIN5mNiVt4/uRBeL4vqxgv/dc94ebewUmDT8YK+uKWHAx6RLs25lS1cKb7vS\n XrQiTiZc53+vK0hYdDB4dl0TINI7HZ0Rlps/yRKt39GmPmqRM51zSsupMs/K0BkY8Bym\n 5GWsuJG3XXFT/m0Fa6zhycKFvCUwRPl1GzCS6ZhScKPnx1tLDcuque+ks7Tz+yNa3b41\n cZ7bA+BiycaiCZ+hJ9FpMyC1LK+l8h3p2mtL6MPMZfsoGaC9RpJz/+EByoxi7To1cwo3\n c2JhYG3XNSUY8q76V9KFWqE2LsBxsF1aM6hGdgh/QH/uZWfgzSfpNcLkUfp88jik1839\n x+oQ==",
        "X-Google-DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=1e100.net; s=20230601; t=1711558067; x=1712162867;\n h=content-transfer-encoding:mime-version:references:in-reply-to\n :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc\n :subject:date:message-id:reply-to;\n bh=46SG9RLhZSJQXgtr6/M3XC3YSSvsoh/NwdGR6vHqARE=;\n b=P/0fzoj9WunN4chWtCCAHdpmoFuuMeeYCPf2MNP9cb+u954DxwZhDHxqOdoqJg2dJ9\n 6GH9iOL8eCA98ZGdC+KAoonvllFaB0k0CTYwAejwmJFFkqE6eBUpABI0h9jkHR6zrjhz\n S/1Hz+I7TdKne+rYHLrTH2NW5QhBuVZXminS8RPiCbuM6hQ3aBm1I11zhKQT498BG00J\n i+cAuJY4mz2MefZ4RTmcDGn6Fd2RVbUhS7DTfD45nLlcdR8oMuEzFNJ0ojL4YffGRJIX\n ic+gJ2oDg55pkk1LvZbBEZsovihn0MmhfPg6JL9lfDBNm9wMBck7xVYIRPCCicl25ViR\n P1KQ==",
        "X-Gm-Message-State": "AOJu0YxRhKqX2P5AvEdoeX9IVaqXXGTW70ZMMLCCLCnTbYe8nZb+Rf6K\n nf1Hv4rxaVRu2l9BoPziiwjCls+B6KaWYYFOtfEVX/hBMWJTQ4szeMz1W+LYIWwqC/d0M+Jd+TW\n b",
        "X-Google-Smtp-Source": "\n AGHT+IHnL3GtNjbQIkNHvD4yIqJ7rJ87Bq8HM6BrHu8UWqJv9qtH8GCBa5LAgXbNaTIBiuXcP2JPKw==",
        "X-Received": "by 2002:a05:6a20:930f:b0:1a3:72d2:c49b with SMTP id\n r15-20020a056a20930f00b001a372d2c49bmr413795pzh.58.1711558067244;\n Wed, 27 Mar 2024 09:47:47 -0700 (PDT)",
        "From": "Stephen Hemminger <stephen@networkplumber.org>",
        "To": "dev@dpdk.org",
        "Cc": "Stephen Hemminger <stephen@networkplumber.org>",
        "Subject": "[PATCH v16 14/15] log: add support for systemd journal",
        "Date": "Wed, 27 Mar 2024 09:45:32 -0700",
        "Message-ID": "<20240327164726.68732-15-stephen@networkplumber.org>",
        "X-Mailer": "git-send-email 2.43.0",
        "In-Reply-To": "<20240327164726.68732-1-stephen@networkplumber.org>",
        "References": "<20200814173441.23086-1-stephen@networkplumber.org>\n <20240327164726.68732-1-stephen@networkplumber.org>",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "X-BeenThere": "dev@dpdk.org",
        "X-Mailman-Version": "2.1.29",
        "Precedence": "list",
        "List-Id": "DPDK patches and discussions <dev.dpdk.org>",
        "List-Unsubscribe": "<https://mails.dpdk.org/options/dev>,\n <mailto:dev-request@dpdk.org?subject=unsubscribe>",
        "List-Archive": "<http://mails.dpdk.org/archives/dev/>",
        "List-Post": "<mailto:dev@dpdk.org>",
        "List-Help": "<mailto:dev-request@dpdk.org?subject=help>",
        "List-Subscribe": "<https://mails.dpdk.org/listinfo/dev>,\n <mailto:dev-request@dpdk.org?subject=subscribe>",
        "Errors-To": "dev-bounces@dpdk.org"
    },
    "content": "If DPDK application is being run as a systemd service, then\nit can use the journal protocol which allows putting more information\nin the log such as priority and other information.\n\nThe use of journal protocol is automatically detected and\nhandled.  Rather than having a dependency on libsystemd,\njust use the protocol directly as defined in:\n\thttps://systemd.io/JOURNAL_NATIVE_PROTOCOL/\n\nSigned-off-by: Stephen Hemminger <stephen@networkplumber.org>\n---\n lib/log/log.c | 154 +++++++++++++++++++++++++++++++++++++++++++++++++-\n 1 file changed, 152 insertions(+), 2 deletions(-)",
    "diff": "diff --git a/lib/log/log.c b/lib/log/log.c\nindex ec0d55273e..650d294120 100644\n--- a/lib/log/log.c\n+++ b/lib/log/log.c\n@@ -17,6 +17,10 @@\n #include <rte_os_shim.h>\n #else\n #include <syslog.h>\n+#include <sys/uio.h>\n+#include <sys/stat.h>\n+#include <sys/socket.h>\n+#include <sys/un.h>\n #endif\n \n #include <rte_log.h>\n@@ -56,6 +60,7 @@ static struct rte_logs {\n \tFILE *file;     /**< Output file set by rte_openlog_stream, or NULL. */\n #ifndef RTE_EXEC_ENV_WINDOWS\n \tenum eal_log_syslog syslog_opt;\n+\tint journal_fd;\n #endif\n \tlog_print_t print_func;\n \n@@ -775,6 +780,138 @@ static cookie_io_functions_t syslog_log_func = {\n \t.close = syslog_log_close,\n };\n \n+/*\n+ * send message using journal protocol to journald\n+ */\n+static int\n+journal_send(uint32_t level, const char *buf, size_t len)\n+{\n+\tstruct iovec iov[3];\n+\tchar msg[] = \"MESSAGE=\";\n+\tchar prio[32];\n+\tint ret;\n+\n+\tiov[0].iov_base = msg;\n+\tiov[0].iov_len = strlen(msg);\n+\n+\tiov[1].iov_base = (char *)(uintptr_t)buf;\n+\tiov[1].iov_len = len;\n+\n+\t/* priority value between 0 (\"emerg\") and 7 (\"debug\") */\n+\tiov[2].iov_base = prio;\n+\tiov[2].iov_len = snprintf(prio, sizeof(prio),\n+\t\t\t\t  \"PRIORITY=%i\\n\", level - 1);\n+\n+\tret = writev(rte_logs.journal_fd, iov, 3);\n+\treturn ret;\n+}\n+\n+__rte_format_printf(3, 0)\n+static int\n+journal_print(FILE *f __rte_unused, uint32_t level, const char *format, va_list ap)\n+{\n+\tchar buf[BUFSIZ];\n+\tsize_t len;\n+\n+\tlen = vsnprintf(buf, sizeof(buf), format, ap);\n+\tif (len == 0)\n+\t\treturn 0;\n+\n+\t/* check for truncation */\n+\tif (len >= sizeof(buf) - 1)\n+\t\tlen = sizeof(buf) - 1;\n+\n+\t/* check that message ends with newline, if not add one */\n+\tif (buf[len - 1] != '\\n')\n+\t\tbuf[len++] = '\\n';\n+\n+\treturn journal_send(level, buf, len);\n+}\n+\n+/* wrapper for log stream to put messages into journal */\n+static ssize_t\n+journal_log_write(__rte_unused void *c, const char *buf, size_t size)\n+{\n+\treturn journal_send(rte_log_cur_msg_loglevel(), buf, size);\n+}\n+\n+static cookie_io_functions_t journal_log_func = {\n+\t.write = journal_log_write,\n+};\n+\n+/*\n+ * Check if stderr is going to system journal.\n+ * This is the documented way to handle systemd journal\n+ *\n+ * See: https://systemd.io/JOURNAL_NATIVE_PROTOCOL/\n+ *\n+ */\n+static bool\n+is_journal(int fd)\n+{\n+\tchar *jenv, *endp = NULL;\n+\tstruct stat st;\n+\tunsigned long dev, ino;\n+\n+\tjenv = getenv(\"JOURNAL_STREAM\");\n+\tif (jenv == NULL)\n+\t\treturn false;\n+\n+\tif (fstat(fd, &st) < 0)\n+\t\treturn false;\n+\n+\t/* systemd sets colon-separated list of device and inode number */\n+\tdev = strtoul(jenv, &endp, 10);\n+\tif (endp == NULL || *endp != ':')\n+\t\treturn false;\t/* missing colon */\n+\n+\tino = strtoul(endp + 1, NULL, 10);\n+\n+\treturn dev == st.st_dev && ino == st.st_ino;\n+}\n+\n+/* Connect to systemd's journal service */\n+static int\n+open_journal(const char *id)\n+{\n+\tchar *syslog_id = NULL;\n+\tstruct sockaddr_un sun = {\n+\t\t.sun_family = AF_UNIX,\n+\t\t.sun_path = \"/run/systemd/journal/socket\",\n+\t};\n+\tssize_t len;\n+\tint s;\n+\n+\ts = socket(AF_UNIX, SOCK_DGRAM, 0);\n+\tif (s < 0)\n+\t\treturn -1;\n+\n+\tif (connect(s, (struct sockaddr *)&sun, sizeof(sun)) < 0)\n+\t\tgoto error;\n+\n+\t/* Send syslog identifier as first message */\n+\tlen = asprintf(&syslog_id, \"SYSLOG_IDENTIFIER=%s\\n\", id);\n+\tif (len == 0)\n+\t\tgoto error;\n+\n+\tif (write(s, syslog_id, len) != len)\n+\t\tgoto error;\n+\n+\tfree(syslog_id);\n+\n+\t/* redirect other log messages to journal */\n+\tFILE *log_stream = fopencookie(NULL, \"w\", journal_log_func);\n+\tif (log_stream != NULL)\n+\t\tdefault_log_stream = log_stream;\n+\n+\treturn s;\n+\n+error:\n+\tfree(syslog_id);\n+\tclose(s);\n+\treturn -1;\n+}\n+\n static void\n log_open_syslog(const char *id, bool is_terminal)\n {\n@@ -797,11 +934,24 @@ log_open_syslog(const char *id, bool is_terminal)\n static void\n log_output_selection(const char *id)\n {\n+#ifdef RTE_EXEC_ENV_WINDOWS\n \tRTE_SET_USED(id);\n-\n-#ifndef RTE_EXEC_ENV_WINDOWS\n+#else\n \tbool is_terminal = isatty(STDERR_FILENO);\n \n+\t/* If stderr is redirected to systemd journal then upgrade */\n+\tif (!is_terminal && is_journal(STDERR_FILENO)) {\n+\t\tint jfd = open_journal(id);\n+\n+\t\tif (jfd < 0) {\n+\t\t\tRTE_LOG_LINE(NOTICE, EAL, \"Cannot connect to journal: %s\",\n+\t\t\t\t     strerror(errno));\n+\t\t} else {\n+\t\t\trte_logs.print_func = journal_print;\n+\t\t\treturn;\n+\t\t}\n+\t}\n+\n \tif (using_syslog(is_terminal)) {\n \t\tlog_open_syslog(id, is_terminal);\n \t\treturn;\n",
    "prefixes": [
        "v16",
        "14/15"
    ]
}