Comments
Patch
From 4ee0db973995d5a0b6903111e149100f6635df55 Mon Sep 17 00:00:00 2001
From: Stefan Tauner <stefan.tauner@student.tuwien.ac.at>
Date: Fri, 8 Jul 2011 13:27:17 +0200
Subject: [PATCH] warn the user if flashrom is x months old
Signed-off-by: Stefan Tauner <stefan.tauner@student.tuwien.ac.at>
---
Makefile | 10 +++++++++-
flash.h | 3 +++
flashrom.c | 15 +++++++++++++++
3 files changed, 27 insertions(+), 1 deletions(-)
@@ -225,7 +225,14 @@ RELEASE := 0.9.3
VERSION := $(RELEASE)-r$(SVNVERSION)
RELEASENAME ?= $(VERSION)
-SVNDEF := -D'FLASHROM_VERSION="$(VERSION)"'
+# Get the last commit time of the current branch in ISO 8601 format (i.e. "%Y-%m-%dT%H:%M:%S") by...
+# - parsing svn info (ugly)
+# - using git log
+# - using the current date (rationale: last commit was no later than $NOW for sure)
+# - "unknown"
+HEADDATE := $(shell LC_ALL=C svn info --xml --non-interactive 2>/dev/null | grep -oP "(?<=<date>).*()?=</date>" || git log -1 --format="%ci" 2>/dev/null | cut -b 1-19 | tr ' ' T || date +"%Y-%m-%dT%H:%M:%S" 2>/dev/null || echo unknown)
+
+SVNDEF := -D'FLASHROM_VERSION="$(VERSION)"' -D'FLASHROM_HEADDATE="$(HEADDATE)"'
# Always enable internal/onboard support for now.
CONFIG_INTERNAL ?= yes
@@ -600,6 +607,7 @@ export:
@rm -rf $(EXPORTDIR)/flashrom-$(RELEASENAME)
@svn export -r BASE . $(EXPORTDIR)/flashrom-$(RELEASENAME)
@sed "s/^SVNVERSION.*/SVNVERSION := $(SVNVERSION)/" Makefile >$(EXPORTDIR)/flashrom-$(RELEASENAME)/Makefile
+ @sed "s/^HEADDATE.*/HEADDATE := $(HEADDATE)/" Makefile >$(EXPORTDIR)/flashrom-$(RELEASENAME)/Makefile
@LC_ALL=C svn log >$(EXPORTDIR)/flashrom-$(RELEASENAME)/ChangeLog
@echo Exported $(EXPORTDIR)/flashrom-$(RELEASENAME)/
@@ -227,6 +227,9 @@ int write_buf_to_file(unsigned char *buf, unsigned long size, const char *filena
/* Something happened that shouldn't happen, but we can go on */
#define ERROR_NONFATAL 0x100
+/* Number of months before an appeal to upgrade is displayed at runtime */
+#define OLD_MONTHS 0
+
/* cli_output.c */
/* Let gcc and clang check for correct printf-style format strings. */
int print(int type, const char *fmt, ...) __attribute__((format(printf, 2, 3)));
@@ -21,6 +21,7 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
+#define _XOPEN_SOURCE 500
#include <stdio.h>
#include <sys/types.h>
#ifndef __LIBPAYLOAD__
@@ -31,6 +32,7 @@
#include <stdlib.h>
#include <ctype.h>
#include <getopt.h>
+#include <time.h>
#if HAVE_UTSNAME == 1
#include <sys/utsname.h>
#endif
@@ -1681,8 +1683,21 @@ void print_sysinfo(void)
void print_version(void)
{
+ struct tm tm;
+ time_t now = time(NULL);
+ time_t then;
msg_ginfo("flashrom v%s", flashrom_version);
print_sysinfo();
+ if (strptime(FLASHROM_HEADDATE, "%Y-%m-%dT%H:%M:%S", &tm) != NULL &&
+ now != (time_t) -1 && (then = mktime(&tm)) != (time_t) -1 &&
+ difftime(now, then) > OLD_MONTHS * 30*24*60*60) {
+ msg_ginfo("WARNING: This version of flashrom is older than "
+ "%d months (last change date is %s).\n",
+ OLD_MONTHS, FLASHROM_HEADDATE);
+ msg_ginfo("flashrom can be dangerous to use - especially on "
+ "new hardware that was not\navailable back when this version "
+ "was released. Please upgrade!\n");
+ }
}
void print_banner(void)
--
1.7.1