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
2118struct 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. */
4843int 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