From fd3d4ec71097451c4d1bdc673dae3dc896520fcb Mon Sep 17 00:00:00 2001 From: Sami Kerola Date: Sun, 25 Jun 2017 12:12:40 +0100 Subject: [PATCH] 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 --- sys-utils/rfkill.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/sys-utils/rfkill.c b/sys-utils/rfkill.c index cf6e7d89ca..7d059a0ffe 100644 --- a/sys-utils/rfkill.c +++ b/sys-utils/rfkill.c @@ -23,6 +23,7 @@ #include #include #include +#include #include #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); } -- 2.47.3