Skip to content

Commit 13736c5

Browse files
nabijaczlewelijohannbg
authored andcommitted
fix(dracut-install): correctly waitpid() for cp
1 parent d010fa0 commit 13736c5

File tree

1 file changed

+10
-16
lines changed

1 file changed

+10
-16
lines changed

src/install/dracut-install.c

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -329,28 +329,22 @@ static int cp(const char *src, const char *dst)
329329

330330
normal_copy:
331331
pid = fork();
332+
const char *preservation = (geteuid() == 0
333+
&& no_xattr == false) ? "--preserve=mode,xattr,timestamps,ownership" : "--preserve=mode,timestamps,ownership";
332334
if (pid == 0) {
333-
if (geteuid() == 0 && no_xattr == false)
334-
execlp("cp", "cp", "--reflink=auto", "--sparse=auto", "--preserve=mode,xattr,timestamps,ownership", "-fL",
335-
src, dst, NULL);
336-
else
337-
execlp("cp", "cp", "--reflink=auto", "--sparse=auto", "--preserve=mode,timestamps,ownership", "-fL", src,
338-
dst, NULL);
339-
_exit(EXIT_FAILURE);
335+
execlp("cp", "cp", "--reflink=auto", "--sparse=auto", preservation, "-fL", src, dst, NULL);
336+
_exit(errno == ENOENT ? 127 : 126);
340337
}
341338

342-
while (waitpid(pid, &ret, 0) < 0) {
339+
while (waitpid(pid, &ret, 0) == -1) {
343340
if (errno != EINTR) {
344-
ret = -1;
345-
if (geteuid() == 0 && no_xattr == false)
346-
log_error("Failed: cp --reflink=auto --sparse=auto --preserve=mode,xattr,timestamps,ownership -fL %s %s",
347-
src, dst);
348-
else
349-
log_error("Failed: cp --reflink=auto --sparse=auto --preserve=mode,timestamps,ownership -fL %s %s",
350-
src, dst);
351-
break;
341+
log_error("ERROR: waitpid() failed: %m");
342+
return 1;
352343
}
353344
}
345+
ret = WIFSIGNALED(ret) ? 128 + WTERMSIG(ret) : WEXITSTATUS(ret);
346+
if (ret != 0)
347+
log_error("ERROR: 'cp --reflink=auto --sparse=auto %s -fL %s %s' failed with %d", preservation, src, dst, ret);
354348
log_debug("cp ret = %d", ret);
355349
return ret;
356350
}

0 commit comments

Comments
 (0)