|
|
bdf832 |
From bb9970a9df95837e39d680021b1f73d231e85406 Mon Sep 17 00:00:00 2001
|
|
|
bdf832 |
From: Stephen Hemminger <shemminger@vyatta.com>
|
|
|
bdf832 |
Date: Tue, 3 May 2011 09:52:43 -0700
|
|
|
bdf832 |
Subject: [PATCH 3/3] Check error returns from write to sysfs
|
|
|
bdf832 |
|
|
|
bdf832 |
Add helper function to check write to sysfs files.
|
|
|
bdf832 |
|
|
|
bdf832 |
Signed-off-by: Petr Sabata <contyk@redhat.com>
|
|
|
bdf832 |
---
|
|
|
bdf832 |
libbridge/libbridge_devif.c | 37 +++++++++++++++++++++++--------------
|
|
|
bdf832 |
1 files changed, 23 insertions(+), 14 deletions(-)
|
|
|
bdf832 |
|
|
|
bdf832 |
diff --git a/libbridge/libbridge_devif.c b/libbridge/libbridge_devif.c
|
|
|
bdf832 |
index aa8bc36..1e83925 100644
|
|
|
bdf832 |
--- a/libbridge/libbridge_devif.c
|
|
|
bdf832 |
+++ b/libbridge/libbridge_devif.c
|
|
|
bdf832 |
@@ -280,25 +280,38 @@ fallback:
|
|
|
bdf832 |
return old_get_port_info(brname, port, info);
|
|
|
bdf832 |
}
|
|
|
bdf832 |
|
|
|
bdf832 |
+static int set_sysfs(const char *path, unsigned long value)
|
|
|
bdf832 |
+{
|
|
|
bdf832 |
+ int fd, ret = 0, cc;
|
|
|
bdf832 |
+ char buf[32];
|
|
|
bdf832 |
+
|
|
|
bdf832 |
+ fd = open(path, O_WRONLY);
|
|
|
bdf832 |
+ if (fd < 0)
|
|
|
bdf832 |
+ return -1;
|
|
|
bdf832 |
+
|
|
|
bdf832 |
+ cc = snprintf(buf, sizeof(buf), "%lu\n", value);
|
|
|
bdf832 |
+ if (write(fd, buf, cc) < 0)
|
|
|
bdf832 |
+ ret = -1;
|
|
|
bdf832 |
+ close(fd);
|
|
|
bdf832 |
+
|
|
|
bdf832 |
+ return ret;
|
|
|
bdf832 |
+}
|
|
|
bdf832 |
+
|
|
|
bdf832 |
|
|
|
bdf832 |
static int br_set(const char *bridge, const char *name,
|
|
|
bdf832 |
unsigned long value, unsigned long oldcode)
|
|
|
bdf832 |
{
|
|
|
bdf832 |
int ret;
|
|
|
bdf832 |
char path[SYSFS_PATH_MAX];
|
|
|
bdf832 |
- FILE *f;
|
|
|
bdf832 |
|
|
|
bdf832 |
- snprintf(path, SYSFS_PATH_MAX, SYSFS_CLASS_NET "%s/%s", bridge, name);
|
|
|
bdf832 |
+ snprintf(path, SYSFS_PATH_MAX, SYSFS_CLASS_NET "%s/bridge/%s",
|
|
|
bdf832 |
+ bridge, name);
|
|
|
bdf832 |
|
|
|
bdf832 |
- f = fopen(path, "w");
|
|
|
bdf832 |
- if (f) {
|
|
|
bdf832 |
- ret = fprintf(f, "%ld\n", value);
|
|
|
bdf832 |
- fclose(f);
|
|
|
bdf832 |
- } else {
|
|
|
bdf832 |
+ if ((ret = set_sysfs(path, value)) < 0) {
|
|
|
bdf832 |
/* fallback to old ioctl */
|
|
|
bdf832 |
struct ifreq ifr;
|
|
|
bdf832 |
unsigned long args[4] = { oldcode, value, 0, 0 };
|
|
|
bdf832 |
-
|
|
|
bdf832 |
+
|
|
|
bdf832 |
strncpy(ifr.ifr_name, bridge, IFNAMSIZ);
|
|
|
bdf832 |
ifr.ifr_data = (char *) &arg;;
|
|
|
bdf832 |
ret = ioctl(br_socket_fd, SIOCDEVPRIVATE, &ifr);
|
|
|
bdf832 |
@@ -348,14 +361,10 @@ static int port_set(const char *bridge, const char *ifname,
|
|
|
bdf832 |
{
|
|
|
bdf832 |
int ret;
|
|
|
bdf832 |
char path[SYSFS_PATH_MAX];
|
|
|
bdf832 |
- FILE *f;
|
|
|
bdf832 |
|
|
|
bdf832 |
snprintf(path, SYSFS_PATH_MAX, SYSFS_CLASS_NET "%s/brport/%s", ifname, name);
|
|
|
bdf832 |
- f = fopen(path, "w");
|
|
|
bdf832 |
- if (f) {
|
|
|
bdf832 |
- ret = fprintf(f, "%ld\n", value);
|
|
|
bdf832 |
- fclose(f);
|
|
|
bdf832 |
- } else {
|
|
|
bdf832 |
+
|
|
|
bdf832 |
+ if ((ret = set_sysfs(path, value)) < 0) {
|
|
|
bdf832 |
int index = get_portno(bridge, ifname);
|
|
|
bdf832 |
|
|
|
bdf832 |
if (index < 0)
|
|
|
bdf832 |
--
|
|
|
bdf832 |
1.7.5.2
|
|
|
bdf832 |
|