summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorMarc Espie <espie@cvs.openbsd.org>2013-05-22 12:14:09 +0000
committerMarc Espie <espie@cvs.openbsd.org>2013-05-22 12:14:09 +0000
commit4be32253d7b9853800c2ef174b980bc4943c564d (patch)
tree2a4c74d92499a34d8761184c3469c704e6496d88 /usr.bin
parent62449f64aaf518f551a453cc5736383f9369a389 (diff)
as checked through thorough tests, youngest->mtime == ctime, so ditch
the extra field. remove some extra abstraction layer: use clock_gettime directly instead of ts_set_from_now (what is "now" anyways) time_to_string takes param by pointer rename "now" into starttime (more accurate term) randomize queue uses arc4random_uniform (prompted by deraadt@) display debug timestamp with ns too (it's debug, so it doesn't really matter whichever way it's done, as long as it's done) okay millert@
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/make/compat.c22
-rw-r--r--usr.bin/make/dir.c9
-rw-r--r--usr.bin/make/dump.c4
-rw-r--r--usr.bin/make/engine.c15
-rw-r--r--usr.bin/make/gnode.h7
-rw-r--r--usr.bin/make/make.c38
-rw-r--r--usr.bin/make/targ.c3
-rw-r--r--usr.bin/make/timestamp.c24
-rw-r--r--usr.bin/make/timestamp.h14
9 files changed, 63 insertions, 73 deletions
diff --git a/usr.bin/make/compat.c b/usr.bin/make/compat.c
index f0f428edc9d..86585e73fb9 100644
--- a/usr.bin/make/compat.c
+++ b/usr.bin/make/compat.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: compat.c,v 1.79 2013/04/23 14:32:53 espie Exp $ */
+/* $OpenBSD: compat.c,v 1.80 2013/05/22 12:14:08 espie Exp $ */
/* $NetBSD: compat.c,v 1.14 1996/11/06 17:59:01 christos Exp $ */
/*
@@ -139,8 +139,8 @@ CompatMake(void *gnp, /* The node to make */
return;
}
- /* All the children were made ok. Now cmtime contains the
- * modification time of the newest child, we need to find out
+ /* All the children were made ok. Now youngest poinst to
+ * the newest child, we need to find out
* if we exist and when we were modified last. The criteria
* for datedness are defined by the Make_OODate function. */
if (DEBUG(MAKE))
@@ -216,18 +216,20 @@ CompatMake(void *gnp, /* The node to make */
* havoc with files that depend on this one.
*/
if (noExecute || is_out_of_date(Dir_MTime(gn)))
- ts_set_from_now(gn->mtime);
- if (is_strictly_before(gn->mtime, gn->cmtime))
- gn->mtime = gn->cmtime;
+ clock_gettime(CLOCK_REALTIME, &gn->mtime);
+ if (is_strictly_before(gn->mtime, gn->youngest->mtime))
+ gn->mtime = gn->youngest->mtime;
if (sib != gn) {
if (noExecute || is_out_of_date(Dir_MTime(sib)))
- ts_set_from_now(sib->mtime);
- if (is_strictly_before(sib->mtime, sib->cmtime))
- sib->mtime = sib->cmtime;
+ clock_gettime(CLOCK_REALTIME,
+ &sib->mtime);
+ if (is_strictly_before(sib->mtime,
+ sib->youngest->mtime))
+ sib->mtime = sib->youngest->mtime;
}
if (DEBUG(MAKE))
printf("update time: %s\n",
- time_to_string(gn->mtime));
+ time_to_string(&gn->mtime));
if (!(gn->type & OP_EXEC)) {
pgn->childMade = true;
Make_TimeStamp(pgn, gn);
diff --git a/usr.bin/make/dir.c b/usr.bin/make/dir.c
index 96cd4e493d0..eac0920b83e 100644
--- a/usr.bin/make/dir.c
+++ b/usr.bin/make/dir.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: dir.c,v 1.62 2013/04/23 14:32:53 espie Exp $ */
+/* $OpenBSD: dir.c,v 1.63 2013/05/22 12:14:08 espie Exp $ */
/* $NetBSD: dir.c,v 1.14 1997/03/29 16:51:26 christos Exp $ */
/*
@@ -570,7 +570,7 @@ Dir_FindFileComplexi(const char *name, const char *ename, Lst path,
* needed, we don't have to fetch it again. */
if (DEBUG(DIR))
printf("Caching %s for %s\n",
- time_to_string(mtime), file);
+ time_to_string(&mtime), file);
record_stamp(file, mtime);
return file;
} else
@@ -614,7 +614,8 @@ Dir_FindFileComplexi(const char *name, const char *ename, Lst path,
ts_set_from_stat(stb, mtime);
if (DEBUG(DIR))
- printf("Caching %s for %s\n", time_to_string(mtime), q);
+ printf("Caching %s for %s\n", time_to_string(&mtime),
+ q);
record_stamp(q, mtime);
return q;
} else {
@@ -724,7 +725,7 @@ Dir_MTime(GNode *gn)
* actually go to the file system. */
if (DEBUG(DIR))
printf("Using cached time %s for %s\n",
- time_to_string(entry->mtime), fullName);
+ time_to_string(&entry->mtime), fullName);
mtime = entry->mtime;
free(entry);
ohash_remove(&mtimes, slot);
diff --git a/usr.bin/make/dump.c b/usr.bin/make/dump.c
index 9819eb06630..1212bff8900 100644
--- a/usr.bin/make/dump.c
+++ b/usr.bin/make/dump.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: dump.c,v 1.4 2013/04/23 14:32:53 espie Exp $ */
+/* $OpenBSD: dump.c,v 1.5 2013/05/22 12:14:08 espie Exp $ */
/*
* Copyright (c) 2012 Marc Espie.
*
@@ -120,7 +120,7 @@ TargPrintNode(GNode *gn, bool full)
if (! (gn->type & (OP_JOIN|OP_USE|OP_EXEC))) {
if (!is_out_of_date(gn->mtime)) {
printf("# last modified %s: %s\n",
- time_to_string(gn->mtime),
+ time_to_string(&gn->mtime),
status_to_string(gn));
} else if (gn->built_status != UNKNOWN) {
printf("# non-existent (maybe): %s\n",
diff --git a/usr.bin/make/engine.c b/usr.bin/make/engine.c
index db585321415..f5ae21da8fa 100644
--- a/usr.bin/make/engine.c
+++ b/usr.bin/make/engine.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: engine.c,v 1.42 2013/05/14 18:47:40 espie Exp $ */
+/* $OpenBSD: engine.c,v 1.43 2013/05/22 12:14:08 espie Exp $ */
/*
* Copyright (c) 2012 Marc Espie.
*
@@ -286,8 +286,7 @@ Job_Touch(GNode *gn)
void
Make_TimeStamp(GNode *parent, GNode *child)
{
- if (is_strictly_before(parent->cmtime, child->mtime)) {
- parent->cmtime = child->mtime;
+ if (is_strictly_before(parent->youngest->mtime, child->mtime)) {
parent->youngest = child;
}
}
@@ -382,7 +381,7 @@ Make_DoAllVar(GNode *gn)
if (child->built_status == MADE)
do_oodate = true;
} else if (is_strictly_before(gn->mtime, child->mtime) ||
- (!is_strictly_before(child->mtime, now) &&
+ (!is_strictly_before(child->mtime, starttime) &&
child->built_status == MADE))
do_oodate = true;
if (do_oodate) {
@@ -446,7 +445,7 @@ Make_OODate(GNode *gn)
if (DEBUG(MAKE)) {
if (!is_out_of_date(gn->mtime))
printf("modified %s...",
- time_to_string(gn->mtime));
+ time_to_string(&gn->mtime));
else
printf("non-existent...");
}
@@ -491,8 +490,8 @@ Make_OODate(GNode *gn)
printf(".EXEC node...");
}
oodate = true;
- } else if (is_strictly_before(gn->mtime, gn->cmtime) ||
- (is_out_of_date(gn->cmtime) &&
+ } else if (is_strictly_before(gn->mtime, gn->youngest->mtime) ||
+ (is_out_of_date(gn->youngest->mtime) &&
(is_out_of_date(gn->mtime) || (gn->type & OP_DOUBLEDEP)))) {
/*
* A node whose modification time is less than that of its
@@ -501,7 +500,7 @@ Make_OODate(GNode *gn)
* or was the object of a :: operator is out-of-date.
*/
if (DEBUG(MAKE)) {
- if (is_strictly_before(gn->mtime, gn->cmtime))
+ if (is_strictly_before(gn->mtime, gn->youngest->mtime))
printf("modified before source(%s)...",
gn->youngest->name);
else if (is_out_of_date(gn->mtime))
diff --git a/usr.bin/make/gnode.h b/usr.bin/make/gnode.h
index 746dfe1c732..2a280abd136 100644
--- a/usr.bin/make/gnode.h
+++ b/usr.bin/make/gnode.h
@@ -1,6 +1,6 @@
#ifndef GNODE_H
#define GNODE_H
-/* $OpenBSD: gnode.h,v 1.25 2013/05/14 18:47:40 espie Exp $ */
+/* $OpenBSD: gnode.h,v 1.26 2013/05/22 12:14:08 espie Exp $ */
/*
* Copyright (c) 2001 Marc Espie.
@@ -37,6 +37,7 @@
#ifndef SYMTABLE_H
#include "symtable.h"
#endif
+#include <assert.h>
/*-
* The structure for an individual graph node. Each node has several
@@ -143,10 +144,8 @@ struct GNode_ {
int unmade; /* The number of unmade children */
struct timespec mtime; /* Its modification time */
- struct timespec cmtime; /* The modification time of its youngest
- * child */
+ GNode *youngest; /* Its youngest child */
- GNode *youngest;
GNode *impliedsrc;
LIST cohorts; /* Other nodes for the :: operator */
LIST parents; /* Nodes that depend on this one */
diff --git a/usr.bin/make/make.c b/usr.bin/make/make.c
index 7ad86885f8e..3b3cb660725 100644
--- a/usr.bin/make/make.c
+++ b/usr.bin/make/make.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: make.c,v 1.66 2013/04/23 14:32:53 espie Exp $ */
+/* $OpenBSD: make.c,v 1.67 2013/05/22 12:14:08 espie Exp $ */
/* $NetBSD: make.c,v 1.10 1996/11/06 17:59:15 christos Exp $ */
/*
@@ -48,9 +48,9 @@
* otherwise.
*
* Make_Update Update all parents of a given child. Performs
- * various bookkeeping chores like the updating
- * of the cmtime field of the parent, filling
- * of the IMPSRC context variable, etc. It will
+ * various bookkeeping chores like finding the
+ * youngest child of the parent, filling
+ * the IMPSRC context variable, etc. It will
* place the parent on the toBeMade queue if it
* should be.
*
@@ -121,22 +121,13 @@ random_setup()
{
randomize_queue = Var_Definedi("RANDOM_ORDER", NULL);
+/* no random delay in the new engine for now */
+#if 0
if (Var_Definedi("RANDOM_DELAY", NULL))
random_delay = strtonum(Var_Value("RANDOM_DELAY"), 0, 1000,
NULL) * 1000000;
+#endif
- if (randomize_queue || random_delay) {
- unsigned int random_seed;
- char *t;
-
- t = Var_Value("RANDOM_SEED");
- if (t != NULL)
- random_seed = strtonum(t, 0, UINT_MAX, NULL);
- else
- random_seed = time(NULL);
- fprintf(stderr, "RANDOM_SEED=%u\n", random_seed);
- srandom(random_seed);
- }
}
static void
@@ -147,7 +138,7 @@ randomize_garray(struct growableArray *g)
GNode *e;
for (i = g->n; i > 0; i--) {
- v = random() % i;
+ v = arc4random_uniform(i);
if (v == i-1)
continue;
else {
@@ -232,12 +223,8 @@ requeue(GNode *gn)
* The unmade field of pgn is decremented and pgn may be placed on
* the toBeMade queue if this field becomes 0.
*
- * If the child was made, the parent's childMade field will be set true
- * and its cmtime set to now.
- *
- * If the child wasn't made, the cmtime field of the parent will be
- * altered if the child's mtime is big enough.
- *
+ * If the child was made, the parent's childMade field will be set to
+ * true
*-----------------------------------------------------------------------
*/
void
@@ -267,9 +254,10 @@ Make_Update(GNode *cgn) /* the child node */
* on this one.
*/
if (noExecute || is_out_of_date(Dir_MTime(cgn)))
- ts_set_from_now(cgn->mtime);
+ clock_gettime(CLOCK_REALTIME, &cgn->mtime);
if (DEBUG(MAKE))
- printf("update time: %s\n", time_to_string(cgn->mtime));
+ printf("update time: %s\n",
+ time_to_string(&cgn->mtime));
}
requeue(cgn);
diff --git a/usr.bin/make/targ.c b/usr.bin/make/targ.c
index e348095878b..8c797866148 100644
--- a/usr.bin/make/targ.c
+++ b/usr.bin/make/targ.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: targ.c,v 1.71 2013/05/14 18:47:40 espie Exp $ */
+/* $OpenBSD: targ.c,v 1.72 2013/05/22 12:14:08 espie Exp $ */
/* $NetBSD: targ.c,v 1.11 1997/02/20 16:51:50 christos Exp $ */
/*
@@ -158,7 +158,6 @@ Targ_NewGNi(const char *name, const char *ename)
gn->childMade = false;
gn->order = 0;
ts_set_out_of_date(gn->mtime);
- ts_set_out_of_date(gn->cmtime);
gn->youngest = gn;
Lst_Init(&gn->cohorts);
Lst_Init(&gn->parents);
diff --git a/usr.bin/make/timestamp.c b/usr.bin/make/timestamp.c
index e00723a6fc8..ad1a282880e 100644
--- a/usr.bin/make/timestamp.c
+++ b/usr.bin/make/timestamp.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: timestamp.c,v 1.9 2013/04/23 14:32:53 espie Exp $ */
+/* $OpenBSD: timestamp.c,v 1.10 2013/05/22 12:14:08 espie Exp $ */
/*
* Copyright (c) 2001 Marc Espie.
@@ -25,12 +25,14 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/time.h>
+#include <stdio.h>
+#include <string.h>
#include "config.h"
#include "defines.h"
#include "timestamp.h"
-struct timespec now; /* The time at the start of this whole process */
+struct timespec starttime;
int
set_times(const char *f)
@@ -38,17 +40,21 @@ set_times(const char *f)
return utimes(f, NULL);
}
+#define PLACEHOLDER "XXXXXXXXX "
char *
-time_to_string(struct timespec time)
+time_to_string(struct timespec *t)
{
struct tm *parts;
static char buf[128];
- time_t t;
-
- t = timestamp2time_t(time);
-
- parts = localtime(&t);
- strftime(buf, sizeof buf, "%H:%M:%S %b %d, %Y", parts);
+ char *s;
+
+ parts = localtime(&t->tv_sec);
+ strftime(buf, sizeof buf, "%H:%M:%S." PLACEHOLDER "%b %d, %Y", parts);
+ s = strstr(buf, PLACEHOLDER);
+ if (s) {
+ snprintf(s, sizeof(PLACEHOLDER), "%09ld", t->tv_nsec);
+ s[9] = ' ';
+ }
buf[sizeof(buf) - 1] = '\0';
return buf;
}
diff --git a/usr.bin/make/timestamp.h b/usr.bin/make/timestamp.h
index e883aa46fe9..b64320bd7ca 100644
--- a/usr.bin/make/timestamp.h
+++ b/usr.bin/make/timestamp.h
@@ -1,7 +1,7 @@
#ifndef TIMESTAMP_H
#define TIMESTAMP_H
-/* $OpenBSD: timestamp.h,v 1.9 2013/04/23 14:32:53 espie Exp $ */
+/* $OpenBSD: timestamp.h,v 1.10 2013/05/22 12:14:08 espie Exp $ */
/*
* Copyright (c) 2001 Marc Espie.
@@ -36,16 +36,14 @@
* ts_set_from_stat(s, t): grab date out of stat(2) buffer.
* b = is_strictly_before(t1, t2):
* check whether t1 is before t2.
- * stamp = timestamp2time_t(t): extract time_t from timestamp.
* ts_set_from_time_t(d, t): create timestamp from time_t.
- * ts_set_from_now(n): grab current date.
*/
/* sysresult = set_times(name): set modification times on a file.
* system call results.
*/
-#define Init_Timestamp() ts_set_from_now(now)
+#define Init_Timestamp() clock_gettime(CLOCK_REALTIME, &starttime)
#define TMIN (sizeof(time_t) == sizeof(int32_t) ? INT32_MIN : INT64_MIN)
#define ts_set_out_of_date(t) (t).tv_sec = TMIN, (t).tv_nsec = 0
@@ -66,14 +64,12 @@ do { \
if (is_out_of_date(t)) \
(t).tv_nsec++; \
} while (0)
-#define ts_set_from_now(n) clock_gettime(CLOCK_REALTIME, &(n))
-#define timestamp2time_t(t) ((t).tv_sec)
extern int set_times(const char *);
-extern struct timespec now; /* The time at the start of this whole
- * process */
-extern char *time_to_string(struct timespec t);
+extern struct timespec starttime; /* The time at the start
+ * of this whole process */
+extern char *time_to_string(struct timespec *);
#endif