diff --git a/core/src/main/java/hudson/lifecycle/ZFSInstaller.java b/core/src/main/java/hudson/lifecycle/ZFSInstaller.java index ce9ec4b07eba3e316f3b8cca4bd5afbda1da6f9f..a23670c4bc64044f5c99689fc92d5133b648e2af 100644 --- a/core/src/main/java/hudson/lifecycle/ZFSInstaller.java +++ b/core/src/main/java/hudson/lifecycle/ZFSInstaller.java @@ -152,7 +152,8 @@ public class ZFSInstaller extends AdministrativeMonitor implements Serializable private String createZfsFileSystem(final TaskListener listener, String rootUsername, String rootPassword) throws IOException, InterruptedException, ZFSException { // capture the UID that Hudson runs under // so that we can allow this user to do everything on this new partition - int uid = LIBC.geteuid(); + final int uid = LIBC.geteuid(); + final int gid = LIBC.getegid(); passwd pwd = LIBC.getpwuid(uid); if(pwd==null) throw new IOException("Failed to obtain the current user information for "+uid); @@ -178,6 +179,14 @@ public class ZFSInstaller extends AdministrativeMonitor implements Serializable out.println("Creating "+name); ZFSFileSystem hudson = zfs.create(name, ZFSFileSystem.class); + // mount temporarily to set the owner right + File dir = Util.createTempDir(); + hudson.setMountPoint(dir); + hudson.mount(); + if(LIBC.chown(dir.getPath(),uid,gid)!=0) + throw new IOException("Failed to chown "+dir); + hudson.unmount(); + try { hudson.setProperty("hudson:managed-by","hudson"); // mark this file system as "managed by Hudson" @@ -286,7 +295,7 @@ public class ZFSInstaller extends AdministrativeMonitor implements Serializable } // re-exec with the system property to indicate where to migrate the data to. - // the 2nd phase starts in the init method. + // the 2nd phase is implemented in the migrate method. JavaVMArguments args = JavaVMArguments.current(); args.setSystemProperty(ZFSInstaller.class.getName()+".migrate",datasetName); Daemon.selfExec(args); diff --git a/core/src/main/java/hudson/util/jna/GNUCLibrary.java b/core/src/main/java/hudson/util/jna/GNUCLibrary.java index 79db6d75089ab924b6a4b2c54dbb818656720919..56e08a5631bb43a6fec00a4cdbe7c118be84b1bd 100644 --- a/core/src/main/java/hudson/util/jna/GNUCLibrary.java +++ b/core/src/main/java/hudson/util/jna/GNUCLibrary.java @@ -42,6 +42,7 @@ public interface GNUCLibrary extends Library { int umask(int mask); int getpid(); int geteuid(); + int getegid(); int getppid(); int chdir(String dir); int getdtablesize(); @@ -61,6 +62,8 @@ public interface GNUCLibrary extends Library { static final int F_GETFD = 1; static final int F_SETFD = 2; static final int FD_CLOEXEC = 1; + + int chown(String fileName, int uid, int gid); // this is listed in http://developer.apple.com/DOCUMENTATION/Darwin/Reference/ManPages/man3/sysctlbyname.3.html