Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755221AbbGCKvk (ORCPT ); Fri, 3 Jul 2015 06:51:40 -0400 Received: from mailout3.w1.samsung.com ([210.118.77.13]:65390 "EHLO mailout3.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755082AbbGCKun (ORCPT ); Fri, 3 Jul 2015 06:50:43 -0400 X-AuditID: cbfec7f4-f79c56d0000012ee-4e-559668e97b4f From: Marcin Niesluchowski To: linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-api@vger.kernel.org Cc: Jonathan Corbet , Greg Kroah-Hartman , Petr Mladek , Tejun Heo , Kay Sievers , Andrew Morton , Joe Perches , Karol Lewandowski , Bartlomiej Zolnierkiewicz , Marcin Niesluchowski Subject: [RFC 6/8] kmsg: add predefined _PID, _TID, _COMM keywords to kmsg* log dict Date: Fri, 03 Jul 2015 12:49:53 +0200 Message-id: <1435920595-30879-7-git-send-email-m.niesluchow@samsung.com> X-Mailer: git-send-email 1.9.1 In-reply-to: <1435920595-30879-1-git-send-email-m.niesluchow@samsung.com> References: <1435920595-30879-1-git-send-email-m.niesluchow@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrKLMWRmVeSWpSXmKPExsVy+t/xK7ovM6aFGpy8wGkxZ/0aNouNM9az Wjw50M5o0bx4PZvF7PuPWSwaP81ltri16jm7xebvHWwWC9uWsFhc3jWHzeLQ2R8sFgv/b2ay +LX8KKMDr8emVZ1sHidm/Gbx2D93DbvH4r7JrB5fVl1j9ujbsorR48yCI+wenzfJeXxc7xnA GcVlk5Kak1mWWqRvl8CV8fVrG2tBk2jF9/4/TA2M9wW6GDk5JARMJBbPa2ODsMUkLtxbD2Rz cQgJLGWU+Dv1PSOE08wkMXHrR3aQKjYBU4m2ZXvAbBGBCImFF5tYQIqYBaYxS5xt3ssMkhAW CJPou3AEqJuDg0VAVeLdozKQMK+Ah8T+rTeZIbbJSZw8NpkVxOYU8JT41LcMLC4EVLPh2Hym CYy8CxgZVjGKppYmFxQnpeca6hUn5haX5qXrJefnbmKEBO6XHYyLj1kdYhTgYFTi4b1wemqo EGtiWXFl7iFGCQ5mJRHe58HTQoV4UxIrq1KL8uOLSnNSiw8xSnOwKInzzt31PkRIID2xJDU7 NbUgtQgmy8TBKdXAuGKZyRXeTVs0N6bfSTi9ZMWKXZNPTl7Dx24tyvuvQd+sViNb5+WSEKs/ 8flq/R3uz/yKtOetMwvuzhM14G5KeTqlecfLwux0o5V65c5qZ2NlA6MfLqrQeDR5y73Kb8Y6 39RWnD1wfYJy8zquI3p+IRbs7IkG/g0KRpa1LfpLjVyNlfPOVC1TYinOSDTUYi4qTgQAg7f1 V1gCAAA= Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2849 Lines: 91 kmsg* devices write operation wrote no dict along with message Due to usage of kmsg devices in userspace dict has been added identifying pid, tid and comm of writing process. Signed-off-by: Marcin Niesluchowski --- kernel/printk/printk.c | 40 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 36 insertions(+), 4 deletions(-) diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index abe78c1..2a7f6a4 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -876,7 +876,34 @@ void log_buf_release(struct kref *ref) kfree(log_b); } -static int kmsg_sys_write(int minor, int level, const char *fmt, ...) +#define MAX_PID_LEN 20 +#define MAX_TID_LEN 20 +/* + * Fromat below describes dict appended to message written from userspace: + * "_PID=\0_TID=\0_COMM=" + * KMSG_DICT_MAX_LEN definition represents maximal length of this dict. + */ +#define KMSG_DICT_MAX_LEN (5 + MAX_PID_LEN + 1 + \ + 5 + MAX_TID_LEN + 1 + \ + 6 + TASK_COMM_LEN) + +static size_t set_kmsg_dict(char *buf) +{ + size_t len; + + len = sprintf(buf, "_PID=%d", task_tgid_nr(current)) + 1; + len += sprintf(buf + len, "_TID=%d", task_pid_nr(current)) + 1; + memcpy(buf + len, "_COMM=", 6); + len += 6; + get_task_comm(buf + len, current); + while (buf[len] != '\0') + len++; + return len; +} + +static int kmsg_sys_write(int minor, int level, + const char *dict, size_t dictlen, + const char *fmt, ...) { va_list args; int ret = -ENXIO; @@ -891,7 +918,7 @@ static int kmsg_sys_write(int minor, int level, const char *fmt, ...) va_start(args, fmt); log_format_and_store(log_b, 1 /* LOG_USER */, level, - NULL, 0, fmt, args); + dict, dictlen, fmt, args); va_end(args); wake_up_interruptible(&log_b->wait); @@ -911,6 +938,8 @@ static ssize_t devkmsg_write(struct kiocb *iocb, struct iov_iter *from) int level = default_message_loglevel; int facility = 1; /* LOG_USER */ size_t len = iov_iter_count(from); + char dict[KMSG_DICT_MAX_LEN]; + size_t dictlen; ssize_t ret = len; int minor = iminor(iocb->ki_filp->f_inode); @@ -950,10 +979,13 @@ static ssize_t devkmsg_write(struct kiocb *iocb, struct iov_iter *from) } } + dictlen = set_kmsg_dict(dict); + if (minor == log_buf.minor) { - printk_emit(facility, level, NULL, 0, "%s", line); + printk_emit(facility, level, dict, dictlen, "%s", line); } else { - int error = kmsg_sys_write(minor, level, "%s", line); + int error = kmsg_sys_write(minor, level, dict, dictlen, + "%s", line); if (error) ret = error; -- 1.9.1 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/