Skip to content

Commit 1aa351a

Browse files
cfd-36Linus Torvalds
authored andcommitted
uml: tidy helper code
Style fixes to arch/um/os/helper.c and tidying up the breakpoint fix a bit. helper.c gets all the usual style fixes - updated copyright all printks get severities Also - errval changes to err in helper_child fixed an obsolete comment run_helper was killing a child process which is guaranteed to be dead or dying anyway Removed the nohang and pname arguments from helper_wait and fixed the declaration and callers. nohang was used only in the slirp driver and I don't think it was needed. I think pname was a bit of overkill in putting out an error message when something goes wrong. 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>
1 parent fce8c41 commit 1aa351a

7 files changed

Lines changed: 36 additions & 50 deletions

File tree

‎arch/um/drivers/net_user.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ static int change_tramp(char **argv, char *output, int output_len)
201201
close(fds[1]);
202202

203203
if (pid > 0)
204-
helper_wait(pid, 0, "change_tramp");
204+
helper_wait(pid);
205205
return pid;
206206
}
207207

‎arch/um/drivers/slip_user.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ static int slip_tramp(char **argv, int fd)
109109
read_output(fds[0], output, output_len);
110110
printk("%s", output);
111111

112-
err = helper_wait(pid, 0, argv[0]);
112+
err = helper_wait(pid);
113113
close(fds[0]);
114114

115115
out_free:

‎arch/um/drivers/slirp_user.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ static void slirp_close(int fd, void *data)
9898
"(%d)\n", pri->pid, errno);
9999
}
100100
#endif
101-
err = helper_wait(pri->pid, 1, "slirp_close");
101+
err = helper_wait(pri->pid);
102102
if (err < 0)
103103
return;
104104

‎arch/um/include/os.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ extern int execvp_noalloc(char *buf, const char *file, char *const argv[]);
207207
extern int run_helper(void (*pre_exec)(void *), void *pre_data, char **argv);
208208
extern int run_helper_thread(int (*proc)(void *), void *arg,
209209
unsigned int flags, unsigned long *stack_out);
210-
extern int helper_wait(int pid, int nohang, char *pname);
210+
extern int helper_wait(int pid);
211211

212212

213213
/* tls.c */

‎arch/um/os-Linux/drivers/ethertap_user.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ static int etap_tramp(char *dev, char *gate, int control_me,
131131
}
132132
if (c != 1) {
133133
printk(UM_KERN_ERR "etap_tramp : uml_net failed\n");
134-
err = helper_wait(pid, 0, "uml_net");
134+
err = helper_wait(pid);
135135
}
136136
return err;
137137
}

‎arch/um/os-Linux/drivers/tuntap_user.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ static int tuntap_open_tramp(char *gate, int *fd_out, int me, int remote,
108108
"errno = %d\n", errno);
109109
return err;
110110
}
111-
helper_wait(pid, 0, "tuntap_open_tramp");
111+
helper_wait(pid);
112112

113113
cmsg = CMSG_FIRSTHDR(&msg);
114114
if (cmsg == NULL) {

‎arch/um/os-Linux/helper.c‎

Lines changed: 30 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,19 @@
11
/*
2-
* Copyright (C) 2002 Jeff Dike (jdike@karaya.com)
2+
* Copyright (C) 2002 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
33
* Licensed under the GPL
44
*/
55

6-
#include <stdio.h>
76
#include <stdlib.h>
87
#include <unistd.h>
98
#include <errno.h>
109
#include <sched.h>
11-
#include <limits.h>
12-
#include <sys/signal.h>
13-
#include <sys/wait.h>
1410
#include <sys/socket.h>
15-
#include "user.h"
11+
#include <sys/wait.h>
12+
#include "kern_constants.h"
1613
#include "kern_util.h"
1714
#include "os.h"
1815
#include "um_malloc.h"
19-
#include "kern_constants.h"
16+
#include "user.h"
2017

2118
struct helper_data {
2219
void (*pre_exec)(void*);
@@ -30,21 +27,19 @@ static int helper_child(void *arg)
3027
{
3128
struct helper_data *data = arg;
3229
char **argv = data->argv;
33-
int errval;
30+
int err;
3431

3532
if (data->pre_exec != NULL)
3633
(*data->pre_exec)(data->pre_data);
37-
errval = execvp_noalloc(data->buf, argv[0], argv);
38-
printk("helper_child - execvp of '%s' failed - errno = %d\n", argv[0],
39-
-errval);
40-
write(data->fd, &errval, sizeof(errval));
41-
kill(os_getpid(), SIGKILL);
34+
err = execvp_noalloc(data->buf, argv[0], argv);
35+
36+
/* If the exec succeeds, we don't get here */
37+
write(data->fd, &err, sizeof(err));
38+
4239
return 0;
4340
}
4441

45-
/* Returns either the pid of the child process we run or -E* on failure.
46-
* XXX The alloc_stack here breaks if this is called in the tracing thread, so
47-
* we need to receive a preallocated stack (a local buffer is ok). */
42+
/* Returns either the pid of the child process we run or -E* on failure. */
4843
int run_helper(void (*pre_exec)(void *), void *pre_data, char **argv)
4944
{
5045
struct helper_data data;
@@ -58,14 +53,15 @@ int run_helper(void (*pre_exec)(void *), void *pre_data, char **argv)
5853
ret = socketpair(AF_UNIX, SOCK_STREAM, 0, fds);
5954
if (ret < 0) {
6055
ret = -errno;
61-
printk("run_helper : pipe failed, errno = %d\n", errno);
56+
printk(UM_KERN_ERR "run_helper : pipe failed, errno = %d\n",
57+
errno);
6258
goto out_free;
6359
}
6460

6561
ret = os_set_exec_close(fds[1]);
6662
if (ret < 0) {
67-
printk("run_helper : setting FD_CLOEXEC failed, ret = %d\n",
68-
-ret);
63+
printk(UM_KERN_ERR "run_helper : setting FD_CLOEXEC failed, "
64+
"ret = %d\n", -ret);
6965
goto out_close;
7066
}
7167

@@ -79,7 +75,8 @@ int run_helper(void (*pre_exec)(void *), void *pre_data, char **argv)
7975
pid = clone(helper_child, (void *) sp, CLONE_VM, &data);
8076
if (pid < 0) {
8177
ret = -errno;
82-
printk("run_helper : clone failed, errno = %d\n", errno);
78+
printk(UM_KERN_ERR "run_helper : clone failed, errno = %d\n",
79+
errno);
8380
goto out_free2;
8481
}
8582

@@ -96,10 +93,9 @@ int run_helper(void (*pre_exec)(void *), void *pre_data, char **argv)
9693
} else {
9794
if (n < 0) {
9895
n = -errno;
99-
printk("run_helper : read on pipe failed, ret = %d\n",
100-
-n);
96+
printk(UM_KERN_ERR "run_helper : read on pipe failed, "
97+
"ret = %d\n", -n);
10198
ret = n;
102-
kill(pid, SIGKILL);
10399
}
104100
CATCH_EINTR(waitpid(pid, NULL, __WCLONE));
105101
}
@@ -129,50 +125,40 @@ int run_helper_thread(int (*proc)(void *), void *arg, unsigned int flags,
129125
pid = clone(proc, (void *) sp, flags, arg);
130126
if (pid < 0) {
131127
err = -errno;
132-
printk("run_helper_thread : clone failed, errno = %d\n",
133-
errno);
128+
printk(UM_KERN_ERR "run_helper_thread : clone failed, "
129+
"errno = %d\n", errno);
134130
return err;
135131
}
136132
if (stack_out == NULL) {
137133
CATCH_EINTR(pid = waitpid(pid, &status, __WCLONE));
138134
if (pid < 0) {
139135
err = -errno;
140-
printk("run_helper_thread - wait failed, errno = %d\n",
141-
errno);
136+
printk(UM_KERN_ERR "run_helper_thread - wait failed, "
137+
"errno = %d\n", errno);
142138
pid = err;
143139
}
144140
if (!WIFEXITED(status) || (WEXITSTATUS(status) != 0))
145-
printk("run_helper_thread - thread returned status "
146-
"0x%x\n", status);
141+
printk(UM_KERN_ERR "run_helper_thread - thread "
142+
"returned status 0x%x\n", status);
147143
free_stack(stack, 0);
148144
} else
149145
*stack_out = stack;
150146
return pid;
151147
}
152148

153-
int helper_wait(int pid, int nohang, char *pname)
149+
int helper_wait(int pid)
154150
{
155151
int ret, status;
156152
int wflags = __WCLONE;
157153

158-
if (nohang)
159-
wflags |= WNOHANG;
160-
161-
if (!pname)
162-
pname = "helper_wait";
163-
164154
CATCH_EINTR(ret = waitpid(pid, &status, wflags));
165155
if (ret < 0) {
166-
printk(UM_KERN_ERR "%s : waitpid process %d failed, "
167-
"errno = %d\n", pname, pid, errno);
156+
printk(UM_KERN_ERR "helper_wait : waitpid process %d failed, "
157+
"errno = %d\n", pid, errno);
168158
return -errno;
169-
} else if (nohang && ret == 0) {
170-
printk(UM_KERN_ERR "%s : process %d has not exited\n",
171-
pname, pid);
172-
return -ECHILD;
173159
} else if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) {
174-
printk(UM_KERN_ERR "%s : process %d didn't exit with "
175-
"status 0\n", pname, pid);
160+
printk(UM_KERN_ERR "helper_wait : process %d exited with "
161+
"status 0x%x\n", pid, status);
176162
return -ECHILD;
177163
} else
178164
return 0;

0 commit comments

Comments
 (0)