diff --git a/extra/acpi/events/legion_ac b/extra/acpi/events/legion_ac deleted file mode 100644 index 7a73755f..00000000 --- a/extra/acpi/events/legion_ac +++ /dev/null @@ -1,2 +0,0 @@ -event=ac_adapter* -action=/usr/bin/legiond-ctl fanset 3 diff --git a/extra/acpi/events/legion_ppd b/extra/acpi/events/legion_ppd deleted file mode 100644 index 8bee03b3..00000000 --- a/extra/acpi/events/legion_ppd +++ /dev/null @@ -1,2 +0,0 @@ -event=wmi PNP0C14:01 000000e7 00000000 -action=/usr/bin/legiond-ctl fanset diff --git a/extra/service/legiond/README.org b/extra/service/legiond/README.org index 47965b43..6af028aa 100644 --- a/extra/service/legiond/README.org +++ b/extra/service/legiond/README.org @@ -21,8 +21,8 @@ Every power-state/power-profile change will reset the timer. ~legiond-cli~ send request to ~legiond~ via [[https://en.wikipedia.org/wiki/Unix_domain_socket][Unix domain socket]]. -When the power-state or power-profile changed, ~acpid.service~ send a request to ~legiond~ via ~legiond-ctl~. -~legiond~ will call a series of utils after a variable delay(depend on ~legiond-ctl~ arguments). +~legiond~ also check if power-state or power-profile change and automatically load the appropriated fan curve + * Configuration #+begin_src shell sudo cp /usr/share/legion_linux/{*.yaml,legiond.ini} /etc/legion_linux/ diff --git a/extra/service/legiond/legiond.c b/extra/service/legiond/legiond.c index f848afcc..bd9a09fd 100644 --- a/extra/service/legiond/legiond.c +++ b/extra/service/legiond/legiond.c @@ -4,6 +4,8 @@ #include "modules/powerstate.h" #include "modules/output.h" +#define BUF_LEN (10 * (sizeof(struct inotify_event) + NAME_MAX + 1)) + LEGIOND_CONFIG config; int delayed = 0; @@ -46,11 +48,38 @@ void set_timer(struct itimerspec *its, long delay_s, long delay_ns, timer_settime(timerid, 0, its, NULL); } +void* fancurve_change() +{ + char buffer[BUF_LEN]; + struct inotify_event *event = NULL; + + while(1) { + int inotify_fd = inotify_init(); + inotify_add_watch(inotify_fd, profile_path, IN_MODIFY); + inotify_add_watch(inotify_fd, ac_path, IN_MODIFY); + + int lengh = read(inotify_fd, buffer, BUF_LEN); + char* p = buffer; + while(p < buffer + lengh) { + event = (struct inotify_event*)p; + if (event->mask & IN_MODIFY) { + pretty("set_fancurve start"); + set_fancurve(get_powerstate(), &config); + pretty("set_fancurve end"); + } + p += sizeof(struct inotify_event) + event->len; + } + close(inotify_fd); + } + return NULL; +} + int main() { // remove socket before create it clear_socket(); + parseconf(&config); // calculate delay @@ -93,12 +122,17 @@ int main() action.sa_handler = term_handler; sigaction(SIGTERM, &action, NULL); + // powerprofile thread + pthread_t thread_id; + pthread_create(&thread_id, NULL, fancurve_change, NULL); + // listen while (1) { int clientfd = accept(fd, NULL, NULL); char ret[20]; memset(ret, 0, sizeof(ret)); recv(clientfd, ret, sizeof(ret), 0); + printf("cmd: \"%s\" received\n", ret); if (ret[0] == 'A') { // delayed means user use legiond-ctl fanset with a parameter @@ -128,6 +162,7 @@ int main() } else { printf("do nothing\n"); } + close(clientfd); } } diff --git a/extra/service/legiond/public.h b/extra/service/legiond/public.h index 41ee42c2..8b9192e2 100644 --- a/extra/service/legiond/public.h +++ b/extra/service/legiond/public.h @@ -1,13 +1,17 @@ +#include #include #include #include #include #include +#include +#include #include #include #include #include #include +#include const char *socket_path = "/run/legiond.socket"; const double delay = 1.5;