Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Segmentation Fault in th-cmd on Raspberry Pi 4 #36

Open
pproenca opened this issue Aug 27, 2023 · 3 comments
Open

Segmentation Fault in th-cmd on Raspberry Pi 4 #36

pproenca opened this issue Aug 27, 2023 · 3 comments

Comments

@pproenca
Copy link

pproenca commented Aug 27, 2023

I ran into a issue recently with th-cmd on my raspberry pi and hope this is the right place to report it.

tl;dr Segmentation Fault in th-cmd on Raspberry Pi When Running with --socket /var/run/thd.socket --passfd --udev Options

Details

When running th-cmd with the --socket /var/run/thd.socket --passfd --udev options, the program crashes with a segmentation fault.

System Information:

  • Raspberry Pi Model: 4B+ 8GB
  • Operating System: RaspiOS 64-bit
  • th-cmd version: 0.5.0
  • glibc version: 2.31 (Debian GLIBC 2.31-13+rpt2+rpi1+deb11u5)

Steps to Reproduce:

  1. Run th-cmd with the command /usr/sbin/th-cmd --socket /var/run/thd.socket --passfd --udev.
  2. Observe segmentation fault.

Expected Results:

The th-cmd should run without any issues.

Actual Results:

Segmentation fault occurs, and the following is observed when debugging with gdb:

Program received signal SIGSEGV, Segmentation fault.
0x0000007ff7e10740 in __GI___strcasecmp (s1=0x5555551c58 "add", s2=0x0) at strcasecmp.c:58
58	strcasecmp.c: No such file or directory.

Additional Information:

Logs from systemd-udevd indicate:

Aug 21 18:00:00 pioshost systemd-udevd[203]: event0: Process '/usr/sbin/th-cmd --socket /var/run/thd.socket --passfd --udev' failed with exit code 1.
Aug 21 18:00:00 pioshost systemd-udevd[210]: event1: Process '/usr/sbin/th-cmd --socket /var/run/thd.socket --passfd --udev' failed with exit code 1.

Debugging Attempts:

  1. Checked system and application logs using journalctl -xe and dmesg. No additional relevant information found.
  2. Reinstalled glibc but the issue persists.
@pproenca pproenca changed the title Segmentation Fault in th-cmd on Raspberry Pi When Running with --socket /var/run/thd.socket --passfd --udev Options Segmentation Fault in th-cmd on Raspberry Pi Aug 27, 2023
@pproenca pproenca changed the title Segmentation Fault in th-cmd on Raspberry Pi Segmentation Fault in th-cmd on Raspberry Pi When Running with --socket /var/run/thd.socket --passfd --udev Options Aug 27, 2023
@pproenca pproenca changed the title Segmentation Fault in th-cmd on Raspberry Pi When Running with --socket /var/run/thd.socket --passfd --udev Options Segmentation Fault in th-cmd on Raspberry Pi 4 Aug 27, 2023
@stuart-bee-ops
Copy link

Also seeing exact same issue on RPi4 with 4GB

@marmarjohnson
Copy link

marmarjohnson commented Mar 3, 2024

Issue seems to be null string into strcasecmp. Don't know how triggerhappy works, but looks like ACTION and DEVNAME are to be passed through environmental variables, aren't defined, and segfaults. It might be that original strcasecmp was OK with a null string, but retropie version isn't.

You can define some bogus environmental variables, e.g., "export DEVNAME=bogus; ACTION=bogus" or patch th-cmd. I've hacked th-cmd.c locally to avoid the segfault, but I'm not certain it's the root of my problems (trying to get wiimote to connect to pi 4 board).


diff --git a/th-cmd.c b/th-cmd.c
index aa2ba34..c40c05f 100644
--- a/th-cmd.c
+++ b/th-cmd.c
@@ -107,6 +107,10 @@ int main(int argc, char *argv[]) {

        int err = 0;
        if (op_udev) {
+         if( getenv("ACTION") == 0 ||
+             getenv("DEVNAME") == 0 ){
+           fprintf(stderr, "ACTION and/or DEVNAME not defined: ACTION=%s DEVNAME=%s\n", getenv("ACTION"), getenv("DEVNAME"));
+         } else {
                if (strcasecmp("add", getenv("ACTION")) == 0) {
                        ctype = CMD_ADD;
                } else if (strcasecmp("remove", getenv("ACTION")) == 0) {
@@ -116,6 +120,7 @@ int main(int argc, char *argv[]) {
                if ( ctype && dev ) {
                        err = send_command( s, ctype, dev, passfd, grab_dev, tag );
                }
+         }
        } else {
                /* get devices from command line */
                if (op_add) ctype = CMD_ADD;

This might have to do with a udev rule recommended to change the permissions

KERNEL=="uinput", MODE="0666"

There's no defined ACTION here.

@jkp
Copy link

jkp commented Mar 27, 2024

Seeing this same issue on a pizero-w. I can get the command to run manually by prefixing with those env variables, but it still crashes when invoked by the udev subsystem even after I hacked the rules to define those variables

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants