diff options
author | Sami Kerola | 2017-06-25 13:12:40 +0200 |
---|---|---|
committer | Sami Kerola | 2017-08-30 21:32:49 +0200 |
commit | fd3d4ec71097451c4d1bdc673dae3dc896520fcb (patch) | |
tree | 42efe253049bb2305ec1e58ae84e0c4a5fb9ac8a /sys-utils/rfkill.c | |
parent | rfkill: use human readable timestamps in event output (diff) | |
download | kernel-qcow2-util-linux-fd3d4ec71097451c4d1bdc673dae3dc896520fcb.tar.gz kernel-qcow2-util-linux-fd3d4ec71097451c4d1bdc673dae3dc896520fcb.tar.xz kernel-qcow2-util-linux-fd3d4ec71097451c4d1bdc673dae3dc896520fcb.zip |
rfkill: inform in syslog when rfkill is invoked
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>
Diffstat (limited to 'sys-utils/rfkill.c')
-rw-r--r-- | sys-utils/rfkill.c | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/sys-utils/rfkill.c b/sys-utils/rfkill.c index cf6e7d89c..7d059a0ff 100644 --- a/sys-utils/rfkill.c +++ b/sys-utils/rfkill.c @@ -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); } |