Commit Graph

38 Commits

Author SHA1 Message Date
Nicolai Dagestad 97660cb42a rfkill: Set scols table name to make the json output valid
[kzak@redhat.com: - s/rfkill/rfkilldevices/]

Fixes: https://github.com/karelzak/util-linux/issues/1339
Signed-off-by: Nicolai Dagestad <nicolai@dagestad.fr>
Signed-off-by: Karel Zak <kzak@redhat.com>
2021-07-20 11:08:23 +02:00
Karel Zak 185bc3a832 rfkill: make RFKILL_EVENT_SIZE_V1 use more portable
The old linux/rfkill.h uses "int", new versions use sizeof() for the
macro ...

Signed-off-by: Karel Zak <kzak@redhat.com>
2021-05-06 17:10:46 +02:00
Karel Zak 787af7ce7c rfkill: fix compiler warning [-Wsign-compare]
Signed-off-by: Karel Zak <kzak@redhat.com>
2021-05-06 16:44:20 +02:00
Karel Zak f798aed128 rfkill: fix compiler warning [-Wformat=]
* `RFKILL_EVENT_SIZE_V1` is defined as sizeof(struct rfkill_event), so let's use %zu

* cast `len` to size_t to make it usable with %zu

Signed-off-by: Karel Zak <kzak@redhat.com>
2021-05-06 12:25:10 +02:00
Karel Zak 20fae1bde2 rfkill: add "toggle" command
Addresses: https://github.com/karelzak/util-linux/issues/1269
Signed-off-by: Karel Zak <kzak@redhat.com>
2021-03-23 15:20:44 +01:00
Karel Zak 061e26d06d rfkill: fix static analyzer warning [coverity scan]
>>>     CID 365738:  Uninitialized variables  (UNINIT)
>>>     Using uninitialized value "ret". Field "ret" is uninitialized.
326             return ret;

Signed-off-by: Karel Zak <kzak@redhat.com>
2021-02-18 11:09:31 +01:00
Sami Kerola 06229abccf
rfkill: stop execution when rfkill device cannot be opened
Without this two error messages are printed when rfkill device
cannot be opened.

    $ rfkill
    rfkill: cannot open /dev/rfkill: No such file or directory
    rfkill: cannot read /dev/rfkill: Bad file descriptor

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-11-14 15:22:34 +00:00
Karel Zak 2c308875a7 misc: consolidate version printing and close_stdout()
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-04-16 15:14:13 +02:00
Karel Zak f99148d6f5 rfkill: don't use lib/path
It seems like crazy overkill for this trivial purpose.

Signed-off-by: Karel Zak <kzak@redhat.com>
2018-06-21 13:07:46 +02:00
Sami Kerola 4dfd172dd8
rfkill: add --output-all option
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2018-05-03 19:56:21 +01:00
Karel Zak 2d6d789b3a rfkill: use scols_column_set_json_type()
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-04-18 16:08:15 +02:00
Patrick Steinhardt 74ccba3ed8 rfkill: include <poll.h> instead of <sys/poll.h>
The POSIX standard states that poll(3P) is being made available by
<poll.h>, not <sys/poll.h>. Most commands already include the correct
header, with the exception of rfkill. Fix that to avoid a warning on
musl-based systems.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
2018-04-11 13:04:53 +02:00
Ruediger Meier 73afd3f8e8 misc: fix typos using codespell
Some more funny typos, please review carefully.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2018-02-16 11:12:52 +01:00
Ruediger Meier 40defd0c4d rfkill: provide RFKILL_TYPE_FM if undefined
As discussed last year it's nice to be compatible to 2.6.32
https://www.spinics.net/lists/util-linux-ng/msg13963.html

BTW also re-define NUM_RFKILL_TYPES if needed, although we are
not really using it.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2018-01-24 12:53:36 +01:00
J William Piggott 4111bb3ab5 lib/timeutils: add common ISO timestamp masks
* Start the ISO format flags at bit 0 instead of bit 1.

* Remove unnecessary _8601 from ISO format flag names to
  avoid line wrapping and to ease readability.

* ISO timestamps have date-time-timzone in common, so move
  the TIMEZONE flag to bit 2 causing all timestamp masks
  to have the first three bits set and the last four bits
  as timestamp 'options'.

* Change the 'SPACE' flag to a 'T' flag, because it makes
  the code and comments more concise.

* Add common ISO timestamp masks.

* Implement the ISO timestamp masks in all applicable code
  using the strxxx_iso() functions.

Signed-off-by: J William Piggott <elseifthen@gmx.com>
2017-11-10 16:34:55 -05:00
Sami Kerola 9e33cddd94 rfkill: fix description name typo
Commit 7d2a9960ad made gps to look like a GUID Partition Table.

Reviewed-by: Karel Zak <kzak@redhat.com>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-10-17 10:15:21 +02:00
Karel Zak dec4fae21b rfkill: fix typo [coverity scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-10-12 14:53:32 +02:00
Karel Zak 7d2a9960ad rfkill: support old "list" output
.. just because we want to be replacement for the original version.

Signed-off-by: Karel Zak <kzak@redhat.com>
2017-10-03 15:35:17 +02:00
Karel Zak 49f4f7b6c5 rfkill: remove duplicate code
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-10-03 14:31:57 +02:00
Karel Zak 18d3a03fda rfkill: refactor actions
* convert action string to ID and use switch()
* add note about default output to the man page

Signed-off-by: Karel Zak <kzak@redhat.com>
2017-10-03 13:44:19 +02:00
Karel Zak 7d8e3bcd15 rfkill: improve default output
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-10-03 13:01:56 +02:00
Karel Zak e8f6060f27 rfkill: fix coding style and error messages
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-09-15 12:28:44 +02:00
Sami Kerola b120966812 rfkill: do not fsync(3) /dev/rfkill file descriptor
Attempt to fsync() this device returns EINVAL, causing the rfkill always to
return EXIT_FAILURE when either block or unblock is requested.  Simply
closing the file descriptor will fix the issue.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-09-15 12:24:31 +02:00
Sami Kerola 4f892d77d5 rfkill: allow use of multiple arguments
There is no reason why multiple arguments could not be supported.

Most common use case is to do multiple control commands in one go without us
of 'all' argument that can cause unnecessary connection breakage.  For
example someone might want to add to a system initialization following
commands.

    rfkill block bluetooth uwb wimax wwan gps fm nfc

That will ensure everything but wifi is turned off with as few commands as
possible, without killing wifi at any point.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-09-15 12:24:31 +02:00
Karel Zak ea05c23ab7 rfkill: add NFC fallback for old headers
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-08-31 20:40:37 +02:00
Karel Zak 3c5022c645 rfkill: cleanup returns
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-08-31 11:16:07 +02:00
Karel Zak f4949fcc3b rfkill: add Sami to authors
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-08-31 10:36:51 +02:00
Karel Zak fcc3efb40e rfkill: cleanup usage()
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-08-31 10:31:21 +02:00
Sami Kerola f806a238f7
rfkill: check id number refers to a device that exists
Earlier all commands happily accepted without detecting failure when
none-existing id number was used.  For example:

$ rfkill block 2017; echo $?
0

The same input after this change looks following.

$ rfkill block 2017; echo $?
rfkill: invalid identifier: 2017
1

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-08-30 20:32:49 +01:00
Sami Kerola 1bee8ec6f8
rfkill: use back and forward compatible test
The rfkill_event struct might grow in future, so ensure the read sizes are
at least the minimum, and allow it to be more.

Reference: https://github.com/torvalds/linux/blob/master/include/uapi/linux/rfkill.h#L90-L102
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-08-30 20:32:49 +01:00
Sami Kerola fd3d4ec710
rfkill: inform in syslog when rfkill is invoked
This should help when trying to explain what or who is flicking wireles on
or off.  Notice that the change is not perfect - if rfkill command is
setting a state that is already set the syslog entry is sent eventhough
there was no effective change.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-08-30 20:32:49 +01:00
Sami Kerola 7d0b3acbb4
rfkill: use human readable timestamps in event output
The event command appears to be something what primarily a developers will
to use when debugging.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-08-30 20:32:48 +01:00
Sami Kerola b3849c66d3
rfkill: use libsmartcols output
This also makes the rfkill to output status when executed without arguments.
That is believed ot be more useful than usage() output.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-08-30 20:32:48 +01:00
Sami Kerola 6955a1d66c
rfkill: do not ignore read error
Read error should be impossible, but when one does happen user certainly
wants to know about that rather than see even more strange issue caused
random data in name variable.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-08-30 20:32:48 +01:00
Sami Kerola b03378e793
rfkill: clarify 'all devices' handling
Stop using RFKILL_IS_INVALID a marker when rfkill is iterating over all
devices.  Addition of RFKIL_IS_ALL should make this a lot easier to digest,
especially if reading code in hurry.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-08-30 20:32:48 +01:00
Sami Kerola 367f40806e
rfkill: make programming style to match util-linux project
Use the usual facilities, add translation strings, move global variables at
the beginning of the file, make usage() look as expected, add standard
command-line option parsing.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-08-30 20:32:48 +01:00
Sami Kerola c0d78c90be
rfkill: make command to build in util-linux project
After this commit the command merely builds, but does not confirm style used
in util-linux project.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-08-30 20:32:48 +01:00
Sami Kerola e69263c03b
rfkill: move files to appropriate locations
Also remove unnecessary items.  Notice that the licence text from COPYING is
moved to top of the command in comment section.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-08-30 20:32:48 +01:00