@@ -134,13 +134,26 @@ int sfs_ls(char* image) {
134134* execlp(), execvp(), and execvpe() search on the $PATH */
135135int sfs_mksquashfs (char * source , char * destination , int offset ) {
136136 pid_t pid = fork ();
137-
138137 if (pid == -1 ) {
139- // error, failed to fork()
138+ perror ( "sfs_mksquashfs fork() failed" );
140139 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.
142144 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 ;
144157 } else {
145158 // we are the child
146159 gchar * offset_string ;
@@ -223,11 +236,11 @@ int sfs_mksquashfs(char *source, char *destination, int offset) {
223236
224237#ifndef AUXILIARY_FILES_DESTINATION
225238 execvp ("mksquashfs" , args );
239+ perror ("execvp(\"mksquashfs\") failed" );
226240#else
227241 execvp (pathToMksquashfs , args );
242+ fprintf (stderr , "execvp(\"%s\") failed: %s\n" , pathToMksquashfs , strerror (errno ));
228243#endif
229-
230- perror ("execlp" ); // exec*() returns only on error
231244 return -1 ; // exec never returns
232245 }
233246 return 0 ;
0 commit comments