summaryrefslogtreecommitdiffstats
path: root/pw
diff options
context:
space:
mode:
authorAlan Somers <asomers@FreeBSD.org>2016-11-18 16:07:08 +0000
committerAlan Somers <asomers@FreeBSD.org>2016-11-18 16:07:08 +0000
commitb442f00957395ba59112d4d0e0eb4f71708d811b (patch)
treebe77a1acfdc292061fba5f25273bf8c69b7d4e14 /pw
parenteaf8d4a9d903595d2f3a388ed56fd20b34d9f80b (diff)
downloadpw-darwin-b442f00957395ba59112d4d0e0eb4f71708d811b.tar.gz
pw-darwin-b442f00957395ba59112d4d0e0eb4f71708d811b.tar.zst
pw-darwin-b442f00957395ba59112d4d0e0eb4f71708d811b.zip
Speed up pw operations that edit /etc/group or /etc/passwd
r285050 fixed a bug in pw that could lead to /etc/passwd or /etc/group corruption on power loss. However, it fixed it by opening those files with O_SYNC, which is very slow, especially on ZFS. This change replaces O_SYNC with appropriately placed fsync()s instead, which is much faster. Using a ZFS tmpdir, the time to run pw's kyua tests drops from 245s to 35s. Reviewed by: allanjude, bapt, vangyzen, garga Tested on pfSense by: garga MFC after: 4 weeks Sponsored by: Spectra Logic Corp Differential Revision: https://reviews.freebsd.org/D8319
Diffstat (limited to 'pw')
-rw-r--r--pw/grupd.c1
-rw-r--r--pw/pw_nis.c1
-rw-r--r--pw/pwupd.c1
3 files changed, 3 insertions, 0 deletions
diff --git a/pw/grupd.c b/pw/grupd.c
index 38d5e5b..5d0df02 100644
--- a/pw/grupd.c
+++ b/pw/grupd.c
@@ -77,6 +77,7 @@ gr_update(struct group * grp, char const * group)
close(tfd);
err(1, "gr_copy()");
}
+ fsync(tfd);
close(tfd);
if (gr_mkdb() == -1) {
gr_fini();
diff --git a/pw/pw_nis.c b/pw/pw_nis.c
index 35b26ea..087c946 100644
--- a/pw/pw_nis.c
+++ b/pw/pw_nis.c
@@ -67,6 +67,7 @@ pw_nisupdate(const char * path, struct passwd * pwd, char const * user)
close(tfd);
err(1, "pw_copy()");
}
+ fsync(tfd);
close(tfd);
if (chmod(pw_tempname(), 0644) == -1)
err(1, "chmod()");
diff --git a/pw/pwupd.c b/pw/pwupd.c
index 3bcb95f..87c3c99 100644
--- a/pw/pwupd.c
+++ b/pw/pwupd.c
@@ -114,6 +114,7 @@ pw_update(struct passwd * pwd, char const * user)
close(tfd);
err(1, "pw_copy()");
}
+ fsync(tfd);
close(tfd);
/*
* in case of deletion of a user, the whole database