diff options
author | Dmitry V. Levin <ldv@altlinux.org> | 2017-07-24 12:10:54 +0000 |
---|---|---|
committer | Dmitry V. Levin <ldv@altlinux.org> | 2017-07-24 12:10:54 +0000 |
commit | de484eced54f1703ef8c7027410d365bc789380b (patch) | |
tree | d04fd4dc90a776596dd7b2c23a66061d2e777265 /tests/ioctl_loop.c | |
parent | 53a56aa0d87db5635410563dab2ab71d2ecf75c7 (diff) | |
download | strace-de484eced54f1703ef8c7027410d365bc789380b.tar.gz |
Introduce print_quoted_cstring
In many places where kernel expects a NUL-terminated string of length
up to a known fixed limit, e.g. when a NUL-terminated string is
a fixed-size field of a structure, strace does not print the last byte
assuming it is NUL, which is not always the case.
Change output format for such strings to distinguish NUL-terminated
strings from non-NUL-terminated ones: append ellipsis to the output
when the string is not NUL-terminated.
* defs.h (print_quoted_cstring): New prototype.
* util.c (print_quoted_cstring): New function.
(printpathn): Use it instead of print_quoted_string with
QUOTE_0_TERMINATED argument.
* print_fields.h (PRINT_FIELD_CSTRING): Likewise.
* btrfs.c (btrfs_ioctl): Likewise.
* dirent.c (SYS_FUNC(getdents)): Likewise.
* dirent64.c (SYS_FUNC(getdents64)): Likewise.
* print_ifindex.c (print_ifindex): Likewise.
* sysmips.c (SYS_FUNC(sysmips)): Likewise.
* ubi.c (ubi_ioctl): Likewise.
* tests/tests.h (print_quoted_cstring): New prototype.
* tests/print_quoted_string.c (print_quoted_cstring): New function.
* tests/ioctl_block.c (main): Update expected output.
* tests/ioctl_dm.c (main): Likewise.
* tests/ioctl_loop.c (print_loop_info, print_loop_info64): Likewise.
* tests/netlink_crypto.c (test_crypto_msg_newalg): Likewise.
Diffstat (limited to 'tests/ioctl_loop.c')
-rw-r--r-- | tests/ioctl_loop.c | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/tests/ioctl_loop.c b/tests/ioctl_loop.c index 4dcbf9ade..3411a4d8f 100644 --- a/tests/ioctl_loop.c +++ b/tests/ioctl_loop.c @@ -39,6 +39,7 @@ #include <sys/sysmacros.h> #include <linux/ioctl.h> #include <linux/loop.h> +#include "print_fields.h" #include "xlat/loop_cmds.h" #ifndef ABBREV @@ -81,8 +82,7 @@ print_loop_info(struct loop_info * const info, bool print_encrypt, else printf("%#x /* LO_FLAGS_??? */", info->lo_flags); - printf(", lo_name=\"%.*s\"", - (int) sizeof(info->lo_name) - 1, info->lo_name); + PRINT_FIELD_CSTRING(", ", *info, lo_name); if (VERBOSE || print_encrypt) printf(", lo_encrypt_key=\"%.*s\"", @@ -144,17 +144,16 @@ print_loop_info64(struct loop_info64 * const info64, bool print_encrypt, printf("%s", flags); else printf("%#x /* LO_FLAGS_??? */", info64->lo_flags); - printf(", lo_file_name=\"%.*s\"", - (int) sizeof(info64->lo_file_name) - 1, info64->lo_file_name); + PRINT_FIELD_CSTRING(", ", *info64, lo_file_name); - if (VERBOSE || print_encrypt) - printf(", lo_crypt_name=\"%.*s\", lo_encrypt_key=\"%.*s\"", - (int) sizeof(info64->lo_crypt_name) - 1, - info64->lo_crypt_name, + if (VERBOSE || print_encrypt) { + PRINT_FIELD_CSTRING(", ", *info64, lo_crypt_name); + printf(", lo_encrypt_key=\"%.*s\"", encrypt_key ? (int) strlen(encrypt_key) : (int) sizeof(info64->lo_encrypt_key), encrypt_key ? encrypt_key : (char *) info64->lo_encrypt_key); + } # if VERBOSE printf(", lo_init=[%#" PRIx64 ", %#" PRIx64 "]}", |