shithub: riscv

Download patch

ref: c06e464ec45dd5880850fa60c850498861c514d3
parent: c823f136df8d3fcfea6adfc6e87924357dacf3c8
author: cinap_lenrek <[email protected]>
date: Fri Sep 11 23:58:46 EDT 2015

cwfs: initialize /env/timezone on boot so dumps are in localtime

when /env/timezone file is missing (boot case), copy /adm/timezone/local
to /env/timezone so localtime() can correct timezone offset.

--- a/sys/src/cmd/cwfs/con.c
+++ b/sys/src/cmd/cwfs/con.c
@@ -7,6 +7,7 @@
 
 static	void	consserve1(void *);
 static	void	installcmds(void);
+static	void	tzinit(char*);
 
 void
 consserve(void)
@@ -599,6 +600,7 @@
 static void
 cmd_version(int, char *[])
 {
+	tzinit("/adm/timezone/local");
 	print("%d-bit %s as of %T\n", sizeof(Off)*8 - 1, service, fs_mktime);
 	print("\tlast boot %T\n", boottime);
 }
@@ -678,6 +680,28 @@
 		return;
 	}
 }
+
+static void
+tzinit(char *file)
+{
+	char buf[1024];
+	Off o;
+	int f, n;
+
+	f = create("#e/timezone", OEXCL|OWRITE, 0666);
+	if(f < 0)
+		return;
+	if(walkto(file) || con_open(FID2, 0)) {
+		print("tzinit: cannot access %s\n", file);
+		close(f);
+		remove("#e/timezone");
+		return;
+	}
+	for(o = 0; (n = con_read(FID2, buf, o, sizeof(buf))) > 0; o += n)
+		write(f, buf, n);
+	close(f);
+}
+
 
 static void
 cmd_time(int argc, char *argv[])