Skip to content

Commit b719a7f

Browse files
authored
Die on mksquashfs failure. (AppImage#1189)
* Die on mksquashfs failure. * review * Use %d to print pid_t
1 parent 90704a0 commit b719a7f

File tree

2 files changed

+29
-8
lines changed

2 files changed

+29
-8
lines changed

ci/test-appimagetool.sh

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,6 @@ if [ "$hash1" != "$hash2" ]; then
119119
fi
120120

121121
log "check --mksquashfs-opt forwarding"
122-
out=$("$appimagetool" appimagetool.AppDir appimagetool.AppImage --mksquashfs-opt "-misspelt-option" 2>&1)
123-
echo "${out}" | grep -q "invalid option"
124122
"$appimagetool" appimagetool.AppDir appimagetool.AppImage.1
125123
"$appimagetool" appimagetool.AppDir appimagetool.AppImage.2 --mksquashfs-opt "-mem" --mksquashfs-opt "100M"
126124
"$appimagetool" appimagetool.AppDir appimagetool.AppImage.3 --mksquashfs-opt "-all-time" --mksquashfs-opt "12345"
@@ -135,3 +133,13 @@ if [ "$hash1" == "$hash3" ]; then
135133
echo "Hashes of regular and mtime-modified AppImages don't differ"
136134
exit 1
137135
fi
136+
137+
log "check appimagetool dies when mksquashfs fails"
138+
set +e # temporarily disable error trapping as next line is supposed to fail
139+
out=$("$appimagetool" appimagetool.AppDir appimagetool.AppImage --mksquashfs-opt "-misspelt-option" 2>&1)
140+
rc=$?
141+
set -e
142+
test ${rc} == 1
143+
echo "${out}" | grep -q "invalid option"
144+
echo "${out}" | grep -qP 'mksquashfs \(pid \d+\) exited with code 1'
145+
echo "${out}" | grep -q "sfs_mksquashfs error"

src/appimagetool.c

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -134,13 +134,26 @@ int sfs_ls(char* image) {
134134
* execlp(), execvp(), and execvpe() search on the $PATH */
135135
int 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

Comments
 (0)