Print this page
10703 smatch unreachable code checking needs reworking
Reviewed by: Toomas Soome <tsoome@me.com>
Reviewed by: Yuri Pankov <yuri.pankov@nexenta.com>
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/test/os-tests/tests/sockfs/conn.c
+++ new/usr/src/test/os-tests/tests/sockfs/conn.c
1 1 /*
2 2 * Copyright 2016 Jeremy Allison
3 3 *
4 4 * Permission is hereby granted, free of charge, to any person obtaining a
5 5 * copy of this software and associated documentation files (the "Software"),
6 6 * to deal in the Software without restriction, including without limitation
7 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 8 * and/or sell copies of the Software, and to permit persons to whom the
9 9 * Software is furnished to do so, subject to the following conditions:
10 10 *
11 11 * The above copyright notice and this permission notice shall be included
12 12 * in all copies or substantial portions of the Software.
↓ open down ↓ |
12 lines elided |
↑ open up ↑ |
13 13 *
14 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 19 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 20 * DEALINGS IN THE SOFTWARE.
21 21 */
22 22
23 +/*
24 + * Copyright 2019 Joyent, Inc.
25 + */
26 +
23 27 #include <sys/param.h>
24 28 #include <sys/types.h>
25 29 #include <sys/stat.h>
26 30 #include <sys/socket.h>
27 31 #include <sys/un.h>
28 32 #include <stdio.h>
29 33 #include <unistd.h>
30 34 #include <string.h>
31 35 #include <errno.h>
32 36 #include <stdint.h>
33 37 #include <stdlib.h>
34 38 #include <pthread.h>
35 39
36 40 extern const char *__progname;
37 41
38 42 static void *
39 43 server(void *varg)
40 44 {
41 45 int ret;
42 46 int sock = (int)varg;
43 47 unsigned int i;
44 48
45 49 for (i = 0; i < 5; i++) {
46 50 struct iovec iov;
47 51 struct msghdr msg;
48 52 uint8_t buf[4096];
49 53
50 54 iov = (struct iovec) {
51 55 .iov_base = buf,
52 56 .iov_len = sizeof (buf)
53 57 };
54 58
55 59 msg = (struct msghdr) {
56 60 .msg_iov = &iov,
57 61 .msg_iovlen = 1,
58 62 };
59 63
60 64 ret = recvmsg(sock, &msg, 0);
61 65 if (ret == -1) {
62 66 fprintf(stderr, "server - recvmsg fail %s\n",
63 67 strerror(errno));
64 68 exit(1);
65 69 }
66 70
67 71 printf("SERVER:%s\n", (char *)msg.msg_iov->iov_base);
68 72 fflush(stdout);
69 73 }
70 74
71 75 exit(0);
72 76 }
73 77
74 78 static void *
75 79 listener(void *varg)
76 80 {
77 81 struct sockaddr_un *addr = varg;
78 82 int ret;
79 83 int lsock;
80 84 int asock;
81 85
82 86 /* Child. */
83 87 lsock = socket(AF_UNIX, SOCK_STREAM, 0);
84 88 if (lsock == -1) {
85 89 fprintf(stderr, "listener - socket fail %s\n", strerror(errno));
86 90 exit(1);
87 91 }
88 92
89 93 ret = bind(lsock, (struct sockaddr *)addr, sizeof (*addr));
90 94 if (ret == -1) {
91 95 fprintf(stderr, "listener - bind fail %s\n", strerror(errno));
92 96 exit(1);
93 97 }
94 98
95 99 ret = listen(lsock, 5);
96 100 if (ret == -1) {
97 101 fprintf(stderr, "listener - listen fail %s\n", strerror(errno));
98 102 exit(1);
99 103 }
100 104
101 105 for (;;) {
102 106 asock = accept(lsock, NULL, 0);
103 107 if (asock == -1) {
104 108 fprintf(stderr, "listener - accept fail %s\n",
105 109 strerror(errno));
106 110 exit(1);
↓ open down ↓ |
74 lines elided |
↑ open up ↑ |
107 111 }
108 112
109 113 /* start worker */
110 114 ret = pthread_create(NULL, NULL, server, (void *)asock);
111 115 if (ret == -1) {
112 116 fprintf(stderr, "%s - thread create fail %s\n",
113 117 __progname, strerror(errno));
114 118 exit(1);
115 119 }
116 120 }
117 -
118 - exit(0);
119 121 }
120 122
121 123 /*
122 124 * This should be a place only root is allowed to write.
123 125 * The test will create and destroy this directory.
124 126 */
125 127 char testdir[100] = "/var/run/os-tests-sockfs";
126 128 struct sockaddr_un addr;
127 129 int test_uid = UID_NOBODY;
128 130
129 131 int
130 132 main(int argc, char **argv)
131 133 {
132 134 int ret;
133 135 int sock;
134 136 unsigned int i;
135 137
136 138 if (argc > 1) {
137 139 ret = strlcpy(testdir, argv[1], sizeof (testdir));
138 140 if (ret >= sizeof (testdir)) {
139 141 fprintf(stderr, "%s: too long\n", argv[1]);
140 142 exit(1);
141 143 }
142 144 }
143 145
144 146 addr.sun_family = AF_UNIX;
145 147 (void) sprintf(addr.sun_path, "%s/s", testdir);
146 148
147 149 if (mkdir(testdir, 0700) != 0) {
148 150 switch (errno) {
149 151 case EEXIST:
150 152 case EISDIR:
151 153 break;
152 154 default:
153 155 perror(testdir);
154 156 exit(1);
155 157 }
156 158 }
157 159 (void) unlink(addr.sun_path);
158 160
159 161 /* Set up the listener. */
160 162 ret = pthread_create(NULL, NULL, listener, &addr);
161 163 if (ret == -1) {
162 164 fprintf(stderr, "%s - thread create fail %s\n",
163 165 argv[0], strerror(errno));
164 166 exit(1);
165 167 }
166 168
167 169 sleep(1);
168 170
169 171 /* Create and connect the socket endpoint. */
170 172
171 173 sock = socket(AF_UNIX, SOCK_STREAM, 0);
172 174 if (sock == -1) {
173 175 fprintf(stderr, "%s - socket fail %s\n",
174 176 argv[0], strerror(errno));
175 177 exit(1);
176 178 }
177 179
178 180 ret = connect(sock, (struct sockaddr *)&addr, sizeof (addr));
179 181 if (ret == -1) {
180 182 fprintf(stderr, "%s - connect fail %s\n",
181 183 argv[0], strerror(errno));
182 184 exit(1);
183 185 }
184 186
185 187 /* Send some messages */
186 188 for (i = 0; i < 5; i++) {
187 189 struct iovec iov;
188 190 struct msghdr msg;
189 191 uint8_t buf[4096];
190 192
191 193 memcpy(buf, "TEST0", sizeof ("TEST0"));
192 194 buf[4] = '0' + i;
193 195
194 196 printf("CLIENT:%s\n", buf);
195 197
196 198 iov = (struct iovec) {
197 199 .iov_base = buf,
198 200 .iov_len = sizeof (buf),
199 201 };
200 202
201 203 msg = (struct msghdr) {
202 204 .msg_iov = &iov,
203 205 .msg_iovlen = 1,
204 206 };
205 207
206 208 ret = sendmsg(sock, &msg, 0);
207 209
208 210 if (ret == -1) {
209 211 fprintf(stderr, "%s - sendmsg fail %s\n",
210 212 argv[0], strerror(errno));
211 213 exit(1);
212 214 }
213 215
214 216 fflush(stdout);
215 217 sleep(1);
216 218 }
217 219
218 220 close(sock);
219 221 return (0);
220 222 }
↓ open down ↓ |
92 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX