summaryrefslogtreecommitdiff
path: root/linux-user/strace.c
diff options
context:
space:
mode:
authorAleksandar Markovic <aleksandar.markovic@imgtec.com>2016-09-22 18:56:58 +0200
committerRiku Voipio <riku.voipio@linaro.org>2016-10-21 15:19:40 +0300
commitda2c8ad7a51651b5409eca5439783c09d5863752 (patch)
tree10d0ed985de649b72d968add91a9c49498332c30 /linux-user/strace.c
parentff71a4545c0d9b452e77a91ab1c46f79a10a9eca (diff)
downloadqemu-da2c8ad7a51651b5409eca5439783c09d5863752.tar.gz
linux-user: Fix syslog() syscall support
There are currently several problems related to syslog() support. For example, if the second argument "bufp" of target syslog() syscall is NULL, the current implementation always returns error code EFAULT. However, NULL is a perfectly valid value for the second argument for many use cases of this syscall. This is, for example, visible from this excerpt of man page for syslog(2): > EINVAL Bad arguments (e.g., bad type; or for type 2, 3, or 4, buf is > NULL, or len is less than zero; or for type 8, the level is > outside the range 1 to 8). Moreover, the argument "bufp" is ignored for all cases of values of the first argument, except 2, 3 and 4. This means that for such cases (the first argument is not 2, 3 or 4), there is no need to pass "buf" between host and target, and it can be set to NULL while calling host's syslog(), without loss of emulation accuracy. Note also that if "bufp" is NULL and the first argument is 2, 3 or 4, the correct returned error code is EINVAL, not EFAULT. All these details are reflected in this patch. "#ifdef TARGET_NR_syslog" is also proprerly inserted when needed. Support for Qemu's "-strace" switch for syslog() syscall is included too. LTP tests syslog11 and syslog12 pass with this patch (while fail without it), on any platform. Changes to original patch by Riku Voipio: fixed error paths in TARGET_SYSLOG_ACTION_READ_ALL to match http://lxr.free-electrons.com/source/kernel/printk/printk.c?v=4.7#L1335 Should fix also the build error in: https://lists.gnu.org/archive/html/qemu-devel/2016-10/msg03721.html Signed-off-by: Aleksandar Markovic <aleksandar.markovic@imgtec.com> Signed-off-by: Riku Voipio <riku.voipio@linaro.org>
Diffstat (limited to 'linux-user/strace.c')
-rw-r--r--linux-user/strace.c72
1 files changed, 72 insertions, 0 deletions
diff --git a/linux-user/strace.c b/linux-user/strace.c
index a0e45b55d1..679f840fea 100644
--- a/linux-user/strace.c
+++ b/linux-user/strace.c
@@ -1827,6 +1827,78 @@ print_rt_sigprocmask(const struct syscallname *name,
}
#endif
+#ifdef TARGET_NR_syslog
+static void
+print_syslog_action(abi_ulong arg, int last)
+{
+ const char *type;
+
+ switch (arg) {
+ case TARGET_SYSLOG_ACTION_CLOSE: {
+ type = "SYSLOG_ACTION_CLOSE";
+ break;
+ }
+ case TARGET_SYSLOG_ACTION_OPEN: {
+ type = "SYSLOG_ACTION_OPEN";
+ break;
+ }
+ case TARGET_SYSLOG_ACTION_READ: {
+ type = "SYSLOG_ACTION_READ";
+ break;
+ }
+ case TARGET_SYSLOG_ACTION_READ_ALL: {
+ type = "SYSLOG_ACTION_READ_ALL";
+ break;
+ }
+ case TARGET_SYSLOG_ACTION_READ_CLEAR: {
+ type = "SYSLOG_ACTION_READ_CLEAR";
+ break;
+ }
+ case TARGET_SYSLOG_ACTION_CLEAR: {
+ type = "SYSLOG_ACTION_CLEAR";
+ break;
+ }
+ case TARGET_SYSLOG_ACTION_CONSOLE_OFF: {
+ type = "SYSLOG_ACTION_CONSOLE_OFF";
+ break;
+ }
+ case TARGET_SYSLOG_ACTION_CONSOLE_ON: {
+ type = "SYSLOG_ACTION_CONSOLE_ON";
+ break;
+ }
+ case TARGET_SYSLOG_ACTION_CONSOLE_LEVEL: {
+ type = "SYSLOG_ACTION_CONSOLE_LEVEL";
+ break;
+ }
+ case TARGET_SYSLOG_ACTION_SIZE_UNREAD: {
+ type = "SYSLOG_ACTION_SIZE_UNREAD";
+ break;
+ }
+ case TARGET_SYSLOG_ACTION_SIZE_BUFFER: {
+ type = "SYSLOG_ACTION_SIZE_BUFFER";
+ break;
+ }
+ default: {
+ print_raw_param("%ld", arg, last);
+ return;
+ }
+ }
+ gemu_log("%s%s", type, get_comma(last));
+}
+
+static void
+print_syslog(const struct syscallname *name,
+ abi_long arg0, abi_long arg1, abi_long arg2,
+ abi_long arg3, abi_long arg4, abi_long arg5)
+{
+ print_syscall_prologue(name);
+ print_syslog_action(arg0, 0);
+ print_pointer(arg1, 0);
+ print_raw_param("%d", arg2, 1);
+ print_syscall_epilogue(name);
+}
+#endif
+
#ifdef TARGET_NR_mknod
static void
print_mknod(const struct syscallname *name,