Skip to content

Disable SMSD exit_on_failure to prevent interpreter termination#211

Open
Copilot wants to merge 6 commits intomasterfrom
copilot/fix-python-gammu-exit
Open

Disable SMSD exit_on_failure to prevent interpreter termination#211
Copilot wants to merge 6 commits intomasterfrom
copilot/fix-python-gammu-exit

Conversation

Copy link
Contributor

Copilot AI commented Feb 5, 2026

SMSD operations (GetStatus(), InjectSMS()) terminate the Python interpreter with exit code 255 when SMSD is not running, rather than raising catchable exceptions.

Root Cause

Gammu's GSM_SMSDConfig initializes exit_on_failure = TRUE, causing library code to call exit() on errors instead of returning error codes.

Changes

gammu/src/smsd.c

  • Use SMSD_SetExitOnFailure(config, FALSE) after SMSD_NewConfig() to disable exit on failure and allow Python exception handling

test/test_smsd.py

  • Add test verifying GetStatus() raises GSMError when daemon not running

Implementation

This fix uses the public SMSD_SetExitOnFailure() API introduced in Gammu PR #965, which provides a proper interface to disable the exit_on_failure flag without accessing internal structure fields. This approach:

  • Uses Gammu's public API (no internal headers required)
  • Is compatible with the opaque GSM_SMSDConfig structure
  • Will work with Gammu versions that include this API (1.42.0+)
Original prompt

This section details on the original issue you should resolve

<issue_title>If SMSD is not running, calls to InjectSMS and GetStatus cause python to quit</issue_title>
<issue_description>To replicate:

  1. Install gammu-smsd (and gammu if needed)
  2. Install or compile the binary distribution of python-gammu
  3. Prepare a working gammu-smsdrc -file (depending on the distro)
  4. Run the following python code
import gammu
smsd = gammu.SMSD('/path/to/gammu-smsdrc')
smsd.GetStatus()
# Or alternatively, attempt to send an SMS
smsd.InjectSMS([ {
    'Text': 'This is a test',
    'SMSC': {'Location': 1},
    'Number': '+1555123456'
}])

Expected results: python-gammu raises an exception or returns an appropriate error value.
Actual results: the python interpreter exits. See below:

~ # ipython
Python 3.6.3 (default, Nov 21 2017, 14:55:19) 
Type 'copyright', 'credits' or 'license' for more information
IPython 6.4.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: import gammu

In [2]: smsd = gammu.SMSD('/etc/gammu-smsdrc')

In [3]: smsd.GetStatus()
python-gammu[1065]: Failed to allocate shared memory segment!, Error 2: No such file or directory

~ #
# Exit code is 255

OS: Alpine Linux 3.7
Gammu SMSD version: 1.38.5
python-gammu version: 2.11 (installed from source via pip)
Python version: 3.6.3

This is particularly annoying, since gammu.SMSD.Shutdown() raises an exception (ERR_NOTRUNNING) which is catchable. In the use case here, we cannot assume the SMSD is always running, thus GetStatus should indicate that without causing the whole program to quit.

The issue also occurs if the SHM is not accessible due to permissions, then the error returned is python-gammu[11522]: Failed to map shared memory segment!, Error 13: Permission denied.


Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.
</issue_description>

<agent_instructions>Add testcase showing this behavior of SMSD and fix it by disabling exit_on_failure flag.</agent_instructions>

Comments on the Issue (you are @copilot in this section)

@nijel The problem is that `Config->exit_on_failure` is set by default by Gammu and python-gammu doesn't disable this.

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

- Disable exit_on_failure flag in SMSD config after creation
- Add test to verify GetStatus raises exception when SMSD is not running
- This fixes the issue where Python would exit instead of raising an exception

Co-authored-by: nijel <212189+nijel@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix python-gammu to prevent exit on SMSD not running Disable SMSD exit_on_failure to prevent interpreter termination Feb 5, 2026
Copilot AI requested a review from nijel February 5, 2026 15:08
@nijel nijel marked this pull request as ready for review February 5, 2026 15:13
@nijel nijel enabled auto-merge (squash) February 5, 2026 15:13
@nijel
Copy link
Member

nijel commented Feb 5, 2026

@copilot Rewrite the flag setting using the new API introduced in gammu/gammu#965. I will adjust the dependency and rebase once new Gammu version is released.

Replace direct access to exit_on_failure field with the new public
SMSD_SetExitOnFailure() API introduced in Gammu PR #965. This avoids
the compilation issue with the opaque GSM_SMSDConfig structure.

The new API provides a proper public interface to disable the
exit_on_failure flag, allowing Python to handle errors as exceptions
instead of terminating the interpreter.

Co-authored-by: nijel <212189+nijel@users.noreply.github.com>
auto-merge was automatically disabled February 5, 2026 16:19

Head branch was pushed to by a user without write access

Copy link
Contributor Author

Copilot AI commented Feb 5, 2026

@copilot Rewrite the flag setting using the new API introduced in gammu/gammu#965. I will adjust the dependency and rebase once new Gammu version is released.

Updated to use SMSD_SetExitOnFailure() API in commit 29636a9.

Copilot AI requested a review from nijel February 5, 2026 16:20
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

Successfully merging this pull request may close these issues.

If SMSD is not running, calls to InjectSMS and GetStatus cause python to quit

2 participants