From 47fa707d46e2887e04e63270e7696e57fff96f37 Mon Sep 17 00:00:00 2001 From: Madeleine <32415621+SpyHoodle@users.noreply.github.com> Date: Sat, 8 Jan 2022 17:15:46 +0000 Subject: [PATCH] Add files via upload --- LICENSE | 339 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ Makefile | 19 +++ config.h | 10 ++ dwmblocks | Bin 0 -> 22184 bytes main.c | 280 ++++++++++++++++++++++++++++++++++++++++++++ main.o | Bin 0 -> 13896 bytes 6 files changed, 648 insertions(+) create mode 100644 LICENSE create mode 100644 Makefile create mode 100644 config.h create mode 100644 dwmblocks create mode 100644 main.c create mode 100644 main.o diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..d159169 --- /dev/null +++ b/LICENSE @@ -0,0 +1,339 @@ + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Lesser General Public License instead.) You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) year name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + , 1 April 1989 + Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..99db3d6 --- /dev/null +++ b/Makefile @@ -0,0 +1,19 @@ +.POSIX: + +PREFIX = /usr/local +CC = gcc + +dwmblocks: main.o + $(CC) main.o -lX11 -Ofast -o dwmblocks +main.o: main.c config.h + $(CC) -Ofast -c main.c +clean: + rm -f *.o *.gch dwmblocks +install: dwmblocks + mkdir -p $(DESTDIR)$(PREFIX)/bin + cp -f dwmblocks $(DESTDIR)$(PREFIX)/bin + chmod 755 $(DESTDIR)$(PREFIX)/bin/dwmblocks +uninstall: + rm -f $(DESTDIR)$(PREFIX)/bin/dwmblocks + +.PHONY: clean install uninstall diff --git a/config.h b/config.h new file mode 100644 index 0000000..55772eb --- /dev/null +++ b/config.h @@ -0,0 +1,10 @@ +#define CMDLENGTH 50 +#define DELIMITER " | " + +const Block blocks[] = { + BLOCK("sb-volume", 0, 5) + BLOCK("sb-disk", 5, 20) + BLOCK("sb-memory", 5, 18) + BLOCK("sb-cpu", 5, 19) + BLOCK("sb-clock", 1, 21) +}; diff --git a/dwmblocks b/dwmblocks new file mode 100644 index 0000000000000000000000000000000000000000..a6fc15b470263e95b2152e4b5c1bdbd758e0c226 GIT binary patch literal 22184 zcmeHPdw5gFl^@AA7z~miKpjGYLPcYeU~FE2fE&v;_H`nI1BTG@5Jr}^oogKJ$d#Oq$_#s#~eoBJ?t;9X6@h`QNLtU-n+O>3`E-z0m6r4rS8aq8~}A z4=Q&*Ff75iouPw59`sR6ar_Y^T+#V>N z$z347?D)|1*DPL+J!9%2Yy>`3%z~HpsEvFgp5&=e$VK;@I>1xAKF+PEF-91b*SxQ^ z>b1fDJ_mU0AWdY?J_x=I*kJP2S@2;nG?;v27X0BX_@i0yjx6}GEdIQZ1;3C5-;o7> zGYfuG7Jt5(Mc$T0{-Z4NZCT_uWWj%&#m?PX@QGRMoXR49J#afdnPm%r!RCE>7WTww#K$VyWi^#GF|K5 zMqik<`!=*S`dM=z1Qp+gU?|{eZEWAjZ8dr}k|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|Rk|s#|h@ZofhSDi7X#gv3-_jaxTn`!!>9j@G zd~JwSkQKKD!rtNyZINQ+fuJ`O-Xb7pMeX!(;|9jtS{m`szr{^k+F(zo;gH_4$s1~? zQ((B5VBBa6dHs!~AZkH>m=*J>Ek?C?1JXiq*t;2jc}gk{1^8Yr_O`g2LpT)2-O>aj zlG9c7yr^r)I%!c~Fu?t4Z1s8IOCU_$0HFj?jK#r!9+;$d)Qts~v9wYJ4nO`0$o}Q~ z8A%;NTE4Hz?0+%Z=@p99m+x;R-Hhu#6?(rzagzG-J`yYt#LN<(L zEf{*&BK76_6-nuNl#29U%1OErZS?L&^78$Sr0Yl-CDVT$W$ZpwD5g?hzCV&wzCV)v zXO6#9=vN4X@_m$~^8FR*Q_M2;9|cA+k?+sw7MB-6<$ErHa$jYgsEUtK-!AkdO$|&a zWteA=W$KHYNV}lYU!k7zU*i9gp)c=CCEah8nmU#JOZ590`tp6Hq?zy6Xs(RqNiZ~i zIe+r`K++DQFzT85KLKXcm+u)Q-TmL_@5|7iSE?&Wx-z3f88>P6*Qi+V5!)>F{zIN? zm>DmrFX`*hr4UPf`Mzay89)>%r*l_%iNB2o8o$(+&$k^yzg{W|YR}+508eXI>dW^! z@|??lGL9nGx9nGrYX{nl{r4>4;;aWhHm6dglhj|SFDX6$8}(D~gUWRko9JH}kb07m zvQb|?AKRR|M&>hBN>3Q1^Aib^<1ZJ_K~sc&QO5k+g`Ok@(8vFBxk{Kx{mCgruaGPi zBTcP+y@~%-oI2AhUW{K4mL6fH|1y8m{*u1y8v5U&TAe +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define POLL_INTERVAL 50 +#define LEN(arr) (sizeof(arr) / sizeof(arr[0])) +#define BLOCK(cmd, interval, signal) {"echo \"$(" cmd ")\"", interval, signal}, +typedef struct { + const char* command; + const unsigned int interval; + const unsigned int signal; +} Block; +#include "config.h" + +#ifdef CLICKABLE_BLOCKS +#undef CLICKABLE_BLOCKS +#define CLICKABLE_BLOCKS 1 +#else +#undef CLICKABLE_BLOCKS +#define CLICKABLE_BLOCKS 0 +#endif + +static Display* dpy; +static int screen; +static Window root; +static unsigned short int statusContinue = 1; +static char outputs[LEN(blocks)][CMDLENGTH + 1 + CLICKABLE_BLOCKS]; +static char statusBar[2][LEN(blocks) * ((LEN(outputs[0]) - 1) + (LEN(DELIMITER) - 1)) + 1]; +static struct epoll_event event, events[LEN(blocks) + 2]; +static int pipes[LEN(blocks)][2]; +static int timerPipe[2]; +static int signalFD; +static int epollFD; +void (*writeStatus)(); + +int gcd(int a, int b) { + int temp; + while (b > 0) { + temp = a % b; + a = b; + b = temp; + } + return a; +} + +void closePipe(int* pipe) { + close(pipe[0]); + close(pipe[1]); +} + +void execBlock(int i, const char* button) { + if (fork() == 0) { + close(pipes[i][0]); + dup2(pipes[i][1], STDOUT_FILENO); + + if (button) + setenv("BLOCK_BUTTON", button, 1); + execl("/bin/sh", "sh", "-c", blocks[i].command); + close(pipes[i][1]); + } +} + +void execBlocks(unsigned long long int time) { + for (int i = 0; i < LEN(blocks); i++) + if (time == 0 || (blocks[i].interval != 0 && time % blocks[i].interval == 0)) + execBlock(i, NULL); +} + +int getStatus(char* new, char* old) { + strcpy(old, new); + new[0] = '\0'; + + for (int i = 0; i < LEN(blocks); i++) { +#ifdef LEADING_DELIMITER + if (strlen(outputs[i])) +#else + if (strlen(new) && strlen(outputs[i])) +#endif + strcat(new, DELIMITER); + strcat(new, outputs[i]); + } + return strcmp(new, old); +} + +void updateBlock(int i) { + char* output = outputs[i]; + char buffer[LEN(outputs[0])]; + int bytesRead = read(pipes[i][0], buffer, LEN(buffer)); + buffer[bytesRead - 1] = '\0'; + + if (bytesRead == LEN(buffer)) { + // Clear the pipe + char ch; + while (read(pipes[i][0], &ch, 1) == 1 && ch != '\n') + ; + } else if (bytesRead == 1) { + output[0] = '\0'; + return; + } + +#if CLICKABLE_BLOCKS + if (blocks[i].signal > 0) { + output[0] = blocks[i].signal; + output++; + } +#endif + + strcpy(output, buffer); +} + +void debug() { + // Only write out if text has changed + if (!getStatus(statusBar[0], statusBar[1])) + return; + + write(STDOUT_FILENO, statusBar[0], strlen(statusBar[0])); + write(STDOUT_FILENO, "\n", 1); +} + +void setRoot() { + // Only set root if text has changed + if (!getStatus(statusBar[0], statusBar[1])) + return; + + Display* d = XOpenDisplay(NULL); + if (d) + dpy = d; + screen = DefaultScreen(dpy); + root = RootWindow(dpy, screen); + XStoreName(dpy, root, statusBar[0]); + XCloseDisplay(dpy); +} + +void signalHandler() { + struct signalfd_siginfo info; + read(signalFD, &info, sizeof(info)); + + for (int j = 0; j < LEN(blocks); j++) { + if (blocks[j].signal == info.ssi_signo - SIGRTMIN) { + char button[] = {'0' + info.ssi_int & 0xff, 0}; + execBlock(j, button); + break; + } + } + + // Clear the pipe after each poll to limit number of signals handled + while (read(signalFD, &info, sizeof(info)) != -1) + ; +} + +void termHandler() { + statusContinue = 0; +} + +void setupSignals() { + signal(SIGTERM, termHandler); + signal(SIGINT, termHandler); + + // Avoid zombie subprocesses + struct sigaction sa; + sa.sa_handler = SIG_DFL; + sigemptyset(&sa.sa_mask); + sa.sa_flags = SA_NOCLDWAIT; + sigaction(SIGCHLD, &sa, 0); + + // Handle block update signals + sigset_t sigset; + sigemptyset(&sigset); + for (int i = 0; i < LEN(blocks); i++) + if (blocks[i].signal > 0) + sigaddset(&sigset, SIGRTMIN + blocks[i].signal); + + signalFD = signalfd(-1, &sigset, 0); + fcntl(signalFD, F_SETFL, O_NONBLOCK); + sigprocmask(SIG_BLOCK, &sigset, NULL); + event.data.u32 = LEN(blocks) + 1; + epoll_ctl(epollFD, EPOLL_CTL_ADD, signalFD, &event); +} + +void statusLoop() { + execBlocks(0); + + while (statusContinue) { + int eventCount = epoll_wait(epollFD, events, LEN(events), POLL_INTERVAL / 10); + + for (int i = 0; i < eventCount; i++) { + unsigned int id = events[i].data.u32; + + if (id == LEN(blocks)) { + unsigned long long int j = 0; + read(timerPipe[0], &j, sizeof(j)); + execBlocks(j); + } else if (id < LEN(blocks)) { + updateBlock(events[i].data.u32); + } else { + signalHandler(); + } + } + if (eventCount) + writeStatus(); + + // Poll every `POLL_INTERVAL` milliseconds + struct timespec toSleep = {.tv_nsec = POLL_INTERVAL * 1000000UL}; + nanosleep(&toSleep, &toSleep); + } +} + +void timerLoop() { + close(timerPipe[0]); + + unsigned int sleepInterval = -1; + for (int i = 0; i < LEN(blocks); i++) + if (blocks[i].interval) + sleepInterval = gcd(blocks[i].interval, sleepInterval); + + unsigned long long int i = 0; + struct timespec sleepTime = {sleepInterval, 0}; + struct timespec toSleep = sleepTime; + + while (1) { + // Sleep for `sleepTime` even on being interrupted + if (nanosleep(&toSleep, &toSleep) == -1) + continue; + + // Notify parent to update blocks + write(timerPipe[1], &i, sizeof(i)); + + // After sleep, reset timer and update counter + toSleep = sleepTime; + i += sleepInterval; + } + + close(timerPipe[1]); +} + +void init() { + epollFD = epoll_create(LEN(blocks) + 1); + event.events = EPOLLIN; + + for (int i = 0; i < LEN(blocks); i++) { + pipe(pipes[i]); + event.data.u32 = i; + epoll_ctl(epollFD, EPOLL_CTL_ADD, pipes[i][0], &event); + } + + pipe(timerPipe); + event.data.u32 = LEN(blocks); + epoll_ctl(epollFD, EPOLL_CTL_ADD, timerPipe[0], &event); + + setupSignals(); +} + +int main(const int argc, const char* argv[]) { + writeStatus = setRoot; + for (int i = 0; i < argc; i++) + if (!strcmp("-d", argv[i])) + writeStatus = debug; + + init(); + + if (fork() == 0) + timerLoop(); + else + statusLoop(); + + close(epollFD); + close(signalFD); + closePipe(timerPipe); + for (int i = 0; i < LEN(pipes); i++) + closePipe(pipes[i]); + return 0; +} diff --git a/main.o b/main.o new file mode 100644 index 0000000000000000000000000000000000000000..54922983d961bedf2dd874d3064923825804ca63 GIT binary patch literal 13896 zcmbtaeRNaDl^^*76x)#up^4dips->wU&aE`#f3DMZSZrDi8scCvp|fIWpI%#t^LHu zh7eQPB(Fl$=WKeCp5(OYb~kBLn&xbB^5JcRsR8G--O`XYo86|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