projects
/
project
/
netifd.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
fcbec58
)
add mac address to device info
author
Felix Fietkau
<nbd@openwrt.org>
Thu, 19 Jan 2012 16:38:01 +0000
(17:38 +0100)
committer
Felix Fietkau
<nbd@openwrt.org>
Thu, 19 Jan 2012 23:01:40 +0000
(
00:01
+0100)
system-linux.c
patch
|
blob
|
history
diff --git
a/system-linux.c
b/system-linux.c
index
f2ee10a
..
1fcf22f
100644
(file)
--- a/
system-linux.c
+++ b/
system-linux.c
@@
-640,24
+640,28
@@
system_if_get_parent(struct device *dev)
}
static bool
}
static bool
-read_
int_file(int dir_fd, const char *file, int *val
)
+read_
string_file(int dir_fd, const char *file, char *buf, int len
)
{
{
- char buf[64];
- int len, fd;
bool ret = false;
bool ret = false;
+ char *c;
+ int fd;
fd = openat(dir_fd, file, O_RDONLY);
if (fd < 0)
return false;
retry:
fd = openat(dir_fd, file, O_RDONLY);
if (fd < 0)
return false;
retry:
- len = read(fd, buf,
sizeof(buf)
);
+ len = read(fd, buf,
len - 1
);
if (len < 0) {
if (errno == EINTR)
goto retry;
} else if (len > 0) {
buf[len] = 0;
if (len < 0) {
if (errno == EINTR)
goto retry;
} else if (len > 0) {
buf[len] = 0;
- *val = strtoul(buf, NULL, 0);
+
+ c = strchr(buf, '\n');
+ if (c)
+ *c = 0;
+
ret = true;
}
ret = true;
}
@@
-666,6
+670,19
@@
retry:
return ret;
}
return ret;
}
+static bool
+read_int_file(int dir_fd, const char *file, int *val)
+{
+ char buf[64];
+ bool ret = false;
+
+ ret = read_string_file(dir_fd, file, buf, sizeof(buf));
+ if (ret)
+ *val = strtoul(buf, NULL, 0);
+
+ return ret;
+}
+
int
system_if_dump_info(struct device *dev, struct blob_buf *b)
{
int
system_if_dump_info(struct device *dev, struct blob_buf *b)
{
@@
-677,6
+694,8
@@
system_if_dump_info(struct device *dev, struct blob_buf *b)
if (read_int_file(dir_fd, "carrier", &val))
blobmsg_add_u8(b, "link", !!val);
if (read_int_file(dir_fd, "carrier", &val))
blobmsg_add_u8(b, "link", !!val);
+ if (read_string_file(dir_fd, "address", buf, sizeof(buf)))
+ blobmsg_add_string(b, "macaddr", buf);
close(dir_fd);
return 0;
close(dir_fd);
return 0;