]> granicus.if.org Git - strace/commitdiff
Pass tcp argument to get_optmem_max/read_int_from_file
authorEugene Syromiatnikov <esyr@redhat.com>
Mon, 25 Dec 2017 22:55:22 +0000 (23:55 +0100)
committerDmitry V. Levin <ldv@altlinux.org>
Sun, 7 Jan 2018 16:46:32 +0000 (16:46 +0000)
In preparation to passing tcp to all tracee-related syscalls.

* defs.h (read_int_from_file): Add "struct tcb *" as the first argument.
* util.c (read_int_from_file): Likewise.
* msghdr.c (get_optmem_max): Add "struct tcb *tcp" as the first
argument, pass it to read_int_from_file call.
(decode_msg_control): Pass tcp to get_optmem_max.

defs.h
msghdr.c
util.c

diff --git a/defs.h b/defs.h
index 2267e8e58ca42e3b80924c63b1f87920a863f3bb..0091a359113b6f0119ade813743eeb6a7c133066 100644 (file)
--- a/defs.h
+++ b/defs.h
@@ -383,7 +383,7 @@ extern unsigned os_release;
 #undef KERNEL_VERSION
 #define KERNEL_VERSION(a, b, c) (((a) << 16) + ((b) << 8) + (c))
 
-extern int read_int_from_file(const char *, int *);
+extern int read_int_from_file(struct tcb *, const char *, int *);
 
 extern void set_sortby(const char *);
 extern void set_overhead(int);
index dd9c4300a75f3bab3bc769e5537992e87c9842e4..c698e54083ded87b3004650521e4b1f77b93ca6b 100644 (file)
--- a/msghdr.c
+++ b/msghdr.c
@@ -262,12 +262,12 @@ print_cmsg_type_data(struct tcb *tcp, const int cmsg_level, const int cmsg_type,
 }
 
 static unsigned int
-get_optmem_max(void)
+get_optmem_max(struct tcb *tcp)
 {
        static int optmem_max;
 
        if (!optmem_max) {
-               if (read_int_from_file("/proc/sys/net/core/optmem_max",
+               if (read_int_from_file(tcp, "/proc/sys/net/core/optmem_max",
                                       &optmem_max) || optmem_max <= 0) {
                        optmem_max = sizeof(long long) * (2 * IOV_MAX + 512);
                } else {
@@ -293,8 +293,8 @@ decode_msg_control(struct tcb *const tcp, const kernel_ulong_t addr,
 #endif
                        sizeof(struct cmsghdr);
 
-       unsigned int control_len = in_control_len > get_optmem_max()
-                                  ? get_optmem_max() : in_control_len;
+       unsigned int control_len = in_control_len > get_optmem_max(tcp)
+                                  ? get_optmem_max(tcp) : in_control_len;
        unsigned int buf_len = control_len;
        char *buf = buf_len < cmsg_size ? NULL : malloc(buf_len);
        if (!buf || umoven(tcp, addr, buf_len, buf) < 0) {
diff --git a/util.c b/util.c
index 0b4c5b7ab0eb31e9e0d00f6029fa2bbc7a80ef90..49cb81b085d0815ae0475ed349d601a4fea60915 100644 (file)
--- a/util.c
+++ b/util.c
@@ -1076,7 +1076,7 @@ print_abnormal_hi(const kernel_ulong_t val)
 #endif
 
 int
-read_int_from_file(const char *const fname, int *const pvalue)
+read_int_from_file(struct tcb *tcp, const char *const fname, int *const pvalue)
 {
        const int fd = open_file(fname, O_RDONLY);
        if (fd < 0)