aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKUMAAN <9maaan@gmail.com>2011-08-23 14:53:55 +0900
committermaximilian attems <max@stro.at>2012-05-19 00:25:23 +0200
commit90c0f08093a76c6e65bc0ed1db04e25826b4edfb (patch)
treea8c54df38035ec66a92674852b62c78c511562e3
parent86fd10667397eaaa263c6ccf9f13653b982bd609 (diff)
downloadklibc-90c0f08093a76c6e65bc0ed1db04e25826b4edfb.tar.gz
[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>
-rw-r--r--usr/kinit/ipconfig/main.c12
-rw-r--r--usr/kinit/ipconfig/netdev.h1
2 files changed, 13 insertions, 0 deletions
diff --git a/usr/kinit/ipconfig/main.c b/usr/kinit/ipconfig/main.c
index 37ca5734e6207..215e27c1c2a9f 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 @@ static void dump_device_config(struct netdev *dev)
{
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 @@ static void dump_device_config(struct netdev *dev)
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 postprocess_device(struct netdev *dev)
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 26d076a2fc6c8..9dd8ec5d0664e 100644
--- a/usr/kinit/ipconfig/netdev.h
+++ b/usr/kinit/ipconfig/netdev.h
@@ -41,6 +41,7 @@ struct netdev {
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 */
};