Commit 4e90c06e authored by Mike Hibler's avatar Mike Hibler

Another speed up for the 'pw' command.

A recent commit to 10-STABLE caught my attention since it was a speed
up of the 'pw' command. Probably not a huge issue in our environment,
but I incorporated it into our patch.
parent 96c85e1b
diff -Nur pw.orig/Makefile pw/Makefile
--- pw.orig/Makefile 2015-08-25 08:41:11.000000000 -0600
+++ pw/Makefile 2016-11-22 12:46:28.248147000 -0700
#
# Incorporate some 10-STABLE speed-ups of temp files and a Utah change
# to pw_user to not make so many group file writes.
#
# cd /usr/src
# sudo patch -p0 < patchfile
#
diff -Nur lib/libutil.orig/gr_util.c lib/libutil/gr_util.c
--- lib/libutil.orig/gr_util.c 2015-08-13 16:38:22.562033943 -0600
+++ lib/libutil/gr_util.c 2016-12-19 15:02:48.150513000 -0700
@@ -25,7 +25,7 @@
*/
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: releng/10.2/lib/libutil/gr_util.c 285205 2015-07-06 13:01:01Z garga $");
+__FBSDID("$FreeBSD: stable/10/lib/libutil/gr_util.c 310173 2016-12-16 20:10:55Z asomers $");
#include <sys/param.h>
#include <sys/errno.h>
@@ -141,7 +141,7 @@
errno = ENAMETOOLONG;
return (-1);
}
- if ((tfd = mkostemp(tempname, O_SYNC)) == -1)
+ if ((tfd = mkostemp(tempname, 0)) == -1)
return (-1);
if (mfd != -1) {
while ((nr = read(mfd, buf, sizeof(buf))) > 0)
diff -Nur lib/libutil.orig/pw_util.c lib/libutil/pw_util.c
--- lib/libutil.orig/pw_util.c 2015-08-13 16:38:22.522033209 -0600
+++ lib/libutil/pw_util.c 2016-12-19 15:02:18.455217000 -0700
@@ -39,7 +39,7 @@
static const char sccsid[] = "@(#)pw_util.c 8.3 (Berkeley) 4/2/94";
#endif
static const char rcsid[] =
- "$FreeBSD: releng/10.2/lib/libutil/pw_util.c 285205 2015-07-06 13:01:01Z garga $";
+ "$FreeBSD: stable/10/lib/libutil/pw_util.c 310173 2016-12-16 20:10:55Z asomers $";
#endif /* not lint */
/*
@@ -226,7 +226,7 @@
errno = ENAMETOOLONG;
return (-1);
}
- if ((tfd = mkostemp(tempname, O_SYNC)) == -1)
+ if ((tfd = mkostemp(tempname, 0)) == -1)
return (-1);
if (mfd != -1) {
while ((nr = read(mfd, buf, sizeof(buf))) > 0)
diff -Nur usr.sbin/pw.orig/Makefile usr.sbin/pw/Makefile
--- usr.sbin/pw.orig/Makefile 2015-08-13 16:36:55.272035347 -0600
+++ usr.sbin/pw/Makefile 2016-11-22 12:52:29.668849000 -0700
@@ -8,6 +8,8 @@
grupd.c pwupd.c fileupd.c psdate.c \
bitmap.c cpdir.c rm_r.c
......@@ -10,9 +60,84 @@ diff -Nur pw.orig/Makefile pw/Makefile
WARNS?= 3
DPADD= ${LIBCRYPT} ${LIBUTIL} ${LIBSBUF}
diff -Nur pw.orig/pw_user.c pw/pw_user.c
--- pw.orig/pw_user.c 2015-08-25 08:41:11.000000000 -0600
+++ pw/pw_user.c 2016-11-22 11:04:11.272539000 -0700
diff -Nur usr.sbin/pw.orig/grupd.c usr.sbin/pw/grupd.c
--- usr.sbin/pw.orig/grupd.c 2015-08-13 16:36:55.382035309 -0600
+++ usr.sbin/pw/grupd.c 2016-12-19 15:06:45.469362000 -0700
@@ -26,16 +26,15 @@
#ifndef lint
static const char rcsid[] =
- "$FreeBSD: releng/10.2/usr.sbin/pw/grupd.c 285092 2015-07-03 14:22:44Z bapt $";
+ "$FreeBSD: stable/10/usr.sbin/pw/grupd.c 310173 2016-12-16 20:10:55Z asomers $";
#endif /* not lint */
+#include <err.h>
#include <grp.h>
#include <libutil.h>
-#include <err.h>
#include <stdio.h>
#include <stdlib.h>
-#include <string.h>
-#include <sys/param.h>
+#include <unistd.h>
#include "pwupd.h"
@@ -75,8 +74,11 @@
}
if (gr_copy(pfd, tfd, gr, old_gr) == -1) {
gr_fini();
+ close(tfd);
err(1, "gr_copy()");
}
+ fsync(tfd);
+ close(tfd);
if (gr_mkdb() == -1) {
gr_fini();
err(1, "gr_mkdb()");
diff -Nur usr.sbin/pw.orig/pw_nis.c usr.sbin/pw/pw_nis.c
--- usr.sbin/pw.orig/pw_nis.c 2015-08-13 16:36:55.272035347 -0600
+++ usr.sbin/pw/pw_nis.c 2016-12-19 15:05:26.747052000 -0700
@@ -26,13 +26,15 @@
#ifndef lint
static const char rcsid[] =
- "$FreeBSD: releng/10.2/usr.sbin/pw/pw_nis.c 285092 2015-07-03 14:22:44Z bapt $";
+ "$FreeBSD: stable/10/usr.sbin/pw/pw_nis.c 310173 2016-12-16 20:10:55Z asomers $";
#endif /* not lint */
#include <sys/types.h>
+
#include <err.h>
#include <pwd.h>
#include <libutil.h>
+#include <unistd.h>
#include "pw.h"
@@ -43,6 +45,7 @@
struct passwd *pw = NULL;
struct passwd *old_pw = NULL;
+ printf("===> %s\n", path);
if (pwd != NULL)
pw = pw_dup(pwd);
@@ -61,8 +64,11 @@
}
if (pw_copy(pfd, tfd, pw, old_pw) == -1) {
pw_fini();
+ close(tfd);
err(1, "pw_copy()");
}
+ fsync(tfd);
+ close(tfd);
if (chmod(pw_tempname(), 0644) == -1)
err(1, "chmod()");
if (rename(pw_tempname(), path) == -1)
diff -Nur usr.sbin/pw.orig/pw_user.c usr.sbin/pw/pw_user.c
--- usr.sbin/pw.orig/pw_user.c 2015-08-13 16:36:55.262049646 -0600
+++ usr.sbin/pw/pw_user.c 2016-11-22 12:52:29.670114000 -0700
@@ -636,6 +636,7 @@
if (mode == M_ADD || getarg(args, 'G') != NULL) {
......@@ -78,3 +203,47 @@ diff -Nur pw.orig/pw_user.c pw/pw_user.c
/* go get a current version of pwd */
pwd = GETPWNAM(name);
diff -Nur usr.sbin/pw.orig/pwupd.c usr.sbin/pw/pwupd.c
--- usr.sbin/pw.orig/pwupd.c 2015-08-13 16:36:55.282035386 -0600
+++ usr.sbin/pw/pwupd.c 2016-12-19 15:10:21.840546000 -0700
@@ -26,21 +26,19 @@
#ifndef lint
static const char rcsid[] =
- "$FreeBSD: releng/10.2/usr.sbin/pw/pwupd.c 285092 2015-07-03 14:22:44Z bapt $";
+ "$FreeBSD: stable/10/usr.sbin/pw/pwupd.c 310173 2016-12-16 20:10:55Z asomers $";
#endif /* not lint */
+#include <sys/wait.h>
+
+#include <err.h>
+#include <errno.h>
+#include <pwd.h>
+#include <libutil.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
-#include <pwd.h>
-#include <libutil.h>
-#include <errno.h>
-#include <err.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/param.h>
-#include <sys/wait.h>
#include "pwupd.h"
@@ -113,8 +111,11 @@
}
if (pw_copy(pfd, tfd, pw, old_pw) == -1) {
pw_fini();
+ close(tfd);
err(1, "pw_copy()");
}
+ fsync(tfd);
+ close(tfd);
/*
* in case of deletion of a user, the whole database
* needs to be regenerated
diff -Nur pw.orig/Makefile pw/Makefile
--- pw.orig/Makefile 2016-11-21 11:09:19.249036000 -0700
+++ pw/Makefile 2016-11-22 06:51:45.802580000 -0700
#
# Incorporate some 10-STABLE speed-ups of temp files and a Utah change
# to pw_user to not make so many group file writes.
#
# cd /usr/src
# sudo patch -p0 < patchfile
#
diff -Nur lib/libutil.orig/gr_util.c lib/libutil/gr_util.c
--- lib/libutil.orig/gr_util.c 2016-05-27 09:26:11.000000000 -0600
+++ lib/libutil/gr_util.c 2016-12-19 16:12:41.313784000 -0700
@@ -25,7 +25,7 @@
*/
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: releng/10.3/lib/libutil/gr_util.c 285205 2015-07-06 13:01:01Z garga $");
+__FBSDID("$FreeBSD: stable/10/lib/libutil/gr_util.c 310173 2016-12-16 20:10:55Z asomers $");
#include <sys/param.h>
#include <sys/errno.h>
@@ -141,7 +141,7 @@
errno = ENAMETOOLONG;
return (-1);
}
- if ((tfd = mkostemp(tempname, O_SYNC)) == -1)
+ if ((tfd = mkostemp(tempname, 0)) == -1)
return (-1);
if (mfd != -1) {
while ((nr = read(mfd, buf, sizeof(buf))) > 0)
diff -Nur lib/libutil.orig/pw_util.c lib/libutil/pw_util.c
--- lib/libutil.orig/pw_util.c 2016-05-27 09:26:11.000000000 -0600
+++ lib/libutil/pw_util.c 2016-12-19 16:12:20.608343000 -0700
@@ -39,7 +39,7 @@
static const char sccsid[] = "@(#)pw_util.c 8.3 (Berkeley) 4/2/94";
#endif
static const char rcsid[] =
- "$FreeBSD: releng/10.3/lib/libutil/pw_util.c 285205 2015-07-06 13:01:01Z garga $";
+ "$FreeBSD: stable/10/lib/libutil/pw_util.c 310173 2016-12-16 20:10:55Z asomers $";
#endif /* not lint */
/*
@@ -226,7 +226,7 @@
errno = ENAMETOOLONG;
return (-1);
}
- if ((tfd = mkostemp(tempname, O_SYNC)) == -1)
+ if ((tfd = mkostemp(tempname, 0)) == -1)
return (-1);
if (mfd != -1) {
while ((nr = read(mfd, buf, sizeof(buf))) > 0)
diff -Nur usr.sbin/pw.orig/Makefile usr.sbin/pw/Makefile
--- usr.sbin/pw.orig/Makefile 2016-05-27 09:23:45.000000000 -0600
+++ usr.sbin/pw/Makefile 2016-12-19 16:06:28.961040000 -0700
@@ -8,6 +8,9 @@
grupd.c pwupd.c psdate.c bitmap.c cpdir.c rm_r.c strtounum.c \
pw_utils.c
......@@ -11,9 +61,73 @@ diff -Nur pw.orig/Makefile pw/Makefile
WARNS?= 3
DPADD= ${LIBCRYPT} ${LIBUTIL} ${LIBSBUF}
diff -Nur pw.orig/pw_user.c pw/pw_user.c
--- pw.orig/pw_user.c 2016-05-27 09:23:45.000000000 -0600
+++ pw/pw_user.c 2016-11-22 06:51:30.409582000 -0700
diff -Nur usr.sbin/pw.orig/grupd.c usr.sbin/pw/grupd.c
--- usr.sbin/pw.orig/grupd.c 2016-05-27 09:23:43.000000000 -0600
+++ usr.sbin/pw/grupd.c 2016-12-19 16:10:31.854770000 -0700
@@ -26,7 +26,7 @@
#ifndef lint
static const char rcsid[] =
- "$FreeBSD: releng/10.3/usr.sbin/pw/grupd.c 287084 2015-08-23 21:42:27Z bapt $";
+ "$FreeBSD: stable/10/usr.sbin/pw/grupd.c 310173 2016-12-16 20:10:55Z asomers $";
#endif /* not lint */
#include <err.h>
@@ -34,6 +34,7 @@
#include <libutil.h>
#include <stdio.h>
#include <stdlib.h>
+#include <unistd.h>
#include "pwupd.h"
@@ -73,8 +74,11 @@
}
if (gr_copy(pfd, tfd, gr, old_gr) == -1) {
gr_fini();
+ close(tfd);
err(1, "gr_copy()");
}
+ fsync(tfd);
+ close(tfd);
if (gr_mkdb() == -1) {
gr_fini();
err(1, "gr_mkdb()");
diff -Nur usr.sbin/pw.orig/pw_nis.c usr.sbin/pw/pw_nis.c
--- usr.sbin/pw.orig/pw_nis.c 2016-05-27 09:23:45.000000000 -0600
+++ usr.sbin/pw/pw_nis.c 2016-12-19 16:11:08.110522000 -0700
@@ -26,7 +26,7 @@
#ifndef lint
static const char rcsid[] =
- "$FreeBSD: releng/10.3/usr.sbin/pw/pw_nis.c 287084 2015-08-23 21:42:27Z bapt $";
+ "$FreeBSD: stable/10/usr.sbin/pw/pw_nis.c 310173 2016-12-16 20:10:55Z asomers $";
#endif /* not lint */
#include <sys/types.h>
@@ -34,6 +34,7 @@
#include <err.h>
#include <pwd.h>
#include <libutil.h>
+#include <unistd.h>
#include "pw.h"
@@ -63,8 +64,11 @@
}
if (pw_copy(pfd, tfd, pw, old_pw) == -1) {
pw_fini();
+ close(tfd);
err(1, "pw_copy()");
}
+ fsync(tfd);
+ close(tfd);
if (chmod(pw_tempname(), 0644) == -1)
err(1, "chmod()");
if (rename(pw_tempname(), path) == -1)
diff -Nur usr.sbin/pw.orig/pw_user.c usr.sbin/pw/pw_user.c
--- usr.sbin/pw.orig/pw_user.c 2016-05-27 09:23:45.000000000 -0600
+++ usr.sbin/pw/pw_user.c 2016-12-19 16:06:28.962164000 -0700
@@ -1486,7 +1486,12 @@
struct passwd *pwd;
struct group *grp;
......@@ -163,3 +277,27 @@ diff -Nur pw.orig/pw_user.c pw/pw_user.c
/* In case of rename we need to walk over the different groups */
if (newname) {
SETGRENT();
diff -Nur usr.sbin/pw.orig/pwupd.c usr.sbin/pw/pwupd.c
--- usr.sbin/pw.orig/pwupd.c 2016-05-27 09:23:45.000000000 -0600
+++ usr.sbin/pw/pwupd.c 2016-12-19 16:09:52.094478000 -0700
@@ -26,7 +26,7 @@
#ifndef lint
static const char rcsid[] =
- "$FreeBSD: releng/10.3/usr.sbin/pw/pwupd.c 287084 2015-08-23 21:42:27Z bapt $";
+ "$FreeBSD: stable/10/usr.sbin/pw/pwupd.c 310173 2016-12-16 20:10:55Z asomers $";
#endif /* not lint */
#include <sys/wait.h>
@@ -111,8 +111,11 @@
}
if (pw_copy(pfd, tfd, pw, old_pw) == -1) {
pw_fini();
+ close(tfd);
err(1, "pw_copy()");
}
+ fsync(tfd);
+ close(tfd);
/*
* in case of deletion of a user, the whole database
* needs to be regenerated
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment