X-Git-Url: https://git.archive.openwrt.org/?p=openwrt.git;a=blobdiff_plain;f=package%2Fnetwork%2Futils%2Frssileds%2Fsrc%2Frssileds.c;h=60d30f13b7d5b2ed68921c8ee61efcc7d5ee4b4e;hp=2f25c846c990b9f07e3c1bac7243d18848fa50b1;hb=c663cbf571aa30e3de7ff7199e03d991f3e8bdbf;hpb=8178ce6c3b3efa008e2c43dbf6b4c59a5ac4bdad diff --git a/package/network/utils/rssileds/src/rssileds.c b/package/network/utils/rssileds/src/rssileds.c index 2f25c846c9..60d30f13b7 100644 --- a/package/network/utils/rssileds/src/rssileds.c +++ b/package/network/utils/rssileds/src/rssileds.c @@ -70,6 +70,32 @@ void log_rules(rule_t *rules) } } +int set_led(struct led *led, unsigned char value) +{ + char buf[8]; + + if ( ! led ) + return -1; + + if ( ! led->controlfd ) + return -1; + + if ( led->state == value ) + return 0; + + snprintf(buf, 8, "%d", value); + + rewind(led->controlfd); + + if ( ! fwrite(buf, sizeof(char), strlen(buf), led->controlfd) ) + return -2; + + fflush(led->controlfd); + led->state=value; + + return 0; +} + int init_led(struct led **led, char *ledname) { struct led *newled; @@ -102,8 +128,15 @@ int init_led(struct led **led, char *ledname) newled->sysfspath = bp; newled->controlfd = bfp; - + *led = newled; + + if ( set_led(newled, 255) ) + goto cleanup_fp; + + if ( set_led(newled, 0) ) + goto cleanup_fp; + return 0; cleanup_fp: @@ -124,29 +157,6 @@ void close_led(struct led **led) (*led)=NULL; } -int set_led(struct led *led, unsigned char value) -{ - char buf[8]; - - if ( ! led ) - return -1; - - if ( ! led->controlfd ) - return -1; - - snprintf(buf, 8, "%d", value); - - rewind(led->controlfd); - - if ( ! fwrite(buf, sizeof(char), strlen(buf), led->controlfd) ) - return -2; - - fflush(led->controlfd); - led->state=value; - - return 0; -} - int quality(const struct iwinfo_ops *iw, const char *ifname) {