suckless/slstatus.git
6 years agoAdd warn() and die()
Laslo Hunhold [Fri, 18 May 2018 08:59:05 +0000 (10:59 +0200)]
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.

6 years agoAudit slstatus.c
Laslo Hunhold [Fri, 18 May 2018 08:07:50 +0000 (10:07 +0200)]
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).

6 years agoProperly handle *snprintf() errors
Laslo Hunhold [Thu, 17 May 2018 21:23:28 +0000 (23:23 +0200)]
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.

6 years agoRemove UNUSED macro
Aaron Marcher [Thu, 17 May 2018 18:05:57 +0000 (20:05 +0200)]
Remove UNUSED macro

Use variables named unused instead which is simpler

6 years agoMark unused parameters, fix compiler warnings
Aaron Marcher [Thu, 17 May 2018 16:29:25 +0000 (18:29 +0200)]
Mark unused parameters, fix compiler warnings

6 years agowifi: Fix order and add missing header
Aaron Marcher [Thu, 17 May 2018 16:14:08 +0000 (18:14 +0200)]
wifi: Fix order and add missing header

<sys/select.h> is needed before <net80211/ieee80211_ioctl.h> on OpenBSD
to define NBBY and shut up compiler warnings.

6 years agowifi: Change memmove to memcpy on OpenBSD
Aaron Marcher [Thu, 17 May 2018 16:08:31 +0000 (18:08 +0200)]
wifi: Change memmove to memcpy on OpenBSD

6 years agoUnify type of in for loops
Aaron Marcher [Thu, 17 May 2018 16:05:38 +0000 (18:05 +0200)]
Unify type of  in for loops

6 years agowifi_essid: Fix coding style
Aaron Marcher [Thu, 17 May 2018 15:59:05 +0000 (17:59 +0200)]
wifi_essid: Fix coding style

Only initialize variables at the beginning of a block

6 years agoUnify type of `i` in for loops
Aaron Marcher [Thu, 17 May 2018 15:40:11 +0000 (17:40 +0200)]
Unify type of `i` in for loops

int for normal indexes
size_t for usage with the LEN macro

6 years agoChange done to int as it is the CPU's natural type
Aaron Marcher [Thu, 17 May 2018 15:28:32 +0000 (17:28 +0200)]
Change done to int as it is the CPU's natural type

6 years agoChange interval to unsigned int
Aaron Marcher [Thu, 17 May 2018 15:25:31 +0000 (17:25 +0200)]
Change interval to unsigned int

6 years agoAdd comments for battery_* functions on OpenBSD
Aaron Marcher [Thu, 17 May 2018 15:24:47 +0000 (17:24 +0200)]
Add comments for battery_* functions on OpenBSD

6 years agoadded comment for temp function (openbsd)
Tobias Tschinkowitz [Thu, 17 May 2018 11:19:29 +0000 (13:19 +0200)]
added comment for temp function (openbsd)

6 years agocorrected calculations for disk space on openbsd
Tobias Tschinkowitz [Thu, 17 May 2018 10:43:21 +0000 (12:43 +0200)]
corrected calculations for disk space on openbsd

6 years agoUpdate README
Aaron Marcher [Wed, 16 May 2018 21:19:33 +0000 (23:19 +0200)]
Update README

6 years agowifi: Fix coding style
Aaron Marcher [Wed, 16 May 2018 21:17:30 +0000 (23:17 +0200)]
wifi: Fix coding style

Use block for single statement ifs
When functions return -1 for error test against 0 not -1
Newlines

6 years agoload_ieee80211_nodereq: Fix typo
Aaron Marcher [Wed, 16 May 2018 21:08:33 +0000 (23:08 +0200)]
load_ieee80211_nodereq: Fix typo

6 years agowifi: Move out common headers
Aaron Marcher [Wed, 16 May 2018 20:57:13 +0000 (22:57 +0200)]
wifi: Move out common headers

6 years agoadded wifi functionality for openbsd
Tobias Tschinkowitz [Wed, 16 May 2018 20:37:43 +0000 (22:37 +0200)]
added wifi functionality for openbsd

display ESSID and signal strength percentage

6 years agocorrected calculation for swap on openbsd
Tobias Tschinkowitz [Wed, 16 May 2018 11:26:34 +0000 (13:26 +0200)]
corrected calculation for swap on openbsd

The swapctl(2) function fills the swapent struct with 512KB blocks.
As we want to display in GB, i just modified the calculation for this to
get the expected output.

6 years agoconsistent calculation of ram_* on openbsd
Tobias Tschinkowitz [Wed, 16 May 2018 07:57:38 +0000 (09:57 +0200)]
consistent calculation of ram_* on openbsd

6 years agoAdd he4d to LICENSE
Aaron Marcher [Wed, 16 May 2018 06:13:09 +0000 (08:13 +0200)]
Add he4d to LICENSE

6 years agoupdated ram_total and ram_free (obsd)
Tobias Tschinkowitz [Tue, 15 May 2018 22:45:41 +0000 (00:45 +0200)]
updated ram_total and ram_free (obsd)

6 years agoCast CPU percentage to int and fix indenation
Aaron Marcher [Mon, 14 May 2018 18:54:48 +0000 (20:54 +0200)]
Cast CPU percentage to int and fix indenation

6 years agofflush(stdout) to print line by line if stdout is not a tty
Josuah Demangeon [Tue, 8 May 2018 13:13:56 +0000 (15:13 +0200)]
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

6 years agoAdd josuah to LICENSE
Aaron Marcher [Tue, 8 May 2018 13:06:55 +0000 (15:06 +0200)]
Add josuah to LICENSE

6 years agoinclude <sys/time.h> before <sys/sensors.h> for time struct timeval
Josuah Demangeon [Tue, 8 May 2018 11:42:17 +0000 (13:42 +0200)]
include <sys/time.h> before <sys/sensors.h> for time struct timeval

sys/sensors.h has two structs struct timeval: sensor and ksensor:

struct sensor {
...
struct timeval tv; /* sensor value last change time */
...
};

6 years agoOnly variable declarations at top of block
Aaron Marcher [Mon, 7 May 2018 13:57:32 +0000 (15:57 +0200)]
Only variable declarations at top of block

6 years agoFix indents (spaces for alignment)
Aaron Marcher [Mon, 7 May 2018 11:48:43 +0000 (13:48 +0200)]
Fix indents (spaces for alignment)

6 years agowifi_perc: Simplify
Aaron Marcher [Mon, 7 May 2018 10:25:34 +0000 (12:25 +0200)]
wifi_perc: Simplify

6 years agonum_files: Variable declarations at top of block
Aaron Marcher [Mon, 7 May 2018 10:17:13 +0000 (12:17 +0200)]
num_files: Variable declarations at top of block

6 years agoFix disk_perc by casting it to int
Aaron Marcher [Mon, 7 May 2018 10:14:46 +0000 (12:14 +0200)]
Fix disk_perc by casting it to int

6 years agodisk_perc: Simplify
Aaron Marcher [Mon, 7 May 2018 09:44:15 +0000 (11:44 +0200)]
disk_perc: Simplify

6 years agocpu: Simplify functions
Aaron Marcher [Mon, 7 May 2018 09:39:59 +0000 (11:39 +0200)]
cpu: Simplify functions

6 years agoUnify header includes
Aaron Marcher [Mon, 7 May 2018 09:21:59 +0000 (11:21 +0200)]
Unify header includes

- Sort Alphabetically
- Same indentation for preprocessor clauses

6 years agoentropy: Small fix
Aaron Marcher [Sun, 6 May 2018 21:09:36 +0000 (23:09 +0200)]
entropy: Small fix

6 years agoentropy: Port to OpenBSD
Aaron Marcher [Sun, 6 May 2018 20:54:32 +0000 (22:54 +0200)]
entropy: Port to OpenBSD

OpenBSD's entropy design is superior to Linux.

6 years agodatetime: Add <stdio.h> for fprintf
Aaron Marcher [Sun, 6 May 2018 20:41:56 +0000 (22:41 +0200)]
datetime: Add <stdio.h> for fprintf

6 years agodatetime: Add error message
Aaron Marcher [Sun, 6 May 2018 20:38:29 +0000 (22:38 +0200)]
datetime: Add error message

6 years agoFix coding style
Aaron Marcher [Sun, 6 May 2018 20:28:56 +0000 (22:28 +0200)]
Fix coding style

- Use block for single statement ifs
- Keep lines to reasonable length (current debate as to reasonable)
- When functions return -1 for error test against 0 not -1
- Do not indent cases another level
- Do not test against NULL and 0 explicitly
- Use tabs for indentation, use spaces for alignment

6 years agoRemove cpu_iowait
Aaron Marcher [Sun, 6 May 2018 19:11:50 +0000 (21:11 +0200)]
Remove cpu_iowait

The third value from load_avg (idle) gives us almost the same
information as cpu_iowait. Plus OpenBSD does not offer an iowait value
as Linux and thus the corresponding function would not be portable.

6 years agocpu_perc: Documentation and readbility improvements
Aaron Marcher [Sun, 6 May 2018 19:10:02 +0000 (21:10 +0200)]
cpu_perc: Documentation and readbility improvements

6 years agocpu_perc: Port to OpenBSD
Aaron Marcher [Sun, 6 May 2018 15:48:37 +0000 (17:48 +0200)]
cpu_perc: Port to OpenBSD

In OpenBSD the CPU usage in percent is now computed using KERN_CPTIME
sysctl.

6 years agoswap_*: Port to OpenBSD
Aaron Marcher [Sat, 5 May 2018 23:20:46 +0000 (01:20 +0200)]
swap_*: Port to OpenBSD

6 years agobattery: Remove full indicator
Aaron Marcher [Fri, 4 May 2018 16:04:53 +0000 (18:04 +0200)]
battery: Remove full indicator

It does not respect charging thresholds and it is not trivial to
implement the indicator in OpenBSD.

6 years agowifi_perc: Fix file descriptor leak
Aaron Marcher [Wed, 2 May 2018 17:41:53 +0000 (19:41 +0200)]
wifi_perc: Fix file descriptor leak

6 years agoAdd examples to config.def.h
Aaron Marcher [Wed, 2 May 2018 10:30:16 +0000 (12:30 +0200)]
Add examples to config.def.h

6 years agouptime: Add missing brace
Aaron Marcher [Wed, 2 May 2018 10:08:54 +0000 (12:08 +0200)]
uptime: Add missing brace

6 years agovolume: Cast SOUND_MIXER_READ_DEVMASK to int to avoid warning.
parazyd [Wed, 2 May 2018 09:38:27 +0000 (11:38 +0200)]
volume: Cast SOUND_MIXER_READ_DEVMASK to int to avoid warning.

6 years agowifi: Various cleanups
Aaron Marcher [Wed, 2 May 2018 06:49:06 +0000 (08:49 +0200)]
wifi: Various cleanups

6 years agouser: Only declare variables in the beginning
Aaron Marcher [Wed, 2 May 2018 06:42:55 +0000 (08:42 +0200)]
user: Only declare variables in the beginning

6 years agouptime: Simplifiy and clean up
Aaron Marcher [Wed, 2 May 2018 06:41:06 +0000 (08:41 +0200)]
uptime: Simplifiy and clean up

6 years agorun_command: Clean up
Aaron Marcher [Wed, 2 May 2018 06:29:36 +0000 (08:29 +0200)]
run_command: Clean up

6 years agokeyboard_indicators: Clean up opening display
Aaron Marcher [Wed, 2 May 2018 06:26:23 +0000 (08:26 +0200)]
keyboard_indicators: Clean up opening display

6 years agoip: Sort headers alphabetically
Aaron Marcher [Wed, 2 May 2018 06:21:32 +0000 (08:21 +0200)]
ip: Sort headers alphabetically

6 years agobattery_state: Unify unknown state with "?" symbol
Aaron Marcher [Wed, 2 May 2018 06:16:21 +0000 (08:16 +0200)]
battery_state: Unify unknown state with "?" symbol

6 years agoUpdate README todo
Aaron Marcher [Tue, 1 May 2018 19:05:50 +0000 (21:05 +0200)]
Update README todo

6 years agoRemove battery_power for various reasons
Aaron Marcher [Tue, 1 May 2018 19:01:25 +0000 (21:01 +0200)]
Remove battery_power for various reasons

- Battery power cannot be easily gatherable via apm(4)
- IMHO it does not represent essential information

6 years agoTweak build system a little bit
Laslo Hunhold [Tue, 1 May 2018 18:50:53 +0000 (20:50 +0200)]
Tweak build system a little bit

Be consistent with brackets and add a comment for OpenBSD to make it
clearer what the actual intent of the uncommented line is.

In the Makefile, add a dependency of slstatus.o from config.mk.

6 years agobattery_perc: Port to OpenBSD
Aaron Marcher [Tue, 1 May 2018 18:45:29 +0000 (20:45 +0200)]
battery_perc: Port to OpenBSD

6 years agocomponents/swap.c | move duplicated code to separate function
Laslo Hunhold [Tue, 1 May 2018 18:20:58 +0000 (20:20 +0200)]
components/swap.c | move duplicated code to separate function

6 years agoUse indentation to increase readability
Laslo Hunhold [Tue, 1 May 2018 17:01:22 +0000 (19:01 +0200)]
Use indentation to increase readability

Granted, this style is definitely not common, but for the short
utility-functions of this program it's just the right choice. This
provides great flexibility, such that in the long run, it will be
possible to also share code between the OS-implementations.

This also keeps the state-keeping at a minimum and makes it clearer
which functions are implemented on which OS without having to jiggle
around with too many files in the process.

6 years agoRevert component-split
Laslo Hunhold [Tue, 1 May 2018 16:10:39 +0000 (18:10 +0200)]
Revert component-split

this reverts the commits from 92ab9ef52ebcb097add97d9f78e67ad1c1d6a6ec up to
d42870d6ca7fb587b38f8cf6d6821ae33a53a696.

After heavy consideration, the component split has more disadvantages
than advantages, especially given there will be utility-functions
sharing quite a lot of code that would then need to be duplicated, as it
does not fit into the util.c due to its speciality.

One big advantage of the component-wise build is readability, and
without doubt, this was achieved here. This point will be addressed
with a different approach that will be visible in the upcoming commits.

One big disadvantage of the component build is the fact that it
introduces state to the build process which is not necessary. Before its
introduction, the only influencing factors where the system-defines
__linux__ and __OpenBSD__. With the components, we are also relying on
the output of uname(1).
Additionally, if the os.mk is not present, make gives the output

     $ make
     Makefile:5: os.mk: No such file or directory
     make: *** No rule to make target 'os.mk'.  Stop.

This could easily be fixed by providing some sort of meta-rule for this
file, however, it indicates the problem we have here, and this entire
statefulness will heavily complicate packaging of this tool and makes
the build process much more complex than it actually has to be.

6 years agoMakefile: add distclean target
Quentin Rameau [Mon, 30 Apr 2018 14:14:05 +0000 (16:14 +0200)]
Makefile: add distclean target

6 years agoMakefile: move OS-specific libs to configure script
Quentin Rameau [Mon, 30 Apr 2018 14:13:12 +0000 (16:13 +0200)]
Makefile: move OS-specific libs to configure script

6 years agoMakefile: separate default flags from user flags
Quentin Rameau [Mon, 30 Apr 2018 14:11:45 +0000 (16:11 +0200)]
Makefile: separate default flags from user flags

6 years agoUpdate LICENSE for Quentin Rameau
Aaron Marcher [Mon, 30 Apr 2018 13:44:41 +0000 (15:44 +0200)]
Update LICENSE for Quentin Rameau

6 years agowifi: OS split
Quentin Rameau [Mon, 30 Apr 2018 13:14:39 +0000 (15:14 +0200)]
wifi: OS split

6 years agouptime: OS split
Quentin Rameau [Mon, 30 Apr 2018 13:14:38 +0000 (15:14 +0200)]
uptime: OS split

6 years agotemperature: OS split
Quentin Rameau [Mon, 30 Apr 2018 13:14:37 +0000 (15:14 +0200)]
temperature: OS split

6 years agoswap: OS split
Quentin Rameau [Mon, 30 Apr 2018 13:14:36 +0000 (15:14 +0200)]
swap: OS split

6 years agoram: OS split
Quentin Rameau [Mon, 30 Apr 2018 13:14:35 +0000 (15:14 +0200)]
ram: OS split

6 years agoentropy: OS split
Quentin Rameau [Mon, 30 Apr 2018 13:14:34 +0000 (15:14 +0200)]
entropy: OS split

6 years agocpu: OS split
Quentin Rameau [Mon, 30 Apr 2018 13:14:33 +0000 (15:14 +0200)]
cpu: OS split

6 years agobattery: OS split
Quentin Rameau [Mon, 30 Apr 2018 13:14:32 +0000 (15:14 +0200)]
battery: OS split

6 years agoMakefile: detect running OS
Quentin Rameau [Mon, 30 Apr 2018 13:14:31 +0000 (15:14 +0200)]
Makefile: detect running OS

6 years agocpu_freq: Port to OpenBSD
Aaron Marcher [Mon, 30 Apr 2018 11:20:24 +0000 (13:20 +0200)]
cpu_freq: Port to OpenBSD

In OpenBSD CPU frequency gets fetched using sysctl now.

6 years agoFix typo in temperature
Aaron Marcher [Sun, 29 Apr 2018 20:44:09 +0000 (22:44 +0200)]
Fix typo in temperature

6 years agoUpdate README for OpenBSD build
Aaron Marcher [Sun, 29 Apr 2018 20:33:15 +0000 (22:33 +0200)]
Update README for OpenBSD build

6 years agouptime: Separate function for readbility
Aaron Marcher [Sun, 29 Apr 2018 18:07:09 +0000 (20:07 +0200)]
uptime: Separate function for readbility

6 years agobattery: Separate function for readbility
Aaron Marcher [Sun, 29 Apr 2018 18:02:42 +0000 (20:02 +0200)]
battery: Separate function for readbility

6 years agoram: Move up includes
Aaron Marcher [Sun, 29 Apr 2018 18:00:38 +0000 (20:00 +0200)]
ram: Move up includes

6 years agoSort LICENSE according to first commit
Aaron Marcher [Sun, 29 Apr 2018 16:50:44 +0000 (18:50 +0200)]
Sort LICENSE according to first commit

6 years agotemp: Port to OpenBSD
Aaron Marcher [Sun, 29 Apr 2018 16:35:41 +0000 (18:35 +0200)]
temp: Port to OpenBSD

In OpenBSD temperature gets fetched using sysctl now.

6 years agoRemove vol_perc() from todo in README
Aaron Marcher [Sun, 29 Apr 2018 14:08:45 +0000 (16:08 +0200)]
Remove vol_perc() from todo in README

6 years agoUpdate LICENSE for parazyd
Aaron Marcher [Sun, 29 Apr 2018 14:05:53 +0000 (16:05 +0200)]
Update LICENSE for parazyd

6 years agoAdd OpenBSD support in volume.c
parazyd [Sun, 29 Apr 2018 13:41:18 +0000 (15:41 +0200)]
Add OpenBSD support in volume.c

6 years agoUpdate LICENSE for Ali H. Fardan
Aaron Marcher [Sun, 29 Apr 2018 11:02:08 +0000 (13:02 +0200)]
Update LICENSE for Ali H. Fardan

6 years agoRemove ipv{4,6}() from todo in README
Aaron Marcher [Sun, 29 Apr 2018 11:00:12 +0000 (13:00 +0200)]
Remove ipv{4,6}() from todo in README

6 years agoip: add OpenBSD support
Ali H. Fardan [Sun, 29 Apr 2018 07:55:38 +0000 (10:55 +0300)]
ip: add OpenBSD support

ip.c already works on OpenBSD, it's just missing some headers:

6 years agoRemove non-portable functions from config.def.h
Aaron Marcher [Mon, 16 Apr 2018 17:09:07 +0000 (19:09 +0200)]
Remove non-portable functions from config.def.h

6 years agoAdd Darron Anderson to LICENSE
Aaron Marcher [Sat, 14 Apr 2018 17:44:54 +0000 (19:44 +0200)]
Add Darron Anderson to LICENSE

Thank you for your contribution.

6 years agoRemove ram_*() from README
Aaron Marcher [Sat, 14 Apr 2018 17:44:25 +0000 (19:44 +0200)]
Remove ram_*() from README

6 years agoAdd OpenBSD RAM stats
Darron Anderson [Sat, 14 Apr 2018 09:41:35 +0000 (09:41 +0000)]
Add OpenBSD RAM stats

6 years agoFormat error messages properly
Aaron Marcher [Wed, 28 Mar 2018 17:46:27 +0000 (19:46 +0200)]
Format error messages properly

Make use of strerror(errno) and format all errors equally:
function ['parameters']: error message

6 years agoRemove program name from error messages
Aaron Marcher [Wed, 28 Mar 2018 16:49:27 +0000 (18:49 +0200)]
Remove program name from error messages

6 years agoGet rid of err.h as it is not portable
Aaron Marcher [Wed, 28 Mar 2018 16:26:56 +0000 (18:26 +0200)]
Get rid of err.h as it is not portable

Replace warn() and warnx() with fprintf() and add <stdio.h> where
necessary.

6 years agoRemove unnecessary headers
Aaron Marcher [Wed, 28 Mar 2018 16:14:08 +0000 (18:14 +0200)]
Remove unnecessary headers

6 years agoRemove ALSA dependency from README
Aaron Marcher [Mon, 26 Mar 2018 16:09:30 +0000 (18:09 +0200)]
Remove ALSA dependency from README

ALSA is not a dependency anymore as we use /dev/mixer. The corresponding
notice about PulseAudio is thus not necessary too.