[klibc] ipconfig: Write $UPTIME as uptime

This patch stores uptime value of sysinfo when ipconfig configured $DEVICE,
and writes $UPTIME as the value to /tmp/net-$DEVICE.conf file.

For example, $UPTIME is equal to '1' which means one second.

Later, other scripts which source the file can calculate the time
when ipconfig configured a $DEVICE . Since the clock of uptime is not
adjusted until reboot, it is useful, while system clock may be
adjusted by some programs like ntpdate or hwclock before other scripts
source the file.

Signed-off-by: KUMAAN <9maaan@gmail.com>
Acked-by: H. Peter Anvin <hpa@linux.intel.com>
[ minor style fix ]
Signed-off-by: maximilian attems <max@stro.at>
diff --git a/usr/kinit/ipconfig/main.c b/usr/kinit/ipconfig/main.c
index 37ca573..215e27c 100644
--- a/usr/kinit/ipconfig/main.c
+++ b/usr/kinit/ipconfig/main.c
@@ -8,6 +8,7 @@
 #include <arpa/inet.h>
 #include <sys/types.h>
 #include <sys/time.h>
+#include <sys/sysinfo.h>
 #include <dirent.h>
 #include <fcntl.h>
 #include <unistd.h>		/* for getopts */
@@ -123,6 +124,11 @@
 {
 	char fn[40];
 	FILE *f;
+	/*
+	 * char UINT64_MAX[] = "18446744073709551615";
+	 * sizeof(UINT64_MAX)==21
+	 */
+	char buf21[21];
 
 	snprintf(fn, sizeof(fn), "/tmp/net-%s.conf", dev->name);
 	f = fopen(fn, "w");
@@ -147,6 +153,8 @@
 				my_inet_ntoa(dev->ip_server));
 		write_option(f, "ROOTPATH", dev->bootpath);
 		write_option(f, "filename", dev->filename);
+		sprintf(buf21, "%ld", (long)dev->uptime);
+		write_option(f, "UPTIME", buf21);
 		fclose(f);
 	}
 }
@@ -180,6 +188,10 @@
 
 static void complete_device(struct netdev *dev)
 {
+	struct sysinfo info;
+
+	if (!sysinfo(&info))
+		dev->uptime = info.uptime;
 	postprocess_device(dev);
 	configure_device(dev);
 	dump_device_config(dev);
diff --git a/usr/kinit/ipconfig/netdev.h b/usr/kinit/ipconfig/netdev.h
index 26d076a..9dd8ec5 100644
--- a/usr/kinit/ipconfig/netdev.h
+++ b/usr/kinit/ipconfig/netdev.h
@@ -41,6 +41,7 @@
 	char nisdomainname[SYS_NMLN];	/* nis domain name      */
 	char bootpath[BPLEN];	/* boot path            */
 	char filename[FNLEN];   /* filename             */
+	long uptime;		/* when complete configuration */
 	struct netdev *next;	/* next configured i/f  */
 };