diff --git a/ci/test-appimagetool.sh b/ci/test-appimagetool.sh index 125e9c19..aaf9491e 100755 --- a/ci/test-appimagetool.sh +++ b/ci/test-appimagetool.sh @@ -119,8 +119,6 @@ if [ "$hash1" != "$hash2" ]; then fi log "check --mksquashfs-opt forwarding" -out=$("$appimagetool" appimagetool.AppDir appimagetool.AppImage --mksquashfs-opt "-misspelt-option" 2>&1) -echo "${out}" | grep -q "invalid option" "$appimagetool" appimagetool.AppDir appimagetool.AppImage.1 "$appimagetool" appimagetool.AppDir appimagetool.AppImage.2 --mksquashfs-opt "-mem" --mksquashfs-opt "100M" "$appimagetool" appimagetool.AppDir appimagetool.AppImage.3 --mksquashfs-opt "-all-time" --mksquashfs-opt "12345" @@ -135,3 +133,13 @@ if [ "$hash1" == "$hash3" ]; then echo "Hashes of regular and mtime-modified AppImages don't differ" exit 1 fi + +log "check appimagetool dies when mksquashfs fails" +set +e # temporarily disable error trapping as next line is supposed to fail +out=$("$appimagetool" appimagetool.AppDir appimagetool.AppImage --mksquashfs-opt "-misspelt-option" 2>&1) +rc=$? +set -e +test ${rc} == 1 +echo "${out}" | grep -q "invalid option" +echo "${out}" | grep -qP 'mksquashfs \(pid \d+\) exited with code 1' +echo "${out}" | grep -q "sfs_mksquashfs error" diff --git a/src/appimagetool.c b/src/appimagetool.c index f007ce31..a4132649 100644 --- a/src/appimagetool.c +++ b/src/appimagetool.c @@ -134,13 +134,26 @@ int sfs_ls(char* image) { * execlp(), execvp(), and execvpe() search on the $PATH */ int sfs_mksquashfs(char *source, char *destination, int offset) { pid_t pid = fork(); - if (pid == -1) { - // error, failed to fork() + perror("sfs_mksquashfs fork() failed"); return(-1); - } else if (pid > 0) { + } + + if (pid > 0) { + // This is the parent process. Wait for the child to termiante and check its exit status. int status; - waitpid(pid, &status, 0); + if(waitpid(pid, &status, 0) == -1) { + perror("sfs_mksquashfs waitpid() failed"); + return(-1); + } + + int retcode = WEXITSTATUS(status); + if (retcode) { + fprintf(stderr, "mksquashfs (pid %d) exited with code %d\n", pid, retcode); + return(-1); + } + + return 0; } else { // we are the child gchar* offset_string; @@ -223,11 +236,11 @@ int sfs_mksquashfs(char *source, char *destination, int offset) { #ifndef AUXILIARY_FILES_DESTINATION execvp("mksquashfs", args); + perror("execvp(\"mksquashfs\") failed"); #else execvp(pathToMksquashfs, args); + fprintf(stderr, "execvp(\"%s\") failed: %s\n", pathToMksquashfs, strerror(errno)); #endif - - perror("execlp"); // exec*() returns only on error return -1; // exec never returns } return 0;