Commit graph

92 commits

Author SHA1 Message Date
Peter Hutterer
395d12d634 util: auto-declare the element variable in ARRAY_FOR_EACH
All cases we have in our code base have an otherwise unused variable to
loop through the array. Let's auto-declare this as part of the loop.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2022-03-09 10:16:07 +10:00
Peter Hutterer
8fecb19147 Use bit(foo) instead of (1 << foo)
Translates to the same thing, but the bit() helper is nicer and less
likely to be typoed.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2021-11-18 10:11:43 +10:00
Peter Hutterer
fc70c4f862 Silence compiler warnings for -Wformat-nonliteral
In the various logging functions where we need to modify the format
argument, disable the compiler warnings. Interestingly, GCC doesn't seem
to mind those but building with clang unleashes pages of warnings.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2021-07-22 23:14:43 +00:00
luokai
87447a0ee9 using secure functions safe_strdup
Signed-off-by: luokai <l18674732394.com>
2021-06-15 11:27:29 +08:00
Peter Hutterer
e72b30f424 tools/record: narrow down the obfuscation range
Let a few obvious modifiers through, including the F-key range. Especially
left control is useful to know if it's down.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2021-05-18 23:14:44 +00:00
Peter Hutterer
cf1abf0818 tools/record: add support for hidraw recording
New commandline switch --with-hidraw. This will open all hidraw devices
associated with this device and add any reports to the output in the
form:

  events:
    - hid:
        time: [0, 0]
        hidraw1: [0x01, 0x02, 0x03, 0x05, 0x06]
	hidraw2: [0x07, 0x08, 0x09, 0x0a, 0x0b]
    - evdev:
      ...

i.e. there's a nesting of `hid` with a list of reports, each with the hidraw
node as dictionary entry.

Because hidraw events do not have timestamps and always occur before the evdev
events, they are in a separate frame (as shown above). We could try to figure
out how to match them with the upcoming evdev frame but it's not worth it for
now.

The timestamp itself is a special key in the hidraw with the timestamp from
clock_gettime.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2021-05-05 03:59:34 +00:00
Peter Hutterer
b38c6ca69f tools/record: linebreak the hid report descriptor every 16 bytes
New output:

 hid: [
    0x05, 0x0d, 0x09, 0x04, 0xa1, 0x01, 0x85, 0x01, 0x09, 0x22, 0xa1, 0x02, 0x09, 0x42, 0x15, 0x00,
    0x25, 0x01, 0x75, 0x01, 0x95, 0x01, 0x81, 0x02, 0x75, 0x01, 0x81, 0x03, 0x75, 0x06, 0x09, 0x51,
    0x25, 0x3f, 0x81, 0x02, 0x26, 0xff, 0x00, 0x75, 0x08, 0x09, 0x48, 0x81, 0x02, 0x09, 0x49, 0x81,
    ...

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2021-04-30 14:54:35 +10:00
Peter Hutterer
7da7cd216f tools/record: print the HID report descriptor as hex
YAML does support hex as long as it's 0x-prefixed. The comment here (probably)
dates from an in-development version of libinput-record that used JSON.
Anyway, let's print the HID report descriptor as hex because that's the common
format for it.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2021-04-30 14:54:35 +10:00
Peter Hutterer
57811e40f0 tools/record: fix a strlen assumption
We want to be able to print single-character strings.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2021-04-30 14:54:35 +10:00
Peter Hutterer
943e258cca tools/record: line up the "neutral state" message
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2021-03-30 09:02:31 +10:00
Peter Hutterer
33b30d4631 tools/record: rework the event printing
For historical (but not very good) reasons, libinput record printed events
from the first device to the output file (or stdout) and buffered everything
else. On ctrl+c, the other devices' descriptions and the buffered events were
appended to the output file.

This makes the printing code rather complex. Simplify it by giving each device
a separate FILE* - the first device points to the real output file, the others
to a tempfile. On Ctrl+C we just append those tempfiles to the real output
file one-by-one and done.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2021-03-30 09:02:31 +10:00
Peter Hutterer
bacf4e5a62 tools/record: rename the output file handling
Less confusing than having output_file, out_file, and outfile.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2021-03-30 09:02:31 +10:00
Peter Hutterer
7957f1980d tools/record: remember the first device in the context
No functional changes since we can get this easily from the list itself, but
in the future the first device will be used more extensively.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2021-03-30 09:02:31 +10:00
Peter Hutterer
0b23cb1ba2 tools/record: append the devices in-order
Using list_insert() here means the last device specified on the commandline is
the one that ends up in the file first - not very obvious...

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2021-03-30 09:02:31 +10:00
Peter Hutterer
0cdf459643 tools/record: get rid of indent push/pop, replace with fixed indents
Our file format is static enough that we don't need to use push/pop, we know
exactly which line is going where. So let's replace it with a static
indent instead.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2021-03-30 09:02:31 +10:00
Peter Hutterer
632eedadf5 tools/record: mark the iprintf function as printf
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2021-03-30 08:33:49 +10:00
Peter Hutterer
9011f91868 tools/record: switch the output file from an fd to a FILE*
This is prep work to be more consistent with the use of tempfile later for
individual devices.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2021-03-30 08:33:49 +10:00
Peter Hutterer
7f4df04d59 tools/record: deduplicate the device opening logic
With a new helper function strv_from_argv we can re-use the device opening
loop for all the use-cases we have.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2021-03-30 08:26:30 +10:00
Peter Hutterer
4da9349a91 tools/record: free the namelist when we're done
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2021-03-26 10:12:40 +10:00
Peter Hutterer
e511f96201 tools/record: localize a variable
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2021-03-26 10:12:40 +10:00
Peter Hutterer
8b822a84c4 tools/record: de-duplicate an error message
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2021-03-26 10:12:40 +10:00
Peter Hutterer
0828fdcea0 tools/record: factor out the output file collection
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2021-03-26 10:12:40 +10:00
Konstantin Kharlamov
3d3d9b7f69 treewide: get rid of tmp argument in list_for_each_safe
Signed-off-by: Konstantin Kharlamov <Hi-Angel@yandex.ru>
2021-03-02 09:10:35 +03:00
Peter Hutterer
1b00eb5e03 tools/record: fix two coverity complaints
In both cases we only read to drain the fd, we don't care about the return
value.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2021-02-23 16:55:58 +10:00
Peter Hutterer
627a3dd2b2 tools/record: use a helper function to get the next event for a device
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2021-02-23 10:56:53 +10:00
Peter Hutterer
4a7dece88c tools/record: switch record over to using epoll
Using poll means more difficult fd management, epoll (together with am
modified version of the libinput_sources) makes this a lot easier by simply
using dispatch.

This means we are no longer reliant on a specific file descriptor order in the
poll array.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2021-02-23 10:56:53 +10:00
Peter Hutterer
ca9067992e tools/record: use safe_basename() to get to the hid report descriptor
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2021-02-23 10:56:53 +10:00
Peter Hutterer
fd9d165a77 tools/record: simplify the behavior to emulate Python's join()
Instead of a boolean "is_first", just change the separator.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2021-02-23 10:56:53 +10:00
Peter Hutterer
59ca971898 tools/record: print a header as first line
To make the file format easier to detect

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2021-02-22 14:53:41 +10:00
Peter Hutterer
4b0f200936 tools/record: fix outdated comment
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2021-02-19 09:09:53 +10:00
Peter Hutterer
a8597e3ab3 tools/record: de-inline our functions
Let's leave this up to the compiler, the usual side-effect of inline (compiler
doesn't complain about an unused static function) doesn't apply here.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2021-02-19 09:09:53 +10:00
Peter Hutterer
f6c05ae4cc tools/record: remove a useless assignment
It's overwritten a few lines south of here.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2021-02-12 07:35:58 +10:00
Peter Hutterer
6c32f78020 tools/record: add some curly braces
list_for_each is just a fancy for loop but it looks weird without braces.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2021-02-12 07:35:58 +10:00
Peter Hutterer
9925594257 tools/record: print the wall clock time every few seconds
For long-running recordings it's useful to know what the actual time was when
a particular event occured. A user can simply check the clock or system logs
for the time and thus know which portion of the recording to focus on.

Let's print the time into the recording, every 5 seconds (aligned at the 5,
10, 15s marks) or, if no events occured in the last 5 seconds, before the next
event. This granularity should be enough to identify the interesting parts of
a recording.

Let's print this as a comment until we have a use-case that requires parsing
this data.

The timer is the simplest approach, it just repeats at a fixed 5 seconds
interval from startup. There may be time drift, we can fix that if needed.

Fixes #560

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2021-01-29 07:31:46 +10:00
Peter Hutterer
0b8ad77624 tools/record: use a pointer to the libinput fd poll entry
No functional changes, this makes the code slightly more readable, especially
once we start adding more "special" fds.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2021-01-29 07:31:46 +10:00
Peter Hutterer
773287e745 tools/record: use a pointer to the signalfd poll entry
No functional changes, this makes the code slightly more readable, especially
once we start adding more "special" fds.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2021-01-29 07:31:46 +10:00
Peter Hutterer
b1f8ea0a5e tools/record: narrow the scope of two variables
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2021-01-29 07:31:46 +10:00
Peter Hutterer
f2133ef0f3 tools/record: initialize all pollfds in the same loop
Minor tidying up the code, set the default values for all fds in the same loop
instead of having it split to wherever the fd is created.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2021-01-29 07:31:46 +10:00
Peter Hutterer
1303adbf1b tools/record: compress a set of printfs into one
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-09-17 12:38:53 +10:00
Peter Hutterer
6e8aba9354 tools/record: prefix the device list with a # character
Too many recordings end up with the device list at the top when users redirect
stderr and stdout to the recordings file. This breaks yaml parsing and
requires manual removal of the first few lines.

Avoid this by prefixing the lines with a command character, this way the yaml
stays correct.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-09-17 12:38:53 +10:00
Peter Hutterer
2d641e6b7b tools/record: add --grab option
Useful to record devices like power buttons, lid switches, etc.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-09-16 23:59:57 +00:00
Rosen Penev
467752047e
[clang-tidy] do not use else after return
Found with readability-else-after-return

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2020-08-27 01:17:24 -07:00
Peter Hutterer
d724dc060b Replace strneq() with strstartswith() for variable prefixes
Leaving in-place all those where we know the length of the prefix, but
replacing all those where we were calling strlen on the prefix.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-06-17 07:52:00 +00:00
Peter Hutterer
d80bbcb028 tools: record: drop quotes from os-release information
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-03-21 11:02:48 +10:00
Peter Hutterer
2b3fd5aa30 tools: record: use the right exit code when the output file is missing
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-03-16 16:21:04 +10:00
Peter Hutterer
6ed3a0b079 tools: record: allow for an output file without --o
libinput record touchpad.yml /dev/input/eventX
or just
  libinput record touchpad.yml
are simpler invocations and since we're quite limited in what we can record
(i.e. only device files) we can just check the argument list to figure out
whether there is something to record to.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-03-16 13:04:50 +10:00
Peter Hutterer
850925910f tools: record: fix dmi recording
Processing os-release in the same buffer that the dmi modalias used caused the
dmi to be recorded as 'dmi: "VERSION_ID=31"'. The cause for that was simply
that the dmi modalias was read but not printed until after the os-release
information was processed.

Fix this two-fold: rearrange that each part now reads and prints in
one go, and rename the buffers so we don't re-use them.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-03-09 10:20:49 +10:00
Peter Hutterer
294298880d tools: record: fix fallback os-release file handling
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-02-21 11:42:01 +10:00
Peter Hutterer
428acee867 tools: record: record basic os-release information as well
Because sometimes it's useful to know what distro a recording was made on, and
the kernel version doesn't always reveal that.

Fixes #428

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-02-19 08:31:18 +00:00
Peter Hutterer
7198e33ecf tools: record: rename a variable to just buf
Better name for re-use

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-02-19 08:31:17 +00:00