@@ -134,13 +134,26 @@ int sfs_ls(char* image) {
134
134
* execlp(), execvp(), and execvpe() search on the $PATH */
135
135
int sfs_mksquashfs (char * source , char * destination , int offset ) {
136
136
pid_t pid = fork ();
137
-
138
137
if (pid == -1 ) {
139
- // error, failed to fork()
138
+ perror ( "sfs_mksquashfs fork() failed" );
140
139
return (-1 );
141
- } else if (pid > 0 ) {
140
+ }
141
+
142
+ if (pid > 0 ) {
143
+ // This is the parent process. Wait for the child to termiante and check its exit status.
142
144
int status ;
143
- waitpid (pid , & status , 0 );
145
+ if (waitpid (pid , & status , 0 ) == -1 ) {
146
+ perror ("sfs_mksquashfs waitpid() failed" );
147
+ return (-1 );
148
+ }
149
+
150
+ int retcode = WEXITSTATUS (status );
151
+ if (retcode ) {
152
+ fprintf (stderr , "mksquashfs (pid %d) exited with code %d\n" , pid , retcode );
153
+ return (-1 );
154
+ }
155
+
156
+ return 0 ;
144
157
} else {
145
158
// we are the child
146
159
gchar * offset_string ;
@@ -223,11 +236,11 @@ int sfs_mksquashfs(char *source, char *destination, int offset) {
223
236
224
237
#ifndef AUXILIARY_FILES_DESTINATION
225
238
execvp ("mksquashfs" , args );
239
+ perror ("execvp(\"mksquashfs\") failed" );
226
240
#else
227
241
execvp (pathToMksquashfs , args );
242
+ fprintf (stderr , "execvp(\"%s\") failed: %s\n" , pathToMksquashfs , strerror (errno ));
228
243
#endif
229
-
230
- perror ("execlp" ); // exec*() returns only on error
231
244
return -1 ; // exec never returns
232
245
}
233
246
return 0 ;
0 commit comments