From: Marcos Mello Date: Wed, 11 Sep 2024 01:38:06 +0000 (-0300) Subject: refactor(dracut-install): simplify open() call in cp() X-Git-Tag: 104~39 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f3bf6c749e6e814345f772ddc57db7ea211efb2f;p=thirdparty%2Fdracut-ng.git refactor(dracut-install): simplify open() call in cp() Flipping `S_IFMT` gives the file mode bits. --- diff --git a/src/install/dracut-install.c b/src/install/dracut-install.c index bb0005206..96bc2eb64 100644 --- a/src/install/dracut-install.c +++ b/src/install/dracut-install.c @@ -364,13 +364,9 @@ static int cp(const char *src, const char *dst) if (source_desc < 0) goto normal_copy; - dest_desc = - open(dst, O_WRONLY | O_CREAT | O_EXCL | O_CLOEXEC, - (sb.st_mode) & (S_ISUID | S_ISGID | S_ISVTX | S_IRWXU | S_IRWXG | S_IRWXO)); - - if (dest_desc < 0) { + dest_desc = open(dst, O_WRONLY | O_CREAT | O_EXCL | O_CLOEXEC, sb.st_mode & ~S_IFMT); + if (dest_desc < 0) goto normal_copy; - } ret = clone_file(dest_desc, source_desc);