ptrrkssn / psmsd

Peter's SMS gateway daemon
BSD 3-Clause "New" or "Revised" License
5 stars 2 forks source link

Segmentation Fault while trying Enable TTY reader #2

Open daddyfix opened 3 years ago

daddyfix commented 3 years ago

Can not get psmsd to run as Enable TTY reader. ( Im new to C programming)

I have tried to solve this problem all day but still can't figure out where the Segmentation Fault (io file read) occurs.

I believe it occurs in function -> tty_read_thread(void *tap) (approx line 1000)

Any pointers will be appreciated.

This is my gdb debug code.

# gdb --args psmsd -t -C/pimedia_scripts/psmsd-master/commands.dat -U/pimedia_scripts/psmsd-master/users.dat -d5
GNU gdb (Debian 8.2.1-2+b3) 8.2.1
Copyright (C) 2018 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "aarch64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from psmsd...done.
(gdb) run
Starting program: /pimedia_scripts/psmsd-master/psmsd -t -C/pimedia_scripts/psmsd-master/commands.dat -U/pimedia_scripts/psmsd-master/users.dat -d5
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/aarch64-linux-gnu/libthread_db.so.1".
*** serial_open("/dev/ttyUSB3", 115200, 30000): Start
ECMD_LOAD: Start
ECMD_LOAD: Name=Finger, Level=0, Path=/bin/finger, Argv=finger -fq
ECMD_LOAD: Name=Uname, Level=0, Path=/bin/uname, Argv=uname -a
ECMD_LOAD: Name=Whoami, Level=0, Path=/bin/echo, Argv=echo %{phone}
ECMD_LOAD: Name=Echo, Level=1, Path=/bin/echo, Argv=echo %*
ECMD_LOAD: Name=Ping, Level=2, Path=/usr/sbin/ping, Argv=ping -- %1
ECMD_LOAD: Name=Run, Level=2, Path=/bin/sh, Argv=sh -c "%*"
ECMD_LOAD: Name=Mail, Level=2, Path=/bin/mailx, Argv=mailx -B -i -r "%{phone}@sms.example.com" -s "%{2-}" %1
ECMD_LOAD: Stop
USERS_LOAD: Start
USERS_LOAD: Name=peter, Phone=+1555123456, Pass=hello, Acl=*
USERS_LOAD: Name=santa, Phone=+1555123456, Pass=christmas, Acl=Wall
USERS_LOAD: Name=mike, Phone=+17058226363, Pass=reno2001, Acl=*
USERS_LOAD: Stop
MAIN: Starting threads:
[New Thread 0x7ff7e2a1e0 (LWP 9190)]
SER_RECV_THREAD: Starting
[New Thread 0x7ff76291e0 (LWP 9191)]
SER_XMIT_THREAD: Starting
XMIT: MSG: +CSCS="HEX", DATA: <null>
[New Thread 0x7ff6e281e0 (LWP 9192)]
FIFO_READ_THREAD: Starting (fifo=/etc/psmsd/fifo)
[New Thread 0x7ff66271e0 (LWP 9193)]
MAIN: Waiting for signals...
TTY_READ_THREAD: Starting
RECV: AT+CSCS="HEX"
IGNORING: AT+CSCS="HEX"
RECV: ERROR
ACKNOWLEDGE OF TYPE: ERROR (rc=1)
XMIT: MSG: +CMGF=1, DATA: <null>
RECV: AT+CMGF=1
IGNORING: AT+CMGF=1
RECV: OK
ACKNOWLEDGE OF TYPE: OK (rc=0)
XMIT: MSG: +CMGL="ALL", DATA: <null>
RECV: AT+CMGL="ALL"
IGNORING: AT+CMGL="ALL"
RECV: OK
ACKNOWLEDGE OF TYPE: OK (rc=0)

Thread 5 "psmsd" received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7ff66271e0 (LWP 9193)]
0x0000007ff7e8f478 in _IO_fgets (buf=0x7ff66268d0 "", 
    n=256, fp=0x0) at iofgets.c:47
47  iofgets.c: No such file or directory.
(gdb) 
ptrrkssn commented 3 years ago

It's probably (a wild guess, totally untested) due to the code using multithreading. Try modifying the Makefile and add "-pthread" to the CC line, like this:

CC=gcc -pthread

then "make clean ; make" to recompile all files.

There might be other problems with the code too though. It was after all written for Solaris and not Linux many years ago, and even though both are Unix variants there are some subtle differences. I'll see if I can move our GSM modem to a Linux system and test it a bit more someday in the future...

daddyfix commented 3 years ago

Compile worked easily after adding '-pthread'

#make clean
rm -f  psmsd psmsc *.o *~ \#* */*~ */#*

root@mobilesvr:/pimedia_scripts/psmsd-master# make
gcc -pthread -O2 -g -Wall    -c -o psmsd.o psmsd.c
gcc -pthread -O2 -g -Wall    -c -o gsm.o gsm.c
gcc -pthread -O2 -g -Wall    -c -o serial.o serial.c
gcc -pthread -O2 -g -Wall    -c -o uucp.o uucp.c
gcc -pthread -O2 -g -Wall    -c -o cap.o cap.c
gcc -pthread -O2 -g -Wall    -c -o queue.o queue.c
gcc -pthread -O2 -g -Wall    -c -o argv.o argv.c
gcc -pthread -O2 -g -Wall    -c -o spawn.o spawn.c
gcc -pthread -O2 -g -Wall    -c -o ptime.o ptime.c
gcc -pthread -O2 -g -Wall    -c -o buffer.o buffer.c
gcc -pthread -O2 -g -Wall    -c -o users.o users.c
gcc -pthread -O2 -g -Wall    -c -o strmisc.o strmisc.c
gcc -pthread -o psmsd psmsd.o gsm.o serial.o uucp.o cap.o queue.o argv.o spawn.o ptime.o buffer.o users.o strmisc.o -lpthread -lpthread
gcc -pthread -O2 -g -Wall    -c -o psmsc.o psmsc.c
gcc -pthread -o psmsc psmsc.o buffer.o users.o strmisc.o -lpthread

But TTY failed again

/psmsd -t -d5
*** serial_open("/dev/ttyUSB3", 115200, 30000): Start
MAIN: Starting threads:
SER_RECV_THREAD: Starting
SER_XMIT_THREAD: Starting
XMIT: MSG: +CSCS="HEX", DATA: <null>
FIFO_READ_THREAD: Starting (fifo=/etc/psmsd/fifo)
MAIN: Waiting for signals...
TTY_READ_THREAD: Starting
Segmentation fault

I sorry about taking your time on an old project. I'm just looking for a package that can manage my GSM for receiving SMS. I tried Gammu but its unreliable for me

I'm going to go over your code and read more on thread for Raspberry Pi and C.

But if you happen to test it on a Linux system please let me know how it goes.

Thanks again for all your help, all the way from Sudbury, Ontario, Canada

ptrrkssn commented 3 years ago

No worries. We'll see if we can get this going. This seems like a real bug btw (not just a Solaris vs Linux portability problem). I probably never really tested the "-t" option back when I wrote it. It stops core dumping for me if I just add the following to tty_read_thread() in psmsd.c:

if (!tty_fp) tty_fp = stdin;

Updated the GIT repo now.

(For our usage we either use the psmsc client for sending SMS, or use the "receive SMS and reply with something" mode in psmsd so we can execute commands recieved via SMS)

daddyfix commented 3 years ago

That's awesome. I'm gonna try it when I get home

Many thanks

On Tue., Oct. 19, 2021, 9:50 a.m. Peter Eriksson, @.***> wrote:

No worries. We'll see if we can get this going. This seems like a real bug btw (not just a Solaris vs Linux portability problem). I probably never really tested the "-t" option back when I wrote it. It stops core dumping for me if I just add the following to tty_read_thread() in psmsd.c:

if (!tty_fp) tty_fp = stdin;

Updated the GIT repo now.

(For our usage we either use the psmsc client for sending SMS, or use the "receive SMS and reply with something" mode in psmsd so we can execute commands recieved via SMS)

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/ptrrkssn/psmsd/issues/2#issuecomment-946743904, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABEIKU33IT3OFGFIKHMZZSLUHVZQVANCNFSM5GHYDRNA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.