Commit Graph

545 Commits (c87c7caa68160e69b5d24ca6f3a202fed18b5eb5)

Author SHA1 Message Date
nirenjan c87c7caa68 Add test cases for clock configuration 2022-04-08 00:16:57 -07:00
nirenjan 0f7cd3fdb3 Add test cases for config get/set with wrong argc 2022-04-08 00:16:39 -07:00
nirenjan 33e940606c Add daemon communication test cases
This change adds an automated test harness that will spin up an instance
of the X52 daemon, connect to its command socket, send commands and
validate the responses. This first set of test cases simply validates
the basic configuration file handling. Subsequent commits will enhance
the tests to improve code coverage.
2022-04-07 23:24:24 -07:00
nirenjan f0ad185421 Fix formatted responses to include the trailing NUL 2022-04-02 08:23:55 -07:00
nirenjan 98822190ed Add a callback to apply one configuration item immediately
The configuration processing works as follows - the configuration
parameters are set in memory, and an apply function applies all the
changes directly to the device. While this works during startup and
reload, it adds a needless overhead when processing config set commands
from the command socket.

This change makes it such that a `config set` command would update the
configuration for that particular key, and then immediately call the
callback function for that key. This has the effect that individual
configuration changes are visible immediately, without having to reapply
every other configuration that hasn't changed.

This commit also removes the `config apply` command, since it is no
longer needed. The `config load` and `config reload` already handle
applying the configuration after reading it.
2022-02-11 13:30:17 -08:00
nirenjan cf6811d923 Check if mouse is enabled before reporting buttons
Prior to this change, the IO thread would always report a mouse button
event, even if the mouse was disabled in configuration, or the uinput
device was not created. This results in unexpected button/wheel events.

This change checks that the uinput device has been created and the mouse
has been enabled in the configuration before reporting a button or wheel
event.
2022-02-03 11:11:41 -08:00
nirenjan 5ab4784b21 Remove unnecessary code from x52d_config_save_file
This is a legacy from when there was a separate print_section function
2021-11-22 10:08:21 -08:00
nirenjan 385f1ca574 Fix typo in logging error handler 2021-11-22 10:06:23 -08:00
nirenjan cf89e3d610 Override `time` from libc
Prior to this change, there were spurious build failures seen in Github
CI, especially on macOS builds, where one test out of ~2000 would fail
randomly. After adding an option to display the diagnostics, it was
determined that the failure was only in the tests that included the
timestamp. This was because the time call was returning different values
between `test_setup` and `pinelog_log_message`. Even though they may
have been called milliseconds apart, the time skew was enough to have a
1 second difference between the two returned values.

This change overrides the `time` method from libc, and returns a static
value. With this change, CI should work fine regardless of how slow the
tests run.
2021-11-11 07:02:21 -08:00
nirenjan e9d4e81a4d Display TAP diagnostics in build log 2021-11-11 06:21:20 -08:00
nirenjan 3896fa0d3e Update protocol documentation for logging command 2021-11-10 22:21:47 -08:00
nirenjan f6c6db6c61 Add command processing for logging configuration
This change adds the `logging show` and `logging set` commands to the
command processor module. This allows setting the log levels of the
individual modules via the socket.
2021-11-10 21:49:54 -08:00
nirenjan 2119e00647 Integrate pinelog module logging functionality 2021-11-10 09:29:27 -08:00
nirenjan f4a8e7c4d5 Do not print NULL module names
Prior to this change, if a module had not registered a name, then the
output would display `(null): `, which was not really helpful. This
change eliminates that by checking if the module name is not NULL prior
to calling the print routines.
2021-11-10 09:27:40 -08:00
nirenjan 417641dee0 Use string buffer when logging messages 2021-11-08 16:22:56 -08:00
nirenjan 86f599fc6e Update logging library to include module and string buffer
This commit adds the following changes to pinelog:

- Optional buffer to write the message to prior to writing to the output
  stream. This reduces the likelihood of log messages from multiple
  threads interleaving due to multiple calls to fputs/fprintf, etc. The
  default is to still write directly to the output stream, but the
  integrator can add a define of PINELOG_BUFFER_SZ to the CFLAGS, and
  this will allow the application to log messages that are shorter than
  the above size, including the timestamp, level and backtrace if any.

- Optional module level logging. This allows more fine-grained
  debugging, where the application can control the log levels of the
  individual modules. By default, when modules are configured, they
  default to the global log level, but this can be overridden by the
  application.
2021-11-08 16:18:30 -08:00
nirenjan 09740e0fe9 Update documentation to include communication protocol 2021-11-07 16:38:06 -08:00
nirenjan 7448334824 Add `config apply` command 2021-11-07 16:06:49 -08:00
nirenjan f2b0110380 Allow upto 1024 arguments
Prior to this change, it was possible for a malicious client to send a
buffer of 1024 NUL bytes, which would cause the parser to overflow the
argv array and eventually crash the program.

This change makes the length of the argv array the same as the length of
the recv buffer, which means that even an input of all 0 bytes would not
cause any issues. The client would just get a bunch of ERR responses in
return.
2021-11-07 15:07:10 -08:00
nirenjan 87bf5881dd Update Changelog to include info about communication 2021-11-07 07:55:48 -08:00
nirenjan e82f9032eb Add 'config get' command to retrieve configuration
The command allows the client to retrieve individual parameters from the
configuration. This follows a similar syntax to the 'config set'
command, with the client supplying the section and key, and if there is
a matching entry in the configuration, it will return the corresponding
value.
2021-11-07 07:52:11 -08:00
nirenjan 2fe7b8af43 Cleanup response protocol
This change removes the unnecessary response length field from the
output buffer. It was added to check for possible issues in the
communication between client and server, but is not needed anymore. This
also makes the communication protocol standardized between client and
server.
2021-11-07 05:47:31 -08:00
nirenjan 20abe8974c Fix x52d_send_command prototype
Prior to this change, the recv call was using the same buflen as that of
the send, which meant that the response would be truncated at by the
client, while the server was sending the entire message. This was
evident by running a Python client which manually called recv with the
maximum buffer size.

This change updates the prototype to take both a bufin (length of the
input buffer), and a bufout (length of the output buffer) argument,
instead of a single buflen. With this change, commands work as expected
in x52ctl.
2021-11-07 05:40:08 -08:00
nirenjan 116b9e2c0c Add config set command to daemon command processor
This change allows setting the configuration from the socket. It behaves
similar to the override, and requires the client to send the section,
key and value, and responds with an OK or error value.
2021-11-05 15:27:24 -07:00
nirenjan 7b8c71dd35 Add command parsing and response logic
This change adds the generic command parsing logic, as well as the
response for the following commands:

* config load <file>
* config reload
* config save
* config dump <file>
2021-11-05 15:10:20 -07:00
nirenjan eb98804607 Make x52ctl send commands as individual args
This change makes the protocol more strict, in that the buffer sent to
the daemon must be a series of NUL separated arguments. This makes it a
little easier to handle the strings, especially those that may have
embedded whitespace.
2021-11-04 22:37:43 -07:00
nirenjan d8a5a2c3b8 Add daemon command handler loop
This change adds the logic to read a packet from the socket, accept
connections from clients, and close connections from clients that have
hung up. This commit does not yet have support for parsing and handling
the commands, and simply echoes the request back to the client.
2021-11-04 18:32:18 -07:00
nirenjan 5a78492140 Make X52 daemon listen on a Unix socket
This change makes X52 daemon listen on a Unix socket. This is in
preparation for changes that will read from the socket and allow clients
to communicate with and control the daemon.
2021-11-04 13:48:18 -07:00
nirenjan abc74d6e37 Fix linking with libintl on macOS 2021-11-04 11:05:52 -07:00
nirenjan 3225d37e6e Add translations for x52ctl.c 2021-11-04 10:52:14 -07:00
nirenjan 931f945133 Add x52ctl daemon communication program 2021-11-04 10:50:10 -07:00
nirenjan 18c0c72c74 Add client communication library
This change adds a library to connect to the X52 daemon and send
commands and receive responses. The library is a thin wrapper around the
POSIX sockets API. While a client could implement the functions
themselves, the library makes it a little bit easier, as well as
allowing for third-party clients to connect to and communicate with the
daemon.
2021-11-04 10:48:59 -07:00
nirenjan 293ba0a99d Remove duplicate check for default PID file 2021-11-03 11:44:24 -07:00
nirenjan 52429e8dc3 Add translations for x52d_config_dump.c 2021-11-03 11:39:19 -07:00
nirenjan 6c3efa44f5 Simplify configuration dumping
Prior to this change, there was a lot of duplicated code within the dump
routines, which would call out to a common `print_section` routine that
had global state. This causes problems from a multi-threaded perspective
in that multiple calls to `x52d_config_save_file` were not MT-safe.

In addition, the dump logic was written such that it could only be used
in the config dump. It is desired that we add functionality to return
the formatted config value as a string in a different part of the code
as well.

This change brings in the shared state into a stack variable, and
changes the dump functions to return a const char *, thereby allowing
for greater reuse, as well as getting rid of the shared state. However,
there is still a little bit of shared state in the `int_dumper` routine.
This can be ignored for now, but we should possibly figure out how to
get rid of the shared state altogether.
2021-11-02 23:25:55 -07:00
nirenjan 6d78ab1940 Add noreturn attribute to tap_bailout
This change is necessary since clang warns on a missing noreturn
attribute.
2021-10-25 12:56:41 -07:00
nirenjan 3c006d0929 Merge commit '6c17e73284fbe49a6bc7890d3e221b95db29d56f' 2021-10-25 12:51:04 -07:00
nirenjan 6c17e73284 Squashed 'lib/pinelog/' changes from 0256807..349b2d6
349b2d6 Use an in-memory pipe for tests

git-subtree-dir: lib/pinelog
git-subtree-split: 349b2d6e8610ca6c62cfc9211c50ded52ebe38ed
2021-10-25 12:51:04 -07:00
nirenjan 581d2c0bbd Replace macos-latest with macos-10.15
This is necessary since Github will soon change macos-latest to point
to macos-11
2021-10-12 12:15:27 -07:00
nirenjan 8d38c4d16b Fix Makefile to build on alternative make implementations
On some systems (notably FreeBSD), the make implementation makes a
distinction between $(builddir)/<path> and <path>, even when builddir is
`.`. This commit removes $(builddir) from all references to generated
files, so that these implementations don't fail. Keeping $(builddir)
causes older versions automake (1.15 and older) to generate a broken
Makefile.
2021-10-12 12:10:36 -07:00
nirenjan 41be44cc94 Add documentation for x52bugreport 2021-10-11 09:54:27 -07:00
nirenjan 2cc3cc5bfe Update bug issue template to use x52bugreport output 2021-10-11 07:22:29 -07:00
nirenjan 8fd16d544a Add bugreport utility
This change adds a utility that generates some output that can be used
to figure out what the user system is, specifically, the versions of the
following:

* libusb
* hidapi (if available)
* kernel
* device info

These parameters can be used to determine if the user is running some
non-standard environment, and make it easier to track down bugs.
2021-10-11 07:22:21 -07:00
nirenjan 1c0d98c474 Fix link to AUR package
Fixes #39
[skip ci] [skip doxy]
2021-10-10 08:35:57 -07:00
nirenjan ad178d3f6d Make doxygen CI build use release parameters.
The previous commit used the value of `sysconfdir` to store the location
of the daemon configuration file inside the generated documentation.
However, the automatically generated documentation was using the default
values, which meant that the config file was located at
`/usr/local/etc/x52d/x52d.conf`, instead of just `/etc/x52d/x52d.conf`.
Updating the arguments to `./configure` to match that of the release
ensures that it will always stay up to date.
2021-10-07 01:14:05 -07:00
nirenjan d9eed14e0d Include default location of x52d.conf in documentation
This change adds the default location of x52d.conf in the release builds
to the public documentation.
2021-10-06 23:44:16 -07:00
nirenjan fec67b5994 Revert "Enable verbose logging in systemd service"
This reverts commit 53957d0813. It was
supposed to be a temporary commit, but it was forgotten about. Reverting
this will restore the old behavior of only logging INFO and higher
priority logs.

Fixes #38.
2021-10-05 22:38:34 -07:00
nirenjan 247e98c5dc Add kernel driver for Saitek X65F joystick
This commit adds the kernel driver for the Saitek X65F joystick. This is
necessary, since it has the same limitation with the thumbstick not
getting recognized on older kernels. The quirks fix has been pushed to
newer stable kernels, and therefore do not require this driver.
2021-09-29 12:59:34 -07:00
nirenjan 9a39e971f1 Disable Ubuntu 16.04 builds in kernel workflow
[skip ci]
2021-09-29 00:35:51 -07:00
nirenjan e7d91fd3a4 Replace all references to x52pro-linux with libx52 2021-09-29 00:30:55 -07:00