view loadtools/ltexit.c @ 964:a96cb97b66a2

ringtools/imy: fix duplicate definition of tdma_durations[] The bug was reported by Vadim Yanitskiy <fixeria@osmocom.org>, although the present fix is slightly different from the contributed patch: because main.c doesn't need this tdma_durations[] array at all, let's simply remove the reference to this array from main.c rather than turn it into an extern. I no longer remember my original thought flow that resulted (by mistake) in tdma_durations[] being multiply defined in main.c and durations.c. My intent might have been to define all globals in main.c and have the reference in durations.c be an extern - and I missed that extern - but without clear memory, I have no certainty. In any case, having this data array defined in the same module that fills it (durations.c) is sensible, so let's make it the new way.
author Mychaela Falconia <falcon@freecalypso.org>
date Thu, 31 Aug 2023 19:38:18 +0000
parents aba969153d20
children
line wrap: on
line source

/*
 * This module implements the loadtool exit command, along with its
 * options for jump-reboot and Iota power-off.
 */

#include <stdio.h>
#include <string.h>
#include <strings.h>
#include <stdlib.h>

static void
exit_bare(rc)
{
	exit(rc);
}

static void
exit_iotaoff(rc)
{
	static char *poweroff_argv[2] = {"poweroff", 0};

	tpinterf_make_cmd(poweroff_argv);
	tpinterf_send_cmd();
	exit(rc);
}

static void
exit_jump0(rc)
{
	static char *jump0_argv[3] = {"jump", "0", 0};

	tpinterf_make_cmd(jump0_argv);
	tpinterf_send_cmd();
	exit(rc);
}

void (*default_exit)() = exit_bare;

static struct kwtab {
	char *kw;
	void (*func)();
} exit_modes[] = {
	{"bare", exit_bare},
	{"iota-off", exit_iotaoff},
	{"jump0", exit_jump0},
	/* backward compat with old gta02.config */
	{"gta02-cutpwr", exit_iotaoff},
	{0, 0}
};

cmd_exit(argc, argv)
	char **argv;
{
	struct kwtab *tp;

	if (argc < 2)
		default_exit(0);
	for (tp = exit_modes; tp->kw; tp++)
		if (!strcmp(tp->kw, argv[1]))
			break;
	if (!tp->func) {
		fprintf(stderr,
			"error: \"%s\" is not an understood exit mode\n",
			argv[1]);
		return(-1);
	}
	tp->func(0);
}

/* called from hwparam.c config file parser */
void
set_default_exit_mode(arg, filename_for_errs, lineno_for_errs)
	char *arg;
	char *filename_for_errs;
	int lineno_for_errs;
{
	char *cp;
	struct kwtab *tp;

	while (isspace(*arg))
		arg++;
	if (!*arg) {
		fprintf(stderr,
		"%s line %d: exit-mode setting requires an argument\n",
			filename_for_errs, lineno_for_errs);
		exit(1);
	}
	for (cp = arg; *cp && !isspace(*cp); cp++)
		;
	*cp = '\0';
	for (tp = exit_modes; tp->kw; tp++)
		if (!strcmp(tp->kw, arg))
			break;
	if (!tp->func) {
		fprintf(stderr,
			"%s line %d: \"%s\" is not an understood exit mode\n",
			filename_for_errs, lineno_for_errs, arg);
		exit(1);
	}
	default_exit = tp->func;
}