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/file-locking/util.c
+++ new/usr/src/test/os-tests/tests/file-locking/util.c
1 1 /*
2 2 * This file and its contents are supplied under the terms of the
↓ open down ↓ |
2 lines elided |
↑ open up ↑ |
3 3 * Common Development and Distribution License ("CDDL"), version 1.0.
4 4 * You may only use this file in accordance with the terms of version
5 5 * 1.0 of the CDDL.
6 6 *
7 7 * A full copy of the text of the CDDL should have accompanied this
8 8 * source. A copy of the CDDL is also available via the Internet at
9 9 * http://www.illumos.org/license/CDDL.
10 10 */
11 11
12 12 /*
13 - * Copyright 2018 Joyent, Inc.
13 + * Copyright 2019 Joyent, Inc.
14 14 */
15 15
16 16 /*
17 17 * Utility functions for use in both acquire-lock and runtests.
18 18 */
19 19
20 20 #include "util.h"
21 21 #include <err.h>
22 22 #include <errno.h>
23 23 #include <poll.h>
24 24 #include <stdarg.h>
25 25 #include <stdio.h>
26 26 #include <stdlib.h>
27 27 #include <strings.h>
28 28 #include <unistd.h>
29 29
30 30
31 31 boolean_t LOG = B_FALSE;
32 32
33 33
34 34 void
35 35 flock_log(const char *format, ...)
36 36 {
37 37 va_list ap;
38 38 if (!LOG) {
39 39 return;
40 40 }
41 41
42 42 va_start(ap, format);
43 43 (void) vfprintf(stderr, format, ap);
44 44 va_end(ap);
45 45 }
46 46
47 47
48 48 boolean_t
49 49 flock_nodata(int fd)
50 50 {
51 51 struct pollfd pfd = { fd, POLLIN, 0 };
52 52 int ret = poll(&pfd, 1, 1000);
53 53
54 54 if (ret == -1) {
55 55 err(EXIT_FAILURE, "poll failed");
56 56 }
57 57
58 58 return (ret == 0);
59 59 }
60 60
61 61
62 62 void
63 63 flock_block(int fd)
64 64 {
65 65 char buf[1];
66 66 int ret = 0;
67 67 while (ret < 1) {
68 68 ret = read(fd, buf, 1);
69 69 if (ret == -1) {
70 70 if (errno == EINTR)
71 71 continue;
72 72 err(EXIT_FAILURE, "read failed");
73 73 }
74 74 }
75 75 }
76 76
77 77
78 78 void
79 79 flock_alert(int fd)
80 80 {
81 81 int ret = 0;
82 82 while (ret < 1) {
83 83 ret = write(fd, "1", 1);
84 84 if (ret == -1) {
85 85 if (errno == EINTR)
86 86 continue;
87 87 err(EXIT_FAILURE, "write failed");
88 88 }
89 89 }
90 90 }
91 91
92 92
93 93 lock_style_t
↓ open down ↓ |
70 lines elided |
↑ open up ↑ |
94 94 flock_styleenum(char *stylestr)
95 95 {
96 96 if (strcmp(stylestr, "posix") == 0) {
97 97 return (LSTYLE_POSIX);
98 98 } else if (strcmp(stylestr, "ofd") == 0) {
99 99 return (LSTYLE_OFD);
100 100 } else if (strcmp(stylestr, "flock") == 0) {
101 101 return (LSTYLE_FLOCK);
102 102 } else {
103 103 errx(EXIT_FAILURE, BAD_LOCK_MESSAGE);
104 - return (LSTYLE_LAST);
105 104 }
106 105 }
107 106
108 107
109 108 char *
110 109 flock_stylestr(lock_style_t style)
111 110 {
112 111 switch (style) {
113 112 case LSTYLE_POSIX:
114 113 return ("posix");
115 114 case LSTYLE_OFD:
116 115 return ("ofd");
117 116 case LSTYLE_FLOCK:
118 117 return ("flock");
119 118 default:
120 119 abort();
121 - return ("<unreachable>");
122 120 }
123 121 }
124 122
125 123
126 124 char *
127 125 flock_stylename(lock_style_t style)
128 126 {
129 127 switch (style) {
130 128 case LSTYLE_POSIX:
131 129 return ("fcntl(2) POSIX");
132 130 case LSTYLE_OFD:
133 131 return ("fcntl(2) OFD");
134 132 case LSTYLE_FLOCK:
135 133 return ("flock(3C)");
136 134 default:
137 135 abort();
138 - return ("<unreachable>");
139 136 }
140 137 }
141 138
142 139
143 140 void
144 141 flock_reinit(struct flock *flp, int ltype)
145 142 {
146 143 bzero(flp, sizeof (*flp));
147 144 flp->l_type = ltype;
148 145 }
149 146
150 147
151 148 char *
152 149 flock_cmdname(int cmd)
153 150 {
154 151 switch (cmd) {
155 152 case F_SETLK:
156 153 return ("F_SETLK");
157 154 case F_OFD_SETLK:
158 155 return ("F_OFD_SETLK");
159 156 case F_SETLKW:
160 157 return ("F_SETLKW");
161 158 case F_OFD_SETLKW:
162 159 return ("F_OFD_SETLKW");
163 160 case F_GETLK:
164 161 return ("F_GETLK");
165 162 case F_OFD_GETLK:
166 163 return ("F_OFD_GETLK");
167 164 case F_FLOCK:
168 165 return ("F_FLOCK");
169 166 case F_FLOCKW:
170 167 return ("F_FLOCKW");
↓ open down ↓ |
22 lines elided |
↑ open up ↑ |
171 168 #if !defined(_LP64)
172 169 case F_OFD_SETLK64:
173 170 return ("F_OFD_SETLK64");
174 171 case F_OFD_SETLKW64:
175 172 return ("F_OFD_SETLKW64");
176 173 case F_OFD_GETLK64:
177 174 return ("F_OFD_GETLK64");
178 175 #endif
179 176 default:
180 177 abort();
181 - return ("<unreachable>");
182 178 }
183 179 }
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX