diff options
author | Jeff Dike <jdike@addtoit.com> | 2008-02-05 01:31:05 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@woody.linux-foundation.org> | 2008-02-05 12:44:29 -0500 |
commit | 1adfd6095e1c654dce5a692db5aa5a2b2a8d6b0d (patch) | |
tree | 229d0af90109b55bf59fe648947d66c4f044cf5a /arch/um | |
parent | bf8fde785b872282e7e86d9ea8a9c4e543985bb3 (diff) |
uml: style fixes in file.c
arch/um/os-Linux/file.c needed some style work -
updated the copyright
cleaned up the includes
CodingStyle fixes
added some missing CATCH_EINTRs
os_set_owner was unused, so it is gone
all printks now have severities
fcntl(F_GETFL) was being called without checking the return
removed an obsolete comment
Signed-off-by: Jeff Dike <jdike@linux.intel.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'arch/um')
-rw-r--r-- | arch/um/include/os.h | 1 | ||||
-rw-r--r-- | arch/um/os-Linux/file.c | 232 |
2 files changed, 118 insertions, 115 deletions
diff --git a/arch/um/include/os.h b/arch/um/include/os.h index fdac1a55d031..daaafc8824b0 100644 --- a/arch/um/include/os.h +++ b/arch/um/include/os.h | |||
@@ -131,7 +131,6 @@ extern int os_set_exec_close(int fd); | |||
131 | extern int os_ioctl_generic(int fd, unsigned int cmd, unsigned long arg); | 131 | extern int os_ioctl_generic(int fd, unsigned int cmd, unsigned long arg); |
132 | extern int os_get_ifname(int fd, char *namebuf); | 132 | extern int os_get_ifname(int fd, char *namebuf); |
133 | extern int os_set_slip(int fd); | 133 | extern int os_set_slip(int fd); |
134 | extern int os_set_owner(int fd, int pid); | ||
135 | extern int os_mode_fd(int fd, int mode); | 134 | extern int os_mode_fd(int fd, int mode); |
136 | 135 | ||
137 | extern int os_seek_file(int fd, unsigned long long offset); | 136 | extern int os_seek_file(int fd, unsigned long long offset); |
diff --git a/arch/um/os-Linux/file.c b/arch/um/os-Linux/file.c index 4f547d75b17e..d7404c621ff7 100644 --- a/arch/um/os-Linux/file.c +++ b/arch/um/os-Linux/file.c | |||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | * Copyright (C) 2002 Jeff Dike (jdike@karaya.com) | 2 | * Copyright (C) 2002 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com) |
3 | * Licensed under the GPL | 3 | * Licensed under the GPL |
4 | */ | 4 | */ |
5 | 5 | ||
@@ -8,13 +8,12 @@ | |||
8 | #include <errno.h> | 8 | #include <errno.h> |
9 | #include <fcntl.h> | 9 | #include <fcntl.h> |
10 | #include <signal.h> | 10 | #include <signal.h> |
11 | #include <sys/types.h> | ||
12 | #include <sys/stat.h> | ||
13 | #include <sys/socket.h> | ||
14 | #include <sys/un.h> | ||
15 | #include <sys/ioctl.h> | 11 | #include <sys/ioctl.h> |
16 | #include <sys/mount.h> | 12 | #include <sys/mount.h> |
17 | #include <sys/uio.h> | 13 | #include <sys/socket.h> |
14 | #include <sys/stat.h> | ||
15 | #include <sys/un.h> | ||
16 | #include "kern_constants.h" | ||
18 | #include "os.h" | 17 | #include "os.h" |
19 | #include "user.h" | 18 | #include "user.h" |
20 | 19 | ||
@@ -42,10 +41,10 @@ int os_stat_fd(const int fd, struct uml_stat *ubuf) | |||
42 | int err; | 41 | int err; |
43 | 42 | ||
44 | CATCH_EINTR(err = fstat64(fd, &sbuf)); | 43 | CATCH_EINTR(err = fstat64(fd, &sbuf)); |
45 | if(err < 0) | 44 | if (err < 0) |
46 | return -errno; | 45 | return -errno; |
47 | 46 | ||
48 | if(ubuf != NULL) | 47 | if (ubuf != NULL) |
49 | copy_stat(ubuf, &sbuf); | 48 | copy_stat(ubuf, &sbuf); |
50 | return err; | 49 | return err; |
51 | } | 50 | } |
@@ -55,27 +54,26 @@ int os_stat_file(const char *file_name, struct uml_stat *ubuf) | |||
55 | struct stat64 sbuf; | 54 | struct stat64 sbuf; |
56 | int err; | 55 | int err; |
57 | 56 | ||
58 | do { | 57 | CATCH_EINTR(err = stat64(file_name, &sbuf)); |
59 | err = stat64(file_name, &sbuf); | 58 | if (err < 0) |
60 | } while((err < 0) && (errno == EINTR)) ; | ||
61 | |||
62 | if(err < 0) | ||
63 | return -errno; | 59 | return -errno; |
64 | 60 | ||
65 | if(ubuf != NULL) | 61 | if (ubuf != NULL) |
66 | copy_stat(ubuf, &sbuf); | 62 | copy_stat(ubuf, &sbuf); |
67 | return err; | 63 | return err; |
68 | } | 64 | } |
69 | 65 | ||
70 | int os_access(const char* file, int mode) | 66 | int os_access(const char *file, int mode) |
71 | { | 67 | { |
72 | int amode, err; | 68 | int amode, err; |
73 | 69 | ||
74 | amode=(mode&OS_ACC_R_OK ? R_OK : 0) | (mode&OS_ACC_W_OK ? W_OK : 0) | | 70 | amode = (mode & OS_ACC_R_OK ? R_OK : 0) | |
75 | (mode&OS_ACC_X_OK ? X_OK : 0) | (mode&OS_ACC_F_OK ? F_OK : 0) ; | 71 | (mode & OS_ACC_W_OK ? W_OK : 0) | |
72 | (mode & OS_ACC_X_OK ? X_OK : 0) | | ||
73 | (mode & OS_ACC_F_OK ? F_OK : 0); | ||
76 | 74 | ||
77 | err = access(file, amode); | 75 | err = access(file, amode); |
78 | if(err < 0) | 76 | if (err < 0) |
79 | return -errno; | 77 | return -errno; |
80 | 78 | ||
81 | return 0; | 79 | return 0; |
@@ -87,7 +85,7 @@ int os_ioctl_generic(int fd, unsigned int cmd, unsigned long arg) | |||
87 | int err; | 85 | int err; |
88 | 86 | ||
89 | err = ioctl(fd, cmd, arg); | 87 | err = ioctl(fd, cmd, arg); |
90 | if(err < 0) | 88 | if (err < 0) |
91 | return -errno; | 89 | return -errno; |
92 | 90 | ||
93 | return err; | 91 | return err; |
@@ -96,7 +94,7 @@ int os_ioctl_generic(int fd, unsigned int cmd, unsigned long arg) | |||
96 | /* FIXME: ensure namebuf in os_get_if_name is big enough */ | 94 | /* FIXME: ensure namebuf in os_get_if_name is big enough */ |
97 | int os_get_ifname(int fd, char* namebuf) | 95 | int os_get_ifname(int fd, char* namebuf) |
98 | { | 96 | { |
99 | if(ioctl(fd, SIOCGIFNAME, namebuf) < 0) | 97 | if (ioctl(fd, SIOCGIFNAME, namebuf) < 0) |
100 | return -errno; | 98 | return -errno; |
101 | 99 | ||
102 | return 0; | 100 | return 0; |
@@ -107,37 +105,22 @@ int os_set_slip(int fd) | |||
107 | int disc, sencap; | 105 | int disc, sencap; |
108 | 106 | ||
109 | disc = N_SLIP; | 107 | disc = N_SLIP; |
110 | if(ioctl(fd, TIOCSETD, &disc) < 0) | 108 | if (ioctl(fd, TIOCSETD, &disc) < 0) |
111 | return -errno; | 109 | return -errno; |
112 | 110 | ||
113 | sencap = 0; | 111 | sencap = 0; |
114 | if(ioctl(fd, SIOCSIFENCAP, &sencap) < 0) | 112 | if (ioctl(fd, SIOCSIFENCAP, &sencap) < 0) |
115 | return -errno; | 113 | return -errno; |
116 | 114 | ||
117 | return 0; | 115 | return 0; |
118 | } | 116 | } |
119 | 117 | ||
120 | int os_set_owner(int fd, int pid) | ||
121 | { | ||
122 | if(fcntl(fd, F_SETOWN, pid) < 0){ | ||
123 | int save_errno = errno; | ||
124 | |||
125 | if(fcntl(fd, F_GETOWN, 0) != pid) | ||
126 | return -save_errno; | ||
127 | } | ||
128 | |||
129 | return 0; | ||
130 | } | ||
131 | |||
132 | int os_mode_fd(int fd, int mode) | 118 | int os_mode_fd(int fd, int mode) |
133 | { | 119 | { |
134 | int err; | 120 | int err; |
135 | 121 | ||
136 | do { | 122 | CATCH_EINTR(err = fchmod(fd, mode)); |
137 | err = fchmod(fd, mode); | 123 | if (err < 0) |
138 | } while((err < 0) && (errno==EINTR)) ; | ||
139 | |||
140 | if(err < 0) | ||
141 | return -errno; | 124 | return -errno; |
142 | 125 | ||
143 | return 0; | 126 | return 0; |
@@ -149,20 +132,20 @@ int os_file_type(char *file) | |||
149 | int err; | 132 | int err; |
150 | 133 | ||
151 | err = os_stat_file(file, &buf); | 134 | err = os_stat_file(file, &buf); |
152 | if(err < 0) | 135 | if (err < 0) |
153 | return err; | 136 | return err; |
154 | 137 | ||
155 | if(S_ISDIR(buf.ust_mode)) | 138 | if (S_ISDIR(buf.ust_mode)) |
156 | return OS_TYPE_DIR; | 139 | return OS_TYPE_DIR; |
157 | else if(S_ISLNK(buf.ust_mode)) | 140 | else if (S_ISLNK(buf.ust_mode)) |
158 | return OS_TYPE_SYMLINK; | 141 | return OS_TYPE_SYMLINK; |
159 | else if(S_ISCHR(buf.ust_mode)) | 142 | else if (S_ISCHR(buf.ust_mode)) |
160 | return OS_TYPE_CHARDEV; | 143 | return OS_TYPE_CHARDEV; |
161 | else if(S_ISBLK(buf.ust_mode)) | 144 | else if (S_ISBLK(buf.ust_mode)) |
162 | return OS_TYPE_BLOCKDEV; | 145 | return OS_TYPE_BLOCKDEV; |
163 | else if(S_ISFIFO(buf.ust_mode)) | 146 | else if (S_ISFIFO(buf.ust_mode)) |
164 | return OS_TYPE_FIFO; | 147 | return OS_TYPE_FIFO; |
165 | else if(S_ISSOCK(buf.ust_mode)) | 148 | else if (S_ISSOCK(buf.ust_mode)) |
166 | return OS_TYPE_SOCK; | 149 | return OS_TYPE_SOCK; |
167 | else return OS_TYPE_FILE; | 150 | else return OS_TYPE_FILE; |
168 | } | 151 | } |
@@ -174,15 +157,15 @@ int os_file_mode(const char *file, struct openflags *mode_out) | |||
174 | *mode_out = OPENFLAGS(); | 157 | *mode_out = OPENFLAGS(); |
175 | 158 | ||
176 | err = access(file, W_OK); | 159 | err = access(file, W_OK); |
177 | if(err && (errno != EACCES)) | 160 | if (err && (errno != EACCES)) |
178 | return -errno; | 161 | return -errno; |
179 | else if(!err) | 162 | else if (!err) |
180 | *mode_out = of_write(*mode_out); | 163 | *mode_out = of_write(*mode_out); |
181 | 164 | ||
182 | err = access(file, R_OK); | 165 | err = access(file, R_OK); |
183 | if(err && (errno != EACCES)) | 166 | if (err && (errno != EACCES)) |
184 | return -errno; | 167 | return -errno; |
185 | else if(!err) | 168 | else if (!err) |
186 | *mode_out = of_read(*mode_out); | 169 | *mode_out = of_read(*mode_out); |
187 | 170 | ||
188 | return err; | 171 | return err; |
@@ -192,21 +175,28 @@ int os_open_file(const char *file, struct openflags flags, int mode) | |||
192 | { | 175 | { |
193 | int fd, err, f = 0; | 176 | int fd, err, f = 0; |
194 | 177 | ||
195 | if(flags.r && flags.w) f = O_RDWR; | 178 | if (flags.r && flags.w) |
196 | else if(flags.r) f = O_RDONLY; | 179 | f = O_RDWR; |
197 | else if(flags.w) f = O_WRONLY; | 180 | else if (flags.r) |
181 | f = O_RDONLY; | ||
182 | else if (flags.w) | ||
183 | f = O_WRONLY; | ||
198 | else f = 0; | 184 | else f = 0; |
199 | 185 | ||
200 | if(flags.s) f |= O_SYNC; | 186 | if (flags.s) |
201 | if(flags.c) f |= O_CREAT; | 187 | f |= O_SYNC; |
202 | if(flags.t) f |= O_TRUNC; | 188 | if (flags.c) |
203 | if(flags.e) f |= O_EXCL; | 189 | f |= O_CREAT; |
190 | if (flags.t) | ||
191 | f |= O_TRUNC; | ||
192 | if (flags.e) | ||
193 | f |= O_EXCL; | ||
204 | 194 | ||
205 | fd = open64(file, f, mode); | 195 | fd = open64(file, f, mode); |
206 | if(fd < 0) | 196 | if (fd < 0) |
207 | return -errno; | 197 | return -errno; |
208 | 198 | ||
209 | if(flags.cl && fcntl(fd, F_SETFD, 1)){ | 199 | if (flags.cl && fcntl(fd, F_SETFD, 1)) { |
210 | err = -errno; | 200 | err = -errno; |
211 | close(fd); | 201 | close(fd); |
212 | return err; | 202 | return err; |
@@ -224,13 +214,13 @@ int os_connect_socket(const char *name) | |||
224 | snprintf(sock.sun_path, sizeof(sock.sun_path), "%s", name); | 214 | snprintf(sock.sun_path, sizeof(sock.sun_path), "%s", name); |
225 | 215 | ||
226 | fd = socket(AF_UNIX, SOCK_STREAM, 0); | 216 | fd = socket(AF_UNIX, SOCK_STREAM, 0); |
227 | if(fd < 0) { | 217 | if (fd < 0) { |
228 | err = -errno; | 218 | err = -errno; |
229 | goto out; | 219 | goto out; |
230 | } | 220 | } |
231 | 221 | ||
232 | err = connect(fd, (struct sockaddr *) &sock, sizeof(sock)); | 222 | err = connect(fd, (struct sockaddr *) &sock, sizeof(sock)); |
233 | if(err) { | 223 | if (err) { |
234 | err = -errno; | 224 | err = -errno; |
235 | goto out_close; | 225 | goto out_close; |
236 | } | 226 | } |
@@ -253,7 +243,7 @@ int os_seek_file(int fd, unsigned long long offset) | |||
253 | unsigned long long actual; | 243 | unsigned long long actual; |
254 | 244 | ||
255 | actual = lseek64(fd, offset, SEEK_SET); | 245 | actual = lseek64(fd, offset, SEEK_SET); |
256 | if(actual != offset) | 246 | if (actual != offset) |
257 | return -errno; | 247 | return -errno; |
258 | return 0; | 248 | return 0; |
259 | } | 249 | } |
@@ -262,7 +252,7 @@ int os_read_file(int fd, void *buf, int len) | |||
262 | { | 252 | { |
263 | int n = read(fd, buf, len); | 253 | int n = read(fd, buf, len); |
264 | 254 | ||
265 | if(n < 0) | 255 | if (n < 0) |
266 | return -errno; | 256 | return -errno; |
267 | return n; | 257 | return n; |
268 | } | 258 | } |
@@ -271,7 +261,7 @@ int os_write_file(int fd, const void *buf, int len) | |||
271 | { | 261 | { |
272 | int n = write(fd, (void *) buf, len); | 262 | int n = write(fd, (void *) buf, len); |
273 | 263 | ||
274 | if(n < 0) | 264 | if (n < 0) |
275 | return -errno; | 265 | return -errno; |
276 | return n; | 266 | return n; |
277 | } | 267 | } |
@@ -282,26 +272,27 @@ int os_file_size(const char *file, unsigned long long *size_out) | |||
282 | int err; | 272 | int err; |
283 | 273 | ||
284 | err = os_stat_file(file, &buf); | 274 | err = os_stat_file(file, &buf); |
285 | if(err < 0){ | 275 | if (err < 0) { |
286 | printk("Couldn't stat \"%s\" : err = %d\n", file, -err); | 276 | printk(UM_KERN_ERR "Couldn't stat \"%s\" : err = %d\n", file, |
277 | -err); | ||
287 | return err; | 278 | return err; |
288 | } | 279 | } |
289 | 280 | ||
290 | if(S_ISBLK(buf.ust_mode)){ | 281 | if (S_ISBLK(buf.ust_mode)) { |
291 | int fd; | 282 | int fd; |
292 | long blocks; | 283 | long blocks; |
293 | 284 | ||
294 | fd = open(file, O_RDONLY, 0); | 285 | fd = open(file, O_RDONLY, 0); |
295 | if(fd < 0) { | 286 | if (fd < 0) { |
296 | err = -errno; | 287 | err = -errno; |
297 | printk("Couldn't open \"%s\", errno = %d\n", file, | 288 | printk(UM_KERN_ERR "Couldn't open \"%s\", " |
298 | errno); | 289 | "errno = %d\n", file, errno); |
299 | return err; | 290 | return err; |
300 | } | 291 | } |
301 | if(ioctl(fd, BLKGETSIZE, &blocks) < 0){ | 292 | if (ioctl(fd, BLKGETSIZE, &blocks) < 0) { |
302 | err = -errno; | 293 | err = -errno; |
303 | printk("Couldn't get the block size of \"%s\", " | 294 | printk(UM_KERN_ERR "Couldn't get the block size of " |
304 | "errno = %d\n", file, errno); | 295 | "\"%s\", errno = %d\n", file, errno); |
305 | close(fd); | 296 | close(fd); |
306 | return err; | 297 | return err; |
307 | } | 298 | } |
@@ -319,8 +310,9 @@ int os_file_modtime(const char *file, unsigned long *modtime) | |||
319 | int err; | 310 | int err; |
320 | 311 | ||
321 | err = os_stat_file(file, &buf); | 312 | err = os_stat_file(file, &buf); |
322 | if(err < 0){ | 313 | if (err < 0) { |
323 | printk("Couldn't stat \"%s\" : err = %d\n", file, -err); | 314 | printk(UM_KERN_ERR "Couldn't stat \"%s\" : err = %d\n", file, |
315 | -err); | ||
324 | return err; | 316 | return err; |
325 | } | 317 | } |
326 | 318 | ||
@@ -334,7 +326,7 @@ int os_set_exec_close(int fd) | |||
334 | 326 | ||
335 | CATCH_EINTR(err = fcntl(fd, F_SETFD, FD_CLOEXEC)); | 327 | CATCH_EINTR(err = fcntl(fd, F_SETFD, FD_CLOEXEC)); |
336 | 328 | ||
337 | if(err < 0) | 329 | if (err < 0) |
338 | return -errno; | 330 | return -errno; |
339 | return err; | 331 | return err; |
340 | } | 332 | } |
@@ -344,24 +336,25 @@ int os_pipe(int *fds, int stream, int close_on_exec) | |||
344 | int err, type = stream ? SOCK_STREAM : SOCK_DGRAM; | 336 | int err, type = stream ? SOCK_STREAM : SOCK_DGRAM; |
345 | 337 | ||
346 | err = socketpair(AF_UNIX, type, 0, fds); | 338 | err = socketpair(AF_UNIX, type, 0, fds); |
347 | if(err < 0) | 339 | if (err < 0) |
348 | return -errno; | 340 | return -errno; |
349 | 341 | ||
350 | if(!close_on_exec) | 342 | if (!close_on_exec) |
351 | return 0; | 343 | return 0; |
352 | 344 | ||
353 | err = os_set_exec_close(fds[0]); | 345 | err = os_set_exec_close(fds[0]); |
354 | if(err < 0) | 346 | if (err < 0) |
355 | goto error; | 347 | goto error; |
356 | 348 | ||
357 | err = os_set_exec_close(fds[1]); | 349 | err = os_set_exec_close(fds[1]); |
358 | if(err < 0) | 350 | if (err < 0) |
359 | goto error; | 351 | goto error; |
360 | 352 | ||
361 | return 0; | 353 | return 0; |
362 | 354 | ||
363 | error: | 355 | error: |
364 | printk("os_pipe : Setting FD_CLOEXEC failed, err = %d\n", -err); | 356 | printk(UM_KERN_ERR "os_pipe : Setting FD_CLOEXEC failed, err = %d\n", |
357 | -err); | ||
365 | close(fds[1]); | 358 | close(fds[1]); |
366 | close(fds[0]); | 359 | close(fds[0]); |
367 | return err; | 360 | return err; |
@@ -378,15 +371,15 @@ int os_set_fd_async(int fd) | |||
378 | flags |= O_ASYNC | O_NONBLOCK; | 371 | flags |= O_ASYNC | O_NONBLOCK; |
379 | if (fcntl(fd, F_SETFL, flags) < 0) { | 372 | if (fcntl(fd, F_SETFL, flags) < 0) { |
380 | err = -errno; | 373 | err = -errno; |
381 | printk("os_set_fd_async : failed to set O_ASYNC and " | 374 | printk(UM_KERN_ERR "os_set_fd_async : failed to set O_ASYNC " |
382 | "O_NONBLOCK on fd # %d, errno = %d\n", fd, errno); | 375 | "and O_NONBLOCK on fd # %d, errno = %d\n", fd, errno); |
383 | return err; | 376 | return err; |
384 | } | 377 | } |
385 | 378 | ||
386 | if ((fcntl(fd, F_SETSIG, SIGIO) < 0) || | 379 | if ((fcntl(fd, F_SETSIG, SIGIO) < 0) || |
387 | (fcntl(fd, F_SETOWN, os_getpid()) < 0)) { | 380 | (fcntl(fd, F_SETOWN, os_getpid()) < 0)) { |
388 | err = -errno; | 381 | err = -errno; |
389 | printk("os_set_fd_async : Failed to fcntl F_SETOWN " | 382 | printk(UM_KERN_ERR "os_set_fd_async : Failed to fcntl F_SETOWN " |
390 | "(or F_SETSIG) fd %d, errno = %d\n", fd, errno); | 383 | "(or F_SETSIG) fd %d, errno = %d\n", fd, errno); |
391 | return err; | 384 | return err; |
392 | } | 385 | } |
@@ -396,10 +389,14 @@ int os_set_fd_async(int fd) | |||
396 | 389 | ||
397 | int os_clear_fd_async(int fd) | 390 | int os_clear_fd_async(int fd) |
398 | { | 391 | { |
399 | int flags = fcntl(fd, F_GETFL); | 392 | int flags; |
393 | |||
394 | flags = fcntl(fd, F_GETFL); | ||
395 | if (flags < 0) | ||
396 | return -errno; | ||
400 | 397 | ||
401 | flags &= ~(O_ASYNC | O_NONBLOCK); | 398 | flags &= ~(O_ASYNC | O_NONBLOCK); |
402 | if(fcntl(fd, F_SETFL, flags) < 0) | 399 | if (fcntl(fd, F_SETFL, flags) < 0) |
403 | return -errno; | 400 | return -errno; |
404 | return 0; | 401 | return 0; |
405 | } | 402 | } |
@@ -409,11 +406,15 @@ int os_set_fd_block(int fd, int blocking) | |||
409 | int flags; | 406 | int flags; |
410 | 407 | ||
411 | flags = fcntl(fd, F_GETFL); | 408 | flags = fcntl(fd, F_GETFL); |
409 | if (flags < 0) | ||
410 | return -errno; | ||
412 | 411 | ||
413 | if(blocking) flags &= ~O_NONBLOCK; | 412 | if (blocking) |
414 | else flags |= O_NONBLOCK; | 413 | flags &= ~O_NONBLOCK; |
414 | else | ||
415 | flags |= O_NONBLOCK; | ||
415 | 416 | ||
416 | if(fcntl(fd, F_SETFL, flags) < 0) | 417 | if (fcntl(fd, F_SETFL, flags) < 0) |
417 | return -errno; | 418 | return -errno; |
418 | 419 | ||
419 | return 0; | 420 | return 0; |
@@ -424,7 +425,7 @@ int os_accept_connection(int fd) | |||
424 | int new; | 425 | int new; |
425 | 426 | ||
426 | new = accept(fd, NULL, 0); | 427 | new = accept(fd, NULL, 0); |
427 | if(new < 0) | 428 | if (new < 0) |
428 | return -errno; | 429 | return -errno; |
429 | return new; | 430 | return new; |
430 | } | 431 | } |
@@ -445,15 +446,17 @@ int os_shutdown_socket(int fd, int r, int w) | |||
445 | { | 446 | { |
446 | int what, err; | 447 | int what, err; |
447 | 448 | ||
448 | if(r && w) what = SHUT_RDWR; | 449 | if (r && w) |
449 | else if(r) what = SHUT_RD; | 450 | what = SHUT_RDWR; |
450 | else if(w) what = SHUT_WR; | 451 | else if (r) |
451 | else { | 452 | what = SHUT_RD; |
452 | printk("os_shutdown_socket : neither r or w was set\n"); | 453 | else if (w) |
454 | what = SHUT_WR; | ||
455 | else | ||
453 | return -EINVAL; | 456 | return -EINVAL; |
454 | } | 457 | |
455 | err = shutdown(fd, what); | 458 | err = shutdown(fd, what); |
456 | if(err < 0) | 459 | if (err < 0) |
457 | return -errno; | 460 | return -errno; |
458 | return 0; | 461 | return 0; |
459 | } | 462 | } |
@@ -477,19 +480,20 @@ int os_rcv_fd(int fd, int *helper_pid_out) | |||
477 | msg.msg_flags = 0; | 480 | msg.msg_flags = 0; |
478 | 481 | ||
479 | n = recvmsg(fd, &msg, 0); | 482 | n = recvmsg(fd, &msg, 0); |
480 | if(n < 0) | 483 | if (n < 0) |
481 | return -errno; | 484 | return -errno; |
482 | else if(n != iov.iov_len) | 485 | else if (n != iov.iov_len) |
483 | *helper_pid_out = -1; | 486 | *helper_pid_out = -1; |
484 | 487 | ||
485 | cmsg = CMSG_FIRSTHDR(&msg); | 488 | cmsg = CMSG_FIRSTHDR(&msg); |
486 | if(cmsg == NULL){ | 489 | if (cmsg == NULL) { |
487 | printk("rcv_fd didn't receive anything, error = %d\n", errno); | 490 | printk(UM_KERN_ERR "rcv_fd didn't receive anything, " |
491 | "error = %d\n", errno); | ||
488 | return -1; | 492 | return -1; |
489 | } | 493 | } |
490 | if((cmsg->cmsg_level != SOL_SOCKET) || | 494 | if ((cmsg->cmsg_level != SOL_SOCKET) || |
491 | (cmsg->cmsg_type != SCM_RIGHTS)){ | 495 | (cmsg->cmsg_type != SCM_RIGHTS)) { |
492 | printk("rcv_fd didn't receive a descriptor\n"); | 496 | printk(UM_KERN_ERR "rcv_fd didn't receive a descriptor\n"); |
493 | return -1; | 497 | return -1; |
494 | } | 498 | } |
495 | 499 | ||
@@ -503,23 +507,22 @@ int os_create_unix_socket(const char *file, int len, int close_on_exec) | |||
503 | int sock, err; | 507 | int sock, err; |
504 | 508 | ||
505 | sock = socket(PF_UNIX, SOCK_DGRAM, 0); | 509 | sock = socket(PF_UNIX, SOCK_DGRAM, 0); |
506 | if(sock < 0) | 510 | if (sock < 0) |
507 | return -errno; | 511 | return -errno; |
508 | 512 | ||
509 | if(close_on_exec) { | 513 | if (close_on_exec) { |
510 | err = os_set_exec_close(sock); | 514 | err = os_set_exec_close(sock); |
511 | if(err < 0) | 515 | if (err < 0) |
512 | printk("create_unix_socket : close_on_exec failed, " | 516 | printk(UM_KERN_ERR "create_unix_socket : " |
513 | "err = %d", -err); | 517 | "close_on_exec failed, err = %d", -err); |
514 | } | 518 | } |
515 | 519 | ||
516 | addr.sun_family = AF_UNIX; | 520 | addr.sun_family = AF_UNIX; |
517 | 521 | ||
518 | /* XXX Be more careful about overflow */ | ||
519 | snprintf(addr.sun_path, len, "%s", file); | 522 | snprintf(addr.sun_path, len, "%s", file); |
520 | 523 | ||
521 | err = bind(sock, (struct sockaddr *) &addr, sizeof(addr)); | 524 | err = bind(sock, (struct sockaddr *) &addr, sizeof(addr)); |
522 | if(err < 0) | 525 | if (err < 0) |
523 | return -errno; | 526 | return -errno; |
524 | 527 | ||
525 | return sock; | 528 | return sock; |
@@ -540,17 +543,18 @@ int os_lock_file(int fd, int excl) | |||
540 | int err, save; | 543 | int err, save; |
541 | 544 | ||
542 | err = fcntl(fd, F_SETLK, &lock); | 545 | err = fcntl(fd, F_SETLK, &lock); |
543 | if(!err) | 546 | if (!err) |
544 | goto out; | 547 | goto out; |
545 | 548 | ||
546 | save = -errno; | 549 | save = -errno; |
547 | err = fcntl(fd, F_GETLK, &lock); | 550 | err = fcntl(fd, F_GETLK, &lock); |
548 | if(err){ | 551 | if (err) { |
549 | err = -errno; | 552 | err = -errno; |
550 | goto out; | 553 | goto out; |
551 | } | 554 | } |
552 | 555 | ||
553 | printk("F_SETLK failed, file already locked by pid %d\n", lock.l_pid); | 556 | printk(UM_KERN_ERR "F_SETLK failed, file already locked by pid %d\n", |
557 | lock.l_pid); | ||
554 | err = save; | 558 | err = save; |
555 | out: | 559 | out: |
556 | return err; | 560 | return err; |