Skip to content

Fix permissions conflict in tmp folder and allow running from root on linux. #23

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,12 @@ private void initdb()
final StopWatch watch = new StopWatch();
watch.start();
List<String> command = new ArrayList<>();
if (SystemUtils.IS_OS_LINUX) {
Long uid = new com.sun.security.auth.module.UnixSystem().getUid();
if (uid == 0) {
command.addAll(Arrays.asList("unshare", "-U"));
}
}
command.addAll(Arrays.asList(
pgBin("initdb"), "-A", "trust", "-U", PG_SUPERUSER,
"-D", dataDirectory.getPath(), "-E", "UTF-8"));
Expand All @@ -259,6 +265,12 @@ private void startPostmaster() throws IOException
}

final List<String> args = new ArrayList<>();
if (SystemUtils.IS_OS_LINUX) {
Long uid = new com.sun.security.auth.module.UnixSystem().getUid();
if (uid == 0) {
args.addAll(Arrays.asList("unshare", "-U"));
}
}
args.addAll(Arrays.asList(
pgBin("pg_ctl"),
"-D", dataDirectory.getPath(),
Expand Down Expand Up @@ -414,7 +426,15 @@ public void close() throws IOException

private void pgCtl(File dir, String action)
{
system(pgBin("pg_ctl"), "-D", dir.getPath(), action, "-m", PG_STOP_MODE, "-t", PG_STOP_WAIT_S, "-w");
final List<String> args = new ArrayList<>();
if (SystemUtils.IS_OS_LINUX) {
Long uid = new com.sun.security.auth.module.UnixSystem().getUid();
if (uid == 0) {
args.addAll(Arrays.asList("unshare", "-U"));
}
}
args.addAll(Arrays.asList(pgBin("pg_ctl"), "-D", dir.getPath(), action, "-m", PG_STOP_MODE, "-t", PG_STOP_WAIT_S, "-w"));
system(args.toArray(new String[args.size()]));
}

private void cleanOldDataDirectories(File parentDirectory)
Expand Down Expand Up @@ -780,7 +800,12 @@ private static File prepareBinaries(PgBinaryResolver pgBinaryResolver, File over

String pgDigest = Hex.encodeHexString(pgArchiveData.getMessageDigest().digest());
File workingDirectory = Optional.ofNullable(overrideWorkingDirectory).orElse(getWorkingDirectory());
pgDir = new File(workingDirectory, String.format("PG-%s", pgDigest));
if (SystemUtils.IS_OS_LINUX || SystemUtils.IS_OS_MAC_OSX) {
Long uid = new com.sun.security.auth.module.UnixSystem().getUid();
pgDir = new File(workingDirectory, String.format("PG-%d-%s", uid, pgDigest));
} else {
pgDir = new File(workingDirectory, String.format("PG-%s", pgDigest));
}

mkdirs(pgDir);
final File unpackLockFile = new File(pgDir, LOCK_FILE_NAME);
Expand Down