[hackers] [smdev][PATCH] Create USB nodes correctly

2021-06-03 Thread Platon Ryzhikov
Linux kernel creates USB devices with nodes like bus/usb/002/007
---
 smdev.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/smdev.c b/smdev.c
index b774908..b9321df 100644
--- a/smdev.c
+++ b/smdev.c
@@ -185,7 +185,7 @@ parsepath(struct rule *rule, struct rulepath *rpath,
if (!rule->path) {
strlcpy(rpath->name, basedevname, sizeof(rpath->name));
snprintf(rpath->path, sizeof(rpath->path), "/dev/%s",
-rpath->name);
+devname);
return;
}
 
-- 
2.31.1




[hackers][slstatus][PATCH] Report average CPU frequency of cluster instead of single-core one

2020-11-11 Thread Platon Ryzhikov
This is especially useful for ARM SoCs with different cores

---
 components/cpu.c | 27 +--
 config.def.h |  4 +++-
 2 files changed, 24 insertions(+), 7 deletions(-)

diff --git a/components/cpu.c b/components/cpu.c
index 9e28003..c326297 100644
--- a/components/cpu.c
+++ b/components/cpu.c
@@ -7,16 +7,31 @@
 
 #if defined(__linux__)
const char *
-   cpu_freq(void)
+   cpu_freq(const char *range)
{
-   uintmax_t freq;
-
-   /* in kHz */
-   if (pscanf("/sys/devices/system/cpu/cpu0/cpufreq/"
-  "scaling_cur_freq", "%ju", ) != 1) {
+   uintmax_t freq, sum_freq;
+   static unsigned int i, cpu0, ncpus;
+
+   sum_freq = 0;
+   /* define first cpu in cluster and their number */
+   if (!range) {
+   cpu0 = 0;
+   ncpus = 1;
+   } else if (sscanf(range, "%u %u", , ) != 2) {
return NULL;
}
 
+   for (i = cpu0; i < cpu0 + ncpus; i += 1) {
+   /* in kHz */
+   if 
(pscanf(bprintf("/sys/devices/system/cpu/cpu%d/cpufreq/"
+  "scaling_cur_freq", i), "%ju", ) != 1) {
+   return NULL;
+   }
+   sum_freq += freq;
+   }
+
+   freq = (double)sum_freq/(double)ncpus;
+
return fmt_human(freq * 1000, 1000);
}
 
diff --git a/config.def.h b/config.def.h
index e06be66..6554bb3 100644
--- a/config.def.h
+++ b/config.def.h
@@ -19,7 +19,9 @@ static const char unknown_str[] = "n/a";
  * battery_remaining   battery remaining HH:MM battery name (BAT0)
  * NULL on OpenBSD/FreeBSD
  * cpu_perccpu usage in percentNULL
- * cpu_freqcpu frequency in MHzNULL
+ * cpu_freqcpu frequency in MHzstring "first_cpu ncpus"
+ * "0 2" means cpu0+cpu1
+ * NULL on OpenBSD/FreeBSD
  * datetimedate and time   format string (%F %T)
  * disk_free   free disk space in GB   mountpoint path (/)
  * disk_perc   disk usage in percent   mountpoint path (/)
-- 
2.29.2



Re: [hackers] [quark] Thoughts on CGI and authentication?

2020-10-25 Thread Platon Ryzhikov
On Thu, 22 Oct 2020 20:52:27 +0200
José Miguel Sánchez García  wrote:

> Hello,
> 
> I'm currently serving my static webpage with quark. I want to add some
> CGI, but the opinion here about CGI support in the server is pretty
> low. I'm trying to update the basecgi patch, but the latest changes
> adding interruptibility seem to complicate the design (the goals of
> these two are kinda opposite to what CGI does right? I mean, these are
> about memory-bounded operation and CGI scripts can generate
> arbitrarily long data, which must be known before even generating the
> response header). I have no experience with HTTP whatsoever, so I want
> to hear better-informed opinions ;)

Hi Jose,

I've recently had an idea that instead of adding support for running
scripts by HTTP server (which in any case leads to new fork() calls)
one could use a library providing HTTP server itself while all the
logic is created separately and is performed using callbacks from
library main loop. In that case one could attempt to handle dynamic
(and static using proper callbacks) content within fixed number of
threads.
-- 
Platon Ryzhikov 



Re: [hackers] [dmenu][PATCH] Replace dmenu_run shell with executed application

2019-02-10 Thread Platon Ryzhikov
How about the following then:
#!/bin/sh
${SHELL:-"/bin/sh"} -c "$(dmenu_path | dmenu "$@") & exit"

This doesn't keep shell in processes but at the same time allows to run scripts

10.02.2019, 14:40, "Hiltjo Posthuma" :
> On Sun, Feb 10, 2019 at 11:40:06AM +0100, Leonardo Taccari wrote:
>>  Hello Nick,
>>
>>  Nick writes:
>>  > [...]
>>  > Ignore if you're too busy, but why is this considered bad practise?
>>  > Is there some case of possible shell escaping or something I'm
>>  > failing to see? I just ask for my own education.
>>  >
>>
>>  (I have no idea if this was original rationale about why not applying
>>  this patch but I will try to share why it can be problematic in
>>  some cases IME.)
>>
>>  According dmenu(1) man page:
>>
>>  > dmenu_run is a script used by dwm(1) which lists programs in the user's
>>  > $PATH and runs the result in their $SHELL.
>>
>>  by using `exec' this is no longer true.
>>
>>  The user's $SHELL is no longer used and what can be typed in
>>  `dmenu_run' is now restricted, (I don't know how usual is but
>>  sometimes I use `|' and other shell commands in dmenu_run).
>
> Exactly this.
>
> It works like this since atleast 2011 (commit
> 56a0d1fa14de915419c037ac2604fe5c5b1fe4a3). If you dig in the git history you
> can see we've had most possible combinations already.
>
> --
> Kind regards,
> Hiltjo



[hackers][smdev][PATCH] Process all uevents in /sys

2018-12-18 Thread Platon Ryzhikov
This patch allows smdev to process uevents which don't contain information 
about devices but may, for example, contain information about modules. Also 
smdev -s will scan whole /sys
---
 smdev.c | 127 
 1 file changed, 64 insertions(+), 63 deletions(-)

diff --git a/smdev.c b/smdev.c
index b774908..59b5485 100644
--- a/smdev.c
+++ b/smdev.c
@@ -85,7 +85,7 @@ main(int argc, char *argv[])
 
umask(0);
if (sflag) {
-   recurse("/sys/devices", populatedev);
+   recurse("/sys", populatedev);
} else {
if (dohotplug() < 0)
eprintf("Environment not set up correctly for 
hotplugging\n");
@@ -126,14 +126,14 @@ dohotplug(void)
action = getenv("ACTION");
devpath = getenv("DEVPATH");
devname = getenv("DEVNAME");
-   if (!minor || !major || !action || !devpath || !devname)
+   if (!action || !devpath)
return -1;
 
-   ev.minor = estrtol(minor, 10);
-   ev.major = estrtol(major, 10);
+   ev.minor = minor?estrtol(minor, 10):-1;
+   ev.major = major?estrtol(major, 10):-1;
ev.action = mapaction(action);
ev.devpath = devpath;
-   ev.devname = devname;
+   ev.devname = devname?devname:".";
return doevent();
 }
 
@@ -249,12 +249,14 @@ removedev(struct event *ev)
if (rule->path && rule->path[0] == '!')
return 0;
 
-   /* Delete device node */
-   unlink(rpath.path);
-   /* Delete symlink */
-   if (rule->path && rule->path[0] == '>') {
-   snprintf(buf, sizeof(buf), "/dev/%s", ev->devname);
-   unlink(buf);
+   if (ev->major > 0 && ev->minor > 0 && ev->devname) {
+   /* Delete device node */
+   unlink(rpath.path);
+   /* Delete symlink */
+   if (rule->path && rule->path[0] == '>') {
+   snprintf(buf, sizeof(buf), "/dev/%s", ev->devname);
+   unlink(buf);
+   }
}
return 0;
 }
@@ -276,58 +278,59 @@ createdev(struct event *ev)
if (rule->path && rule->path[0] == '!')
goto runrule;
 
-   snprintf(buf, sizeof(buf), "%d:%d", ev->major, ev->minor);
-   if ((type = devtype(buf)) < 0)
-   return -1;
-
-   /* Parse path and create the directory tree */
-   parsepath(rule, , ev->devname);
-   if (!(dirc = strdup(rpath.path)))
-   eprintf("strdup:");
-   strlcpy(buf, dirname(dirc), sizeof(buf));
-   free(dirc);
-   umask(022);
-   if (mkpath(buf, 0755) < 0)
-   eprintf("mkdir %s:", buf);
-   umask(0);
+   if (ev->major > 0 && ev->minor > 0 && ev->devname) {
+   snprintf(buf, sizeof(buf), "%d:%d", ev->major, ev->minor);
+   if ((type = devtype(buf)) < 0)
+   return -1;
 
-   if (mknod(rpath.path, rule->mode | type,
- makedev(ev->major, ev->minor)) < 0 &&
-   errno != EEXIST)
-   eprintf("mknod %s:", rpath.path);
-
-   errno = 0;
-   pw = getpwnam(rule->user);
-   if (!pw) {
-   if (errno)
-   eprintf("getpwnam %s:", rule->user);
-   else
-   eprintf("getpwnam %s: no such user\n",
-rule->user);
-   }
+   /* Parse path and create the directory tree */
+   parsepath(rule, , ev->devname);
+   if (!(dirc = strdup(rpath.path)))
+   eprintf("strdup:");
+   strlcpy(buf, dirname(dirc), sizeof(buf));
+   free(dirc);
+   umask(022);
+   if (mkpath(buf, 0755) < 0)
+   eprintf("mkdir %s:", buf);
+   umask(0);
+
+   if (mknod(rpath.path, rule->mode | type,
+ makedev(ev->major, ev->minor)) < 0 &&
+   errno != EEXIST)
+   eprintf("mknod %s:", rpath.path);
+
+   errno = 0;
+   pw = getpwnam(rule->user);
+   if (!pw) {
+   if (errno)
+   eprintf("getpwnam %s:", rule->user);
+   else
+   eprintf("getpwnam %s: no such user\n",
+rule->user);
+   }
 
-   errno = 0;
-   gr = getgrnam(rule->group);
-   if (!gr) {
-   if (errno)
-   eprintf("getgrnam %s:", rule->group);
-   else
-   eprintf("getgrnam %s: no such group\n",
-rule->group);
-   }
+   errno = 0;
+   gr = getgrnam(rule->group);
+   if (!gr) {
+   if (errno)
+   eprintf("getgrnam %s:", rule->group);
+ 

[hackers][ubase][PATCH] Fix build errors on some ARM64 Linux systems

2018-08-27 Thread Platon Ryzhikov
These changes are required on Arch Linux ARM to build ubase. This does not 
affect x86 build.

---
 libutil/tty.c | 1 +
 mknod.c   | 1 +
 mountpoint.c  | 1 +
 stat.c| 3 ++-
 4 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/libutil/tty.c b/libutil/tty.c
index bceb01e..8a2cd73 100644
--- a/libutil/tty.c
+++ b/libutil/tty.c
@@ -1,6 +1,7 @@
 /* See LICENSE file for copyright and license details. */
 #include 
 #include 
+#include 
 
 #include 
 #include 
diff --git a/mknod.c b/mknod.c
index 8de35c7..27f91e0 100644
--- a/mknod.c
+++ b/mknod.c
@@ -1,6 +1,7 @@
 /* See LICENSE file for copyright and license details. */
 #include 
 #include 
+#include 
 
 #include 
 #include 
diff --git a/mountpoint.c b/mountpoint.c
index 8f205a2..fd3a133 100644
--- a/mountpoint.c
+++ b/mountpoint.c
@@ -1,6 +1,7 @@
 /* See LICENSE file for copyright and license details. */
 #include 
 #include 
+#include 
 
 #include 
 #include 
diff --git a/stat.c b/stat.c
index 220a659..3f91566 100644
--- a/stat.c
+++ b/stat.c
@@ -1,6 +1,7 @@
 /* See LICENSE file for copyright and license details. */
 #include 
 #include 
+#include 
 
 #include 
 #include 
@@ -86,4 +87,4 @@ main(int argc, char *argv[])
}
 
return ret;
-}
\ No newline at end of file
+}
-- 
2.18.0




[hackers][sbase][PATCH] Fix build errors on some ARM64 Linux systems

2018-08-27 Thread Platon Ryzhikov
These changes are required on Arch Linux ARM to build sbase. This does not 
affect x86 build.
---
 ls.c  | 1 +
 tar.c | 1 +
 2 files changed, 2 insertions(+)

diff --git a/ls.c b/ls.c
index b716aba..9e79fcb 100644
--- a/ls.c
+++ b/ls.c
@@ -1,6 +1,7 @@
 /* See LICENSE file for copyright and license details. */
 #include 
 #include 
+#include 
 
 #include 
 #include 
diff --git a/tar.c b/tar.c
index a6ead2e..9359bfd 100644
--- a/tar.c
+++ b/tar.c
@@ -1,6 +1,7 @@
 /* See LICENSE file for copyright and license details. */
 #include 
 #include 
+#include 
 
 #include 
 #include 
-- 
2.18.0



[hackers][ubase][PATCH] Fix segfault in killall5 without -o

2018-06-28 Thread Platon Ryzhikov
---
 killall5.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/killall5.c b/killall5.c
index 14790b9..4d22b98 100644
--- a/killall5.c
+++ b/killall5.c
@@ -73,7 +73,7 @@ main(int argc, char *argv[])

SLIST_INIT(_head);

-   for (p = strtok(arg, ","); p; p = strtok(NULL, ",")) {
+   if (arg) for (p = strtok(arg, ","); p; p = strtok(NULL, ",")) {
pe = emalloc(sizeof(*pe));
pe->pid = estrtol(p, 10);
SLIST_INSERT_HEAD(_head, pe, entry);
--
2.18.0