mirror of https://github.com/nirenjan/libx52.git
Add config set command to daemon command processor
This change allows setting the configuration from the socket. It behaves similar to the override, and requires the client to send the section, key and value, and responds with an OK or error value.reverse-scroll
parent
7b8c71dd35
commit
116b9e2c0c
|
@ -224,7 +224,7 @@ static void cmd_config(char *buffer, int *buflen, int argc, char **argv)
|
||||||
|
|
||||||
x52d_config_load(argv[2]);
|
x52d_config_load(argv[2]);
|
||||||
x52d_config_apply();
|
x52d_config_apply();
|
||||||
OK("load", argv[2]);
|
OK("config", "load", argv[2]);
|
||||||
} else {
|
} else {
|
||||||
// Invalid number of args
|
// Invalid number of args
|
||||||
ERR_fmt("Unexpected arguments for 'config load' command; got %d, expected 3", argc);
|
ERR_fmt("Unexpected arguments for 'config load' command; got %d, expected 3", argc);
|
||||||
|
@ -235,7 +235,7 @@ static void cmd_config(char *buffer, int *buflen, int argc, char **argv)
|
||||||
MATCH(1, "reload") {
|
MATCH(1, "reload") {
|
||||||
if (argc == 2) {
|
if (argc == 2) {
|
||||||
raise(SIGHUP);
|
raise(SIGHUP);
|
||||||
OK("reload");
|
OK("config", "reload");
|
||||||
} else {
|
} else {
|
||||||
ERR_fmt("Unexpected arguments for 'config reload' command; got %d, expected 2", argc);
|
ERR_fmt("Unexpected arguments for 'config reload' command; got %d, expected 2", argc);
|
||||||
}
|
}
|
||||||
|
@ -250,7 +250,7 @@ static void cmd_config(char *buffer, int *buflen, int argc, char **argv)
|
||||||
}
|
}
|
||||||
|
|
||||||
x52d_config_save(argv[2]);
|
x52d_config_save(argv[2]);
|
||||||
OK("dump", argv[2]);
|
OK("config", "dump", argv[2]);
|
||||||
} else {
|
} else {
|
||||||
ERR_fmt("Unexpected arguments for 'config dump' command; got %d, expected 3", argc);
|
ERR_fmt("Unexpected arguments for 'config dump' command; got %d, expected 3", argc);
|
||||||
}
|
}
|
||||||
|
@ -261,13 +261,28 @@ static void cmd_config(char *buffer, int *buflen, int argc, char **argv)
|
||||||
MATCH(1, "save") {
|
MATCH(1, "save") {
|
||||||
if (argc == 2) {
|
if (argc == 2) {
|
||||||
raise(SIGUSR1);
|
raise(SIGUSR1);
|
||||||
OK("save");
|
OK("config", "save");
|
||||||
} else {
|
} else {
|
||||||
ERR_fmt("Unexpected arguments for 'config save' command; got %d, expected 2", argc);
|
ERR_fmt("Unexpected arguments for 'config save' command; got %d, expected 2", argc);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MATCH(1, "set") {
|
||||||
|
if (argc == 5) {
|
||||||
|
int rc = x52d_config_set(argv[2], argv[3], argv[4]);
|
||||||
|
if (rc != 0) {
|
||||||
|
ERR_fmt("Error %d setting '%s.%s'='%s': %s", rc,
|
||||||
|
argv[2], argv[3], argv[4], strerror(rc));
|
||||||
|
} else {
|
||||||
|
OK("config", "set", argv[2], argv[3], argv[4]);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
ERR_fmt("Unexpected arguments for 'config set' command; got %d, expected 5", argc);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
ERR_fmt("Unknown subcommand '%s' for 'config' command", argv[1]);
|
ERR_fmt("Unknown subcommand '%s' for 'config' command", argv[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,8 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
#include "pinelog.h"
|
#include "pinelog.h"
|
||||||
#include "x52d_config.h"
|
#include "x52d_config.h"
|
||||||
#include "x52d_const.h"
|
#include "x52d_const.h"
|
||||||
|
@ -55,6 +57,17 @@ void x52d_config_save(const char *cfg_file)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int x52d_config_set(const char *section, const char *key, const char *value)
|
||||||
|
{
|
||||||
|
if (section == NULL || key == NULL || value == NULL) {
|
||||||
|
return EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
PINELOG_TRACE("Processing config set '%s.%s'='%s'", section, key, value);
|
||||||
|
|
||||||
|
return x52d_config_process_kv(&x52d_config, section, key, value);
|
||||||
|
}
|
||||||
|
|
||||||
/* Callback stubs
|
/* Callback stubs
|
||||||
* TODO: Remove the ones below when their implementation is complete
|
* TODO: Remove the ones below when their implementation is complete
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -75,6 +75,8 @@ void x52d_cfg_set_Profiles_Directory(char* param);
|
||||||
void x52d_cfg_set_Profiles_ClutchEnabled(bool param);
|
void x52d_cfg_set_Profiles_ClutchEnabled(bool param);
|
||||||
void x52d_cfg_set_Profiles_ClutchLatched(bool param);
|
void x52d_cfg_set_Profiles_ClutchLatched(bool param);
|
||||||
|
|
||||||
|
int x52d_config_process_kv(void *user, const char *section, const char *key, const char *value);
|
||||||
|
|
||||||
int x52d_config_set_defaults(struct x52d_config *cfg);
|
int x52d_config_set_defaults(struct x52d_config *cfg);
|
||||||
|
|
||||||
int x52d_config_load_file(struct x52d_config *cfg, const char *cfg_file);
|
int x52d_config_load_file(struct x52d_config *cfg, const char *cfg_file);
|
||||||
|
@ -91,4 +93,6 @@ void x52d_config_apply(void);
|
||||||
int x52d_config_save_file(struct x52d_config *cfg, const char *cfg_file);
|
int x52d_config_save_file(struct x52d_config *cfg, const char *cfg_file);
|
||||||
void x52d_config_save(const char *cfg_file);
|
void x52d_config_save(const char *cfg_file);
|
||||||
|
|
||||||
|
int x52d_config_set(const char *section, const char *key, const char *value);
|
||||||
|
|
||||||
#endif // !defined X52D_CONFIG_H
|
#endif // !defined X52D_CONFIG_H
|
||||||
|
|
|
@ -131,7 +131,7 @@ static int date_format_parser(struct x52d_config *cfg, size_t offset, const char
|
||||||
|
|
||||||
/* Map for config->param */
|
/* Map for config->param */
|
||||||
#define CFG(section, key, name, type, def) {#section, #key, type ## _parser, offsetof(struct x52d_config, name)},
|
#define CFG(section, key, name, type, def) {#section, #key, type ## _parser, offsetof(struct x52d_config, name)},
|
||||||
const struct config_map {
|
static const struct config_map {
|
||||||
const char *section;
|
const char *section;
|
||||||
const char *key;
|
const char *key;
|
||||||
parser_fn parser;
|
parser_fn parser;
|
||||||
|
@ -143,7 +143,7 @@ const struct config_map {
|
||||||
{NULL, NULL, NULL, 0}
|
{NULL, NULL, NULL, 0}
|
||||||
};
|
};
|
||||||
|
|
||||||
static int process_config_kv(void *user, const char *section, const char *key, const char *value)
|
int x52d_config_process_kv(void *user, const char *section, const char *key, const char *value)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
int rc = 0;
|
int rc = 0;
|
||||||
|
@ -186,7 +186,7 @@ int x52d_config_set_defaults(struct x52d_config *cfg) {
|
||||||
|
|
||||||
PINELOG_TRACE("Setting configuration defaults");
|
PINELOG_TRACE("Setting configuration defaults");
|
||||||
#define CFG(section, key, name, parser, def) \
|
#define CFG(section, key, name, parser, def) \
|
||||||
rc = process_config_kv(cfg, #section, #key, #def); \
|
rc = x52d_config_process_kv(cfg, #section, #key, #def); \
|
||||||
if (rc != 0) { \
|
if (rc != 0) { \
|
||||||
return rc; \
|
return rc; \
|
||||||
}
|
}
|
||||||
|
@ -203,7 +203,7 @@ int x52d_config_load_file(struct x52d_config *cfg, const char *cfg_file)
|
||||||
}
|
}
|
||||||
|
|
||||||
PINELOG_TRACE("Loading configuration from file %s", cfg_file);
|
PINELOG_TRACE("Loading configuration from file %s", cfg_file);
|
||||||
rc = ini_parse(cfg_file, process_config_kv, cfg);
|
rc = ini_parse(cfg_file, x52d_config_process_kv, cfg);
|
||||||
if (rc < 0) {
|
if (rc < 0) {
|
||||||
PINELOG_ERROR(_("Failed processing configuration file %s - code %d"),
|
PINELOG_ERROR(_("Failed processing configuration file %s - code %d"),
|
||||||
cfg_file, rc);
|
cfg_file, rc);
|
||||||
|
@ -326,7 +326,7 @@ int x52d_config_apply_overrides(struct x52d_config *cfg)
|
||||||
tmp->section,
|
tmp->section,
|
||||||
tmp->key,
|
tmp->key,
|
||||||
tmp->value);
|
tmp->value);
|
||||||
rc = process_config_kv(cfg,
|
rc = x52d_config_process_kv(cfg,
|
||||||
tmp->section,
|
tmp->section,
|
||||||
tmp->key,
|
tmp->key,
|
||||||
tmp->value);
|
tmp->value);
|
||||||
|
|
|
@ -8,7 +8,7 @@ msgid ""
|
||||||
msgstr ""
|
msgstr ""
|
||||||
"Project-Id-Version: libx52 0.2.3\n"
|
"Project-Id-Version: libx52 0.2.3\n"
|
||||||
"Report-Msgid-Bugs-To: https://github.com/nirenjan/libx52/issues\n"
|
"Report-Msgid-Bugs-To: https://github.com/nirenjan/libx52/issues\n"
|
||||||
"POT-Creation-Date: 2021-11-05 15:09-0700\n"
|
"POT-Creation-Date: 2021-11-05 15:27-0700\n"
|
||||||
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
||||||
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
||||||
"Language-Team: LANGUAGE <LL@li.org>\n"
|
"Language-Team: LANGUAGE <LL@li.org>\n"
|
||||||
|
@ -678,22 +678,22 @@ msgstr ""
|
||||||
msgid "Timed out when polling for command"
|
msgid "Timed out when polling for command"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: daemon/x52d_command.c:330
|
#: daemon/x52d_command.c:345
|
||||||
#, c-format
|
#, c-format
|
||||||
msgid "Error reading from client %d: %s"
|
msgid "Error reading from client %d: %s"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: daemon/x52d_command.c:341
|
#: daemon/x52d_command.c:356
|
||||||
#, c-format
|
#, c-format
|
||||||
msgid "Short write to client %d; expected %d bytes, wrote %d bytes"
|
msgid "Short write to client %d; expected %d bytes, wrote %d bytes"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: daemon/x52d_config.c:26
|
#: daemon/x52d_config.c:28
|
||||||
#, c-format
|
#, c-format
|
||||||
msgid "Error %d setting configuration defaults: %s"
|
msgid "Error %d setting configuration defaults: %s"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: daemon/x52d_config.c:53
|
#: daemon/x52d_config.c:55
|
||||||
#, c-format
|
#, c-format
|
||||||
msgid "Error %d saving configuration file: %s"
|
msgid "Error %d saving configuration file: %s"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
10
po/xx_PL.po
10
po/xx_PL.po
|
@ -7,7 +7,7 @@ msgid ""
|
||||||
msgstr ""
|
msgstr ""
|
||||||
"Project-Id-Version: libx52 0.2.3\n"
|
"Project-Id-Version: libx52 0.2.3\n"
|
||||||
"Report-Msgid-Bugs-To: https://github.com/nirenjan/libx52/issues\n"
|
"Report-Msgid-Bugs-To: https://github.com/nirenjan/libx52/issues\n"
|
||||||
"POT-Creation-Date: 2021-11-05 15:09-0700\n"
|
"POT-Creation-Date: 2021-11-05 15:27-0700\n"
|
||||||
"PO-Revision-Date: 2021-11-04 15:35-0700\n"
|
"PO-Revision-Date: 2021-11-04 15:35-0700\n"
|
||||||
"Last-Translator: Nirenjan Krishnan <nirenjan@gmail.com>\n"
|
"Last-Translator: Nirenjan Krishnan <nirenjan@gmail.com>\n"
|
||||||
"Language-Team: Dummy Language for testing i18n\n"
|
"Language-Team: Dummy Language for testing i18n\n"
|
||||||
|
@ -729,23 +729,23 @@ msgstr "Erroray enwhay ollingpay orfay ommandcay: %s"
|
||||||
msgid "Timed out when polling for command"
|
msgid "Timed out when polling for command"
|
||||||
msgstr "Imedtay outay enwhay ollingpay orfay ommandcay"
|
msgstr "Imedtay outay enwhay ollingpay orfay ommandcay"
|
||||||
|
|
||||||
#: daemon/x52d_command.c:330
|
#: daemon/x52d_command.c:345
|
||||||
#, c-format
|
#, c-format
|
||||||
msgid "Error reading from client %d: %s"
|
msgid "Error reading from client %d: %s"
|
||||||
msgstr "Erroray eadingray omfray ientclay %d: %s"
|
msgstr "Erroray eadingray omfray ientclay %d: %s"
|
||||||
|
|
||||||
#: daemon/x52d_command.c:341
|
#: daemon/x52d_command.c:356
|
||||||
#, c-format
|
#, c-format
|
||||||
msgid "Short write to client %d; expected %d bytes, wrote %d bytes"
|
msgid "Short write to client %d; expected %d bytes, wrote %d bytes"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
"Ortshay itewray otay ientclay %d; expecteday %d ytesbay, otewray %d ytesbay"
|
"Ortshay itewray otay ientclay %d; expecteday %d ytesbay, otewray %d ytesbay"
|
||||||
|
|
||||||
#: daemon/x52d_config.c:26
|
#: daemon/x52d_config.c:28
|
||||||
#, c-format
|
#, c-format
|
||||||
msgid "Error %d setting configuration defaults: %s"
|
msgid "Error %d setting configuration defaults: %s"
|
||||||
msgstr "Erroray %d ettingsay onfigurationcay efaultsday: %s"
|
msgstr "Erroray %d ettingsay onfigurationcay efaultsday: %s"
|
||||||
|
|
||||||
#: daemon/x52d_config.c:53
|
#: daemon/x52d_config.c:55
|
||||||
#, c-format
|
#, c-format
|
||||||
msgid "Error %d saving configuration file: %s"
|
msgid "Error %d saving configuration file: %s"
|
||||||
msgstr "Erroray %d avingsay onfigurationcay ilefay: %s"
|
msgstr "Erroray %d avingsay onfigurationcay ilefay: %s"
|
||||||
|
|
Loading…
Reference in New Issue