]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
rfkill: inform in syslog when rfkill is invoked
authorSami Kerola <kerolasa@iki.fi>
Sun, 25 Jun 2017 11:12:40 +0000 (12:12 +0100)
committerSami Kerola <kerolasa@iki.fi>
Wed, 30 Aug 2017 19:32:49 +0000 (20:32 +0100)
This should help when trying to explain what or who is flicking wireles on
or off.  Notice that the change is not perfect - if rfkill command is
setting a state that is already set the syslog entry is sent eventhough
there was no effective change.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
sys-utils/rfkill.c

index cf6e7d89caa59850aa339e5dd579bc9f8ece7304..7d059a0ffeb3fa2d210456ea9c8cfae43f2d76e4 100644 (file)
@@ -23,6 +23,7 @@
 #include <libsmartcols.h>
 #include <linux/rfkill.h>
 #include <sys/poll.h>
+#include <sys/syslog.h>
 #include <sys/time.h>
 
 #include "c.h"
@@ -388,6 +389,7 @@ static int rfkill_block(uint8_t block, const char *param)
        };
        ssize_t len;
        int fd;
+       char *message = NULL;
 
        id = rfkill_id_to_type(param);
 
@@ -397,12 +399,15 @@ static int rfkill_block(uint8_t block, const char *param)
                return 1;
        case RFKILL_IS_TYPE:
                event.type = id.type;
+               xasprintf(&message, "type %s", param);
                break;
        case RFKILL_IS_INDEX:
                event.op = RFKILL_OP_CHANGE;
                event.idx = id.index;
+               xasprintf(&message, "id %d", id.index);
                break;
        case RFKILL_IS_ALL:
+               message = xstrdup("all");
                break;
        default:
                abort();
@@ -411,12 +416,17 @@ static int rfkill_block(uint8_t block, const char *param)
        fd = open(_PATH_DEV_RFKILL, O_RDWR);
        if (fd < 0) {
                warn(_("cannot open %s"), _PATH_DEV_RFKILL);
+               free(message);
                return 1;
        }
 
        len = write(fd, &event, sizeof(event));
        if (len < 0)
                warn(_("write failed: %s"), _PATH_DEV_RFKILL);
+       openlog("rfkill", 0, LOG_USER);
+       syslog(LOG_NOTICE, "%s set for %s", block ? "block" : "unblock", message);
+       free(message);
+       closelog();
        return close_fd(fd);
 }