Commit 99082359 authored by Bob Ham's avatar Bob Ham
Browse files

Check the machine name against a whitelist/blacklist

Instead of conflicting with Wys and relying on device-specific
packages to bring in the right daemons, have Hægtesse check the
machine name (/proc/device-tree/model) against a whitelist/blacklist
pair to determine whether it should run.  If it should not run, exit
with a status that systemd recognises as meaning it should not be
restarted.
parent badba806
Pipeline #43314 passed with stage
in 48 seconds
......@@ -7,13 +7,10 @@ StartLimitIntervalSec=0
# We need PulseAudio
Requires=pulseaudio.service
# Don't run Haegtesse and Wys at the same time
Conflicts=wys.service
[Service]
ExecStart=/usr/bin/haegtesse
Restart=always
Restart=on-failure
RestartSec=500ms
[Install]
WantedBy=phone-voice-call-audio.target
WantedBy=default.target
......@@ -8,5 +8,5 @@ export DEB_BUILD_MAINT_OPTIONS = hardening=+all
override_dh_link:
dh_link
ifeq ($(DEB_HOST_ARCH_OS),linux)
dh_link usr/lib/systemd/user/haegtesse.service usr/lib/systemd/user/phone-voice-call-audio.target.wants/haegtesse.service
dh_link usr/lib/systemd/user/haegtesse.service usr/lib/systemd/user/default.target.wants/haegtesse.service
endif
......@@ -37,4 +37,26 @@ libmchk_proj = subproject('libmachine-check')
libmchk_dep = libmchk_proj.get_variable('libmachine_check_dep')
app_name = meson.project_name()
datadir = get_option('datadir')
if datadir.startswith('/')
full_datadir = datadir
else
full_datadir = join_paths(get_option('prefix'), datadir)
endif
config_data = configuration_data()
config_data.set_quoted('APP_DATA_NAME', app_name)
subdir('src')
install_subdir (
'machine-check',
install_dir: join_paths (datadir, 'machine-check',
meson.project_name()),
strip_directory: true
)
......@@ -119,9 +119,10 @@ context_notify_cb (pa_context *audio, gboolean *ready)
*ready = FALSE;
break;
case PA_CONTEXT_FAILED:
case PA_CONTEXT_TERMINATED:
haeg_error ("Error in PulseAudio context: %s",
pa_strerror (pa_context_errno (audio)));
break;
case PA_CONTEXT_TERMINATED:
case PA_CONTEXT_READY:
*ready = TRUE;
break;
......@@ -183,6 +184,8 @@ set_up_audio_context (HaegAudio *self)
{
g_main_context_iteration (NULL, TRUE);
}
pa_context_set_state_callback (self->ctx, NULL, NULL);
}
......@@ -200,10 +203,11 @@ stream_notify_cb (pa_stream *stream, gboolean *ready)
*ready = FALSE;
break;
case PA_STREAM_FAILED:
case PA_STREAM_TERMINATED:
haeg_error
("Error in PulseAudio stream: %s",
pa_strerror (pa_context_errno (pa_stream_get_context (stream))));
break;
case PA_STREAM_TERMINATED:
case PA_STREAM_READY:
*ready = TRUE;
break;
......@@ -324,6 +328,9 @@ set_up_audio_streams (HaegAudio *self)
g_main_context_iteration (NULL, TRUE);
}
pa_stream_set_state_callback (self->to_spk, NULL, NULL);
pa_stream_set_state_callback (self->from_mic, NULL, NULL);
dump_stream_buffer_attrs (self->to_spk, "Speaker");
dump_stream_buffer_attrs (self->from_mic, "Microphone");
}
......
......@@ -26,17 +26,21 @@
#include "haeg-port.h"
#include "haeg-audio.h"
#include "haeg-port-monitor.h"
#include "config.h"
#include "mchk-machine-check.h"
#include <glib.h>
#include <glib/gi18n.h>
#include <stdio.h>
#include <locale.h>
#include <errno.h>
#define TTY_CHUNK_SIZE 320
#define SAMPLE_LEN 2
static GMainLoop *main_loop = NULL;
struct haegtesse_data
{
......@@ -306,20 +310,82 @@ static void
run ()
{
struct haegtesse_data data;
GMainLoop * loop;
memset (&data, 0, sizeof (struct haegtesse_data));
set_up (&data);
loop = g_main_loop_new (NULL, FALSE);
main_loop = g_main_loop_new (NULL, FALSE);
printf (APPLICATION_NAME " started\n");
g_main_loop_run (loop);
g_main_loop_unref (loop);
g_main_loop_run (main_loop);
g_main_loop_unref (main_loop);
main_loop = NULL;
tear_down (&data);
}
static void
check_machine ()
{
gboolean ok, passed;
GError *error = NULL;
ok = mchk_check_machine (APP_DATA_NAME,
NULL,
&passed,
&error);
if (!ok)
{
g_warning ("Error checking machine name against"
" whitelist/blacklist, continuing anyway");
g_error_free (error);
}
else if (!passed)
{
g_message ("Machine name did not pass"
" whitelist/blacklist check, exiting");
exit (EXIT_SUCCESS);
}
}
static void
terminate (int signal)
{
if (main_loop)
{
g_main_loop_quit (main_loop);
}
}
/** Ignore signals which make systemd refrain from restarting us due
* to "Restart=on-failure": SIGHUP, SIGINT, and SIGPIPE.
*/
static void
setup_signals ()
{
void (*ret)(int);
#define try_setup(NUM,handler) \
ret = signal (SIG##NUM, handler); \
if (ret == SIG_ERR) \
{ \
g_error ("Error setting signal handler: %s", \
g_strerror (errno)); \
}
try_setup (HUP, SIG_IGN);
try_setup (INT, SIG_IGN);
try_setup (PIPE, SIG_IGN);
try_setup (TERM, terminate);
#undef try_setup
}
int
main (int argc, char **argv)
{
......@@ -329,6 +395,9 @@ main (int argc, char **argv)
setlocale(LC_ALL, "");
// Check the machine whitelist/blacklist
check_machine ();
GOptionEntry options[] =
{
{ NULL }
......@@ -342,6 +411,8 @@ main (int argc, char **argv)
g_print ("Error parsing options: %s\n", error->message);
}
setup_signals ();
run ();
return 0;
......
......@@ -19,21 +19,33 @@
# SPDX-License-Identifier: GPL-3.0-or-later
#
haegtesse_deps = [ dependency('gobject-2.0'),
dependency('gio-unix-2.0'),
dependency('libpulse'),
dependency('libpulse-mainloop-glib'),
dependency('libudev'),
]
executable('haegtesse',
['main.c',
'util.h', 'util.c',
'haeg-sample-buffer.h', 'haeg-sample-buffer.c',
'haeg-port.h', 'haeg-port.c',
'haeg-audio.h', 'haeg-audio.c',
'haeg-port-monitor.h', 'haeg-port-monitor.c',
],
dependencies : haegtesse_deps,
include_directories : include_directories('..'),
install : true)
haegtesse_deps = [
libmchk_dep,
dependency('gobject-2.0'),
dependency('gio-unix-2.0'),
dependency('libpulse'),
dependency('libpulse-mainloop-glib'),
dependency('libudev'),
]
config_h = configure_file (
output: 'config.h',
configuration: config_data
)
executable (
'haegtesse',
config_h,
[
'main.c',
'util.h', 'util.c',
'haeg-sample-buffer.h', 'haeg-sample-buffer.c',
'haeg-port.h', 'haeg-port.c',
'haeg-audio.h', 'haeg-audio.c',
'haeg-port-monitor.h', 'haeg-port-monitor.c',
],
dependencies : haegtesse_deps,
include_directories : include_directories('..'),
install : true
)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment