summaryrefslogtreecommitdiffstats
path: root/usr.sbin/config
diff options
context:
space:
mode:
authorpeter <peter@FreeBSD.org>1996-01-12 08:57:10 +0000
committerpeter <peter@FreeBSD.org>1996-01-12 08:57:10 +0000
commit5b70a95cd827978a62482802e9ff51d4e958da7e (patch)
tree87f917319075f55b3a7df24a1226cb5fd2de48e6 /usr.sbin/config
parentb90ef46a2fbc1f210795d01c9dee181dbf3f1922 (diff)
downloadFreeBSD-src-5b70a95cd827978a62482802e9ff51d4e958da7e.zip
FreeBSD-src-5b70a95cd827978a62482802e9ff51d4e958da7e.tar.gz
Make a little more effort to avoid touching certain generated files if
they were not changed. This makes 'make depend' more useful.
Diffstat (limited to 'usr.sbin/config')
-rw-r--r--usr.sbin/config/config.h1
-rw-r--r--usr.sbin/config/main.c65
-rw-r--r--usr.sbin/config/mkglue.c5
-rw-r--r--usr.sbin/config/mkioconf.c10
-rw-r--r--usr.sbin/config/mkmakefile.c5
-rw-r--r--usr.sbin/config/mkswapconf.c9
6 files changed, 84 insertions, 11 deletions
diff --git a/usr.sbin/config/config.h b/usr.sbin/config/config.h
index 41e492f..65c9b66 100644
--- a/usr.sbin/config/config.h
+++ b/usr.sbin/config/config.h
@@ -192,6 +192,7 @@ char *get_word();
char *get_quoted_word();
char *path();
char *raise();
+void moveifchanged();
int do_trace;
diff --git a/usr.sbin/config/main.c b/usr.sbin/config/main.c
index 3369504..a203769 100644
--- a/usr.sbin/config/main.c
+++ b/usr.sbin/config/main.c
@@ -44,8 +44,11 @@ static char sccsid[] = "@(#)main.c 8.1 (Berkeley) 6/6/93";
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/file.h>
+#include <sys/mman.h>
#include <stdio.h>
#include <ctype.h>
+#include <err.h>
+#include <sysexits.h>
#include "y.tab.h"
#include "config.h"
@@ -328,3 +331,65 @@ path(file)
}
return (cp);
}
+
+/*
+ * moveifchanged --
+ * compare two files; rename if changed.
+ */
+void
+moveifchanged(const char *from_name, const char *to_name)
+{
+ char *p, *q;
+ int changed;
+ size_t tsize;
+ struct stat from_sb, to_sb;
+ int from_fd, to_fd;
+
+ changed = 0;
+
+ if ((from_fd = open(from_name, O_RDONLY)) < 0)
+ err(EX_OSERR, "moveifchanged open(%s)", from_name);
+
+ if ((to_fd = open(to_name, O_RDONLY)) < 0)
+ changed++;
+
+ if (!changed && fstat(from_fd, &from_sb) < 0)
+ err(EX_OSERR, "moveifchanged fstat(%s)", from_name);
+
+ if (!changed && fstat(to_fd, &to_sb) < 0)
+ err(EX_OSERR, "moveifchanged fstat(%s)", to_name);
+
+ if (!changed && from_sb.st_size != to_sb.st_size)
+ changed++;
+
+ tsize = (size_t)from_sb.st_size;
+
+ if (!changed) {
+ p = mmap(NULL, tsize, PROT_READ, 0, from_fd, (off_t)0);
+ if ((long)p == -1)
+ err(EX_OSERR, "mmap %s", from_name);
+ q = mmap(NULL, tsize, PROT_READ, 0, to_fd, (off_t)0);
+ if ((long)q == -1)
+ err(EX_OSERR, "mmap %s", to_name);
+
+ changed = memcmp(p, q, tsize);
+ munmap(p, tsize);
+ munmap(q, tsize);
+ }
+ if (changed) {
+ if (rename(from_name, to_name) < 0)
+ err(EX_OSERR, "rename(%s, %s)", from_name, to_name);
+ } else {
+ if (unlink(from_name) < 0)
+ err(EX_OSERR, "unlink(%s, %s)", from_name);
+ }
+
+#ifdef DIAG
+ if (changed)
+ printf("CHANGED! rename (%s, %s)\n", from_name, to_name);
+ else
+ printf("SAME! unlink (%s)\n", from_name);
+#endif
+
+ return;
+}
diff --git a/usr.sbin/config/mkglue.c b/usr.sbin/config/mkglue.c
index aa5ecfe..d5174c7 100644
--- a/usr.sbin/config/mkglue.c
+++ b/usr.sbin/config/mkglue.c
@@ -346,9 +346,9 @@ vector()
int dev_id;
FILE *fp;
- fp = fopen(path("vector.h"), "w");
+ fp = fopen(path("vector.h.new"), "w");
if (fp == NULL) {
- perror(path("vector.h"));
+ perror(path("vector.h.new"));
exit(1);
}
fprintf(fp, "/*\n");
@@ -367,6 +367,7 @@ vector()
fprintf(fp, "\"\n\n");
fprintf(fp, "#define\tNR_DEVICES\t%d\n", dev_id);
(void) fclose(fp);
+ moveifchanged(path("vector.h.new"), path("vector.h"));
}
vector_devtab(fp, table, dev_idp)
diff --git a/usr.sbin/config/mkioconf.c b/usr.sbin/config/mkioconf.c
index 378b6fb..9eda8f0 100644
--- a/usr.sbin/config/mkioconf.c
+++ b/usr.sbin/config/mkioconf.c
@@ -608,9 +608,9 @@ i386_ioconf()
static char *old_d_name;
static char old_shandler[32 + 1];
- fp = fopen(path("ioconf.c"), "w");
+ fp = fopen(path("ioconf.c.new"), "w");
if (fp == 0) {
- perror(path("ioconf.c"));
+ perror(path("ioconf.c.new"));
exit(1);
}
fprintf(fp, "/*\n");
@@ -622,9 +622,9 @@ i386_ioconf()
fprintf(fp, "#include \"ioconf.h\"\n");
fprintf(fp, "\n");
fprintf(fp, "#define C (caddr_t)\n");
- fp1 = fopen(path("ioconf.h"), "w");
+ fp1 = fopen(path("ioconf.h.new"), "w");
if (fp1 == 0) {
- perror(path("ioconf.h"));
+ perror(path("ioconf.h.new"));
exit(1);
}
fprintf(fp1, "/*\n");
@@ -701,6 +701,8 @@ i386_ioconf()
fprintf(fp1, "\n");
fprintf(fp1, "#endif /* IOCONF_H */\n");
(void) fclose(fp1);
+ moveifchanged(path("ioconf.c.new"), path("ioconf.c"));
+ moveifchanged(path("ioconf.h.new"), path("ioconf.h"));
}
isa_biotab(fp, table)
diff --git a/usr.sbin/config/mkmakefile.c b/usr.sbin/config/mkmakefile.c
index c129ee6..0f057f4 100644
--- a/usr.sbin/config/mkmakefile.c
+++ b/usr.sbin/config/mkmakefile.c
@@ -150,9 +150,9 @@ makefile()
perror(line);
exit(1);
}
- ofp = fopen(path("Makefile"), "w");
+ ofp = fopen(path("Makefile.new"), "w");
if (ofp == 0) {
- perror(path("Makefile"));
+ perror(path("Makefile.new"));
exit(1);
}
fprintf(ofp, "KERN_IDENT=%s\n", raise(ident));
@@ -234,6 +234,7 @@ makefile()
}
(void) fclose(ifp);
(void) fclose(ofp);
+ moveifchanged(path("Makefile.new"), path("Makefile"));
#ifdef notyet
if (warn_make_clean) {
printf("WARNING: Unknown options used (not in ../../conf/options or ./options.%s).\n", machinename);
diff --git a/usr.sbin/config/mkswapconf.c b/usr.sbin/config/mkswapconf.c
index 39d964b..1d5756f 100644
--- a/usr.sbin/config/mkswapconf.c
+++ b/usr.sbin/config/mkswapconf.c
@@ -66,6 +66,7 @@ do_swap(fl)
register struct file_list *fl;
{
FILE *fp;
+ char newswapname[80];
char swapname[80];
register struct file_list *swap;
dev_t dev;
@@ -75,9 +76,10 @@ do_swap(fl)
return (fl->f_next);
}
(void) sprintf(swapname, "swap%s.c", fl->f_fn);
- fp = fopen(path(swapname), "w");
+ (void) sprintf(newswapname, "swap%s.c.new", fl->f_fn);
+ fp = fopen(path(newswapname), "w");
if (fp == 0) {
- perror(path(swapname));
+ perror(path(newswapname));
exit(1);
}
fprintf(fp, "#include <sys/param.h>\n");
@@ -90,7 +92,7 @@ do_swap(fl)
*/
swap = fl->f_next;
if (swap == 0 || swap->f_type != SWAPSPEC) {
- (void) unlink(path(swapname));
+ (void) unlink(path(newswapname));
fclose(fp);
return (swap);
}
@@ -107,6 +109,7 @@ do_swap(fl)
fprintf(fp, "\n");
fprintf(fp, "void\nsetconf()\n{\n}\n");
fclose(fp);
+ moveifchanged(path(newswapname), path(swapname));
return (swap);
}
OpenPOWER on IntegriCloud