From 6068e3ac2f5e4fb5fe93b1d61ef01b886c4479a0 Mon Sep 17 00:00:00 2001 From: coast Date: Thu, 29 May 2025 22:52:30 +0200 Subject: [PATCH] Upload files to ".suckless/slstatus/components" --- .suckless/slstatus/components/run_command.c | 31 +++ .suckless/slstatus/components/run_command.o | Bin 0 -> 2120 bytes .suckless/slstatus/components/swap.c | 274 ++++++++++++++++++++ .suckless/slstatus/components/swap.o | Bin 0 -> 3880 bytes .suckless/slstatus/components/temperature.c | 73 ++++++ 5 files changed, 378 insertions(+) create mode 100644 .suckless/slstatus/components/run_command.c create mode 100644 .suckless/slstatus/components/run_command.o create mode 100644 .suckless/slstatus/components/swap.c create mode 100644 .suckless/slstatus/components/swap.o create mode 100644 .suckless/slstatus/components/temperature.c diff --git a/.suckless/slstatus/components/run_command.c b/.suckless/slstatus/components/run_command.c new file mode 100644 index 0000000..93bf6da --- /dev/null +++ b/.suckless/slstatus/components/run_command.c @@ -0,0 +1,31 @@ +/* See LICENSE file for copyright and license details. */ +#include +#include + +#include "../slstatus.h" +#include "../util.h" + +const char * +run_command(const char *cmd) +{ + char *p; + FILE *fp; + + if (!(fp = popen(cmd, "r"))) { + warn("popen '%s':", cmd); + return NULL; + } + + p = fgets(buf, sizeof(buf) - 1, fp); + if (pclose(fp) < 0) { + warn("pclose '%s':", cmd); + return NULL; + } + if (!p) + return NULL; + + if ((p = strrchr(buf, '\n'))) + p[0] = '\0'; + + return buf[0] ? buf : NULL; +} diff --git a/.suckless/slstatus/components/run_command.o b/.suckless/slstatus/components/run_command.o new file mode 100644 index 0000000000000000000000000000000000000000..14993236eef25ebc1dd7e5d36d46ba914e2c970b GIT binary patch literal 2120 zcmbtUO=}ZT6upzQw$&J;C{!vk8?A~Cnb4vXl%&OW3blw@L{!Q&owi`};mibET~sI) z0~W*|RDxf)7TmgWArui;E-KV}X5LLEL$c8WZ{EG-j7Ot5Hi?^{>|URk*uZtNuaRR{ibHev&BE)qhUc z-v{PaWBo)c!fXVj+1NF1Y<=^8?;J$dFq>5HlOKtm2L;IgVr}=L)cuEr2k%^}R;o@} zA3oy^k5RR_TJap^(A31ln0{_*cJ91xjvA(6>bY!gG&_A{jFiS$s@$3Zo-d)WPrzY z7yc$l2J&ET!rukSfc_9S;a5R2;&mT~bf8bME&2_`i+)e7w;tm~uSa;qG+}t_CEs2k zgZDD*SHyCiRon2LHJ^+{+qcPB@H{fy3LMD!9g=}FbjmC#SA56dr+3No?cyWlFPCdZ z)#Z2X`s*BugwD$Rl53Zo<_!MJ&^a1!?LaI`UiotWWfn?ZFiFWjEaxXOZJ~70q{N`jmPIzycNot-*`OUU8nQU zf@H`!o2s0Gc!i9n@mGDq3!6mO~dKWi#O HBOd=3SeX5} literal 0 HcmV?d00001 diff --git a/.suckless/slstatus/components/swap.c b/.suckless/slstatus/components/swap.c new file mode 100644 index 0000000..f270d93 --- /dev/null +++ b/.suckless/slstatus/components/swap.c @@ -0,0 +1,274 @@ +/* See LICENSE file for copyright and license details. */ +#include +#include +#include +#include + +#include "../slstatus.h" +#include "../util.h" + +#if defined(__linux__) + static int + get_swap_info(long *s_total, long *s_free, long *s_cached) + { + FILE *fp; + struct { + const char *name; + const size_t len; + long *var; + } ent[] = { + { "SwapTotal", sizeof("SwapTotal") - 1, s_total }, + { "SwapFree", sizeof("SwapFree") - 1, s_free }, + { "SwapCached", sizeof("SwapCached") - 1, s_cached }, + }; + size_t line_len = 0, i, left; + char *line = NULL; + + /* get number of fields we want to extract */ + for (i = 0, left = 0; i < LEN(ent); i++) + if (ent[i].var) + left++; + + if (!(fp = fopen("/proc/meminfo", "r"))) { + warn("fopen '/proc/meminfo':"); + return 1; + } + + /* read file line by line and extract field information */ + while (left > 0 && getline(&line, &line_len, fp) >= 0) { + for (i = 0; i < LEN(ent); i++) { + if (ent[i].var && + !strncmp(line, ent[i].name, ent[i].len)) { + sscanf(line + ent[i].len + 1, + "%ld kB\n", ent[i].var); + left--; + break; + } + } + } + free(line); + if (ferror(fp)) { + warn("getline '/proc/meminfo':"); + return 1; + } + + fclose(fp); + return 0; + } + + const char * + swap_free(const char *unused) + { + long free; + + if (get_swap_info(NULL, &free, NULL)) + return NULL; + + return fmt_human(free * 1024, 1024); + } + + const char * + swap_perc(const char *unused) + { + long total, free, cached; + + if (get_swap_info(&total, &free, &cached) || total == 0) + return NULL; + + return bprintf("%d", 100 * (total - free - cached) / total); + } + + const char * + swap_total(const char *unused) + { + long total; + + if (get_swap_info(&total, NULL, NULL)) + return NULL; + + return fmt_human(total * 1024, 1024); + } + + const char * + swap_used(const char *unused) + { + long total, free, cached; + + if (get_swap_info(&total, &free, &cached)) + return NULL; + + return fmt_human((total - free - cached) * 1024, 1024); + } +#elif defined(__OpenBSD__) + #include + #include + #include + #include + + static int + getstats(int *total, int *used) + { + struct swapent *sep, *fsep; + int rnswap, nswap, i; + + if ((nswap = swapctl(SWAP_NSWAP, 0, 0)) < 1) { + warn("swaptctl 'SWAP_NSWAP':"); + return 1; + } + if (!(fsep = sep = calloc(nswap, sizeof(*sep)))) { + warn("calloc 'nswap':"); + return 1; + } + if ((rnswap = swapctl(SWAP_STATS, (void *)sep, nswap)) < 0) { + warn("swapctl 'SWAP_STATA':"); + return 1; + } + if (nswap != rnswap) { + warn("getstats: SWAP_STATS != SWAP_NSWAP"); + return 1; + } + + *total = 0; + *used = 0; + + for (i = 0; i < rnswap; i++) { + *total += sep->se_nblks >> 1; + *used += sep->se_inuse >> 1; + } + + free(fsep); + + return 0; + } + + const char * + swap_free(const char *unused) + { + int total, used; + + if (getstats(&total, &used)) + return NULL; + + return fmt_human((total - used) * 1024, 1024); + } + + const char * + swap_perc(const char *unused) + { + int total, used; + + if (getstats(&total, &used)) + return NULL; + + if (total == 0) + return NULL; + + return bprintf("%d", 100 * used / total); + } + + const char * + swap_total(const char *unused) + { + int total, used; + + if (getstats(&total, &used)) + return NULL; + + return fmt_human(total * 1024, 1024); + } + + const char * + swap_used(const char *unused) + { + int total, used; + + if (getstats(&total, &used)) + return NULL; + + return fmt_human(used * 1024, 1024); + } +#elif defined(__FreeBSD__) + #include + #include + #include + #include + #include + + static int getswapinfo(struct kvm_swap *swap_info, size_t size) + { + kvm_t *kd; + + kd = kvm_openfiles(NULL, "/dev/null", NULL, 0, NULL); + if (kd == NULL) { + warn("kvm_openfiles '/dev/null':"); + return 0; + } + + if (kvm_getswapinfo(kd, swap_info, size, 0 /* Unused flags */) < 0) { + warn("kvm_getswapinfo:"); + kvm_close(kd); + return 0; + } + + kvm_close(kd); + return 1; + } + + const char * + swap_free(const char *unused) + { + struct kvm_swap swap_info[1]; + long used, total; + + if (!getswapinfo(swap_info, 1)) + return NULL; + + total = swap_info[0].ksw_total; + used = swap_info[0].ksw_used; + + return fmt_human((total - used) * getpagesize(), 1024); + } + + const char * + swap_perc(const char *unused) + { + struct kvm_swap swap_info[1]; + long used, total; + + if (!getswapinfo(swap_info, 1)) + return NULL; + + total = swap_info[0].ksw_total; + used = swap_info[0].ksw_used; + + return bprintf("%d", used * 100 / total); + } + + const char * + swap_total(const char *unused) + { + struct kvm_swap swap_info[1]; + long total; + + if (!getswapinfo(swap_info, 1)) + return NULL; + + total = swap_info[0].ksw_total; + + return fmt_human(total * getpagesize(), 1024); + } + + const char * + swap_used(const char *unused) + { + struct kvm_swap swap_info[1]; + long used; + + if (!getswapinfo(swap_info, 1)) + return NULL; + + used = swap_info[0].ksw_used; + + return fmt_human(used * getpagesize(), 1024); + } +#endif diff --git a/.suckless/slstatus/components/swap.o b/.suckless/slstatus/components/swap.o new file mode 100644 index 0000000000000000000000000000000000000000..b5cf1d73b6d4f1234c0583bf3b80ef16075db861 GIT binary patch literal 3880 zcmb`JZERCj7{^cd0u{!kB4`bU)TBreE$!H3BS_Y5z`+zlV3Qfe(zUmAS>J4L!;mFv z$~4zn-x4DxnrPw&qhE;l!Ni2rfP(ssPei`>lDO%JMocgop+5g}&)KfmHZjpBx#v9R zcb=E?a?iQ<$(_+%Z7vs6;$l14VoOoR-d(<^4+wRDX>0|H9E>~^8I6pL9tdCNl`B(8 zUhP;PAOmg=`_sJE30rPX`$OC`{G6X3_6KePB4xlWm9b^QXvBXQUcLpdVSk@Z-xsd) znFg=jPsVKJt7m!Th70x{Uh4(omCFrY`9m--8gqhL_I#$k^2GZD_L%4R%w=Oauffyo z@Xv4M)oH(17)Q-nQJZIB{v3i@?(?N+wd~nDbFCcWl~29V{_EwRc(upRYvdX=zqL}$ z)Td5Is~NwS*D`)zl={;1=XrJ1&8uY=HGk&jh~I6QR!N(wmp|B3n_lCR6Ns8udE-mb z|HD|L(FoT+##RV0?^a{uRa)32-()Sb(P_o2oSQN)J#r}WXyj1ju}F*-=ZZIcG2Ed2 z=#l$j_}$$6e(r%AjRs|2&8yq}XIKYK@srtQR*p7WVGN9-uNF>=(Y=TmplDVHWD4S$0hwz2h@q;GO?89SmInTed<#30Go z?xCS=zQFDWM>qPyy}@uW?CTD7_lA19#fhM;p#5b&dT-AELI$!O(oA1>e(x?`y%wTJXay zc%cO^x8Tz)c#Zff+DEm2;yohvS_}KPrTvd`>&5#>44;r@>vLM#$J6FA*5s4;OB1fxSCMnxD!H;Ntx!R?v$HHeM)B3~{ZA5tmDJnca!GkYIYaSN^2$7UUox2{=xP;t4T*E; zvGS2WwjO8BE(5Z$My|K&ldp+titifsVqk$-iui{owIDYG?>KzbM;PB|$X)b+JJPUG zCx9`DGygrr5YuV?Z~enEW;fM#QT`KlNV>|e>H*0@4!bjQKF>d&l3cK=h0^Jd^VMwsPstyhDd~y* z$Gxlk)&4ij4VOzY|66ikxO;G)JN*%}*-}kmQAnKQcdj4q44CA&RV|cG|Gxl} C2eDHC literal 0 HcmV?d00001 diff --git a/.suckless/slstatus/components/temperature.c b/.suckless/slstatus/components/temperature.c new file mode 100644 index 0000000..7cf1394 --- /dev/null +++ b/.suckless/slstatus/components/temperature.c @@ -0,0 +1,73 @@ +/* See LICENSE file for copyright and license details. */ +#include + +#include "../slstatus.h" +#include "../util.h" + + +#if defined(__linux__) + #include + + const char * + temp(const char *file) + { + uintmax_t temp; + + if (pscanf(file, "%ju", &temp) != 1) + return NULL; + + return bprintf("%ju", temp / 1000); + } +#elif defined(__OpenBSD__) + #include + #include /* before for struct timeval */ + #include + #include + + const char * + temp(const char *unused) + { + int mib[5]; + size_t size; + struct sensor temp; + + mib[0] = CTL_HW; + mib[1] = HW_SENSORS; + mib[2] = 0; /* cpu0 */ + mib[3] = SENSOR_TEMP; + mib[4] = 0; /* temp0 */ + + size = sizeof(temp); + + if (sysctl(mib, 5, &temp, &size, NULL, 0) < 0) { + warn("sysctl 'SENSOR_TEMP':"); + return NULL; + } + + /* kelvin to celsius */ + return bprintf("%d", (int)((float)(temp.value-273150000) / 1E6)); + } +#elif defined(__FreeBSD__) + #include + #include + #include + + #define ACPI_TEMP "hw.acpi.thermal.%s.temperature" + + const char * + temp(const char *zone) + { + char buf[256]; + int temp; + size_t len; + + len = sizeof(temp); + snprintf(buf, sizeof(buf), ACPI_TEMP, zone); + if (sysctlbyname(buf, &temp, &len, NULL, 0) < 0 + || !len) + return NULL; + + /* kelvin to decimal celcius */ + return bprintf("%d.%d", (temp - 2731) / 10, abs((temp - 2731) % 10)); + } +#endif