Commit graph

220 commits

Author SHA1 Message Date
Laslo Hunhold
422cadfd5f Implement esnprintf() and make formatted calls more efficient
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.
2018-05-19 19:44:02 +02:00
Laslo Hunhold
80fc20d1d6 Add warn() and die()
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.
2018-05-18 11:13:05 +02:00
Laslo Hunhold
a4fe8c9741 Audit slstatus.c
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).
2018-05-18 10:08:03 +02:00
Laslo Hunhold
c83b388a3f Properly handle *snprintf() errors
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.
2018-05-17 23:26:56 +02:00
Aaron Marcher
f9609f4ff4 Change done to int as it is the CPU's natural type 2018-05-17 17:28:32 +02:00
Josuah Demangeon
7e29da026b fflush(stdout) to print line by line if stdout is not a tty
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
2018-05-08 15:18:32 +02:00
Aaron Marcher
666f285201 Only variable declarations at top of block 2018-05-07 15:57:32 +02:00
Aaron Marcher
2289798b6d Remove program name from error messages 2018-03-28 18:49:27 +02:00
Aaron Marcher
aced832622 Remove unnecessary headers 2018-03-28 18:14:08 +02:00
SiIky
9ca1ac62f9 Print unknown_str in case of error
func can return NULL in case of error, but no checking is done when
printing, and unknown_str wasn't being used anywhere.
2018-02-17 18:08:27 +00:00
Laslo Hunhold
914440b4fc
Properly declare buf as extern and fix all unused-warnings 2017-09-17 17:38:07 +02:00
Laslo Hunhold
eea99fc0ac
Rewrite Makefile to accomodate file split 2017-09-17 17:37:49 +02:00
Aaron Marcher
6820631175
Split into multiple files
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
2017-09-17 17:26:45 +02:00
Aaron Marcher
8e25af7dc3
Add blank line after setlocale
setlocale() has to be separated from the signal handling.
2017-09-16 14:11:49 +02:00
Kurt Van Dijck
fb1f1dea2e
slstatus: set locale
I want my date & time printed according my locale settings.
This commit enables that

Signed-off-by: Kurt Van Dijck <dev.kurt@vandijck-laurijssen.be>
2017-09-16 14:10:35 +02:00
Kurt Van Dijck
72a5e52a35
slstatus: add cpu_iowait
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>
2017-09-16 13:46:40 +02:00
Kamil Cholewiński
b7d7ce9c5f
slstatus load_avg format string 2017-09-10 14:08:20 +02:00
Aaron Marcher
8f5219b6da
Added IPv6 address function
- Renamed "ip" function to "ipv4"
- Added "ipv6" function
- Adjusted README and config.def.h accordingly
2017-08-14 18:00:46 +02:00
Laslo Hunhold
0f7e022381
Fix a little logic error 2017-08-14 11:35:52 +02:00
Laslo Hunhold
e1e1b1d79a
Add pscanf()
This reduces a lot of equivalent code to one function call.
2017-08-14 08:24:54 +02:00
Laslo Hunhold
796b661284
Refactor main()
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.
2017-08-13 23:45:16 +02:00
Laslo Hunhold
3468a6e368
Simplify signal handling a bit 2017-08-13 23:32:14 +02:00
Laslo Hunhold
450e8e6e6b
Remove unnecessary prototypes 2017-08-13 23:32:06 +02:00
Laslo Hunhold
ecf2779904
Remove unnecessary blank lines after license-notice 2017-08-13 23:31:56 +02:00
Aaron Marcher
c4779c9b15
Removed #define for unknown_str
Debugging #define is very difficult. The performance overhead of static const
char is negligible.
2017-08-12 13:27:30 +02:00
Aaron Marcher
be12b6b350
Removed #define for update interval
Debugging #define, especially in mathematical constructs is very
difficult. The performance overhead of static const int is negligible.
2017-08-12 13:16:12 +02:00
Ali H. Fardan
2c114ec2b5
keyboard_indicators: fix segfault when -s is specified 2017-08-12 12:50:11 +02:00
Aaron Marcher
6f01174392
Fixed possible NULL-deref and removed unnecessary XOpenDisplay()
- 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.
2017-08-11 14:33:02 +02:00
Laslo Hunhold
1814061396
Add and use LEN() macro 2017-08-11 13:43:11 +02:00
Laslo Hunhold
178c23e3d2
Refactor battery_state() 2017-08-11 00:20:47 +02:00
Laslo Hunhold
00ce7a746a
Print usage() when we are left with arguments 2017-08-10 22:33:05 +02:00
Laslo Hunhold
c9d47405f4
Reduce -o | -n to -s
What we really want is to either output to WM_NAME or stdout. If we want
just one single line, we do slstatus | head -n 1.
2017-08-10 22:32:57 +02:00
Laslo Hunhold
4d33c36014
Remove d- and v-flags
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.
2017-08-10 22:32:48 +02:00
Laslo Hunhold
958c34052a
Convert slstatus.1 to mandoc, simplify it and remove -h
We also change the semantics of -v to only return the version
information.
There is now no need for usage() to exit with anything other than 1.
2017-08-10 22:32:28 +02:00
aaron marcher
4b4b2ac079
add num_files() function for maildirs ;) 2017-08-06 15:02:16 +02:00
Aaron Marcher
1c8aa5318f
check for fgets/fscanf return values 2017-06-13 00:06:56 +02:00
Aaron Marcher
597cdc6b5c
use a static buffer instead of dynamic memory 2017-06-13 00:06:04 +02:00
Aaron Marcher
abbaa7af44
remove format characters from stat functions 2017-06-12 23:59:21 +02:00
Aaron Marcher
832b21ca4b
add cpu_freq function 2017-06-12 23:56:21 +02:00
Aaron Marcher
259e967cbf
add battery_power function 2017-06-12 23:55:27 +02:00
Aaron Marcher
870d68d44e
added option to output only once and exit afterwards 2017-05-11 19:06:45 +02:00
Aaron Marcher
d144c8de3d
simplified and improved vol_perc() 2017-04-20 22:30:04 +02:00
Aaron Marcher
c288663ebd
fix overflow in run_command() 2017-04-20 22:20:19 +02:00
Aaron Marcher
b2714032e5
username(): get rid of unneeded uid variable 2017-04-20 22:18:24 +02:00
Tobias Stoeckmann
35295f1902 On success, fgets always terminates the result.
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>
2017-04-04 21:27:31 +02:00
Tobias Stoeckmann
b1e7c40b21 Fixed out of boundary write on long lines.
The terminating nul character ('\0') could be written outside the boundary of
the buffer which is used to read characters. If "sizeof(buffer)" characters
are read, the resulting value must not be used as index, because that's an off
by one.

Read sizeof(buffer)-1 bytes instead.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2017-04-02 13:12:03 +02:00
Aaron Marcher
cceeec0efa
loading thresholds state 2017-03-30 17:32:20 +02:00
Aaron Marcher
b11dd2db0e
Fixed XCloseDisplay() which is not reached in keyboard_indicators() 2017-01-23 21:01:41 +01:00
Aaron Marcher
823f2d047f
Added keyboard_indicators (Fixes #31) 2017-01-16 12:10:56 +01:00
Aaron Marcher
3f976aabc0
Makefile fix and vol_perc fix for mute 2017-01-09 12:05:29 +01:00