aboutsummaryrefslogtreecommitdiffstats
path: root/arch/um/os-Linux/file.c
diff options
context:
space:
mode:
Diffstat (limited to 'arch/um/os-Linux/file.c')
-rw-r--r--arch/um/os-Linux/file.c287
1 files changed, 138 insertions, 149 deletions
diff --git a/arch/um/os-Linux/file.c b/arch/um/os-Linux/file.c
index f83462758627..b5afcfd0f861 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,18 +8,16 @@
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#include "kern_util.h"
21 19
22static void copy_stat(struct uml_stat *dst, struct stat64 *src) 20static void copy_stat(struct uml_stat *dst, const struct stat64 *src)
23{ 21{
24 *dst = ((struct uml_stat) { 22 *dst = ((struct uml_stat) {
25 .ust_dev = src->st_dev, /* device */ 23 .ust_dev = src->st_dev, /* device */
@@ -43,10 +41,10 @@ int os_stat_fd(const int fd, struct uml_stat *ubuf)
43 int err; 41 int err;
44 42
45 CATCH_EINTR(err = fstat64(fd, &sbuf)); 43 CATCH_EINTR(err = fstat64(fd, &sbuf));
46 if(err < 0) 44 if (err < 0)
47 return -errno; 45 return -errno;
48 46
49 if(ubuf != NULL) 47 if (ubuf != NULL)
50 copy_stat(ubuf, &sbuf); 48 copy_stat(ubuf, &sbuf);
51 return err; 49 return err;
52} 50}
@@ -56,27 +54,26 @@ int os_stat_file(const char *file_name, struct uml_stat *ubuf)
56 struct stat64 sbuf; 54 struct stat64 sbuf;
57 int err; 55 int err;
58 56
59 do { 57 CATCH_EINTR(err = stat64(file_name, &sbuf));
60 err = stat64(file_name, &sbuf); 58 if (err < 0)
61 } while((err < 0) && (errno == EINTR)) ;
62
63 if(err < 0)
64 return -errno; 59 return -errno;
65 60
66 if(ubuf != NULL) 61 if (ubuf != NULL)
67 copy_stat(ubuf, &sbuf); 62 copy_stat(ubuf, &sbuf);
68 return err; 63 return err;
69} 64}
70 65
71int os_access(const char* file, int mode) 66int os_access(const char *file, int mode)
72{ 67{
73 int amode, err; 68 int amode, err;
74 69
75 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) |
76 (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);
77 74
78 err = access(file, amode); 75 err = access(file, amode);
79 if(err < 0) 76 if (err < 0)
80 return -errno; 77 return -errno;
81 78
82 return 0; 79 return 0;
@@ -88,7 +85,7 @@ int os_ioctl_generic(int fd, unsigned int cmd, unsigned long arg)
88 int err; 85 int err;
89 86
90 err = ioctl(fd, cmd, arg); 87 err = ioctl(fd, cmd, arg);
91 if(err < 0) 88 if (err < 0)
92 return -errno; 89 return -errno;
93 90
94 return err; 91 return err;
@@ -97,7 +94,7 @@ int os_ioctl_generic(int fd, unsigned int cmd, unsigned long arg)
97/* FIXME: ensure namebuf in os_get_if_name is big enough */ 94/* FIXME: ensure namebuf in os_get_if_name is big enough */
98int os_get_ifname(int fd, char* namebuf) 95int os_get_ifname(int fd, char* namebuf)
99{ 96{
100 if(ioctl(fd, SIOCGIFNAME, namebuf) < 0) 97 if (ioctl(fd, SIOCGIFNAME, namebuf) < 0)
101 return -errno; 98 return -errno;
102 99
103 return 0; 100 return 0;
@@ -108,37 +105,22 @@ int os_set_slip(int fd)
108 int disc, sencap; 105 int disc, sencap;
109 106
110 disc = N_SLIP; 107 disc = N_SLIP;
111 if(ioctl(fd, TIOCSETD, &disc) < 0) 108 if (ioctl(fd, TIOCSETD, &disc) < 0)
112 return -errno; 109 return -errno;
113 110
114 sencap = 0; 111 sencap = 0;
115 if(ioctl(fd, SIOCSIFENCAP, &sencap) < 0) 112 if (ioctl(fd, SIOCSIFENCAP, &sencap) < 0)
116 return -errno; 113 return -errno;
117 114
118 return 0; 115 return 0;
119} 116}
120 117
121int os_set_owner(int fd, int pid)
122{
123 if(fcntl(fd, F_SETOWN, pid) < 0){
124 int save_errno = errno;
125
126 if(fcntl(fd, F_GETOWN, 0) != pid)
127 return -save_errno;
128 }
129
130 return 0;
131}
132
133int os_mode_fd(int fd, int mode) 118int os_mode_fd(int fd, int mode)
134{ 119{
135 int err; 120 int err;
136 121
137 do { 122 CATCH_EINTR(err = fchmod(fd, mode));
138 err = fchmod(fd, mode); 123 if (err < 0)
139 } while((err < 0) && (errno==EINTR)) ;
140
141 if(err < 0)
142 return -errno; 124 return -errno;
143 125
144 return 0; 126 return 0;
@@ -150,64 +132,73 @@ int os_file_type(char *file)
150 int err; 132 int err;
151 133
152 err = os_stat_file(file, &buf); 134 err = os_stat_file(file, &buf);
153 if(err < 0) 135 if (err < 0)
154 return err; 136 return err;
155 137
156 if(S_ISDIR(buf.ust_mode)) 138 if (S_ISDIR(buf.ust_mode))
157 return OS_TYPE_DIR; 139 return OS_TYPE_DIR;
158 else if(S_ISLNK(buf.ust_mode)) 140 else if (S_ISLNK(buf.ust_mode))
159 return OS_TYPE_SYMLINK; 141 return OS_TYPE_SYMLINK;
160 else if(S_ISCHR(buf.ust_mode)) 142 else if (S_ISCHR(buf.ust_mode))
161 return OS_TYPE_CHARDEV; 143 return OS_TYPE_CHARDEV;
162 else if(S_ISBLK(buf.ust_mode)) 144 else if (S_ISBLK(buf.ust_mode))
163 return OS_TYPE_BLOCKDEV; 145 return OS_TYPE_BLOCKDEV;
164 else if(S_ISFIFO(buf.ust_mode)) 146 else if (S_ISFIFO(buf.ust_mode))
165 return OS_TYPE_FIFO; 147 return OS_TYPE_FIFO;
166 else if(S_ISSOCK(buf.ust_mode)) 148 else if (S_ISSOCK(buf.ust_mode))
167 return OS_TYPE_SOCK; 149 return OS_TYPE_SOCK;
168 else return OS_TYPE_FILE; 150 else return OS_TYPE_FILE;
169} 151}
170 152
171int os_file_mode(char *file, struct openflags *mode_out) 153int os_file_mode(const char *file, struct openflags *mode_out)
172{ 154{
173 int err; 155 int err;
174 156
175 *mode_out = OPENFLAGS(); 157 *mode_out = OPENFLAGS();
176 158
177 err = access(file, W_OK); 159 err = access(file, W_OK);
178 if(err && (errno != EACCES)) 160 if (err && (errno != EACCES))
179 return -errno; 161 return -errno;
180 else if(!err) 162 else if (!err)
181 *mode_out = of_write(*mode_out); 163 *mode_out = of_write(*mode_out);
182 164
183 err = access(file, R_OK); 165 err = access(file, R_OK);
184 if(err && (errno != EACCES)) 166 if (err && (errno != EACCES))
185 return -errno; 167 return -errno;
186 else if(!err) 168 else if (!err)
187 *mode_out = of_read(*mode_out); 169 *mode_out = of_read(*mode_out);
188 170
189 return err; 171 return err;
190} 172}
191 173
192int os_open_file(char *file, struct openflags flags, int mode) 174int os_open_file(const char *file, struct openflags flags, int mode)
193{ 175{
194 int fd, err, f = 0; 176 int fd, err, f = 0;
195 177
196 if(flags.r && flags.w) f = O_RDWR; 178 if (flags.r && flags.w)
197 else if(flags.r) f = O_RDONLY; 179 f = O_RDWR;
198 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;
199 else f = 0; 184 else f = 0;
200 185
201 if(flags.s) f |= O_SYNC; 186 if (flags.s)
202 if(flags.c) f |= O_CREAT; 187 f |= O_SYNC;
203 if(flags.t) f |= O_TRUNC; 188 if (flags.c)
204 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;
194 if (flags.a)
195 f |= O_APPEND;
205 196
206 fd = open64(file, f, mode); 197 fd = open64(file, f, mode);
207 if(fd < 0) 198 if (fd < 0)
208 return -errno; 199 return -errno;
209 200
210 if(flags.cl && fcntl(fd, F_SETFD, 1)){ 201 if (flags.cl && fcntl(fd, F_SETFD, 1)) {
211 err = -errno; 202 err = -errno;
212 close(fd); 203 close(fd);
213 return err; 204 return err;
@@ -216,7 +207,7 @@ int os_open_file(char *file, struct openflags flags, int mode)
216 return fd; 207 return fd;
217} 208}
218 209
219int os_connect_socket(char *name) 210int os_connect_socket(const char *name)
220{ 211{
221 struct sockaddr_un sock; 212 struct sockaddr_un sock;
222 int fd, err; 213 int fd, err;
@@ -225,13 +216,13 @@ int os_connect_socket(char *name)
225 snprintf(sock.sun_path, sizeof(sock.sun_path), "%s", name); 216 snprintf(sock.sun_path, sizeof(sock.sun_path), "%s", name);
226 217
227 fd = socket(AF_UNIX, SOCK_STREAM, 0); 218 fd = socket(AF_UNIX, SOCK_STREAM, 0);
228 if(fd < 0) { 219 if (fd < 0) {
229 err = -errno; 220 err = -errno;
230 goto out; 221 goto out;
231 } 222 }
232 223
233 err = connect(fd, (struct sockaddr *) &sock, sizeof(sock)); 224 err = connect(fd, (struct sockaddr *) &sock, sizeof(sock));
234 if(err) { 225 if (err) {
235 err = -errno; 226 err = -errno;
236 goto out_close; 227 goto out_close;
237 } 228 }
@@ -254,7 +245,7 @@ int os_seek_file(int fd, unsigned long long offset)
254 unsigned long long actual; 245 unsigned long long actual;
255 246
256 actual = lseek64(fd, offset, SEEK_SET); 247 actual = lseek64(fd, offset, SEEK_SET);
257 if(actual != offset) 248 if (actual != offset)
258 return -errno; 249 return -errno;
259 return 0; 250 return 0;
260} 251}
@@ -263,7 +254,7 @@ int os_read_file(int fd, void *buf, int len)
263{ 254{
264 int n = read(fd, buf, len); 255 int n = read(fd, buf, len);
265 256
266 if(n < 0) 257 if (n < 0)
267 return -errno; 258 return -errno;
268 return n; 259 return n;
269} 260}
@@ -272,37 +263,38 @@ int os_write_file(int fd, const void *buf, int len)
272{ 263{
273 int n = write(fd, (void *) buf, len); 264 int n = write(fd, (void *) buf, len);
274 265
275 if(n < 0) 266 if (n < 0)
276 return -errno; 267 return -errno;
277 return n; 268 return n;
278} 269}
279 270
280int os_file_size(char *file, unsigned long long *size_out) 271int os_file_size(const char *file, unsigned long long *size_out)
281{ 272{
282 struct uml_stat buf; 273 struct uml_stat buf;
283 int err; 274 int err;
284 275
285 err = os_stat_file(file, &buf); 276 err = os_stat_file(file, &buf);
286 if(err < 0){ 277 if (err < 0) {
287 printk("Couldn't stat \"%s\" : err = %d\n", file, -err); 278 printk(UM_KERN_ERR "Couldn't stat \"%s\" : err = %d\n", file,
279 -err);
288 return err; 280 return err;
289 } 281 }
290 282
291 if(S_ISBLK(buf.ust_mode)){ 283 if (S_ISBLK(buf.ust_mode)) {
292 int fd; 284 int fd;
293 long blocks; 285 long blocks;
294 286
295 fd = open(file, O_RDONLY, 0); 287 fd = open(file, O_RDONLY, 0);
296 if(fd < 0) { 288 if (fd < 0) {
297 err = -errno; 289 err = -errno;
298 printk("Couldn't open \"%s\", errno = %d\n", file, 290 printk(UM_KERN_ERR "Couldn't open \"%s\", "
299 errno); 291 "errno = %d\n", file, errno);
300 return err; 292 return err;
301 } 293 }
302 if(ioctl(fd, BLKGETSIZE, &blocks) < 0){ 294 if (ioctl(fd, BLKGETSIZE, &blocks) < 0) {
303 err = -errno; 295 err = -errno;
304 printk("Couldn't get the block size of \"%s\", " 296 printk(UM_KERN_ERR "Couldn't get the block size of "
305 "errno = %d\n", file, errno); 297 "\"%s\", errno = %d\n", file, errno);
306 close(fd); 298 close(fd);
307 return err; 299 return err;
308 } 300 }
@@ -314,14 +306,15 @@ int os_file_size(char *file, unsigned long long *size_out)
314 return 0; 306 return 0;
315} 307}
316 308
317int os_file_modtime(char *file, unsigned long *modtime) 309int os_file_modtime(const char *file, unsigned long *modtime)
318{ 310{
319 struct uml_stat buf; 311 struct uml_stat buf;
320 int err; 312 int err;
321 313
322 err = os_stat_file(file, &buf); 314 err = os_stat_file(file, &buf);
323 if(err < 0){ 315 if (err < 0) {
324 printk("Couldn't stat \"%s\" : err = %d\n", file, -err); 316 printk(UM_KERN_ERR "Couldn't stat \"%s\" : err = %d\n", file,
317 -err);
325 return err; 318 return err;
326 } 319 }
327 320
@@ -329,26 +322,13 @@ int os_file_modtime(char *file, unsigned long *modtime)
329 return 0; 322 return 0;
330} 323}
331 324
332int os_get_exec_close(int fd, int *close_on_exec)
333{
334 int ret;
335
336 CATCH_EINTR(ret = fcntl(fd, F_GETFD));
337
338 if(ret < 0)
339 return -errno;
340
341 *close_on_exec = (ret & FD_CLOEXEC) ? 1 : 0;
342 return ret;
343}
344
345int os_set_exec_close(int fd) 325int os_set_exec_close(int fd)
346{ 326{
347 int err; 327 int err;
348 328
349 CATCH_EINTR(err = fcntl(fd, F_SETFD, FD_CLOEXEC)); 329 CATCH_EINTR(err = fcntl(fd, F_SETFD, FD_CLOEXEC));
350 330
351 if(err < 0) 331 if (err < 0)
352 return -errno; 332 return -errno;
353 return err; 333 return err;
354} 334}
@@ -358,53 +338,51 @@ int os_pipe(int *fds, int stream, int close_on_exec)
358 int err, type = stream ? SOCK_STREAM : SOCK_DGRAM; 338 int err, type = stream ? SOCK_STREAM : SOCK_DGRAM;
359 339
360 err = socketpair(AF_UNIX, type, 0, fds); 340 err = socketpair(AF_UNIX, type, 0, fds);
361 if(err < 0) 341 if (err < 0)
362 return -errno; 342 return -errno;
363 343
364 if(!close_on_exec) 344 if (!close_on_exec)
365 return 0; 345 return 0;
366 346
367 err = os_set_exec_close(fds[0]); 347 err = os_set_exec_close(fds[0]);
368 if(err < 0) 348 if (err < 0)
369 goto error; 349 goto error;
370 350
371 err = os_set_exec_close(fds[1]); 351 err = os_set_exec_close(fds[1]);
372 if(err < 0) 352 if (err < 0)
373 goto error; 353 goto error;
374 354
375 return 0; 355 return 0;
376 356
377 error: 357 error:
378 printk("os_pipe : Setting FD_CLOEXEC failed, err = %d\n", -err); 358 printk(UM_KERN_ERR "os_pipe : Setting FD_CLOEXEC failed, err = %d\n",
359 -err);
379 close(fds[1]); 360 close(fds[1]);
380 close(fds[0]); 361 close(fds[0]);
381 return err; 362 return err;
382} 363}
383 364
384int os_set_fd_async(int fd, int owner) 365int os_set_fd_async(int fd)
385{ 366{
386 int err; 367 int err, flags;
368
369 flags = fcntl(fd, F_GETFL);
370 if (flags < 0)
371 return -errno;
387 372
388 /* XXX This should do F_GETFL first */ 373 flags |= O_ASYNC | O_NONBLOCK;
389 if(fcntl(fd, F_SETFL, O_ASYNC | O_NONBLOCK) < 0){ 374 if (fcntl(fd, F_SETFL, flags) < 0) {
390 err = -errno; 375 err = -errno;
391 printk("os_set_fd_async : failed to set O_ASYNC and " 376 printk(UM_KERN_ERR "os_set_fd_async : failed to set O_ASYNC "
392 "O_NONBLOCK on fd # %d, errno = %d\n", fd, errno); 377 "and O_NONBLOCK on fd # %d, errno = %d\n", fd, errno);
393 return err; 378 return err;
394 } 379 }
395#ifdef notdef
396 if(fcntl(fd, F_SETFD, 1) < 0){
397 printk("os_set_fd_async : Setting FD_CLOEXEC failed, "
398 "errno = %d\n", errno);
399 }
400#endif
401 380
402 if((fcntl(fd, F_SETSIG, SIGIO) < 0) || 381 if ((fcntl(fd, F_SETSIG, SIGIO) < 0) ||
403 (fcntl(fd, F_SETOWN, owner) < 0)){ 382 (fcntl(fd, F_SETOWN, os_getpid()) < 0)) {
404 err = -errno; 383 err = -errno;
405 printk("os_set_fd_async : Failed to fcntl F_SETOWN " 384 printk(UM_KERN_ERR "os_set_fd_async : Failed to fcntl F_SETOWN "
406 "(or F_SETSIG) fd %d to pid %d, errno = %d\n", fd, 385 "(or F_SETSIG) fd %d, errno = %d\n", fd, errno);
407 owner, errno);
408 return err; 386 return err;
409 } 387 }
410 388
@@ -413,10 +391,14 @@ int os_set_fd_async(int fd, int owner)
413 391
414int os_clear_fd_async(int fd) 392int os_clear_fd_async(int fd)
415{ 393{
416 int flags = fcntl(fd, F_GETFL); 394 int flags;
395
396 flags = fcntl(fd, F_GETFL);
397 if (flags < 0)
398 return -errno;
417 399
418 flags &= ~(O_ASYNC | O_NONBLOCK); 400 flags &= ~(O_ASYNC | O_NONBLOCK);
419 if(fcntl(fd, F_SETFL, flags) < 0) 401 if (fcntl(fd, F_SETFL, flags) < 0)
420 return -errno; 402 return -errno;
421 return 0; 403 return 0;
422} 404}
@@ -426,11 +408,15 @@ int os_set_fd_block(int fd, int blocking)
426 int flags; 408 int flags;
427 409
428 flags = fcntl(fd, F_GETFL); 410 flags = fcntl(fd, F_GETFL);
411 if (flags < 0)
412 return -errno;
429 413
430 if(blocking) flags &= ~O_NONBLOCK; 414 if (blocking)
431 else flags |= O_NONBLOCK; 415 flags &= ~O_NONBLOCK;
416 else
417 flags |= O_NONBLOCK;
432 418
433 if(fcntl(fd, F_SETFL, flags) < 0) 419 if (fcntl(fd, F_SETFL, flags) < 0)
434 return -errno; 420 return -errno;
435 421
436 return 0; 422 return 0;
@@ -441,7 +427,7 @@ int os_accept_connection(int fd)
441 int new; 427 int new;
442 428
443 new = accept(fd, NULL, 0); 429 new = accept(fd, NULL, 0);
444 if(new < 0) 430 if (new < 0)
445 return -errno; 431 return -errno;
446 return new; 432 return new;
447} 433}
@@ -462,15 +448,17 @@ int os_shutdown_socket(int fd, int r, int w)
462{ 448{
463 int what, err; 449 int what, err;
464 450
465 if(r && w) what = SHUT_RDWR; 451 if (r && w)
466 else if(r) what = SHUT_RD; 452 what = SHUT_RDWR;
467 else if(w) what = SHUT_WR; 453 else if (r)
468 else { 454 what = SHUT_RD;
469 printk("os_shutdown_socket : neither r or w was set\n"); 455 else if (w)
456 what = SHUT_WR;
457 else
470 return -EINVAL; 458 return -EINVAL;
471 } 459
472 err = shutdown(fd, what); 460 err = shutdown(fd, what);
473 if(err < 0) 461 if (err < 0)
474 return -errno; 462 return -errno;
475 return 0; 463 return 0;
476} 464}
@@ -494,19 +482,20 @@ int os_rcv_fd(int fd, int *helper_pid_out)
494 msg.msg_flags = 0; 482 msg.msg_flags = 0;
495 483
496 n = recvmsg(fd, &msg, 0); 484 n = recvmsg(fd, &msg, 0);
497 if(n < 0) 485 if (n < 0)
498 return -errno; 486 return -errno;
499 else if(n != iov.iov_len) 487 else if (n != iov.iov_len)
500 *helper_pid_out = -1; 488 *helper_pid_out = -1;
501 489
502 cmsg = CMSG_FIRSTHDR(&msg); 490 cmsg = CMSG_FIRSTHDR(&msg);
503 if(cmsg == NULL){ 491 if (cmsg == NULL) {
504 printk("rcv_fd didn't receive anything, error = %d\n", errno); 492 printk(UM_KERN_ERR "rcv_fd didn't receive anything, "
493 "error = %d\n", errno);
505 return -1; 494 return -1;
506 } 495 }
507 if((cmsg->cmsg_level != SOL_SOCKET) || 496 if ((cmsg->cmsg_level != SOL_SOCKET) ||
508 (cmsg->cmsg_type != SCM_RIGHTS)){ 497 (cmsg->cmsg_type != SCM_RIGHTS)) {
509 printk("rcv_fd didn't receive a descriptor\n"); 498 printk(UM_KERN_ERR "rcv_fd didn't receive a descriptor\n");
510 return -1; 499 return -1;
511 } 500 }
512 501
@@ -514,29 +503,28 @@ int os_rcv_fd(int fd, int *helper_pid_out)
514 return new; 503 return new;
515} 504}
516 505
517int os_create_unix_socket(char *file, int len, int close_on_exec) 506int os_create_unix_socket(const char *file, int len, int close_on_exec)
518{ 507{
519 struct sockaddr_un addr; 508 struct sockaddr_un addr;
520 int sock, err; 509 int sock, err;
521 510
522 sock = socket(PF_UNIX, SOCK_DGRAM, 0); 511 sock = socket(PF_UNIX, SOCK_DGRAM, 0);
523 if(sock < 0) 512 if (sock < 0)
524 return -errno; 513 return -errno;
525 514
526 if(close_on_exec) { 515 if (close_on_exec) {
527 err = os_set_exec_close(sock); 516 err = os_set_exec_close(sock);
528 if(err < 0) 517 if (err < 0)
529 printk("create_unix_socket : close_on_exec failed, " 518 printk(UM_KERN_ERR "create_unix_socket : "
530 "err = %d", -err); 519 "close_on_exec failed, err = %d", -err);
531 } 520 }
532 521
533 addr.sun_family = AF_UNIX; 522 addr.sun_family = AF_UNIX;
534 523
535 /* XXX Be more careful about overflow */
536 snprintf(addr.sun_path, len, "%s", file); 524 snprintf(addr.sun_path, len, "%s", file);
537 525
538 err = bind(sock, (struct sockaddr *) &addr, sizeof(addr)); 526 err = bind(sock, (struct sockaddr *) &addr, sizeof(addr));
539 if(err < 0) 527 if (err < 0)
540 return -errno; 528 return -errno;
541 529
542 return sock; 530 return sock;
@@ -557,17 +545,18 @@ int os_lock_file(int fd, int excl)
557 int err, save; 545 int err, save;
558 546
559 err = fcntl(fd, F_SETLK, &lock); 547 err = fcntl(fd, F_SETLK, &lock);
560 if(!err) 548 if (!err)
561 goto out; 549 goto out;
562 550
563 save = -errno; 551 save = -errno;
564 err = fcntl(fd, F_GETLK, &lock); 552 err = fcntl(fd, F_GETLK, &lock);
565 if(err){ 553 if (err) {
566 err = -errno; 554 err = -errno;
567 goto out; 555 goto out;
568 } 556 }
569 557
570 printk("F_SETLK failed, file already locked by pid %d\n", lock.l_pid); 558 printk(UM_KERN_ERR "F_SETLK failed, file already locked by pid %d\n",
559 lock.l_pid);
571 err = save; 560 err = save;
572 out: 561 out:
573 return err; 562 return err;