Browse Source

file.c: move *xattr parsers to a separate file

* xattr.c: New file.
* Makefile.am (strace_SOURCES): Add it.
* file.c: Move sys_setxattr, sys_fsetxattr, sys_getxattr, sys_fgetxattr,
sys_listxattr, sys_flistxattr, sys_removexattr, sys_fremovexattr,
and related code to xattr.c.
Dmitry V. Levin 5 years ago
parent
commit
769ffe9797
3 changed files with 174 additions and 171 deletions
  1. 2
    1
      Makefile.am
  2. 0
    170
      file.c
  3. 172
    0
      xattr.c

+ 2
- 1
Makefile.am View File

@@ -70,7 +70,8 @@ strace_SOURCES =	\
70 70
 	umount.c	\
71 71
 	util.c		\
72 72
 	v4l2.c		\
73
-	vsprintf.c
73
+	vsprintf.c	\
74
+	xattr.c
74 75
 
75 76
 if USE_LIBUNWIND
76 77
 strace_SOURCES += unwind.c

+ 0
- 170
file.c View File

@@ -180,12 +180,6 @@ struct __old_kernel_stat {
180 180
 #undef st_ctime
181 181
 
182 182
 #include <fcntl.h>
183
-#ifdef HAVE_LINUX_XATTR_H
184
-# include <linux/xattr.h>
185
-#else
186
-# define XATTR_CREATE 1
187
-# define XATTR_REPLACE 2
188
-#endif
189 183
 
190 184
 #ifdef MAJOR_IN_SYSMACROS
191 185
 # include <sys/sysmacros.h>
@@ -1687,167 +1681,3 @@ sys_getcwd(struct tcb *tcp)
1687 1681
 	}
1688 1682
 	return 0;
1689 1683
 }
1690
-
1691
-#include "xlat/xattrflags.h"
1692
-
1693
-static void
1694
-print_xattr_val(struct tcb *tcp, int failed,
1695
-		unsigned long arg,
1696
-		unsigned long insize,
1697
-		unsigned long size)
1698
-{
1699
-	if (insize == 0)
1700
-		failed = 1;
1701
-	if (!failed) {
1702
-		unsigned long capacity = 4 * size + 1;
1703
-		unsigned char *buf = (capacity < size) ? NULL : malloc(capacity);
1704
-		if (buf == NULL || /* probably a bogus size argument */
1705
-			umoven(tcp, arg, size, (char *) &buf[3 * size]) < 0) {
1706
-			failed = 1;
1707
-		}
1708
-		else {
1709
-			unsigned char *out = buf;
1710
-			unsigned char *in = &buf[3 * size];
1711
-			size_t i;
1712
-			for (i = 0; i < size; ++i) {
1713
-				if (in[i] >= ' ' && in[i] <= 0x7e)
1714
-					*out++ = in[i];
1715
-				else {
1716
-#define tohex(n) "0123456789abcdef"[n]
1717
-					*out++ = '\\';
1718
-					*out++ = 'x';
1719
-					*out++ = tohex(in[i] / 16);
1720
-					*out++ = tohex(in[i] % 16);
1721
-				}
1722
-			}
1723
-			/* Don't print terminating NUL if there is one.  */
1724
-			if (i > 0 && in[i - 1] == '\0')
1725
-				out -= 4;
1726
-			*out = '\0';
1727
-			tprintf(", \"%s\", %ld", buf, insize);
1728
-		}
1729
-		free(buf);
1730
-	}
1731
-	if (failed)
1732
-		tprintf(", 0x%lx, %ld", arg, insize);
1733
-}
1734
-
1735
-int
1736
-sys_setxattr(struct tcb *tcp)
1737
-{
1738
-	if (entering(tcp)) {
1739
-		printpath(tcp, tcp->u_arg[0]);
1740
-		tprints(", ");
1741
-		printstr(tcp, tcp->u_arg[1], -1);
1742
-		print_xattr_val(tcp, 0, tcp->u_arg[2], tcp->u_arg[3], tcp->u_arg[3]);
1743
-		tprints(", ");
1744
-		printflags(xattrflags, tcp->u_arg[4], "XATTR_???");
1745
-	}
1746
-	return 0;
1747
-}
1748
-
1749
-int
1750
-sys_fsetxattr(struct tcb *tcp)
1751
-{
1752
-	if (entering(tcp)) {
1753
-		printfd(tcp, tcp->u_arg[0]);
1754
-		tprints(", ");
1755
-		printstr(tcp, tcp->u_arg[1], -1);
1756
-		print_xattr_val(tcp, 0, tcp->u_arg[2], tcp->u_arg[3], tcp->u_arg[3]);
1757
-		tprints(", ");
1758
-		printflags(xattrflags, tcp->u_arg[4], "XATTR_???");
1759
-	}
1760
-	return 0;
1761
-}
1762
-
1763
-int
1764
-sys_getxattr(struct tcb *tcp)
1765
-{
1766
-	if (entering(tcp)) {
1767
-		printpath(tcp, tcp->u_arg[0]);
1768
-		tprints(", ");
1769
-		printstr(tcp, tcp->u_arg[1], -1);
1770
-	} else {
1771
-		print_xattr_val(tcp, syserror(tcp), tcp->u_arg[2], tcp->u_arg[3],
1772
-				tcp->u_rval);
1773
-	}
1774
-	return 0;
1775
-}
1776
-
1777
-int
1778
-sys_fgetxattr(struct tcb *tcp)
1779
-{
1780
-	if (entering(tcp)) {
1781
-		printfd(tcp, tcp->u_arg[0]);
1782
-		tprints(", ");
1783
-		printstr(tcp, tcp->u_arg[1], -1);
1784
-	} else {
1785
-		print_xattr_val(tcp, syserror(tcp), tcp->u_arg[2], tcp->u_arg[3],
1786
-				tcp->u_rval);
1787
-	}
1788
-	return 0;
1789
-}
1790
-
1791
-static void
1792
-print_xattr_list(struct tcb *tcp, unsigned long addr, unsigned long size)
1793
-{
1794
-	if (syserror(tcp)) {
1795
-		tprintf("%#lx", addr);
1796
-	} else {
1797
-		if (!addr) {
1798
-			tprints("NULL");
1799
-		} else {
1800
-			unsigned long len =
1801
-				(size < (unsigned long) tcp->u_rval) ?
1802
-					size : (unsigned long) tcp->u_rval;
1803
-			printstr(tcp, addr, len);
1804
-		}
1805
-	}
1806
-	tprintf(", %lu", size);
1807
-}
1808
-
1809
-int
1810
-sys_listxattr(struct tcb *tcp)
1811
-{
1812
-	if (entering(tcp)) {
1813
-		printpath(tcp, tcp->u_arg[0]);
1814
-		tprints(", ");
1815
-	} else {
1816
-		print_xattr_list(tcp, tcp->u_arg[1], tcp->u_arg[2]);
1817
-	}
1818
-	return 0;
1819
-}
1820
-
1821
-int
1822
-sys_flistxattr(struct tcb *tcp)
1823
-{
1824
-	if (entering(tcp)) {
1825
-		printfd(tcp, tcp->u_arg[0]);
1826
-		tprints(", ");
1827
-	} else {
1828
-		print_xattr_list(tcp, tcp->u_arg[1], tcp->u_arg[2]);
1829
-	}
1830
-	return 0;
1831
-}
1832
-
1833
-int
1834
-sys_removexattr(struct tcb *tcp)
1835
-{
1836
-	if (entering(tcp)) {
1837
-		printpath(tcp, tcp->u_arg[0]);
1838
-		tprints(", ");
1839
-		printstr(tcp, tcp->u_arg[1], -1);
1840
-	}
1841
-	return 0;
1842
-}
1843
-
1844
-int
1845
-sys_fremovexattr(struct tcb *tcp)
1846
-{
1847
-	if (entering(tcp)) {
1848
-		printfd(tcp, tcp->u_arg[0]);
1849
-		tprints(", ");
1850
-		printstr(tcp, tcp->u_arg[1], -1);
1851
-	}
1852
-	return 0;
1853
-}

+ 172
- 0
xattr.c View File

@@ -0,0 +1,172 @@
1
+#include "defs.h"
2
+
3
+#ifdef HAVE_LINUX_XATTR_H
4
+# include <linux/xattr.h>
5
+#else
6
+# define XATTR_CREATE 1
7
+# define XATTR_REPLACE 2
8
+#endif
9
+
10
+#include "xlat/xattrflags.h"
11
+
12
+static void
13
+print_xattr_val(struct tcb *tcp, int failed,
14
+		unsigned long arg,
15
+		unsigned long insize,
16
+		unsigned long size)
17
+{
18
+	if (insize == 0)
19
+		failed = 1;
20
+	if (!failed) {
21
+		unsigned long capacity = 4 * size + 1;
22
+		unsigned char *buf = (capacity < size) ? NULL : malloc(capacity);
23
+		if (buf == NULL || /* probably a bogus size argument */
24
+			umoven(tcp, arg, size, (char *) &buf[3 * size]) < 0) {
25
+			failed = 1;
26
+		}
27
+		else {
28
+			unsigned char *out = buf;
29
+			unsigned char *in = &buf[3 * size];
30
+			size_t i;
31
+			for (i = 0; i < size; ++i) {
32
+				if (in[i] >= ' ' && in[i] <= 0x7e)
33
+					*out++ = in[i];
34
+				else {
35
+#define tohex(n) "0123456789abcdef"[n]
36
+					*out++ = '\\';
37
+					*out++ = 'x';
38
+					*out++ = tohex(in[i] / 16);
39
+					*out++ = tohex(in[i] % 16);
40
+				}
41
+			}
42
+			/* Don't print terminating NUL if there is one.  */
43
+			if (i > 0 && in[i - 1] == '\0')
44
+				out -= 4;
45
+			*out = '\0';
46
+			tprintf(", \"%s\", %ld", buf, insize);
47
+		}
48
+		free(buf);
49
+	}
50
+	if (failed)
51
+		tprintf(", 0x%lx, %ld", arg, insize);
52
+}
53
+
54
+int
55
+sys_setxattr(struct tcb *tcp)
56
+{
57
+	if (entering(tcp)) {
58
+		printpath(tcp, tcp->u_arg[0]);
59
+		tprints(", ");
60
+		printstr(tcp, tcp->u_arg[1], -1);
61
+		print_xattr_val(tcp, 0, tcp->u_arg[2], tcp->u_arg[3], tcp->u_arg[3]);
62
+		tprints(", ");
63
+		printflags(xattrflags, tcp->u_arg[4], "XATTR_???");
64
+	}
65
+	return 0;
66
+}
67
+
68
+int
69
+sys_fsetxattr(struct tcb *tcp)
70
+{
71
+	if (entering(tcp)) {
72
+		printfd(tcp, tcp->u_arg[0]);
73
+		tprints(", ");
74
+		printstr(tcp, tcp->u_arg[1], -1);
75
+		print_xattr_val(tcp, 0, tcp->u_arg[2], tcp->u_arg[3], tcp->u_arg[3]);
76
+		tprints(", ");
77
+		printflags(xattrflags, tcp->u_arg[4], "XATTR_???");
78
+	}
79
+	return 0;
80
+}
81
+
82
+int
83
+sys_getxattr(struct tcb *tcp)
84
+{
85
+	if (entering(tcp)) {
86
+		printpath(tcp, tcp->u_arg[0]);
87
+		tprints(", ");
88
+		printstr(tcp, tcp->u_arg[1], -1);
89
+	} else {
90
+		print_xattr_val(tcp, syserror(tcp), tcp->u_arg[2], tcp->u_arg[3],
91
+				tcp->u_rval);
92
+	}
93
+	return 0;
94
+}
95
+
96
+int
97
+sys_fgetxattr(struct tcb *tcp)
98
+{
99
+	if (entering(tcp)) {
100
+		printfd(tcp, tcp->u_arg[0]);
101
+		tprints(", ");
102
+		printstr(tcp, tcp->u_arg[1], -1);
103
+	} else {
104
+		print_xattr_val(tcp, syserror(tcp), tcp->u_arg[2], tcp->u_arg[3],
105
+				tcp->u_rval);
106
+	}
107
+	return 0;
108
+}
109
+
110
+static void
111
+print_xattr_list(struct tcb *tcp, unsigned long addr, unsigned long size)
112
+{
113
+	if (syserror(tcp)) {
114
+		tprintf("%#lx", addr);
115
+	} else {
116
+		if (!addr) {
117
+			tprints("NULL");
118
+		} else {
119
+			unsigned long len =
120
+				(size < (unsigned long) tcp->u_rval) ?
121
+					size : (unsigned long) tcp->u_rval;
122
+			printstr(tcp, addr, len);
123
+		}
124
+	}
125
+	tprintf(", %lu", size);
126
+}
127
+
128
+int
129
+sys_listxattr(struct tcb *tcp)
130
+{
131
+	if (entering(tcp)) {
132
+		printpath(tcp, tcp->u_arg[0]);
133
+		tprints(", ");
134
+	} else {
135
+		print_xattr_list(tcp, tcp->u_arg[1], tcp->u_arg[2]);
136
+	}
137
+	return 0;
138
+}
139
+
140
+int
141
+sys_flistxattr(struct tcb *tcp)
142
+{
143
+	if (entering(tcp)) {
144
+		printfd(tcp, tcp->u_arg[0]);
145
+		tprints(", ");
146
+	} else {
147
+		print_xattr_list(tcp, tcp->u_arg[1], tcp->u_arg[2]);
148
+	}
149
+	return 0;
150
+}
151
+
152
+int
153
+sys_removexattr(struct tcb *tcp)
154
+{
155
+	if (entering(tcp)) {
156
+		printpath(tcp, tcp->u_arg[0]);
157
+		tprints(", ");
158
+		printstr(tcp, tcp->u_arg[1], -1);
159
+	}
160
+	return 0;
161
+}
162
+
163
+int
164
+sys_fremovexattr(struct tcb *tcp)
165
+{
166
+	if (entering(tcp)) {
167
+		printfd(tcp, tcp->u_arg[0]);
168
+		tprints(", ");
169
+		printstr(tcp, tcp->u_arg[1], -1);
170
+	}
171
+	return 0;
172
+}

Loading…
Cancel
Save