From 4723f7e4a720af17a9dde25c9c2046159eee5fe9 Mon Sep 17 00:00:00 2001 From: "Carsten Haitzler (Rasterman)" Date: Thu, 17 May 2018 03:13:58 +0900 Subject: [PATCH] add rfkill actions to sysactions.conf - necessary for bluez so bluez itself wont go rfkill block or unblock the bt device. you have to rfkill unblock separately if it's blocked. this is needed to make bluez at a minimum work right. possibly should be added to connman too. but this is the first step. --- data/etc/sysactions.conf.in | 2 + src/bin/e_sys_main.c | 76 ++++++++++++++++++++++++++++++++++--- 2 files changed, 73 insertions(+), 5 deletions(-) diff --git a/data/etc/sysactions.conf.in b/data/etc/sysactions.conf.in index bcbd032c4..4b799679c 100644 --- a/data/etc/sysactions.conf.in +++ b/data/etc/sysactions.conf.in @@ -51,6 +51,8 @@ action: /bin/mount @MOUNT@ action: /bin/umount @UMOUNT@ action: /usr/bin/eject @EJECT@ action: l2ping /usr/bin/l2ping +action: rfkill-unblock /bin/rfkill unblock +action: rfkill-block /bin/rfkill block # root is allowed to do anything - but it needs to be here explicitly anyway user: root allow: * diff --git a/src/bin/e_sys_main.c b/src/bin/e_sys_main.c index e5e4e7a7a..fee9ae97a 100644 --- a/src/bin/e_sys_main.c +++ b/src/bin/e_sys_main.c @@ -66,6 +66,7 @@ main(int argc, Eina_Bool mnt = EINA_FALSE; const char *act = NULL; #endif + Eina_Bool rfkill = EINA_FALSE; gid_t gid, gl[65536], egid; for (i = 1; i < argc; i++) @@ -88,11 +89,23 @@ main(int argc, test = 1; action = argv[2]; } - else if (!strcmp(argv[1], "l2ping")) - { - action = argv[1]; - output = argv[2]; - } + else if (!strcmp(argv[1], "l2ping")) + { + action = argv[1]; + output = argv[2]; + } + else if (!strcmp(argv[1], "rfkill-unblock")) + { + rfkill = EINA_TRUE; + action = argv[1]; + output = argv[2]; + } + else if (!strcmp(argv[1], "rfkill-block")) + { + rfkill = EINA_TRUE; + action = argv[1]; + output = argv[2]; + } #ifdef HAVE_EEZE_MOUNT else { @@ -282,6 +295,59 @@ main(int argc, putenv("PATH=/bin:/usr/bin:/sbin:/usr/sbin"); putenv("IFS= \t\n"); + if ((!test) && (rfkill)) + { + Eina_Strbuf *buf = NULL; + const char *s; + + buf = eina_strbuf_new(); + if (!buf) exit(30); + for (s = output; *s; s++) + { + if (!(((*s >= 'a') && (*s <= 'z')) || + ((*s >= 'A') && (*s <= 'Z')) || + ((*s >= '0') && (*s <= '9')) || + (*s == '-') || (*s == '+') || (*s == ',') || (*s == '.') || + (*s == '/') || (*s == ':') || (*s == '=') || (*s == '@') || + (*s == '^'))) + break; + } + if (*s == 0) + { + char *rfk = strdup(cmd); + if (rfk) + { + char *pc = strchr(rfk, ' '); + if (pc) + { + *pc = 0; + FILE *p = popen(rfk, "r"); + if (p) + { + char lin[1024]; + char dev[1024]; + int id = -1; + + while (fgets(lin, sizeof(lin), p)) + { + lin[sizeof(lin) - 1] = 0; + if (sscanf(lin, "%i %*s %s %*s %*s", &id, dev) != 2) + id = -1; + else + { + if (!strcmp(dev, output)) break; + } + } + pclose(p); + eina_strbuf_append_printf(buf, "%s %i", cmd, id); + return system(eina_strbuf_string_get(buf)); + } + } + } + } + exit(30); + } + if ((!test) #ifdef HAVE_EEZE_MOUNT && (!mnt)