Skip to content

Commit

Permalink
change config keys to be kernel env friendly
Browse files Browse the repository at this point in the history
  • Loading branch information
anibalportero committed May 27, 2024
1 parent 905f44b commit 51a6800
Show file tree
Hide file tree
Showing 32 changed files with 539 additions and 404 deletions.
2 changes: 1 addition & 1 deletion apparmor.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ static void load_from_list(const char *prof)

void pv_apparmor_load_profiles()
{
char *profiles = pv_config_get_str(CI_SYSTEM_APPARMOR_PROFILES);
char *profiles = pv_config_get_str(PV_SYSTEM_APPARMOR_PROFILES);
if (!profiles)
return;

Expand Down
2 changes: 1 addition & 1 deletion blkid.c
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ static int get_blkid_ubifs(struct blkid_info *info, const char *key)
* */
int get_blkid(struct blkid_info *info, const char *key)
{
if (!strncmp(pv_config_get_str(CI_STORAGE_FSTYPE), "ubifs",
if (!strncmp(pv_config_get_str(PV_STORAGE_FSTYPE), "ubifs",
strlen("ubifs")))
return get_blkid_ubifs(info, key);

Expand Down
421 changes: 271 additions & 150 deletions config.c

Large diffs are not rendered by default.

172 changes: 86 additions & 86 deletions config.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,92 +30,92 @@
// GENERIC

typedef enum {
CI_BOOTLOADER_FITCONFIG,
CI_BOOTLOADER_MTD_ENV,
CI_BOOTLOADER_MTD_ONLY,
CI_BOOTLOADER_TYPE,
CI_CACHE_DEVMETADIR,
CI_CACHE_USRMETADIR,
CI_CONTROL_REMOTE,
CI_CONTROL_REMOTE_ALWAYS,
CI_CREDS_HOST,
CI_CREDS_ID,
CI_CREDS_PORT,
CI_CREDS_PROXY_HOST,
CI_CREDS_PROXY_NOPROXYCONNECT,
CI_CREDS_PROXY_PORT,
CI_CREDS_PRN,
CI_CREDS_SECRET,
CI_CREDS_TPM_CERT,
CI_CREDS_TPM_KEY,
CI_CREDS_TYPE,
CI_DEBUG_SHELL,
CI_DEBUG_SHELL_AUTOLOGIN,
CI_DEBUG_SSH,
CI_DEBUG_SSH_AUTHORIZED_KEYS,
CI_DISK_EXPORTSDIR,
CI_DISK_VOLDIR,
CI_DISK_WRITABLEDIR,
CI_DROPBEAR_CACHE_DIR,
CI_FACTORY_AUTOTOK,
CI_LIBTHTTP_CERTDIR,
CI_LIBTHTTP_LOG_LEVEL,
CI_LOG_CAPTURE,
CI_LOG_CAPTURE_DMESG,
CI_LOG_BUF_NITEMS,
CI_LOG_DIR,
CI_LOG_FILETREE_TS_FMT,
CI_LOG_LEVEL,
CI_LOG_LOGGERS,
CI_LOG_MAXSIZE,
CI_LOG_PUSH,
CI_LOG_SERVER_OUTPUTS,
CI_LOG_SINGLEFILE_TS_FMT,
CI_LOG_STDOUT,
CI_LOG_STDOUT_TS_FMT,
CI_LXC_LOG_LEVEL,
CI_METADATA_DEVMETA_INTERVAL,
CI_METADATA_USRMETA_INTERVAL,
CI_NET_BRADDRESS4,
CI_NET_BRDEV,
CI_NET_BRMASK4,
CI_POLICY,
CI_REVISION_RETRIES,
CI_REVISION_RETRIES_TIMEOUT,
CI_SECUREBOOT_CHECKSUM,
CI_SECUREBOOT_HANDLERS,
CI_SECUREBOOT_MODE,
CI_SECUREBOOT_TRUSTSTORE,
CI_STORAGE_DEVICE,
CI_STORAGE_FSTYPE,
CI_STORAGE_GC_KEEP_FACTORY,
CI_STORAGE_GC_RESERVED,
CI_STORAGE_GC_THRESHOLD_DEFERTIME,
CI_STORAGE_GC_THRESHOLD,
CI_STORAGE_LOGTEMPSIZE,
CI_STORAGE_MNTPOINT,
CI_STORAGE_MNTTYPE,
CI_STORAGE_OPTS,
CI_STORAGE_WAIT,
CI_SYSTEM_APPARMOR_PROFILES,
CI_SYSTEM_CONFDIR,
CI_SYSTEM_DRIVERS_LOAD_EARLY_AUTO,
CI_SYSTEM_ETCDIR,
CI_SYSTEM_INIT_MODE,
CI_SYSTEM_LIBDIR,
CI_SYSTEM_MEDIADIR,
CI_SYSTEM_MOUNT_SECURITYFS,
CI_SYSTEM_RUNDIR,
CI_SYSTEM_USRDIR,
CI_UPDATER_COMMIT_DELAY,
CI_UPDATER_GOALS_TIMEOUT,
CI_UPDATER_INTERVAL,
CI_UPDATER_NETWORK_TIMEOUT,
CI_UPDATER_USE_TMP_OBJECTS,
CI_WDT_ENABLED,
CI_WDT_MODE,
CI_WDT_TIMEOUT,
CI_MAX
PV_BOOTLOADER_FITCONFIG,
PV_BOOTLOADER_MTD_ENV,
PV_BOOTLOADER_MTD_ONLY,
PV_BOOTLOADER_TYPE,
PV_CACHE_DEVMETADIR,
PV_CACHE_USRMETADIR,
PV_CONTROL_REMOTE,
PV_CONTROL_REMOTE_ALWAYS,
PV_CREDS_HOST,
PV_CREDS_ID,
PV_CREDS_PORT,
PV_CREDS_PROXY_HOST,
PV_CREDS_PROXY_NOPROXYCONNECT,
PV_CREDS_PROXY_PORT,
PV_CREDS_PRN,
PV_CREDS_SECRET,
PV_CREDS_TPM_CERT,
PV_CREDS_TPM_KEY,
PV_CREDS_TYPE,
PV_DEBUG_SHELL,
PV_DEBUG_SHELL_AUTOLOGIN,
PV_DEBUG_SSH,
PV_DEBUG_SSH_AUTHORIZED_KEYS,
PV_DISK_EXPORTSDIR,
PV_DISK_VOLDIR,
PV_DISK_WRITABLEDIR,
PV_DROPBEAR_CACHE_DIR,
PV_FACTORY_AUTOTOK,
PV_LIBTHTTP_CERTDIR,
PV_LIBTHTTP_LOG_LEVEL,
PV_LOG_CAPTURE,
PV_LOG_CAPTURE_DMESG,
PV_LOG_BUF_NITEMS,
PV_LOG_DIR,
PV_LOG_FILETREE_TS_FMT,
PV_LOG_LEVEL,
PV_LOG_LOGGERS,
PV_LOG_MAXSIZE,
PV_LOG_PUSH,
PV_LOG_SERVER_OUTPUTS,
PV_LOG_SINGLEFILE_TS_FMT,
PV_LOG_STDOUT,
PV_LOG_STDOUT_TS_FMT,
PV_LXC_LOG_LEVEL,
PV_METADATA_DEVMETA_INTERVAL,
PV_METADATA_USRMETA_INTERVAL,
PV_NET_BRADDRESS4,
PV_NET_BRDEV,
PV_NET_BRMASK4,
PV_POLICY,
PV_REVISION_RETRIES,
PV_REVISION_RETRIES_TIMEOUT,
PV_SECUREBOOT_CHECKSUM,
PV_SECUREBOOT_HANDLERS,
PV_SECUREBOOT_MODE,
PV_SECUREBOOT_TRUSTSTORE,
PV_STORAGE_DEVICE,
PV_STORAGE_FSTYPE,
PV_STORAGE_GC_KEEP_FACTORY,
PV_STORAGE_GC_RESERVED,
PV_STORAGE_GC_THRESHOLD_DEFERTIME,
PV_STORAGE_GC_THRESHOLD,
PV_STORAGE_LOGTEMPSIZE,
PV_STORAGE_MNTPOINT,
PV_STORAGE_MNTTYPE,
PV_STORAGE_OPTS,
PV_STORAGE_WAIT,
PV_SYSTEM_APPARMOR_PROFILES,
PV_SYSTEM_CONFDIR,
PV_SYSTEM_DRIVERS_LOAD_EARLY_AUTO,
PV_SYSTEM_ETCDIR,
PV_SYSTEM_INIT_MODE,
PV_SYSTEM_LIBDIR,
PV_SYSTEM_MEDIADIR,
PV_SYSTEM_MOUNT_SECURITYFS,
PV_SYSTEM_RUNDIR,
PV_SYSTEM_USRDIR,
PV_UPDATER_COMMIT_DELAY,
PV_UPDATER_GOALS_TIMEOUT,
PV_UPDATER_INTERVAL,
PV_UPDATER_NETWORK_TIMEOUT,
PV_UPDATER_USE_TMP_OBJECTS,
PV_WDT_ENABLED,
PV_WDT_MODE,
PV_WDT_TIMEOUT,
PV_MAX
} config_index_t;

bool pv_config_get_bool(config_index_t ci);
Expand Down
13 changes: 13 additions & 0 deletions config_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,19 @@ int config_parse_cmdline(struct dl_list *list, char *hint)
return 0;
}

extern char **environ;

int config_parse_env(struct dl_list *list)
{
char **envs = environ
while (*envs) {
// TODO: check begins with "PV_", parse and add to list
envs++;
}

return 0;
}

int load_key_value_file(const char *path, struct dl_list *list)
{
FILE *fp;
Expand Down
1 change: 1 addition & 0 deletions config_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "utils/list.h"

int config_parse_cmdline(struct dl_list *list, char *hint);
int config_parse_env(struct dl_list *list);
int load_key_value_file(const char *path, struct dl_list *list);
char *config_get_value(struct dl_list *list, char *key);
void config_iterate_items(struct dl_list *list,
Expand Down
2 changes: 1 addition & 1 deletion ctrl.c
Original file line number Diff line number Diff line change
Expand Up @@ -770,7 +770,7 @@ static int pv_ctrl_check_command(int req_fd, struct pv_cmd **cmd)
goto error;
}

if (!pv_config_get_bool(CI_CONTROL_REMOTE) &&
if (!pv_config_get_bool(PV_CONTROL_REMOTE) &&
((*cmd)->op == CMD_GO_REMOTE)) {
pv_ctrl_write_error_response(
req_fd, HTTP_STATUS_CONFLICT,
Expand Down
6 changes: 3 additions & 3 deletions debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ void pv_debug_start_shell()
}
dprintf(con_fd, "\n");

if (c[0] == 'd' || pv_config_get_bool(CI_DEBUG_SHELL_AUTOLOGIN))
if (c[0] == 'd' || pv_config_get_bool(PV_DEBUG_SHELL_AUTOLOGIN))
shell_pid =
tsh_run("/sbin/getty -n -l /bin/sh 0 console", 0, NULL);
}
Expand All @@ -98,7 +98,7 @@ void pv_debug_start_ssh()

pv_log(DEBUG, "starting SSH server...");

const char *keys = pv_config_get_str(CI_DEBUG_SSH_AUTHORIZED_KEYS);
const char *keys = pv_config_get_str(PV_DEBUG_SSH_AUTHORIZED_KEYS);

if (!keys || !strcmp(keys, "__default__"))
pv_paths_pv_usrmeta_key(path, PATH_MAX, SSH_KEY_FNAME);
Expand Down Expand Up @@ -140,7 +140,7 @@ void pv_debug_stop_ssh()

void pv_debug_check_ssh_running()
{
if (pv_config_get_bool(CI_DEBUG_SSH))
if (pv_config_get_bool(PV_DEBUG_SSH))
pv_debug_start_ssh();
else
pv_debug_stop_ssh();
Expand Down
4 changes: 2 additions & 2 deletions drivers.c
Original file line number Diff line number Diff line change
Expand Up @@ -180,11 +180,11 @@ static int _pv_drivers_modprobe(char **modules, mod_action_t action)

void pv_drivers_load_early()
{
if (!pv_config_get_bool(CI_SYSTEM_DRIVERS_LOAD_EARLY_AUTO))
if (!pv_config_get_bool(PV_SYSTEM_DRIVERS_LOAD_EARLY_AUTO))
return;

// load fs module from pantavisor.conf
char *fstype = pv_config_get_str(CI_STORAGE_FSTYPE);
char *fstype = pv_config_get_str(PV_STORAGE_FSTYPE);
if (pv_drivers_load_single(fstype, NULL) != 0)
pv_log(WARN, "cannot load filesystem module");

Expand Down
10 changes: 5 additions & 5 deletions init.c
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ static int other_mounts()
if (ret < 0)
exit_error(errno, "Could not mount /run");

if (pv_config_get_bool(CI_SYSTEM_MOUNT_SECURITYFS)) {
if (pv_config_get_bool(PV_SYSTEM_MOUNT_SECURITYFS)) {
ret = mount("none", "/sys/kernel/security", "securityfs", 0,
NULL);
if (ret < 0)
Expand Down Expand Up @@ -417,9 +417,9 @@ int main(int argc, char *argv[])

// in case of standalone is set, we only start debugging tools up in main thread
if (init_mode == IM_STANDALONE) {
if (pv_config_get_bool(CI_DEBUG_SHELL))
if (pv_config_get_bool(PV_DEBUG_SHELL))
pv_debug_start_shell();
if (pv_config_get_bool(CI_DEBUG_SSH))
if (pv_config_get_bool(PV_DEBUG_SSH))
pv_debug_start_ssh();
else
tsh_run("ifconfig lo up", 0, NULL);
Expand Down Expand Up @@ -451,9 +451,9 @@ int main(int argc, char *argv[])
if (pv_config_get_wdt_mode() >= WDT_STARTUP)
pv_wdt_start();

if (pv_config_get_bool(CI_DEBUG_SHELL))
if (pv_config_get_bool(PV_DEBUG_SHELL))
pv_debug_start_shell();
if (pv_config_get_bool(CI_DEBUG_SSH))
if (pv_config_get_bool(PV_DEBUG_SSH))
pv_debug_start_ssh();
else
tsh_run("ifconfig lo up", 0, NULL);
Expand Down
6 changes: 3 additions & 3 deletions log.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ static void __vlog(char *module, int level, const char *fmt, va_list args)

static void log_libthttp(int level, const char *fmt, va_list args)
{
if (level > pv_config_get_int(CI_LIBTHTTP_LOG_LEVEL))
if (level > pv_config_get_int(PV_LIBTHTTP_LOG_LEVEL))
return;

if (log_init_pid != getpid())
Expand All @@ -102,7 +102,7 @@ static void pv_log_init(const char *rev)
mount_bind(storage_logs_path, pv_logs_path);

pv_buffer_init(MAX_BUFFER_COUNT,
pv_config_get_int(CI_LOG_BUF_NITEMS) * 1024);
pv_config_get_int(PV_LOG_BUF_NITEMS) * 1024);

if (pv_logserver_init(rev))
pv_log(ERROR, "logserver initialization failed");
Expand All @@ -127,7 +127,7 @@ void __log(char *module, int level, const char *fmt, ...)
{
va_list args;

if ((level != FATAL) && (level > pv_config_get_int(CI_LOG_LEVEL)))
if ((level != FATAL) && (level > pv_config_get_int(PV_LOG_LEVEL)))
return;

va_start(args, fmt);
Expand Down
8 changes: 4 additions & 4 deletions logserver/logserver.c
Original file line number Diff line number Diff line change
Expand Up @@ -861,7 +861,7 @@ void pv_logserver_toggle(struct pantavisor *pv, const char *running_rev)
return;

// only start if we have log_capture configured
if (pv_config_get_bool(CI_LOG_CAPTURE)) {
if (pv_config_get_bool(PV_LOG_CAPTURE)) {
logserver_start(running_rev);
}
}
Expand Down Expand Up @@ -910,7 +910,7 @@ int pv_logserver_init(const char *rev)
if (!rev)
return -1;

if (pv_config_get_bool(CI_LOG_CAPTURE)) {
if (pv_config_get_bool(PV_LOG_CAPTURE)) {
logserver.active_out = pv_config_get_log_server_outputs();
logserver_load_outputs();
}
Expand Down Expand Up @@ -950,7 +950,7 @@ int pv_logserver_init(const char *rev)
logserver_start_service(rev);
pv_log(DEBUG, "started log service with pid %d", (int)logserver.pid);

if (pv_config_get_bool(CI_LOG_CAPTURE_DMESG))
if (pv_config_get_bool(PV_LOG_CAPTURE_DMESG))
logserver_capture_dmesg();

return 0;
Expand Down Expand Up @@ -1016,7 +1016,7 @@ int pv_logserver_send_vlog(bool is_platform, char *platform, char *src,
.src = src,
};

if ((level != FATAL) && (level > pv_config_get_int(CI_LOG_LEVEL)))
if ((level != FATAL) && (level > pv_config_get_int(PV_LOG_LEVEL)))
return 0;

struct buffer *log_buf = pv_buffer_get(true);
Expand Down
2 changes: 1 addition & 1 deletion logserver/logserver_filetree.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ static char *create_dir(const struct logserver_log *log, bool is_pv)

static int add_log(struct logserver_out *out, const struct logserver_log *log)
{
if (log->lvl > pv_config_get_int(CI_LOG_LEVEL))
if (log->lvl > pv_config_get_int(PV_LOG_LEVEL))
return 0;

bool is_pv = !strncmp(log->plat, MAIN_PLATFORM, strlen(MAIN_PLATFORM));
Expand Down
2 changes: 1 addition & 1 deletion logserver/logserver_singlefile.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ static char *create_dir(const struct logserver_log *log)

static int add_log(struct logserver_out *out, const struct logserver_log *log)
{
if (log->lvl > pv_config_get_int(CI_LOG_LEVEL))
if (log->lvl > pv_config_get_int(PV_LOG_LEVEL))
return 0;

char *path = create_dir(log);
Expand Down
Loading

0 comments on commit 51a6800

Please sign in to comment.