Commit Graph

430 Commits

Author SHA1 Message Date
tripledonkey d088baea4f
use statvfs f_frsize for file system block size (#405)
* use statvfs f_frsize for file system block size
2020-04-08 16:06:35 +02:00
Ingo Bürk 582432fcc6
Merge pull request #402 from Stunkymonkey/format_placeholder-wireless_info
use format_placeholder for wireless_info
2020-04-08 08:41:14 +02:00
Felix Buehler 44fad4d2cd use format_placeholder for volume 2020-04-07 23:02:30 +02:00
Ingo Bürk e697a1f19f
Merge pull request #404 from Stunkymonkey/format_placeholder-file_content
use format_placeholder for file_content
2020-04-07 08:31:57 +02:00
Felix Buehler f0b5758c72 use format_placeholder for file_content 2020-04-03 16:15:38 +02:00
Felix Buehler fc95763f7b remove goto-labels from wireless_info 2020-04-03 16:01:55 +02:00
Ingo Bürk 1858cd8dfb
Merge pull request #401 from Stunkymonkey/format_placeholder-time
use format_placeholder for time
2020-04-03 08:38:30 +02:00
Ingo Bürk 4980193dc7
Merge pull request #400 from Stunkymonkey/format_placeholder-run_watch
use format_placeholder for run_watch
2020-04-03 08:38:04 +02:00
Ingo Bürk ffa429d145
Merge pull request #399 from Stunkymonkey/format_placeholder-path_exists
use format_placeholder for path_exists
2020-04-03 08:37:05 +02:00
Felix Buehler ae2566f28e use format_placeholder for wireless_info 2020-03-31 17:05:48 +02:00
Felix Buehler 7418b5bebb use format_placeholder for time 2020-03-31 16:13:24 +02:00
Felix Buehler dd683f618a use format_placeholder for run_watch 2020-03-31 16:08:07 +02:00
Felix Buehler 84c0eddd66 use format_placeholder for path_exists 2020-03-31 16:01:17 +02:00
Ingo Bürk b4c1bb97af
Merge pull request #398 from Stunkymonkey/format_placeholder-mem
use format_placeholder for mem
2020-03-31 15:31:34 +02:00
Felix Buehler 066e813331 use format_placeholder for mem 2020-03-31 15:21:46 +02:00
Ingo Bürk b4555f53e2
Merge pull request #396 from Stunkymonkey/format_placeholder-ipv6_addr
use format_placeholder for ipv6_addr
2020-03-31 15:06:51 +02:00
Felix Buehler ebaeb8fb23 use format_placeholder for ipv6_addr 2020-03-31 15:03:18 +02:00
Felix Buehler 7aa3031cb6 use format_placeholder for load 2020-03-31 14:56:21 +02:00
Samuel Holland 585d0700c7 avoid out-of-bounds read after invalid %cpu conversion
In the case where no CPU number is given, skipping a character of
padding actually skips the null terminator, causing further iterations
through the loop to read out of bounds. Have sscanf() return the number
of characters read, instead of reconstructing it from the CPU number.

This was observed as a failure in test 024-cpu-usage-invalid-cpu.
2020-03-28 21:02:02 -05:00
nia 9b8403ac84 print_volume: Native NetBSD audio support
Avoid using the OSS emulation layer to fetch the master volume,
and instead share the audioio code with OpenBSD.

Avoid a failed read on the master control's mute enum if it can't
be found, because sometimes there isn't one.
2020-03-11 23:29:56 +00:00
Ingo Bürk 6eb70f10d2
Merge pull request #390 from Stunkymonkey/format_placeholder-eth
use format_placeholder for eth.info
2020-03-06 13:52:11 +01:00
Felix Buehler e60eb9f3d1 use format_placeholder for disk.info 2020-03-03 21:32:49 +01:00
Felix Buehler 48119d890a use format_placeholder for eth.info 2020-03-03 21:31:56 +01:00
Ingo Bürk ae67594b6d
Merge pull request #386 from Stunkymonkey/format_placeholder-date
use format_placeholder for ddate
2020-02-21 17:35:20 +01:00
Felix Buehler 0a5f0ef115 use exact size for known strings 2020-02-21 15:23:37 +01:00
Felix Buehler 3ceb0b8fcf use format_placeholder for ddate 2020-02-18 20:22:36 +01:00
Felix Buehler 2ef1d7440a use format_placeholder for cpu_temperature 2020-02-18 17:51:12 +01:00
Ingo Bürk b61e959a58
Merge pull request #381 from Stunkymonkey/format_wireless
add wireless format-options
2020-02-17 08:34:09 +01:00
Felix Buehler 42e7147291 add wireless format-options 2020-02-10 22:33:20 +01:00
Felix Buehler b5a804d1af use format_placeholder for battery 2020-02-10 21:05:18 +01:00
zsugabubus ad29f204b7
print_mem: Fix overflow on 32-bit systems
Values stored as `unsigned long` in "/proc/meminfo" but they were
handled as `long`.

On 32-bit systems with 4G memory it results in integer overflow.
2019-11-24 23:41:46 +01:00
grmat abfe05c8bd Introduce format_percentage for battery (#371)
Allow custom output, backwards-compatible to integer_battery_capacity
2019-11-16 16:26:26 +01:00
MK13 572c96d63e Introduce memory options 'unit' and 'decimals'
Previously the format placeholders were auto-converted to the maximum possible
unit, e.g. /proc/meminfo reports MemTotal of 16307104kB which will get
converted to 15.6GiB. It is now possible to specifiy the target unit, e.g. Mi,
which will be used for the conversion - in the example it would lead to
15924.9MiB.

The resulting number can now be further formatted via the decimal option. It
allows to specify the number of decimals to use, e.g. 15.6GiB vs. 15GiB or
15924.9MiB vs. 15925MiB.
2019-10-26 15:32:32 +02:00
Sascha Wessel 3d6b1b576b wireless: update %signal and %quality based on station info on Linux (#368)
Use station info instead of bss info to update %signal and %quality.
Bss info is based on scan info and doesn't get updated often. Station
info get's updated with every beacon. Bss info still used as fallback.
2019-10-21 08:48:50 +02:00
Olivier Gayot 49cf3d7edb Mention the return value of the slurp function and the implications
Signed-off-by: Olivier Gayot <olivier.gayot@sigexec.com>
2019-09-19 15:48:59 +02:00
Olivier Gayot 4cf8bebf71 Do not return true from slurp() if it failed to read
Failing to read() some data into the destination buffer from the slurp()
function was not considered an error. This means that we were
potentially leaving the caller with an uninitialized destination buffer
without letting him know it's uninitialized.

It is quite unlikely that a single call to read() would ever fail right
after a successful call to open(..., O_RDONLY). However, one practical
example of this happening is when the file being opened is actually a
directory.

Fixed by propagating the error (i.e. returning false from slurp()) if
the call to read() fails.

Signed-off-by: Olivier Gayot <olivier.gayot@sigexec.com>
2019-09-19 15:47:14 +02:00
Thomas Klausner 5aec4a5da3 Improve NetBSD port. (#361)
Detect and link against ossaudio.

Comment out unused code and functions.
2019-07-29 13:46:20 -07:00
Michael Stapelberg e84f9588df print_cpu_usage: use buffered file API
fixes #343
fixes #344
2019-07-29 21:46:08 +02:00
Michael Stapelberg 23da59920c make pulseaudio an optional dependency, follow best practices
For my thoughts about optional dependencies, see
https://michael.stapelberg.ch/posts/2019-05-23-optional-dependencies/

This commit follows the best practices outlined in that article:

1. The travis config was modified to verify both code paths build and link/don’t
   link against pulseaudio.

2. If pulseaudio is missing, the build fails until packagers explicitly pass a
   --disable flag. In practice, I think the only situation when this flag should
   be set is in source-based linux distributions where users can express
   package-level compilation preferences (e.g. Gentoo USE flags).

3. The --version output now reflects the status of the optional dependency.

fixes #359
2019-07-29 21:07:40 +02:00
Thomas Klausner 667e38abab On NetBSD, include sys/socket.h for AF_INET{,6}. 2019-07-21 21:17:59 +02:00
Ingo Bürk 86a4ff0333
Merge pull request #355 from jasperla/header_fix
Fix headers meant for OpenBSD, but snuck in for FreeBSD
2019-07-21 15:28:40 +02:00
Michael Stapelberg 02a47cd196 battery: include sys/sysctl.h on OpenBSD
This is required so that CTL_HW and others are defined (ran into this on OpenBSD
6.5).
2019-07-12 14:44:03 +02:00
Jasper Lievisse Adriaanse 70b954b122 Fix headers meant for OpenBSD, but snuck in for FreeBSD 2019-07-08 20:14:59 +02:00
Jasper Lievisse Adriaanse 3a51673c05 Extend battery handling on OpenBSD (#351)
If acpibat watts value is not available, try current (for batteries
that report in amps), then convert to watts.

originally submitted by @jcs
2019-07-08 17:53:25 +02:00
Sam Newbold 300b31b2df
print_file_contents: allocate enough to include \0
related to #331
Previously, if max_chars was read, the null byte would be written
past the end of buf.
2019-06-10 16:36:18 +02:00
Dennis Vesterlund 9b5f6ae5f4 Added function to print content from file (#331)
Added a function to print file contents to status bar without newlines.
Added tests for print file contents function
Added manpage entry for file contents
2019-02-21 15:34:32 +01:00
Michael Stapelberg 0e4fd9ad4a fix ethernet speed display for 100 Gbit/s cards
Before this fix, i3status would display 34464 Mbit/s instead of 100000 Mbit/s,
because it was only looking at ecmd.speed, ignoring ecmd.speed_hi.
2019-01-27 22:32:47 +01:00
eplanet 96923a5bc0 Fix non Linux build for #309 2019-01-23 10:44:48 +01:00
Michael Stapelberg a57cdc84e2
Switch to autotools (#316) 2019-01-23 08:56:40 +01:00
Denton Liu 7efbeeaf6c Implement %devicename specifier for volume module (#325)
This commit implements the %devicename specifier for the volume module
for both PulseAudio and ALSA. This way, i3status will be able to display
the specific device that corresponds to the volume indicator.

Note that this is not implemented for the OSS API but is left in a state
where someone can pick it up for the future.
2019-01-23 08:45:51 +01:00
Eugene Dzhurinsky 696ddf461f
Fixed ALSA capture device monitoring.
When using ALSA, the "Capture" mixer doesn't have the playback channel,
instead "capture"-related methods should be used to get information
about the current volume / state of the mixer.
2019-01-03 21:59:33 -05:00
eplanet 1b7501b7ea Corrections according to PR review 2018-11-15 22:27:23 +01:00
eplanet ac6c2a7d46 Add timezone switch 2018-11-10 10:47:05 +01:00
Orestis 2d38178063
Merge pull request #319 from eplanet/fix-etc-mtab
Read /proc/mounts if /etc/mtab can't be read
2018-11-08 11:52:47 +02:00
eplanet e545525148 Read /proc/mounts if /etc/mtab can't be read 2018-11-08 07:59:15 +01:00
eplanet bc5cc6f238 Fix error messages 2018-11-07 23:01:36 +01:00
TwentyFourD 6914f8e5b5
print_cpu_usage.c: Support non-consecutive CPUs
Fixes #308
2018-11-05 12:30:52 +02:00
Gaël PORTAY 0b8aa86ecb print_cpu_usage: fix invalid %cpu placeholder output
Currently, the module cpu_usage prints %cpu0 information for the invalid
%cpu placeholder (i.e. the cpu number is missing).

Consider the following configuration.

	order += "cpu_usage"

	cpu_usage {
		format = "cpu0=%cpu0 cpu1=%cpu1 cpu=%cpu"
		# missing cpu number -------------------^
	}

The configuration above produces the output below.

	$ i3status -c config
	i3status: trying to auto-detect output_format setting
	i3status: auto-detected "term"
	cpu0=-2% cpu1=-49% cpu=-2%
	cpu0=06% cpu1=02% cpu=06%
	cpu0=05% cpu1=06% cpu=05%
	...

The module prints %cpu0 at the third placeholder where it should report
an error.

This commit fixes this behavior by initializing `number' to -1. If the
cpu is missing in %cpu placeholder, the sscanf function does not set
`number'. Because `number' is -1 (lower to 0), an error is reported and
the placeholder is skipped.

	$ i3status -c ./config
	i3status: trying to auto-detect output_format setting
	i3status: auto-detected "term"
	provided CPU number '-1' above detected number of CPU 4
	cpu0= cpu1=-48% cpu=
	provided CPU number '-1' above detected number of CPU 4
	cpu0= cpu1=11% cpu=
	provided CPU number '-1' above detected number of CPU 4
	cpu0= cpu1=03% cpu=
	...
2018-10-21 20:51:53 -04:00
arcnmx ddadc8e4d7 Provide a more natural volume percentage with ALSA.
The rationale of the code is explained in the header:
http://git.alsa-project.org/?p=alsa-utils.git;a=blob;f=alsamixer/volume_mapping.c;h=1c0d7c45e6686239464e1b0bbc8983ea57f3914f;hb=HEAD
> The mapping is designed so that the position in the interval is
> proportional to the volume as a human ear would perceive it (i.e., the
> position is the cubic root of the linear sample multiplication
> factor).

and the commit message:
http://git.alsa-project.org/?p=alsa-utils.git;a=commit;h=34bb514b5fd1d6f91ba9a7b3a70b0ea0c6014250
> use a mapping where the bar height is proportional to the audible
> volume, i.e., where the amplitude is the cube of the bar height.

and further explanation can be found in the pull request:
https://github.com/i3/i3status/pull/268#pullrequestreview-147429763
2018-10-11 00:21:03 +03:00
David96 6a5e5b8ac4 Add support for "POWER_SUPPLY_STATUS=Not charging" (fixes #304) 2018-09-03 20:50:36 +02:00
Max Christian Pohle 04d09aac49 Added %interface to the ethernet options 2018-08-24 23:43:35 +02:00
= d003edcba6 Fix for issue 300: Correctly print usage for cpu 10 2018-07-31 00:27:13 -05:00
Ingo Bürk 639a67f752
Merge pull request #296 from Stunkymonkey/include-order
switch to clang 3.8 & ignore include sort order
2018-07-16 16:18:06 +02:00
Ingo Bürk 0b25052cd0
Merge pull request #299 from tuxillo/patch-2
Detect interface type on DragonFly BSD
2018-07-16 16:13:47 +02:00
Antonio Huete Jimenez afd7e44d97 Detect interface type on DragonFly BSD 2018-07-15 21:59:18 +00:00
Antonio Huete Jimenez deca11c0a0 Do not use pulseaudio for DragonFly BSD 2018-07-14 20:23:22 +00:00
Felix Buehler d099a907f6 fix clang errors 2018-07-13 15:11:43 +02:00
Felix Buehler 52e9f6f63b able to print percentage
its now possible to have percentage before and after a variable. except
for the date. But percentage with dates does not make much sense to me, so
i skipped it.
2018-07-13 15:03:31 +02:00
Ingo Bürk 9aafc38370
Merge pull request #256 from oyvinht/master
Read multiple batteries on DragonFly BSD.
2018-07-13 12:31:04 +02:00
Ingo Bürk 302966374b
Merge pull request #292 from Stunkymonkey/format_quality
add format_quality option in wireless
2018-06-29 23:10:53 +02:00
Felix Buehler 4ea804b751 add format_quality option in wireless 2018-06-29 22:56:09 +02:00
Olivier Gayot 03c8908ec6 Stop requiring CAP_NET_ADMIN
Since the following commit in the Linux kernel tree

  0fdc100bdc4b ethtool: allow non-netadmin to query settings

it is no longer necessary to have the CAP_NET_ADMIN capability to query
a device speed using ioctl(..., SIOCETHTOOL) in conjonction with the
ETHTOOL_GSET ethtool command.

The mentioned commit landed first in the 2.6.37 version of the Kernel.
This version is no longer maintained nowdays.

Since it is not necessary anymore, it is strongly prefered from a
security standpoint to drop the CAP_NET_ADMIN capability from the
binary.

Signed-off-by: Olivier Gayot <olivier.gayot@sigexec.com>
2018-06-25 11:53:05 +02:00
Olivier Gayot c221b4d331 Prevent potential crash if glob() fails
Calling globfree(NULL) is undefined behaviour. In Linux (glibc), it
results in a segmentation fault.

It is also undefined behaviour to call globfree(&pglob) if a previous
call to glob(&pglob) returned an error.

Signed-off-by: Olivier Gayot <olivier.gayot@sigexec.com>
2018-06-20 14:20:17 +02:00
Olivier Gayot 445b1925e3 Fix potential memory leak on Linux
The function slurp_all_batteries(), on Linux, allocates memory
dynamically

Signed-off-by: Olivier Gayot <olivier.gayot@sigexec.com>
2018-06-20 14:20:17 +02:00
Olivier Gayot c64195d147 Fix invalid handling of glob() errors on Linux
The manual of glob(3) says that the function returns 0 on successful
completion. Any other integer value should be considered an error, not
only negative integers.

In practice, *BSD systems use negative values but Linux uses positive
integers.

Signed-off-by: Olivier Gayot <olivier.gayot@sigexec.com>
2018-06-20 14:20:17 +02:00
Olivier Gayot 95c068358a Fix use of undefined macro __OpenBSD__
Compiling on Linux with -Wundef produces the following warning:

  warning: "__OpenBSD__" is not defined, evaluates to 0 [-Wundef]

Signed-off-by: Olivier Gayot <olivier.gayot@sigexec.com>
2018-06-20 14:20:17 +02:00
Olivier Gayot a6dd14c8c6 Avoid assigning a new value to a var before using the old value
Signed-off-by: Olivier Gayot <olivier.gayot@sigexec.com>
2018-06-20 14:20:17 +02:00
Olivier Gayot 598b76cc53 Make sure the arguments passed to printf/die(...) match the format
Signed-off-by: Olivier Gayot <olivier.gayot@sigexec.com>
2018-06-20 14:20:17 +02:00
Olivier Gayot ca8c3e7337 No longer use a temporary buffer in the die() function
Before the following change

  f947d0a Breaks configfiles! Major refactoring of i3status, see below

The die(fmt, ...) function was outputting the reason to the status bar
in addition to stderr. For this reason, it was meaningful to create a
temporary string according to the format string and then passing it
around to the different functions.

Nowadays, we only display the error message to stderr so calling
fprintf(stderr, ...) is much simpler.

Signed-off-by: Olivier Gayot <olivier.gayot@sigexec.com>
2018-06-20 11:01:59 +02:00
Olivier Gayot 451ff9be0b Fix shown IP address belonging to wrong interface
The following commit:

  6a75ea9 Show IP address when address has a label

introduced a way to show the IP address of an interface when a label is
associated to the IP.

When a label is associated to an IP, the structure returned by
getifaddrs() has the label concatenated to the interface name in the
.ifa_name field as in the following example:

    struct ifaddrs ifaddr = {
       .ifa_name = "eth0:mylabel",
    };

As a consequence, using a strict comparison between the interface name
and the .ifa_name field yields a falsy result. However, checking if the
.ifa_name starts with the interface name (e.g. eth0) does not work
either because other network interfaces can have a name which starts
with eth0.

This commit solves the issue by stripping out the optional label from
the .ifa_name field before making a strict comparison with the interface
name.

Fix #283

Signed-off-by: Olivier Gayot <olivier.gayot@sigexec.com>
2018-06-11 22:06:57 +02:00
Olivier Gayot 99a6fb5e49 Simplify the algorithm used to determine the IP address
Signed-off-by: Olivier Gayot <olivier.gayot@sigexec.com>
2018-06-04 19:59:09 +02:00
Ingo Bürk b850f5852d
Merge pull request #270 from Stunkymonkey/mem-support
initial support of memory-usage for linux
2018-05-19 22:08:42 +02:00
eplanet 9a8106fab9 Fix MacOS build 2018-05-15 13:34:36 +02:00
Benedikt Heine cba8f55938 Simplify the memory thresholds 2018-05-04 18:46:59 +02:00
Benedikt Heine 7839e93c9b Rename ram variables consistently 2018-05-04 18:46:38 +02:00
Felix Buehler c55754542e Implement support for memory-usage on Linux 2018-04-11 22:36:41 +02:00
Ingo Bürk 82d25dc362
Merge pull request #275 from winks/patch-2
Fix NULL value on OpenBSD when there is no acpitz0
2018-04-08 15:53:19 +02:00
Florian Anderiasch 46b5c264d1 Fix NULL value on OpenBSD when there is no acpitz0
Using %degrees on OpenBSD resulted in garbage values if sysctl doesn't
know about any cpu temperature sensors.
2018-04-06 19:56:55 +02:00
Dan Robertson 6a75ea9aea
Show IP address when address has a label
If an address has been added with a label, ensure the correct address is
shown.
2018-03-29 10:46:36 +00:00
Øyvin Halfdan Thuv 3e1213123f Read multiple batteries on DragonFly BSD.
Using ACPI to read individual battery information instead of just
accumulations from sysctl.
2018-03-27 11:52:08 +02:00
Ingo Bürk 4345fa9d97
Merge branch 'master' into master 2018-03-27 09:26:55 +02:00
Ingo Bürk 3aec438a51
Merge pull request #243 from jasperla/fei_error
Remove overly aggressive #error
2018-03-27 09:07:53 +02:00
Carlin Bingham 5b416d4ac0 OpenBSD: fix volume display on some hardware
On some hardware the AUDIO_MIXER_READ ioctl requires the current number
of channels to be set, and the mute device found needs to be checked if
it belongs to the master output device.
2018-02-13 02:12:04 +13:00
Gerome Fournier 9212ee658b Make iface_type() work on FreeBSD 2018-02-07 11:26:34 +01:00
johcgt d5c69a9d60 Treat zero battery capacity as "not available" (#259)
`print_battery_info` computes `batt_info.percentage_remaining` by
dividing batt_info.remaining by `full`. If `full` is `0` then the
battery remaining will be reported as "inf".

Before this, it tries to set `full` to either the design capacity or to
the last known good charge. It determines if these values are available
by checking whether their fields in `batt_info` are non-negative. As it
initialized `batt_info` with values of `-1`, a non-negative value
implies that something has provided a value.

`slurp_all_batteries` and `add_battery_info` however initialize these
fields to zero, so if these functions are called then
`batt_info.full_design` will always be used.

This means that on systems that don't provide a value for design
capacity the percentage remaining will be reported as "inf", unless the
user has set `last_full_capacity` to `true` in their `i3status.conf`.

This patch changes `print_battery_info` to expect values for the battery
capacity to be strictly greater than zero. This seems reasonable as a
battery with a capacity of zero isn't useful.

An alternative solution would be to change `slurp_all_batteries` and
`add_battery_info` to initialize `batt_info` with `-1`, as
`print_battery_info` does. This is less appealing as `add_battery_info`
is accumulating the values, so using `-1` would introduce off-by-one
errors without additional code to avoid them.
2018-01-28 15:37:51 +01:00
Emeric Planet 657c0498db Update comment as in #247 (#254) 2017-12-11 12:16:00 +01:00
Emeric Planet 53fb9b4f18 Add IPv6 address when IPv4 isn't available (#247) 2017-12-11 11:38:31 +01:00
eplanet 20a701bdf0 Call tzset at each time print 2017-12-09 15:48:18 +01:00
Jasper Lievisse Adriaanse 83d0b621c0 Remove overly aggressive #error
Change-Id: I8c20606d386d713cac51b620d1fcdb479a3622fe
2017-09-04 13:30:21 +02:00
kousu 62d0905c7f Be more cautious about handling invalid battery measurements. 2017-08-24 19:00:08 -04:00