Even if we extend the flag to be an n-flag with a numerical input, we
already have other Unix-tools to take care of us much more flexibly,
e.g. with head(1) you can easily get the first 10 outputs with
slstatus -s | head -n 10,
but also e.g. discard the first one and then get the consecutive 10
outputs.
For the X11-root-window-name, you can limit the runtime with timeout(1)
or a comparable solution.
This reverts commit fa8b939990.
Within the components, snprintf() was unchecked and had inefficient
calls in some places.
We implement esnprintf() that does all the dirty laundry for us
and use it exclusively now.
Given slstatus is a tool that runs in the background, most likely run
from .xinitrc, it's important to prepend the name of the tool to error
messages so it becomes clear where the error is coming from.
To make this much more consistent, this commit adds warn() and die()
utility functions consistent with other suckless projects and adapts all
calls to fprintf(stderr, *) to the warn() and die() functions, greatly
increasing the readability of the code.
1) Remove setlocale() (locales are harmful and any 'issues' shall
be fixed in different ways that are expected).
2) Disable buffering on stdout with setbuf() rather than flushing
it each time.
3) Make error messages more consistent.
4) Add error checks where applicable.
5) Make code a bit more readable where res is assigned.
6) Use XFlush() rather than XSync() (we don't need to wait for the
XServer to react, which could lead to long hangs on our side).
Posix guarantees that the resulting string is null-terminated, even if
we have an overflow. Instead of doing what has already been done,
properly warn when there has been an error or overflow, so the user can
do something about it.
To reproduce the issue:
$ slstatus -s | tee
then it would print only when the stdout buffer is full, by block
of multiple lines.
fflush() makes sure the line is printed at every loop iteration
For multiple reasons the program is now split:
- Make future porting to OpenBSD easier
- Assign header includes to individiual functions
- Make future program extensions easier
- Recompile only changed parts
This commit introduces the cpu_iowait item, this is the percentage
of cpu time spent waiting on disks. High numbers typically indicate
that your system is not responsive due to disk IO.
This commit also avoid sleeping inside the cpu_perc and cpu_iowait
functions: waiting in either one implies lost info for the other.
Signed-off-by: Kurt Van Dijck <dev.kurt@vandijck-laurijssen.be>
We remove the hack with the sleep and global "delay"-variable and use a
monotonic clock to derive the desired monotonic properties of the tool.
Inside each function that demands a personal delay we can then just do a
nanosleep() and be done with it.
It's a shame that timespec is so ugly to work with, but there's really
no way to make it more beautiful. However, at this cost though we
finally can set the interval times in milliseconds and not only just
seconds.
We remove setlocale(), because nothing good ever came out of this
function.
Besides that we have some more code refactoring, especially in the
argument loop which saves us a bit of complexity.
- Added a check for the return value of XOpenDisplay() in main().
This fixes a possible NULL-deref.
- Removed unnsecessary XOpenDisplay and XCloseDisplay from
keyboard_indicators(). The ones in main() are sufficent.
d-flag: There's no need for that, use the &-operator or fork+exec in a
non-shell-context. In the latter case you get the PID for free.
v-flag: If you want to find out which version of a package is installed,
consult your package manager. That's his job.
If fgets succeeds, then the resulting char array is always
terminated by a '\0'. No need to keep extra space, therefore
sizeof(buf) is the correct argument.
Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>