Skip to content

Commit

Permalink
Die on mksquashfs failure. (#1189)
Browse files Browse the repository at this point in the history
* Die on mksquashfs failure.

* review

* Use %d to print pid_t
  • Loading branch information
lalten authored Sep 29, 2022
1 parent 90704a0 commit b719a7f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 8 deletions.
12 changes: 10 additions & 2 deletions ci/test-appimagetool.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
25 changes: 19 additions & 6 deletions src/appimagetool.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit b719a7f

Please sign in to comment.