aprs.me/lib/aprsme/signal_handler.ex
Graham McIntire 288b9fbbb2
fix: address security vulnerabilities and concurrency issues
- Fix SQL injection in partition_manager, db_optimizer, and release.ex
- Fix XSS vulnerabilities with proper HTML escaping in LiveViews
- Add proper error handling for email delivery functions
- Fix race conditions with advisory locks and atomic operations
- Replace unsupervised spawn/Task.start with supervised alternatives
- Convert ETS operations to GenServer serialization for thread safety
- Change ETS tables from :public to :protected access
- Add client limits to prevent unbounded memory growth
- Add PubSub cleanup in GenServer terminate callbacks
- Fix device upsert to use atomic Repo.insert_all
2026-03-23 16:59:09 -05:00

39 lines
947 B
Elixir

defmodule Aprsme.SignalHandler do
@moduledoc """
Handles OS signals like SIGTERM for graceful shutdown.
"""
use GenServer
require Logger
def start_link(opts) do
GenServer.start_link(__MODULE__, opts, name: __MODULE__)
end
def init(_opts) do
# Install signal handler for SIGTERM
# :os.set_signal/2 always returns :ok
:ok = :os.set_signal(:sigterm, :handle)
Logger.info("SIGTERM signal handler installed")
{:ok, %{}}
end
# Handle SIGTERM signal
def handle_info({:signal, :sigterm}, state) do
Logger.info("Received SIGTERM signal, initiating graceful shutdown...")
# Trigger graceful shutdown with spawn_link to ensure cleanup if parent crashes
spawn_link(fn ->
Aprsme.ShutdownHandler.shutdown()
end)
{:noreply, state}
end
def handle_info(msg, state) do
Logger.debug("SignalHandler received unexpected message: #{inspect(msg)}")
{:noreply, state}
end
end