1 commit bb9970a9df95837e39d680021b1f73d231e85406
2 Author: Stephen Hemminger <shemminger@vyatta.com>
3 Date: Tue May 3 09:52:43 2011 -0700
5 Check error returns from write to sysfs
7 Add helper function to check write to sysfs files.
9 Fix incorrect sysfs path in br_set.
11 [Thomas De Schampheleire: update commit message only]
12 Signed-off-by: Thomas De Schampheleire <thomas.de.schampheleire@gmail.com>
14 diff --git a/libbridge/libbridge_devif.c b/libbridge/libbridge_devif.c
15 index aa8bc36..1e83925 100644
16 --- a/libbridge/libbridge_devif.c
17 +++ b/libbridge/libbridge_devif.c
18 @@ -280,25 +280,38 @@ fallback:
19 return old_get_port_info(brname, port, info);
22 +static int set_sysfs(const char *path, unsigned long value)
24 + int fd, ret = 0, cc;
27 + fd = open(path, O_WRONLY);
31 + cc = snprintf(buf, sizeof(buf), "%lu\n", value);
32 + if (write(fd, buf, cc) < 0)
40 static int br_set(const char *bridge, const char *name,
41 unsigned long value, unsigned long oldcode)
44 char path[SYSFS_PATH_MAX];
47 - snprintf(path, SYSFS_PATH_MAX, SYSFS_CLASS_NET "%s/%s", bridge, name);
48 + snprintf(path, SYSFS_PATH_MAX, SYSFS_CLASS_NET "%s/bridge/%s",
51 - f = fopen(path, "w");
53 - ret = fprintf(f, "%ld\n", value);
56 + if ((ret = set_sysfs(path, value)) < 0) {
57 /* fallback to old ioctl */
59 unsigned long args[4] = { oldcode, value, 0, 0 };
62 strncpy(ifr.ifr_name, bridge, IFNAMSIZ);
63 ifr.ifr_data = (char *) &args;
64 ret = ioctl(br_socket_fd, SIOCDEVPRIVATE, &ifr);
65 @@ -348,14 +361,10 @@ static int port_set(const char *bridge, const char *ifname,
68 char path[SYSFS_PATH_MAX];
71 snprintf(path, SYSFS_PATH_MAX, SYSFS_CLASS_NET "%s/brport/%s", ifname, name);
72 - f = fopen(path, "w");
74 - ret = fprintf(f, "%ld\n", value);
78 + if ((ret = set_sysfs(path, value)) < 0) {
79 int index = get_portno(bridge, ifname);