Implement Linux syslog(2) syscall; just enough to make Linux dmesg(8)

utility work.

MFC after:	2 weeks
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D22465
This commit is contained in:
Edward Tomasz Napierala 2019-12-29 15:53:55 +00:00
parent 645532a448
commit ee0fe82ee2
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=356177
6 changed files with 67 additions and 4 deletions

View File

@ -60,7 +60,6 @@ UNIMPLEMENTED(uselib);
UNIMPLEMENTED(vserver);
DUMMY(sendfile);
DUMMY(syslog);
DUMMY(setfsuid);
DUMMY(setfsgid);
DUMMY(sysfs);

View File

@ -63,7 +63,6 @@ UNIMPLEMENTED(vserver);
DUMMY(stime);
DUMMY(olduname);
DUMMY(syslog);
DUMMY(uname);
DUMMY(vhangup);
DUMMY(swapoff);

View File

@ -65,7 +65,6 @@ UNIMPLEMENTED(uselib);
UNIMPLEMENTED(vserver);
DUMMY(sendfile);
DUMMY(syslog);
DUMMY(setfsuid);
DUMMY(setfsgid);
DUMMY(vhangup);

View File

@ -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>
@ -2289,3 +2290,66 @@ linux_mincore(struct thread *td, struct linux_mincore_args *args)
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);
}

View File

@ -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

View File

@ -64,7 +64,6 @@ UNIMPLEMENTED(vserver);
DUMMY(stime);
DUMMY(fstat);
DUMMY(olduname);
DUMMY(syslog);
DUMMY(uname);
DUMMY(vhangup);
DUMMY(vm86old);