]> git.ipfire.org Git - thirdparty/dracut.git/commitdiff
dracut: only copy xattr, if root
authorHarald Hoyer <harald@redhat.com>
Wed, 18 Jan 2017 09:38:00 +0000 (10:38 +0100)
committerHarald Hoyer <harald@redhat.com>
Wed, 18 Jan 2017 09:38:00 +0000 (10:38 +0100)
otherwise cp complains a lot about not being able to copy xattrs

dracut-init.sh
install/dracut-install.c

index e8100a459cc6846ee6e4059df01b2ba4d10f62ed..ac3dd82b6134af5f2b9bd0fe597ab832ded180ab 100644 (file)
 #
 export LC_MESSAGES=C
 
-export DRACUT_CP="cp --reflink=auto --sparse=auto --preserve=mode,timestamps,xattr,links -dfr"
+if [[ "$UID" = "0" ]]; then
+    export DRACUT_CP="cp --reflink=auto --sparse=auto --preserve=mode,timestamps,xattr,links -dfr"
+else
+    export DRACUT_CP="cp --reflink=auto --sparse=auto --preserve=mode,timestamps,links -dfr"
+fi
 
 # is_func <command>
 # Check whether $1 is a function.
index cc64bd69b1bbc0c815f9720bdb4dce664fce73f2..32faee6f8ea08cc24259267895f09d2efe6e7390 100644 (file)
@@ -275,8 +275,13 @@ static int cp(const char *src, const char *dst)
                 if (ret == 0) {
                         struct timeval tv[2];
                         if (fchown(dest_desc, sb.st_uid, sb.st_gid) != 0)
-                                if(fchown(dest_desc, (uid_t) - 1, sb.st_gid) != 0)
-                                    log_error("Failed to chown %s: %m", dst);
+                                if(fchown(dest_desc, (uid_t) - 1, sb.st_gid) != 0) {
+                                        if (geteuid() == 0)
+                                                log_error("Failed to chown %s: %m", dst);
+                                        else
+                                                log_info("Failed to chown %s: %m", dst);
+                                }
+
                         tv[0].tv_sec = sb.st_atime;
                         tv[0].tv_usec = 0;
                         tv[1].tv_sec = sb.st_mtime;
@@ -295,16 +300,24 @@ static int cp(const char *src, const char *dst)
  normal_copy:
         pid = fork();
         if (pid == 0) {
-                execlp("cp", "cp", "--reflink=auto", "--sparse=auto", "--preserve=mode,timestamps,xattr", "-fL", src, dst,
-                       NULL);
+                if (geteuid() == 0)
+                        execlp("cp", "cp", "--reflink=auto", "--sparse=auto", "--preserve=mode,xattr,timestamps", "-fL", src, dst,
+                               NULL);
+                else
+                        execlp("cp", "cp", "--reflink=auto", "--sparse=auto", "--preserve=mode,timestamps", "-fL", src, dst,
+                               NULL);
                 _exit(EXIT_FAILURE);
         }
 
         while (waitpid(pid, &ret, 0) < 0) {
                 if (errno != EINTR) {
                         ret = -1;
-                        log_error("Failed: cp --reflink=auto --sparse=auto --preserve=mode,timestamps,xattr -fL %s %s", src,
-                                  dst);
+                        if (geteuid() == 0)
+                                log_error("Failed: cp --reflink=auto --sparse=auto --preserve=mode,xattr,timestamps -fL %s %s", src,
+                                          dst);
+                        else
+                                log_error("Failed: cp --reflink=auto --sparse=auto --preserve=mode,timestamps -fL %s %s", src,
+                                          dst);
                         break;
                 }
         }