Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AP_Scripting: add DIR_DISABLE param to disable loading scripts from given directory #15621

Merged
merged 1 commit into from
Oct 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions libraries/AP_Scripting/AP_Scripting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,14 @@ const AP_Param::GroupInfo AP_Scripting::var_info[] = {
// @User: Standard
AP_GROUPINFO("USER4", 8, AP_Scripting, _user[3], 0.0),

// @Param: DIR_DISABLE
// @DisplayName: Directory disable
// @Description: This will stop scripts being loaded from the given locations
// @Bitmask: 0:ROMFS, 1:APM/scripts
// @RebootRequired: True
// @User: Advanced
AP_GROUPINFO("DIR_DISABLE", 9, AP_Scripting, _dir_disable, 0),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would have preferred an ENABLE parameter probably..


AP_GROUPEND
};

Expand Down
7 changes: 7 additions & 0 deletions libraries/AP_Scripting/AP_Scripting.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ class AP_Scripting
bool session;
} terminal;

enum class SCR_DIR {
ROMFS = 1 << 0,
SCRIPTS = 1 << 1,
};
uint16_t get_disabled_dir() { return uint16_t(_dir_disable.get());}

private:

bool repl_start(void);
Expand All @@ -63,6 +69,7 @@ class AP_Scripting
AP_Int32 _script_vm_exec_count;
AP_Int32 _script_heap_size;
AP_Int8 _debug_level;
AP_Int16 _dir_disable;

bool _init_failed; // true if memory allocation failed

Expand Down
16 changes: 14 additions & 2 deletions libraries/AP_Scripting/lua_scripts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -363,8 +363,20 @@ void lua_scripts::run(void) {
load_generated_bindings(L);

// Scan the filesystem in an appropriate manner and autostart scripts
load_all_scripts_in_dir(L, SCRIPTING_DIRECTORY);
load_all_scripts_in_dir(L, "@ROMFS/scripts");
// Skip those directores disabled with SCR_DIR_DISABLE param
uint16_t dir_disable = AP_Scripting::get_singleton()->get_disabled_dir();
bool loaded = false;
if ((dir_disable & uint16_t(AP_Scripting::SCR_DIR::SCRIPTS)) == 0) {
load_all_scripts_in_dir(L, SCRIPTING_DIRECTORY);
loaded = true;
}
if ((dir_disable & uint16_t(AP_Scripting::SCR_DIR::ROMFS)) == 0) {
load_all_scripts_in_dir(L, "@ROMFS/scripts");
loaded = true;
}
if (!loaded) {
gcs().send_text(MAV_SEVERITY_CRITICAL, "Lua: All directory's disabled see SCR_DIR_DISABLE");
}

#ifndef __clang_analyzer__
succeeded_initial_load = true;
Expand Down