Date: Sun, 23 Aug 2020 19:59:38 +0000 (UTC) From: Edward Tomasz Napierala <trasz@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org Subject: svn commit: r364519 - in stable/12/sys: amd64/linux amd64/linux32 arm64/linux compat/linux i386/linux Message-ID: <202008231959.07NJxcLT003328@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: trasz Date: Sun Aug 23 19:59:38 2020 New Revision: 364519 URL: https://svnweb.freebsd.org/changeset/base/364519 Log: MFC r356177: Implement Linux syslog(2) syscall; just enough to make Linux dmesg(8) utility work. Sponsored by: The FreeBSD Foundation Modified: stable/12/sys/amd64/linux/linux_dummy.c stable/12/sys/amd64/linux32/linux32_dummy.c stable/12/sys/arm64/linux/linux_dummy.c stable/12/sys/compat/linux/linux_misc.c stable/12/sys/compat/linux/linux_misc.h stable/12/sys/i386/linux/linux_dummy.c Directory Properties: stable/12/ (props changed) Modified: stable/12/sys/amd64/linux/linux_dummy.c ============================================================================== --- stable/12/sys/amd64/linux/linux_dummy.c Sun Aug 23 19:54:03 2020 (r364518) +++ stable/12/sys/amd64/linux/linux_dummy.c Sun Aug 23 19:59:38 2020 (r364519) @@ -60,7 +60,6 @@ UNIMPLEMENTED(uselib); UNIMPLEMENTED(vserver); DUMMY(sendfile); -DUMMY(syslog); DUMMY(setfsuid); DUMMY(setfsgid); DUMMY(sysfs); Modified: stable/12/sys/amd64/linux32/linux32_dummy.c ============================================================================== --- stable/12/sys/amd64/linux32/linux32_dummy.c Sun Aug 23 19:54:03 2020 (r364518) +++ stable/12/sys/amd64/linux32/linux32_dummy.c Sun Aug 23 19:59:38 2020 (r364519) @@ -63,7 +63,6 @@ UNIMPLEMENTED(vserver); DUMMY(stime); DUMMY(olduname); -DUMMY(syslog); DUMMY(uname); DUMMY(vhangup); DUMMY(swapoff); Modified: stable/12/sys/arm64/linux/linux_dummy.c ============================================================================== --- stable/12/sys/arm64/linux/linux_dummy.c Sun Aug 23 19:54:03 2020 (r364518) +++ stable/12/sys/arm64/linux/linux_dummy.c Sun Aug 23 19:59:38 2020 (r364519) @@ -65,7 +65,6 @@ UNIMPLEMENTED(uselib); UNIMPLEMENTED(vserver); DUMMY(sendfile); -DUMMY(syslog); DUMMY(setfsuid); DUMMY(setfsgid); DUMMY(vhangup); Modified: stable/12/sys/compat/linux/linux_misc.c ============================================================================== --- stable/12/sys/compat/linux/linux_misc.c Sun Aug 23 19:54:03 2020 (r364518) +++ stable/12/sys/compat/linux/linux_misc.c Sun Aug 23 19:59:38 2020 (r364519) @@ -47,6 +47,7 @@ __FBSDID("$FreeBSD$"); #include <sys/malloc.h> #include <sys/mman.h> #include <sys/mount.h> +#include <sys/msgbuf.h> #include <sys/mutex.h> #include <sys/namei.h> #include <sys/priv.h> @@ -2626,4 +2627,67 @@ linux_mincore(struct thread *td, struct linux_mincore_ if (args->start & PAGE_MASK) return (EINVAL); return (kern_mincore(td, args->start, args->len, args->vec)); +} + +#define SYSLOG_TAG "<6>" + +int +linux_syslog(struct thread *td, struct linux_syslog_args *args) +{ + char buf[128], *src, *dst; + u_int seq; + int buflen, error; + + if (args->type != LINUX_SYSLOG_ACTION_READ_ALL) { + linux_msg(td, "syslog unsupported type 0x%x", args->type); + return (EINVAL); + } + + if (args->len < 6) { + td->td_retval[0] = 0; + return (0); + } + + error = priv_check(td, PRIV_MSGBUF); + if (error) + return (error); + + mtx_lock(&msgbuf_lock); + msgbuf_peekbytes(msgbufp, NULL, 0, &seq); + mtx_unlock(&msgbuf_lock); + + dst = args->buf; + error = copyout(&SYSLOG_TAG, dst, sizeof(SYSLOG_TAG)); + /* The -1 is to skip the trailing '\0'. */ + dst += sizeof(SYSLOG_TAG) - 1; + + while (error == 0) { + mtx_lock(&msgbuf_lock); + buflen = msgbuf_peekbytes(msgbufp, buf, sizeof(buf), &seq); + mtx_unlock(&msgbuf_lock); + + if (buflen == 0) + break; + + for (src = buf; src < buf + buflen && error == 0; src++) { + if (*src == '\0') + continue; + + if (dst >= args->buf + args->len) + goto out; + + error = copyout(src, dst, 1); + dst++; + + if (*src == '\n' && *(src + 1) != '<' && + dst + sizeof(SYSLOG_TAG) < args->buf + args->len) { + error = copyout(&SYSLOG_TAG, + dst, sizeof(SYSLOG_TAG)); + dst += sizeof(SYSLOG_TAG) - 1; + } + } + } +out: + td->td_retval[0] = dst - args->buf; + return (error); } Modified: stable/12/sys/compat/linux/linux_misc.h ============================================================================== --- stable/12/sys/compat/linux/linux_misc.h Sun Aug 23 19:54:03 2020 (r364518) +++ stable/12/sys/compat/linux/linux_misc.h Sun Aug 23 19:59:38 2020 (r364519) @@ -149,6 +149,9 @@ extern int stclohz; #define LINUX_GRND_NONBLOCK 0x0001 #define LINUX_GRND_RANDOM 0x0002 +/* Linux syslog flags */ +#define LINUX_SYSLOG_ACTION_READ_ALL 3 + #if defined(__amd64__) && !defined(COMPAT_LINUX32) int linux_ptrace_status(struct thread *td, int pid, int status); #endif Modified: stable/12/sys/i386/linux/linux_dummy.c ============================================================================== --- stable/12/sys/i386/linux/linux_dummy.c Sun Aug 23 19:54:03 2020 (r364518) +++ stable/12/sys/i386/linux/linux_dummy.c Sun Aug 23 19:59:38 2020 (r364519) @@ -64,7 +64,6 @@ UNIMPLEMENTED(vserver); DUMMY(stime); DUMMY(fstat); DUMMY(olduname); -DUMMY(syslog); DUMMY(uname); DUMMY(vhangup); DUMMY(vm86old);
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202008231959.07NJxcLT003328>