Patchwork warn the user if flashrom is x months old

login
register
about
Submitter Stefan Tauner
Date 2011-07-08 11:35:23
Message ID <201107081135.p68BZQDb010778@mail2.student.tuwien.ac.at>
Download mbox | patch
Permalink /patch/3259/
State Bitrotted
Headers show

Comments

Stefan Tauner - 2011-07-08 11:35:23
i had the idea to implement an expiration date for flashrom binaries
(i.e. a time bomb). in the case distributions ship ancient binaries
(in the future) this may save a bunch of hardware.

i noted two reactions back then when i proposed this idea on IRC in my
todo.txt:
 <twice11> If I validated software to work on some system, I don't want
 it to suddenly break one year later.
 <agaran> twice11: but kind notify that version you use is %d days old
 (and repeated every multiple of time or 100days or so) could be nice

this proof of concept is probably not mergeable - especially the
strptime() might be a problem (alternatives welcome), but i still think
it is worth to think about something like this. comments?
Carl-Daniel Hailfinger - 2011-07-08 17:12:11
Am 08.07.2011 13:35 schrieb Stefan Tauner:
> i had the idea to implement an expiration date for flashrom binaries
> (i.e. a time bomb). in the case distributions ship ancient binaries
> (in the future) this may save a bunch of hardware.
>
> i noted two reactions back then when i proposed this idea on IRC in my
> todo.txt:
>  <twice11> If I validated software to work on some system, I don't want
>  it to suddenly break one year later.
>  <agaran> twice11: but kind notify that version you use is %d days old
>  (and repeated every multiple of time or 100days or so) could be nice
>
> this proof of concept is probably not mergeable - especially the
> strptime() might be a problem (alternatives welcome), but i still think
> it is worth to think about something like this. comments?
>   

Good idea, but we will have to make sure this won't cause problems for
users of live CDs and FreeDOS distributions etc...

Regards,
Carl-Daniel
Bernd Blaauw - 2011-07-08 17:25:05
Op 8-7-2011 19:12, Carl-Daniel Hailfinger schreef:
> Am 08.07.2011 13:35 schrieb Stefan Tauner:
> Good idea, but we will have to make sure this won't cause problems for
> users of live CDs and FreeDOS distributions etc...

What is the warning you want to give out, in which situations/conditions 
and is there any way/option/parameter to override it on the commandline 
in a automated/scripted way?

flashrom -r bios.bin -usingoutdatedversionatmyownrisk

So, does it make sense to warn if all operations already succeed?
If reads even already fail, then upgrading definately is in order, 
hoping flashrom code has progressed far enough meanwhile to succesfully 
perform the read.
Carl-Daniel Hailfinger - 2011-07-08 21:49:59
Am 08.07.2011 19:25 schrieb Bernd Blaauw:
> Op 8-7-2011 19:12, Carl-Daniel Hailfinger schreef:
>> Am 08.07.2011 13:35 schrieb Stefan Tauner:
>> Good idea, but we will have to make sure this won't cause problems for
>> users of live CDs and FreeDOS distributions etc...
>
> What is the warning you want to give out, in which
> situations/conditions and is there any way/option/parameter to
> override it on the commandline in a automated/scripted way?

Uh oh, not what I meant.

A warning message is OK under certain circumstances. Changing program
behaviour is NOT OK (and will be vetoed).

That said, you're right that a warning message for a perfectly working
flashrom does not really make sense. OTOH, warning the user before
he/she trashes the system is a good idea, and that is best done during
read, not only if everything already failed.

Regards,
Carl-Daniel

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(-)

diff --git a/Makefile b/Makefile
index a35df06..c77fcbe 100644
--- a/Makefile
+++ b/Makefile
@@ -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)/
 
diff --git a/flash.h b/flash.h
index 9c6d535..4d47e48 100644
--- a/flash.h
+++ b/flash.h
@@ -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)));
diff --git a/flashrom.c b/flashrom.c
index d5892ca..6a24306 100644
--- a/flashrom.c
+++ b/flashrom.c
@@ -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