bridge-utils: add upstream patch fixing sysfs writes
[buildroot-gz.git] / package / bridge-utils / 0003-sysfs-write-fixes.patch
bloba7ff1979f5e823d8f2ad2040f1ee8c77e9039921
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;
25 + char buf[32];
27 + fd = open(path, O_WRONLY);
28 + if (fd < 0)
29 + return -1;
31 + cc = snprintf(buf, sizeof(buf), "%lu\n", value);
32 + if (write(fd, buf, cc) < 0)
33 + ret = -1;
34 + close(fd);
36 + return ret;
40 static int br_set(const char *bridge, const char *name,
41 unsigned long value, unsigned long oldcode)
43 int ret;
44 char path[SYSFS_PATH_MAX];
45 - FILE *f;
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",
49 + bridge, name);
51 - f = fopen(path, "w");
52 - if (f) {
53 - ret = fprintf(f, "%ld\n", value);
54 - fclose(f);
55 - } else {
56 + if ((ret = set_sysfs(path, value)) < 0) {
57 /* fallback to old ioctl */
58 struct ifreq ifr;
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,
67 int ret;
68 char path[SYSFS_PATH_MAX];
69 - FILE *f;
71 snprintf(path, SYSFS_PATH_MAX, SYSFS_CLASS_NET "%s/brport/%s", ifname, name);
72 - f = fopen(path, "w");
73 - if (f) {
74 - ret = fprintf(f, "%ld\n", value);
75 - fclose(f);
76 - } else {
78 + if ((ret = set_sysfs(path, value)) < 0) {
79 int index = get_portno(bridge, ifname);
81 if (index < 0)