31
31
32
32
#include "einfo.h"
33
33
#include "rc.h"
34
+ #include "rc_exec.h"
34
35
#include "_usage.h"
35
36
#include "helpers.h"
36
37
@@ -51,33 +52,26 @@ const char *usagestring = NULL;
51
52
52
53
static int mount_proc (void )
53
54
{
54
- pid_t pid ;
55
55
pid_t rc ;
56
56
int status ;
57
+ const char * argv [] = { "mount" , "-t" , "proc" , "proc" , "/proc" , NULL };
58
+ struct rc_exec_result res ;
59
+ struct rc_exec_args args = rc_exec_args_init (argv );
57
60
58
61
if (exists ("/proc/version" ))
59
62
return 0 ;
60
- pid = fork ();
61
- switch (pid ) {
62
- case -1 :
63
- syslog (LOG_ERR , "Unable to fork" );
64
- return -1 ;
65
- break ;
66
- case 0 :
67
- /* attempt to mount /proc */
68
- execlp ("mount" , "mount" , "-t" , "proc" , "proc" , "/proc" , NULL );
69
- syslog (LOG_ERR , "Unable to execute mount" );
70
- exit (1 );
71
- break ;
72
- default :
73
- /* wait for child process */
74
- while ((rc = wait (& status )) != pid )
75
- if (rc < 0 && errno == ECHILD )
76
- break ;
77
- if (rc != pid || !WIFEXITED (status ) || WEXITSTATUS (status ) != 0 )
78
- syslog (LOG_ERR , "mount returned non-zero exit status" );
79
- break ;
63
+
64
+ res = rc_exec (& args );
65
+ if (res .pid < 0 ) {
66
+ syslog (LOG_ERR , "Failed to execute mount" );
67
+ return -1 ;
80
68
}
69
+ while ((rc = wait (& status )) != res .pid )
70
+ if (rc < 0 && errno == ECHILD )
71
+ break ;
72
+ if (rc != res .pid || !WIFEXITED (status ) || WEXITSTATUS (status ) != 0 )
73
+ syslog (LOG_ERR , "mount returned non-zero exit status" );
74
+
81
75
if (!exists ("/proc/version" )) {
82
76
syslog (LOG_ERR , "Could not mount /proc" );
83
77
return -1 ;
0 commit comments