aboutsummaryrefslogtreecommitdiffstats
path: root/arch/um
diff options
context:
space:
mode:
authorJeff Dike <jdike@addtoit.com>2007-10-16 04:27:11 -0400
committerLinus Torvalds <torvalds@woody.linux-foundation.org>2007-10-16 12:43:06 -0400
commit512b6fb1c14d4c34f23a3419b0789ad01914a899 (patch)
tree29e51c256dde41db297cff28767bf4dc4a1dc73f /arch/um
parentb21d4b08b6686fa13bf9d4cae1ae08cb23ea3d53 (diff)
uml: userspace files should call libc directly
A number of files that were changed in the recent removal of tt mode are userspace files which call the os_* wrappers instead of calling libc directly. A few other files were affected by this, through This patch makes these call glibc directly. There are also style fixes in the affected areas. os_print_error has no remaining callers, so it is deleted. There is a interface change to os_set_exec_close, eliminating a parameter which was always the same. The callers are fixed as well. os_process_pc got its error path cleaned up. 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.h3
-rw-r--r--arch/um/kernel/ksyms.c1
-rw-r--r--arch/um/kernel/physmem.c4
-rw-r--r--arch/um/os-Linux/aio.c4
-rw-r--r--arch/um/os-Linux/drivers/ethertap_user.c61
-rw-r--r--arch/um/os-Linux/drivers/tuntap_user.c24
-rw-r--r--arch/um/os-Linux/file.c102
-rw-r--r--arch/um/os-Linux/helper.c8
-rw-r--r--arch/um/os-Linux/mem.c6
-rw-r--r--arch/um/os-Linux/process.c37
-rw-r--r--arch/um/os-Linux/skas/process.c4
-rw-r--r--arch/um/os-Linux/start_up.c5
12 files changed, 138 insertions, 121 deletions
diff --git a/arch/um/include/os.h b/arch/um/include/os.h
index 76048ba10875..e861c8adb44f 100644
--- a/arch/um/include/os.h
+++ b/arch/um/include/os.h
@@ -128,9 +128,8 @@ static inline struct openflags of_cloexec(struct openflags flags)
128extern int os_stat_file(const char *file_name, struct uml_stat *buf); 128extern int os_stat_file(const char *file_name, struct uml_stat *buf);
129extern int os_stat_fd(const int fd, struct uml_stat *buf); 129extern int os_stat_fd(const int fd, struct uml_stat *buf);
130extern int os_access(const char *file, int mode); 130extern int os_access(const char *file, int mode);
131extern void os_print_error(int error, const char* str);
132extern int os_get_exec_close(int fd, int *close_on_exec); 131extern int os_get_exec_close(int fd, int *close_on_exec);
133extern int os_set_exec_close(int fd, int close_on_exec); 132extern int os_set_exec_close(int fd);
134extern int os_ioctl_generic(int fd, unsigned int cmd, unsigned long arg); 133extern int os_ioctl_generic(int fd, unsigned int cmd, unsigned long arg);
135extern int os_get_ifname(int fd, char *namebuf); 134extern int os_get_ifname(int fd, char *namebuf);
136extern int os_set_slip(int fd); 135extern int os_set_slip(int fd);
diff --git a/arch/um/kernel/ksyms.c b/arch/um/kernel/ksyms.c
index 341234d04ab8..4b750014925d 100644
--- a/arch/um/kernel/ksyms.c
+++ b/arch/um/kernel/ksyms.c
@@ -40,7 +40,6 @@ EXPORT_SYMBOL(uml_strdup);
40EXPORT_SYMBOL(os_stat_fd); 40EXPORT_SYMBOL(os_stat_fd);
41EXPORT_SYMBOL(os_stat_file); 41EXPORT_SYMBOL(os_stat_file);
42EXPORT_SYMBOL(os_access); 42EXPORT_SYMBOL(os_access);
43EXPORT_SYMBOL(os_print_error);
44EXPORT_SYMBOL(os_get_exec_close); 43EXPORT_SYMBOL(os_get_exec_close);
45EXPORT_SYMBOL(os_set_exec_close); 44EXPORT_SYMBOL(os_set_exec_close);
46EXPORT_SYMBOL(os_getpid); 45EXPORT_SYMBOL(os_getpid);
diff --git a/arch/um/kernel/physmem.c b/arch/um/kernel/physmem.c
index 1fe86d8cf092..e66432f42485 100644
--- a/arch/um/kernel/physmem.c
+++ b/arch/um/kernel/physmem.c
@@ -99,7 +99,9 @@ void __init setup_physmem(unsigned long start, unsigned long reserve_end,
99 err = os_map_memory((void *) uml_reserved, physmem_fd, offset, 99 err = os_map_memory((void *) uml_reserved, physmem_fd, offset,
100 len - offset, 1, 1, 1); 100 len - offset, 1, 1, 1);
101 if (err < 0) { 101 if (err < 0) {
102 os_print_error(err, "Mapping memory"); 102 printf("setup_physmem - mapping %ld bytes of memory at 0x%p "
103 "failed - errno = %d\n", len - offset,
104 (void *) uml_reserved, err);
103 exit(1); 105 exit(1);
104 } 106 }
105 107
diff --git a/arch/um/os-Linux/aio.c b/arch/um/os-Linux/aio.c
index 68454daf958d..4158118c4a56 100644
--- a/arch/um/os-Linux/aio.c
+++ b/arch/um/os-Linux/aio.c
@@ -226,8 +226,8 @@ static int init_aio_24(void)
226 goto out; 226 goto out;
227 227
228out_close_pipe: 228out_close_pipe:
229 os_close_file(fds[0]); 229 close(fds[0]);
230 os_close_file(fds[1]); 230 close(fds[1]);
231 aio_req_fd_w = -1; 231 aio_req_fd_w = -1;
232 aio_req_fd_r = -1; 232 aio_req_fd_r = -1;
233out: 233out:
diff --git a/arch/um/os-Linux/drivers/ethertap_user.c b/arch/um/os-Linux/drivers/ethertap_user.c
index 61d3953c7ac9..d74eedb7e682 100644
--- a/arch/um/os-Linux/drivers/ethertap_user.c
+++ b/arch/um/os-Linux/drivers/ethertap_user.c
@@ -87,11 +87,11 @@ static void etap_pre_exec(void *arg)
87 struct etap_pre_exec_data *data = arg; 87 struct etap_pre_exec_data *data = arg;
88 88
89 dup2(data->control_remote, 1); 89 dup2(data->control_remote, 1);
90 os_close_file(data->data_me); 90 close(data->data_me);
91 os_close_file(data->control_me); 91 close(data->control_me);
92} 92}
93 93
94static int etap_tramp(char *dev, char *gate, int control_me, 94static int etap_tramp(char *dev, char *gate, int control_me,
95 int control_remote, int data_me, int data_remote) 95 int control_remote, int data_me, int data_remote)
96{ 96{
97 struct etap_pre_exec_data pe_data; 97 struct etap_pre_exec_data pe_data;
@@ -101,7 +101,7 @@ static int etap_tramp(char *dev, char *gate, int control_me,
101 char gate_buf[sizeof("nnn.nnn.nnn.nnn\0")]; 101 char gate_buf[sizeof("nnn.nnn.nnn.nnn\0")];
102 char *setup_args[] = { "uml_net", version_buf, "ethertap", dev, 102 char *setup_args[] = { "uml_net", version_buf, "ethertap", dev,
103 data_fd_buf, gate_buf, NULL }; 103 data_fd_buf, gate_buf, NULL };
104 char *nosetup_args[] = { "uml_net", version_buf, "ethertap", 104 char *nosetup_args[] = { "uml_net", version_buf, "ethertap",
105 dev, data_fd_buf, NULL }; 105 dev, data_fd_buf, NULL };
106 char **args, c; 106 char **args, c;
107 107
@@ -121,8 +121,8 @@ static int etap_tramp(char *dev, char *gate, int control_me,
121 121
122 if(pid < 0) 122 if(pid < 0)
123 err = pid; 123 err = pid;
124 os_close_file(data_remote); 124 close(data_remote);
125 os_close_file(control_remote); 125 close(control_remote);
126 CATCH_EINTR(n = read(control_me, &c, sizeof(c))); 126 CATCH_EINTR(n = read(control_me, &c, sizeof(c)));
127 if(n != sizeof(c)){ 127 if(n != sizeof(c)){
128 err = -errno; 128 err = -errno;
@@ -151,19 +151,23 @@ static int etap_open(void *data)
151 if(err) 151 if(err)
152 return err; 152 return err;
153 153
154 err = os_pipe(data_fds, 0, 0); 154 err = socketpair(AF_UNIX, SOCK_DGRAM, 0, data_fds);
155 if(err < 0){ 155 if(err){
156 printk("data os_pipe failed - err = %d\n", -err); 156 err = -errno;
157 printk("etap_open - data socketpair failed - err = %d\n",
158 errno);
157 return err; 159 return err;
158 } 160 }
159 161
160 err = os_pipe(control_fds, 1, 0); 162 err = socketpair(AF_UNIX, SOCK_STREAM, 0, control_fds);
161 if(err < 0){ 163 if(err){
162 printk("control os_pipe failed - err = %d\n", -err); 164 err = -errno;
163 return err; 165 printk("etap_open - control socketpair failed - err = %d\n",
166 errno);
167 goto out_close_data;
164 } 168 }
165 169
166 err = etap_tramp(pri->dev_name, pri->gate_addr, control_fds[0], 170 err = etap_tramp(pri->dev_name, pri->gate_addr, control_fds[0],
167 control_fds[1], data_fds[0], data_fds[1]); 171 control_fds[1], data_fds[0], data_fds[1]);
168 output_len = UM_KERN_PAGE_SIZE; 172 output_len = UM_KERN_PAGE_SIZE;
169 output = kmalloc(output_len, UM_GFP_KERNEL); 173 output = kmalloc(output_len, UM_GFP_KERNEL);
@@ -178,13 +182,21 @@ static int etap_open(void *data)
178 182
179 if(err < 0){ 183 if(err < 0){
180 printk("etap_tramp failed - err = %d\n", -err); 184 printk("etap_tramp failed - err = %d\n", -err);
181 return err; 185 goto out_close_control;
182 } 186 }
183 187
184 pri->data_fd = data_fds[0]; 188 pri->data_fd = data_fds[0];
185 pri->control_fd = control_fds[0]; 189 pri->control_fd = control_fds[0];
186 iter_addresses(pri->dev, etap_open_addr, &pri->control_fd); 190 iter_addresses(pri->dev, etap_open_addr, &pri->control_fd);
187 return data_fds[0]; 191 return data_fds[0];
192
193out_close_control:
194 close(control_fds[0]);
195 close(control_fds[1]);
196out_close_data:
197 close(data_fds[0]);
198 close(data_fds[1]);
199 return err;
188} 200}
189 201
190static void etap_close(int fd, void *data) 202static void etap_close(int fd, void *data)
@@ -192,11 +204,19 @@ static void etap_close(int fd, void *data)
192 struct ethertap_data *pri = data; 204 struct ethertap_data *pri = data;
193 205
194 iter_addresses(pri->dev, etap_close_addr, &pri->control_fd); 206 iter_addresses(pri->dev, etap_close_addr, &pri->control_fd);
195 os_close_file(fd); 207 close(fd);
196 os_shutdown_socket(pri->data_fd, 1, 1); 208
197 os_close_file(pri->data_fd); 209 if(shutdown(pri->data_fd, SHUT_RDWR) < 0)
210 printk("etap_close - shutdown data socket failed, errno = %d\n",
211 errno);
212
213 if(shutdown(pri->control_fd, SHUT_RDWR) < 0)
214 printk("etap_close - shutdown control socket failed, "
215 "errno = %d\n", errno);
216
217 close(pri->data_fd);
198 pri->data_fd = -1; 218 pri->data_fd = -1;
199 os_close_file(pri->control_fd); 219 close(pri->control_fd);
200 pri->control_fd = -1; 220 pri->control_fd = -1;
201} 221}
202 222
@@ -216,13 +236,14 @@ static void etap_add_addr(unsigned char *addr, unsigned char *netmask,
216 etap_open_addr(addr, netmask, &pri->control_fd); 236 etap_open_addr(addr, netmask, &pri->control_fd);
217} 237}
218 238
219static void etap_del_addr(unsigned char *addr, unsigned char *netmask, 239static void etap_del_addr(unsigned char *addr, unsigned char *netmask,
220 void *data) 240 void *data)
221{ 241{
222 struct ethertap_data *pri = data; 242 struct ethertap_data *pri = data;
223 243
224 if(pri->control_fd == -1) 244 if(pri->control_fd == -1)
225 return; 245 return;
246
226 etap_close_addr(addr, netmask, &pri->control_fd); 247 etap_close_addr(addr, netmask, &pri->control_fd);
227} 248}
228 249
diff --git a/arch/um/os-Linux/drivers/tuntap_user.c b/arch/um/os-Linux/drivers/tuntap_user.c
index f848b4ea9343..72a2ff61556d 100644
--- a/arch/um/os-Linux/drivers/tuntap_user.c
+++ b/arch/um/os-Linux/drivers/tuntap_user.c
@@ -62,7 +62,7 @@ static void tuntap_pre_exec(void *arg)
62 struct tuntap_pre_exec_data *data = arg; 62 struct tuntap_pre_exec_data *data = arg;
63 63
64 dup2(data->stdout, 1); 64 dup2(data->stdout, 1);
65 os_close_file(data->close_me); 65 close(data->close_me);
66} 66}
67 67
68static int tuntap_open_tramp(char *gate, int *fd_out, int me, int remote, 68static int tuntap_open_tramp(char *gate, int *fd_out, int me, int remote,
@@ -88,7 +88,7 @@ static int tuntap_open_tramp(char *gate, int *fd_out, int me, int remote,
88 if(pid < 0) 88 if(pid < 0)
89 return -pid; 89 return -pid;
90 90
91 os_close_file(remote); 91 close(remote);
92 92
93 msg.msg_name = NULL; 93 msg.msg_name = NULL;
94 msg.msg_namelen = 0; 94 msg.msg_namelen = 0;
@@ -125,7 +125,7 @@ static int tuntap_open_tramp(char *gate, int *fd_out, int me, int remote,
125 return -EINVAL; 125 return -EINVAL;
126 } 126 }
127 *fd_out = ((int *) CMSG_DATA(cmsg))[0]; 127 *fd_out = ((int *) CMSG_DATA(cmsg))[0];
128 os_set_exec_close(*fd_out, 1); 128 os_set_exec_close(*fd_out);
129 return 0; 129 return 0;
130} 130}
131 131
@@ -154,20 +154,22 @@ static int tuntap_open(void *data)
154 if(ioctl(pri->fd, TUNSETIFF, (void *) &ifr) < 0){ 154 if(ioctl(pri->fd, TUNSETIFF, (void *) &ifr) < 0){
155 err = -errno; 155 err = -errno;
156 printk("TUNSETIFF failed, errno = %d\n", errno); 156 printk("TUNSETIFF failed, errno = %d\n", errno);
157 os_close_file(pri->fd); 157 close(pri->fd);
158 return err; 158 return err;
159 } 159 }
160 } 160 }
161 else { 161 else {
162 err = os_pipe(fds, 0, 0); 162 err = socketpair(AF_UNIX, SOCK_DGRAM, 0, fds);
163 if(err < 0){ 163 if(err){
164 printk("tuntap_open : os_pipe failed - err = %d\n", 164 err = -errno;
165 -err); 165 printk("tuntap_open : socketpair failed - errno = %d\n",
166 errno);
166 return err; 167 return err;
167 } 168 }
168 169
169 buffer = get_output_buffer(&len); 170 buffer = get_output_buffer(&len);
170 if(buffer != NULL) len--; 171 if(buffer != NULL)
172 len--;
171 used = 0; 173 used = 0;
172 174
173 err = tuntap_open_tramp(pri->gate_addr, &pri->fd, fds[0], 175 err = tuntap_open_tramp(pri->gate_addr, &pri->fd, fds[0],
@@ -186,7 +188,7 @@ static int tuntap_open(void *data)
186 printk("%s", output); 188 printk("%s", output);
187 free_output_buffer(buffer); 189 free_output_buffer(buffer);
188 190
189 os_close_file(fds[0]); 191 close(fds[0]);
190 iter_addresses(pri->dev, open_addr, pri->dev_name); 192 iter_addresses(pri->dev, open_addr, pri->dev_name);
191 } 193 }
192 194
@@ -199,7 +201,7 @@ static void tuntap_close(int fd, void *data)
199 201
200 if(!pri->fixed_config) 202 if(!pri->fixed_config)
201 iter_addresses(pri->dev, close_addr, pri->dev_name); 203 iter_addresses(pri->dev, close_addr, pri->dev_name);
202 os_close_file(fd); 204 close(fd);
203 pri->fd = -1; 205 pri->fd = -1;
204} 206}
205 207
diff --git a/arch/um/os-Linux/file.c b/arch/um/os-Linux/file.c
index 5f10c3031ef2..b542a3a021bf 100644
--- a/arch/um/os-Linux/file.c
+++ b/arch/um/os-Linux/file.c
@@ -82,13 +82,6 @@ int os_access(const char* file, int mode)
82 return 0; 82 return 0;
83} 83}
84 84
85void os_print_error(int error, const char* str)
86{
87 errno = error < 0 ? -error : error;
88
89 perror(str);
90}
91
92/* FIXME? required only by hostaudio (because it passes ioctls verbatim) */ 85/* FIXME? required only by hostaudio (because it passes ioctls verbatim) */
93int os_ioctl_generic(int fd, unsigned int cmd, unsigned long arg) 86int os_ioctl_generic(int fd, unsigned int cmd, unsigned long arg)
94{ 87{
@@ -181,19 +174,19 @@ int os_file_mode(char *file, struct openflags *mode_out)
181 174
182 *mode_out = OPENFLAGS(); 175 *mode_out = OPENFLAGS();
183 176
184 err = os_access(file, OS_ACC_W_OK); 177 err = access(file, W_OK);
185 if((err < 0) && (err != -EACCES)) 178 if(err && (errno != EACCES))
186 return(err); 179 return -errno;
187 180 else if(!err)
188 *mode_out = of_write(*mode_out); 181 *mode_out = of_write(*mode_out);
189
190 err = os_access(file, OS_ACC_R_OK);
191 if((err < 0) && (err != -EACCES))
192 return(err);
193 182
194 *mode_out = of_read(*mode_out); 183 err = access(file, R_OK);
184 if(err && (errno != EACCES))
185 return -errno;
186 else if(!err)
187 *mode_out = of_read(*mode_out);
195 188
196 return(0); 189 return err;
197} 190}
198 191
199int os_open_file(char *file, struct openflags flags, int mode) 192int os_open_file(char *file, struct openflags flags, int mode)
@@ -212,15 +205,15 @@ int os_open_file(char *file, struct openflags flags, int mode)
212 205
213 fd = open64(file, f, mode); 206 fd = open64(file, f, mode);
214 if(fd < 0) 207 if(fd < 0)
215 return(-errno); 208 return -errno;
216 209
217 if(flags.cl && fcntl(fd, F_SETFD, 1)){ 210 if(flags.cl && fcntl(fd, F_SETFD, 1)){
218 err = -errno; 211 err = -errno;
219 os_close_file(fd); 212 close(fd);
220 return err; 213 return err;
221 } 214 }
222 215
223 return(fd); 216 return fd;
224} 217}
225 218
226int os_connect_socket(char *name) 219int os_connect_socket(char *name)
@@ -292,31 +285,33 @@ int os_file_size(char *file, unsigned long long *size_out)
292 err = os_stat_file(file, &buf); 285 err = os_stat_file(file, &buf);
293 if(err < 0){ 286 if(err < 0){
294 printk("Couldn't stat \"%s\" : err = %d\n", file, -err); 287 printk("Couldn't stat \"%s\" : err = %d\n", file, -err);
295 return(err); 288 return err;
296 } 289 }
297 290
298 if(S_ISBLK(buf.ust_mode)){ 291 if(S_ISBLK(buf.ust_mode)){
299 int fd; 292 int fd;
300 long blocks; 293 long blocks;
301 294
302 fd = os_open_file(file, of_read(OPENFLAGS()), 0); 295 fd = open(file, O_RDONLY, 0);
303 if(fd < 0){ 296 if(fd < 0) {
304 printk("Couldn't open \"%s\", errno = %d\n", file, -fd); 297 err = -errno;
305 return(fd); 298 printk("Couldn't open \"%s\", errno = %d\n", file,
299 errno);
300 return err;
306 } 301 }
307 if(ioctl(fd, BLKGETSIZE, &blocks) < 0){ 302 if(ioctl(fd, BLKGETSIZE, &blocks) < 0){
308 err = -errno; 303 err = -errno;
309 printk("Couldn't get the block size of \"%s\", " 304 printk("Couldn't get the block size of \"%s\", "
310 "errno = %d\n", file, errno); 305 "errno = %d\n", file, errno);
311 os_close_file(fd); 306 close(fd);
312 return(err); 307 return err;
313 } 308 }
314 *size_out = ((long long) blocks) * 512; 309 *size_out = ((long long) blocks) * 512;
315 os_close_file(fd); 310 close(fd);
316 return(0);
317 } 311 }
318 *size_out = buf.ust_size; 312 else *size_out = buf.ust_size;
319 return(0); 313
314 return 0;
320} 315}
321 316
322int os_file_modtime(char *file, unsigned long *modtime) 317int os_file_modtime(char *file, unsigned long *modtime)
@@ -334,35 +329,28 @@ int os_file_modtime(char *file, unsigned long *modtime)
334 return 0; 329 return 0;
335} 330}
336 331
337int os_get_exec_close(int fd, int* close_on_exec) 332int os_get_exec_close(int fd, int *close_on_exec)
338{ 333{
339 int ret; 334 int ret;
340 335
341 do { 336 CATCH_EINTR(ret = fcntl(fd, F_GETFD));
342 ret = fcntl(fd, F_GETFD);
343 } while((ret < 0) && (errno == EINTR)) ;
344 337
345 if(ret < 0) 338 if(ret < 0)
346 return(-errno); 339 return -errno;
347 340
348 *close_on_exec = (ret&FD_CLOEXEC) ? 1 : 0; 341 *close_on_exec = (ret & FD_CLOEXEC) ? 1 : 0;
349 return(ret); 342 return ret;
350} 343}
351 344
352int os_set_exec_close(int fd, int close_on_exec) 345int os_set_exec_close(int fd)
353{ 346{
354 int flag, err; 347 int err;
355
356 if(close_on_exec) flag = FD_CLOEXEC;
357 else flag = 0;
358 348
359 do { 349 CATCH_EINTR(err = fcntl(fd, F_SETFD, FD_CLOEXEC));
360 err = fcntl(fd, F_SETFD, flag);
361 } while((err < 0) && (errno == EINTR)) ;
362 350
363 if(err < 0) 351 if(err < 0)
364 return(-errno); 352 return -errno;
365 return(err); 353 return err;
366} 354}
367 355
368int os_pipe(int *fds, int stream, int close_on_exec) 356int os_pipe(int *fds, int stream, int close_on_exec)
@@ -371,16 +359,16 @@ int os_pipe(int *fds, int stream, int close_on_exec)
371 359
372 err = socketpair(AF_UNIX, type, 0, fds); 360 err = socketpair(AF_UNIX, type, 0, fds);
373 if(err < 0) 361 if(err < 0)
374 return(-errno); 362 return -errno;
375 363
376 if(!close_on_exec) 364 if(!close_on_exec)
377 return(0); 365 return 0;
378 366
379 err = os_set_exec_close(fds[0], 1); 367 err = os_set_exec_close(fds[0]);
380 if(err < 0) 368 if(err < 0)
381 goto error; 369 goto error;
382 370
383 err = os_set_exec_close(fds[1], 1); 371 err = os_set_exec_close(fds[1]);
384 if(err < 0) 372 if(err < 0)
385 goto error; 373 goto error;
386 374
@@ -388,9 +376,9 @@ int os_pipe(int *fds, int stream, int close_on_exec)
388 376
389 error: 377 error:
390 printk("os_pipe : Setting FD_CLOEXEC failed, err = %d\n", -err); 378 printk("os_pipe : Setting FD_CLOEXEC failed, err = %d\n", -err);
391 os_close_file(fds[1]); 379 close(fds[1]);
392 os_close_file(fds[0]); 380 close(fds[0]);
393 return(err); 381 return err;
394} 382}
395 383
396int os_set_fd_async(int fd, int owner) 384int os_set_fd_async(int fd, int owner)
@@ -537,7 +525,7 @@ int os_create_unix_socket(char *file, int len, int close_on_exec)
537 return -errno; 525 return -errno;
538 526
539 if(close_on_exec) { 527 if(close_on_exec) {
540 err = os_set_exec_close(sock, 1); 528 err = os_set_exec_close(sock);
541 if(err < 0) 529 if(err < 0)
542 printk("create_unix_socket : close_on_exec failed, " 530 printk("create_unix_socket : close_on_exec failed, "
543 "err = %d", -err); 531 "err = %d", -err);
diff --git a/arch/um/os-Linux/helper.c b/arch/um/os-Linux/helper.c
index d81af7b8587a..7a72dbb61b0d 100644
--- a/arch/um/os-Linux/helper.c
+++ b/arch/um/os-Linux/helper.c
@@ -11,6 +11,7 @@
11#include <limits.h> 11#include <limits.h>
12#include <sys/signal.h> 12#include <sys/signal.h>
13#include <sys/wait.h> 13#include <sys/wait.h>
14#include <sys/socket.h>
14#include "user.h" 15#include "user.h"
15#include "kern_util.h" 16#include "kern_util.h"
16#include "os.h" 17#include "os.h"
@@ -54,13 +55,14 @@ int run_helper(void (*pre_exec)(void *), void *pre_data, char **argv)
54 if (stack == 0) 55 if (stack == 0)
55 return -ENOMEM; 56 return -ENOMEM;
56 57
57 ret = os_pipe(fds, 1, 0); 58 ret = socketpair(AF_UNIX, SOCK_STREAM, 0, fds);
58 if (ret < 0) { 59 if (ret < 0) {
59 printk("run_helper : pipe failed, ret = %d\n", -ret); 60 ret = -errno;
61 printk("run_helper : pipe failed, errno = %d\n", errno);
60 goto out_free; 62 goto out_free;
61 } 63 }
62 64
63 ret = os_set_exec_close(fds[1], 1); 65 ret = os_set_exec_close(fds[1]);
64 if (ret < 0) { 66 if (ret < 0) {
65 printk("run_helper : setting FD_CLOEXEC failed, ret = %d\n", 67 printk("run_helper : setting FD_CLOEXEC failed, ret = %d\n",
66 -ret); 68 -ret);
diff --git a/arch/um/os-Linux/mem.c b/arch/um/os-Linux/mem.c
index c6378c6d10d2..436f8d20b20f 100644
--- a/arch/um/os-Linux/mem.c
+++ b/arch/um/os-Linux/mem.c
@@ -218,7 +218,7 @@ int __init create_tmp_file(unsigned long long len)
218 218
219 err = fchmod(fd, 0777); 219 err = fchmod(fd, 0777);
220 if(err < 0){ 220 if(err < 0){
221 perror("os_mode_fd"); 221 perror("fchmod");
222 exit(1); 222 exit(1);
223 } 223 }
224 224
@@ -226,7 +226,7 @@ int __init create_tmp_file(unsigned long long len)
226 * increase the file size by one byte, to the desired length. 226 * increase the file size by one byte, to the desired length.
227 */ 227 */
228 if (lseek64(fd, len - 1, SEEK_SET) < 0) { 228 if (lseek64(fd, len - 1, SEEK_SET) < 0) {
229 perror("os_seek_file"); 229 perror("lseek64");
230 exit(1); 230 exit(1);
231 } 231 }
232 232
@@ -247,7 +247,7 @@ int __init create_mem_file(unsigned long long len)
247 247
248 fd = create_tmp_file(len); 248 fd = create_tmp_file(len);
249 249
250 err = os_set_exec_close(fd, 1); 250 err = os_set_exec_close(fd);
251 if(err < 0){ 251 if(err < 0){
252 errno = -err; 252 errno = -err;
253 perror("exec_close"); 253 perror("exec_close");
diff --git a/arch/um/os-Linux/process.c b/arch/um/os-Linux/process.c
index 8b57eb3647f5..90b480cf78f4 100644
--- a/arch/um/os-Linux/process.c
+++ b/arch/um/os-Linux/process.c
@@ -7,6 +7,7 @@
7#include <unistd.h> 7#include <unistd.h>
8#include <errno.h> 8#include <errno.h>
9#include <signal.h> 9#include <signal.h>
10#include <fcntl.h>
10#include <sys/mman.h> 11#include <sys/mman.h>
11#include <sys/ptrace.h> 12#include <sys/ptrace.h>
12#include <sys/wait.h> 13#include <sys/wait.h>
@@ -28,31 +29,32 @@
28unsigned long os_process_pc(int pid) 29unsigned long os_process_pc(int pid)
29{ 30{
30 char proc_stat[STAT_PATH_LEN], buf[256]; 31 char proc_stat[STAT_PATH_LEN], buf[256];
31 unsigned long pc; 32 unsigned long pc = ARBITRARY_ADDR;
32 int fd, err; 33 int fd, err;
33 34
34 sprintf(proc_stat, "/proc/%d/stat", pid); 35 sprintf(proc_stat, "/proc/%d/stat", pid);
35 fd = os_open_file(proc_stat, of_read(OPENFLAGS()), 0); 36 fd = open(proc_stat, O_RDONLY, 0);
36 if (fd < 0) { 37 if (fd < 0) {
37 printk(UM_KERN_ERR "os_process_pc - couldn't open '%s', " 38 printk(UM_KERN_ERR "os_process_pc - couldn't open '%s', "
38 "err = %d\n", proc_stat, -fd); 39 "errno = %d\n", proc_stat, errno);
39 return ARBITRARY_ADDR; 40 goto out;
40 } 41 }
41 CATCH_EINTR(err = read(fd, buf, sizeof(buf))); 42 CATCH_EINTR(err = read(fd, buf, sizeof(buf)));
42 if (err < 0) { 43 if (err < 0) {
43 printk(UM_KERN_ERR "os_process_pc - couldn't read '%s', " 44 printk(UM_KERN_ERR "os_process_pc - couldn't read '%s', "
44 "err = %d\n", proc_stat, errno); 45 "err = %d\n", proc_stat, errno);
45 os_close_file(fd); 46 goto out_close;
46 return ARBITRARY_ADDR;
47 } 47 }
48 os_close_file(fd); 48 os_close_file(fd);
49 pc = ARBITRARY_ADDR; 49 pc = ARBITRARY_ADDR;
50 if (sscanf(buf, "%*d " COMM_SCANF " %*c %*d %*d %*d %*d %*d %*d %*d " 50 if (sscanf(buf, "%*d " COMM_SCANF " %*c %*d %*d %*d %*d %*d %*d %*d "
51 "%*d %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d " 51 "%*d %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d "
52 "%*d %*d %*d %*d %*d %lu", &pc) != 1) { 52 "%*d %*d %*d %*d %*d %lu", &pc) != 1)
53 printk(UM_KERN_ERR "os_process_pc - couldn't find pc in '%s'\n", 53 printk(UM_KERN_ERR "os_process_pc - couldn't find pc in '%s'\n",
54 buf); 54 buf);
55 } 55 out_close:
56 close(fd);
57 out:
56 return pc; 58 return pc;
57} 59}
58 60
@@ -60,25 +62,26 @@ int os_process_parent(int pid)
60{ 62{
61 char stat[STAT_PATH_LEN]; 63 char stat[STAT_PATH_LEN];
62 char data[256]; 64 char data[256];
63 int parent, n, fd; 65 int parent = FAILURE_PID, n, fd;
64 66
65 if (pid == -1) 67 if (pid == -1)
66 return -1; 68 return parent;
67 69
68 snprintf(stat, sizeof(stat), "/proc/%d/stat", pid); 70 snprintf(stat, sizeof(stat), "/proc/%d/stat", pid);
69 fd = os_open_file(stat, of_read(OPENFLAGS()), 0); 71 fd = open(stat, O_RDONLY, 0);
70 if (fd < 0) { 72 if (fd < 0) {
71 printk(UM_KERN_ERR "Couldn't open '%s', err = %d\n", stat, -fd); 73 printk(UM_KERN_ERR "Couldn't open '%s', errno = %d\n", stat,
72 return FAILURE_PID; 74 errno);
75 return parent;
73 } 76 }
74 77
75 CATCH_EINTR(n = read(fd, data, sizeof(data))); 78 CATCH_EINTR(n = read(fd, data, sizeof(data)));
76 os_close_file(fd); 79 close(fd);
77 80
78 if (n < 0) { 81 if (n < 0) {
79 printk(UM_KERN_ERR "Couldn't read '%s', err = %d\n", stat, 82 printk(UM_KERN_ERR "Couldn't read '%s', errno = %d\n", stat,
80 errno); 83 errno);
81 return FAILURE_PID; 84 return parent;
82 } 85 }
83 86
84 parent = FAILURE_PID; 87 parent = FAILURE_PID;
diff --git a/arch/um/os-Linux/skas/process.c b/arch/um/os-Linux/skas/process.c
index 8e96c6dc6c90..47efe9087eee 100644
--- a/arch/um/os-Linux/skas/process.c
+++ b/arch/um/os-Linux/skas/process.c
@@ -28,7 +28,7 @@
28 28
29int is_skas_winch(int pid, int fd, void *data) 29int is_skas_winch(int pid, int fd, void *data)
30{ 30{
31 if (pid != os_getpgrp()) 31 if (pid != getpgrp())
32 return 0; 32 return 0;
33 33
34 register_winch_irq(-1, fd, -1, data, 0); 34 register_winch_irq(-1, fd, -1, data, 0);
@@ -233,7 +233,7 @@ static int userspace_tramp(void *stack)
233 "failed - errno = %d\n", errno); 233 "failed - errno = %d\n", errno);
234 } 234 }
235 235
236 os_stop_process(os_getpid()); 236 kill(os_getpid(), SIGSTOP);
237 return 0; 237 return 0;
238} 238}
239 239
diff --git a/arch/um/os-Linux/start_up.c b/arch/um/os-Linux/start_up.c
index c5c36dbe819b..7b81f6c08a5e 100644
--- a/arch/um/os-Linux/start_up.c
+++ b/arch/um/os-Linux/start_up.c
@@ -28,13 +28,14 @@
28static int ptrace_child(void) 28static int ptrace_child(void)
29{ 29{
30 int ret; 30 int ret;
31 /* Calling os_getpid because some libcs cached getpid incorrectly */
31 int pid = os_getpid(), ppid = getppid(); 32 int pid = os_getpid(), ppid = getppid();
32 int sc_result; 33 int sc_result;
33 34
34 change_sig(SIGWINCH, 0); 35 change_sig(SIGWINCH, 0);
35 if (ptrace(PTRACE_TRACEME, 0, 0, 0) < 0) { 36 if (ptrace(PTRACE_TRACEME, 0, 0, 0) < 0) {
36 perror("ptrace"); 37 perror("ptrace");
37 os_kill_process(pid, 0); 38 kill(pid, SIGKILL);
38 } 39 }
39 kill(pid, SIGSTOP); 40 kill(pid, SIGSTOP);
40 41
@@ -496,7 +497,7 @@ int __init parse_iomem(char *str, int *add)
496 file++; 497 file++;
497 fd = open(file, O_RDWR, 0); 498 fd = open(file, O_RDWR, 0);
498 if (fd < 0) { 499 if (fd < 0) {
499 os_print_error(fd, "parse_iomem - Couldn't open io file"); 500 perror("parse_iomem - Couldn't open io file");
500 goto out; 501 goto out;
501 } 502 }
502 503