Kevin Day [Sun, 3 Jan 2021 03:11:02 +0000 (21:11 -0600)]
Update: thread support.
Finish wrapping the pthread functions using f_thread.
I have observed some problems under GLIBC where static linking and -pthreads do not appear to work.
This is a problem with GLIBC as far as I can tell and I must ignore it to the extend that I can.
That said, because of the problems I decided to disable static compiling by default.
Either a better libc should be used or the static libraries should be compiled with thread support disabled.
I have not yet decided whether or not I intend to have thread suppot enabled or disabled by default.
The current default as of this commit is enabled.
There are some tweaks to the build settings to make things slightly easier when building with threads disabled vs threads enabled.
Completely separate f_signal from f_thread (where previously f_signal has conditional thread support).
Add a threadsafe option to fl_execute_parameter_t to conditionally use a threadsafe signal handler or not.
Kevin Day [Thu, 31 Dec 2020 22:21:04 +0000 (16:21 -0600)]
Progress: controller program, restructure some of f*_execute functionality, and add or update documentation.
For the controller program:
- add "freeze", "thaw", "pause", and "resume".
- improve simulation to actually perform an execute, but with a stub execution (an empty bash script).
- print more information when performing the stubbed simulation.
- simulation should not stop on errors when simulating, there are a number of cases where stopping is still happening.
- add a microsleep during the stubbed execution to better simulate synchronous vs asynchronous behavior.
- The F_schedule is no longer being returned from the child process, do not treat it as a child exit state.
- add more documentation.
Kevin Day [Wed, 30 Dec 2020 21:13:29 +0000 (15:13 -0600)]
Progress: control program, adding numerous FLL projects as needed.
This focuses primarily on getting control groups working.
There are also some f_account changes, but nothing in the control program used the f_account changes.
Kevin Day [Sat, 26 Dec 2020 03:39:17 +0000 (21:39 -0600)]
Progress: controller program and other changes.
Lots of changes with the most notable described below.
This adds support for capabilities, which depends on the external libcap (-lcap).
This introduces a problem because it is POSIX complaint in the sense of a draft and Linux has adopted it.
The end result is that instead of being in libc, the functions are defined in libcap.
To address this complication, a new project f_capability, is added to conditional compile in support and otherwise provide stubs.
This allows the rest of the projects to just call the f_capability functions without needing as many macros.
A define macro is still needed and the appropriate libary (-lcap) is still needed (or not if disabled).
I have further observed that when adding -lcap, the ar progam's ficklness on the order becomes a problem.
As a temporary work around, I am appending the "build_libraries" after all libaries introduced by a mode.
Kevin Day [Sun, 20 Dec 2020 04:04:04 +0000 (22:04 -0600)]
Progress: controller program and execute function improvements.
Get rid f fl_execute_parameter_option_fixated.
A better approach is just to allow a 0 to be passed instead of the string (aka: NULL).
The execute functions can then detect whether or not full fixation is needed.
An additional parameter check is now needed as if the program is 0 then there must be at least 1 argument defined.
Due to design changes the 'method' property for individual rule actions no longer needs to be on the rule action structure.
In fact, it is now confusing as each action represents only a single action (itself).
Add support for the "script" rule setting to designate the script program to run for scripts.
Kevin Day [Sun, 20 Dec 2020 00:05:49 +0000 (18:05 -0600)]
Progress: controller program and related changes, such a adding fll_environment.
The environment loading functionality is likely to be very common.
Create fll_environment (because it depends on fl_string) and provide the environment variable loading functionality.
Replace the related code from Featureless Make to use the code from fll_environment.
Instead of using two string arrays, use an array of string maps for the environment.
Make the appropriate changes in all affected projects.
Add the fll_execute_as() function to perform an execution without a fork() operation.
This will become important once I write the f_asynchronous and related projects.
A new execute parameter option fl_execute_parameter_option_fixated is introduced to allow for execution without automatically prepending the program name at index 0.
There are existing projects that have to reconstruct an array to meet the structure of the execute functions (which then reconstructs the array again...essentially back to how it started).
This is a bit ridiculous and an artifact of the previous design.
With this new execute parameter option, the array is not reconstructed and assumed to be correct.
The controller program now sets the environment variables on the executed process (which currently only script execution is written).
Kevin Day [Sat, 19 Dec 2020 04:55:00 +0000 (22:55 -0600)]
Update: rewrite the execute functions to accept a parameter structure.
This changes the programs so that the execute function that handles piping data to the child in a separate function to normal execute function.
This happens via a private function and is therefore transparent to the caller.
The caller can select options to pass to tweak the operation of the execute function.
While I do not like using structures in this way as it complicate the code in one respect, in another respect it simplifies things.
There are also fewer parameters passed which is easier on the registers.
The f_execute_asynchronous_t structure is not needed with this design.
Future changes will include a new project (likely called f_asynchronous) to assist in performing asynchronous tasks.
Note: this go around I am trying constant pointers.
This makes it compatible when passing constants through.
Kevin Day [Fri, 18 Dec 2020 04:18:00 +0000 (22:18 -0600)]
Progress: controller program, working on execute script logic.
I have been tossing around how exactly I want to implement the execute with piped data.
I have decided that I should clean up the parameters and redesign it to accept a few specialized structures.
Before I do that, I wanted to confirm that the pipe to shell (such as bash) works as I expect it to.
This tweaks the code to a temporary state where I can automatically execute some bash script with some string piped to it.
This seems to work as expected and errors out as expected.
I also need to write some asynchronous functions to help with managing asynchronous processes.
This might require a new series of projects (f_asynchronous, fl_asynchronous, etc..).
Note: "bash" was used as the default script, but I really need to provide some sort of configuration to change this.
Kevin Day [Thu, 17 Dec 2020 05:40:42 +0000 (23:40 -0600)]
Progress: controller program, featureless make tweaks, and execute cleanup.
I am going to be using controller program to codestorm how I want the execute functions to handle forking with child.
I may simplify the "pipe" arguments to only accept an input pipe and then write a execute fork functions that perform the fork and return to the caller so that the caller fully handles everything.
This would allow for the "non-fork" (as in "fork" is not in the function names) functions to only focus on simple executions.
This could then make way for the asynchronous behavior that is planned.
Kevin Day [Tue, 15 Dec 2020 17:47:00 +0000 (11:47 -0600)]
Update: wrap some macros in functions and minor cleanups.
The macro design has its uses but to save compiled size provide functions that are essentially wrappers to the macros.
Macros can also be flakey and sensitive while being harder to debug.
The delete functions that wrap the macros use the delete_simple macro.
Make the fss_macro.h and its contents private.
When decreasing, instead of using "if (X - 1 > 0)..." use "if (X > 1)...".
This avoids performing a math operation when it could otherwise be avoided.
Kevin Day [Mon, 14 Dec 2020 01:46:11 +0000 (19:46 -0600)]
Update: f_memory tweaks, always call memset() on new allocations.
This is already done with reallocations.
Be consistent and also do this for allocations.
The size parameters represent the size of the memory structure, which should always be non-zero and positive.
The length parameter, on the other hand, is just the amount of time the structure is to be allocation, which should always be non-negative.
The length parameter, therefore, can be 0 and if it is then do nothing (this relaxes the parameter restrictions).
Kevin Day [Sun, 13 Dec 2020 21:47:18 +0000 (15:47 -0600)]
Feature: the execute functions now support custom pipes.
This is necessary for the parent process to directly pipe date to/from a child process.
One of the intended goals is for something like the controller program to directly execute a bash script from a string generated by the parent (where this is no file).
The standard input can be used by the child process as pipe data.
When a pipe is passed then the execute functions are asynchronous instead of blocking.
The caller must properly handling all blocking operations as appropriate.
Kevin Day [Sun, 13 Dec 2020 21:01:33 +0000 (15:01 -0600)]
Update: always ensure standard file descriptors are closed on program exit.
Explicitly close file descritpros on exit.
This is especially important now that the program could be a child process and the file descriptor could be open between a parent process.
Kevin Day [Sun, 13 Dec 2020 19:01:48 +0000 (13:01 -0600)]
Security: A child process of an execv() family of functions may leak memory if script is called.
When calling a bash script, the exit() call gets triggered but memory is never cleared.
I am suspecting that this is happening because the script is run in the current process space whereas when calling a binary the process changes for the child.
There are new status codes: F_child, F_child_not, F_parent, F_parent_not.
The execute functions do not know what type of file is being executed.
Return F_child for the child process and allow the caller to handle the exit behavior of the child process.
This required significant changes to the Featureless Make, but the Featureless Make now always clears memory even for scripts.
The firewall program also had to be changed.
Instead of solving the potentially issues there, I decided to (for the time being) just mimic the previous behavior and call exit for the child process.
The firewall program needs a rewrite anyway, so I am holding off on major changes.
Refactor, cleanup, and improve the execute family of functions.
This was my original commit plans but when I observed the memory leak the refactor and cleanup became this security related commit.
As per cleanup plans:
- Moved common code into shared private functions.
- Change parameter checking granularity.
- Allow for 0 length strings as arguments.
- Avoid memory allocation inside execute functions.
- Consistently check WIFEXITED() on child process result.
- Update the documentation to follow more recent practices.
Kevin Day [Sun, 13 Dec 2020 04:09:40 +0000 (22:09 -0600)]
Progress: contoller program.
This focuses on getting the simulation code working as desired.
While --test is what triggers simulation mode, if --validate is specified, then additional information on rules are provided.
Break apart the default pid file name to operate on a per entry basis.
This will allow for multiple controllers to co-exist with different pid files (and likewise eventually socket files).
This fixes a lot of bugs/mistakes that cropped up during the previous codestorming as well as restructures some of the data types.
Kevin Day [Thu, 10 Dec 2020 04:14:45 +0000 (22:14 -0600)]
Progress: controller program.
This includes changes using static variables that was introduced in a previous commit at the entire fll project level.
Begin implementing the simulation execution.
There is much to do here and the simulation is already showing problems that need to be resolved (such as in the rule loading process).
Kevin Day [Thu, 10 Dec 2020 01:39:57 +0000 (19:39 -0600)]
Cleanup: use const more, but in a way that works with pointers.
The standard practice is to specify const first.
In the case of pointers, anything to the left of such a declaration represents what is being pointed to.
This means const cannot be used in this case unless the pointer is intending to point to a constant.
The const qualifier may instead be put after the pointer symbol '*' to designate that the pointer and not what is being pointed to is to be a constant.
It seems that I tend to forget this behavior.
This makes a pass at existing uses of such pointers, adding const in the appropriate way.
Kevin Day [Sun, 6 Dec 2020 04:48:43 +0000 (22:48 -0600)]
Progress: controller program.
Change "timeout" property to the more generic "number".
This can then be used for types "timeout" and "item", whereas the "item" number represents the location within the items list.
This is not known until all entry items are loaded and is therefore updated during the pre-process phase.
This implements the pre-process phase after the load phase.
The pre-process will perform additional checks, such as determining if "ready" is set somewhere in the active chain.
This makes sure recursion to an item already on the stack is not allowed.
Do some cleanups, reducing the if/then nesting by adding "do nothing" comment and letting the "else" condition handle the case appropriately.
Internally, line counting starts at 0, but when dealing with presenting the lines to users, the lines start at 1.
Change the behavior to increase the line number appropriately for entries.
The same will likely need to be done for rules.
Kevin Day [Fri, 4 Dec 2020 05:08:59 +0000 (23:08 -0600)]
Cleanup: _F_types_h should be _F_type_h and some macros have misplaces the "s".
The f_type project is singular, so do not use an "s" in the name.
Some of the macros in the type_array.h file were not converted from having the "s" after the _t to more accurately matching the type name.
For example uint8s_t should have macros using uint8s_t instead of uint8_ts.
Kevin Day [Thu, 3 Dec 2020 02:55:54 +0000 (20:55 -0600)]
Cleanup: move "macro_" prefix to after program name.
With the macro_ being defined after f_, fl_, and fll_, it makes more sense to follow the same logic with programs.
For example, macro_iki_read_X() is now iki_read_macro_X().
This more accurately associates the macro with the program via styling practices.
Kevin Day [Thu, 3 Dec 2020 01:01:29 +0000 (19:01 -0600)]
Update: memory changes, memory bugfixes, and minor controller program fixes.
Do some minor cleanup with the allocation functions.
The *_delete_simple() and *_destroy_simple() macros need to always set size to 0, because they are always ignoring the return status.
Also move the relating check outside of the for loop for performance reasons.
Minor cleanups in memory functions.
Add additional parameter checks to the memory create functions.
Add additional size and length checks in the memory delete and destroy functions.
Fix bug in f_macro_memory_structure_macro_increment() where if condition is obviously wrong (two '>' checks are used against each other!).
Change behavior to increment against "used" instead of "size", more consistently.
Rewrite the *_increase() and *_increase_by() functions due to bugs and inconsistencies.
Only use variables when needed for performance and resource reasons.
Get rid of the F_array_too_large on success behavior as the current design doesn't handle the cases where both F_array_too_large and an error occurs afterwards.
Fix mistake in controller program where I forgot to actually set the allocated sizes.
Use counter instead of pointer for entry item in controller program.
In some cases, use fl_string_dynamic_terminate_after() instead of fl_string_dynamic_terminate() (there will likely be more of these changes).
Kevin Day [Tue, 1 Dec 2020 03:48:15 +0000 (21:48 -0600)]
Update: provide file mode macros in f_file.
I would rather provide static constant strings, but the Posix file string functions that use this expect a non-constant string.
This is unsafe, so just stick with macros.
Kevin Day [Tue, 1 Dec 2020 02:21:57 +0000 (20:21 -0600)]
Update: status code changes, adding "_not" in more places.
I am not a fan of having so many "_not".
I believe I even made efforts to reduce its usage in the past.
Having said that, there ended up being too many different cases where "_not" makes sense.
I want things to be consistent, so this commit introduces "_not" more thoroughly unless it makes sense not to.
There are also cases where I have prefixes, such as "un" in unknown.
Change this to be consistent with the "_not" logic.
This results in changes like F_unknown -> F_known_not.
Other minor cleanups exist, such as F_interrupted -> F_interrupt.
I expect down the road there will be changes where these "_not" are used in functions where the "_not" is not used.
(Example: it may be that a function returns F_number (with error bit set) on invalid number, but it may be better to now use F_number_not.)
Kevin Day [Mon, 30 Nov 2020 03:38:36 +0000 (21:38 -0600)]
Bugfix: provide static variable "fll_error_string_null_s".
When using the fl_color_print functions, the context before and after pointers may safely be NULL.
When using the printf functions, the context before and after pointers cannot safely be NULL.
In the second case, a global static is now provided that is essentially a NULL string of a compatible type.
Kevin Day [Sun, 29 Nov 2020 06:58:58 +0000 (00:58 -0600)]
Bugfix: featureless make is not copying settings directory.
The contents of the directory are being copied instead of the directory itself.
Change the behavior to instead copy the entire directory and not just its contents.
Also move the directory check into its own line instead of inline inside of an if condition.
The signal check is moved with it.
Kevin Day [Mon, 23 Nov 2020 03:56:11 +0000 (21:56 -0600)]
Progress: controller program.
Wrap up some of the existing rules code.
Begin writing the entry code.
This seems like a good time to start using and referencing my unit of time called "Time".
Use MegaTime (aka: milliseconds) to handle the time, which will be stored in a 64bit unsigned integer as units of Time.
Kevin Day [Mon, 23 Nov 2020 03:54:32 +0000 (21:54 -0600)]
Cleanup: fix comment in featureless make program.
Add a @fixme for UTF-8 because I noticed that I was not using UTF-8 character support.
If environment variables should only be ASCII, update the documentation to better reflect this.
Kevin Day [Thu, 19 Nov 2020 04:30:45 +0000 (22:30 -0600)]
Progress: controller program.
Wrap up the current implementation of the rule read functions.
Utilize a (private) cache, reducing the parameters and reducing the amount of allocations.
How I am using the cache changed as I went and I need to come back and review it again before completing this program.
Kevin Day [Sun, 15 Nov 2020 23:36:55 +0000 (17:36 -0600)]
Bugfix: Embedded List is not properly handling delimits on write.
This is hard to observe because of how bash handles newlines.
For example:
echo "$(echo -e " To {\n World\n \\\\\\\\\\\\\\{\n")"
Would produce a string where the slashes after world actually represent a total of 4 slashes.
The problem with bash is that it "guesses" the number of slashes.
Another concern is that there are two quotes, so a slash has to be escaped twice for such a string in bash.
As a more complex example, see:
# echo "$(echo -e "\\\\\\\\\\\\\\")" | byte_dump -tcw 5
Once past the confusing behavior of backslash escaping in Bash, one can then observe that this project is incorrectly escaping backslashes.
In the case of Embedded List close character (the close brace '}') only the first backslash needs to be escaped.
In the case of Embedded List open character (the open brace '{') every even backslash must be escaped (and there should only be a single unescaped odd backslash).
The problem is that the code is treating the close brace as an open brace, resulting in too many backslashes.
There is also an ends of EOL boolean that appears to be being incorrectly set.
The EOL is detected at range->start position, but the position is being reset to the saved "start" position.
Kevin Day [Sun, 15 Nov 2020 22:16:17 +0000 (16:16 -0600)]
Update: FSS Extended List should be non-recursive.
Update specification to make this more clear.
The Extended List read functions are updated to handle this.
The Extended List read program is essentially copied from the Basic List read program and then updated accordingly.
The Extended List write functions and programs need to not escape the opening brace inside a content.
Kevin Day [Sat, 14 Nov 2020 05:33:15 +0000 (23:33 -0600)]
Update: create FSS Embedded List and other minor fixes.
The FSS-0008 Embedded List is just copied from FSS-0003 Extended List.
Fix some minor problems observed during this transition.
I will need to follow up with rewriting the FSS-0003 Extended List code.
I will probably just use FSS-0002 Basic List as a fresh starting point given that list is not recursive.
Kevin Day [Sat, 14 Nov 2020 05:03:51 +0000 (23:03 -0600)]
Progress: controller.
Begin prototyping and writing the controller code.
While working on this I suddenly realized that I accidentally treated FSS-0003 (Extended List) as FSS-0008 (Embedded List)!
This needs to be fixed so I am saving the progress as-is with all the note and other mess and will correct the FSS-0003 accident.
Kevin Day [Tue, 10 Nov 2020 02:21:04 +0000 (20:21 -0600)]
Progress: init.
Begin preparations for implementing this.
After review, I suspect this will be more complex than the control and controller programs.
To that end, I am switching focus to those two programs.
Kevin Day [Thu, 5 Nov 2020 03:12:05 +0000 (21:12 -0600)]
Feature: Stub out the Control program.
This is a part of the traditional "init" process, such as those done in sysvinit or initng.
Unlike those, this only communicates with the "Controller" program to give the "Controller" program commands.
For the booting part of the process, see the "Init" program.
This is also intended to be control from service "Controller" program.
Kevin Day [Thu, 5 Nov 2020 03:10:06 +0000 (21:10 -0600)]
Feature: Stub out the Controller program.
This is a part of the traditional "init" process, such as those done in sysvinit or initng.
Unlike those, this only performs tasks and manages services.
For the booting part of the process, see the "Init" program.
This is also intended to be controlled from user space via the "Control" program.
Kevin Day [Thu, 5 Nov 2020 02:22:19 +0000 (20:22 -0600)]
Update: Re-create Init program with barebones source structure.
The Init program will instead be developed as an init-only program.
The goal will be to not implement any service management.
This means that another progrram will be written for that purpose (which will be called something like "control" and/or "controller").
Kevin Day [Thu, 5 Nov 2020 02:05:07 +0000 (20:05 -0600)]
Bugfix: color print is bleeding into GCC messages.
When GCC has an error or warning, the print messages end up discolored.
This seems to be an artifact of how streams work and the newline.
Move all final newlines out of the color context printing and print the newlines in a separate command.
This appears to avoid the mentioned problem.
Kevin Day [Wed, 4 Nov 2020 06:32:04 +0000 (00:32 -0600)]
Bugfix: Fake building monolithic FLL is not compiling due to header directory structure problems.
The header directory structure is being preserved by the bootstrap.sh but not by Fake.
Introduce a new setting, 'path_headers_preserve' as a yes/no boolean.
This designates that the path for headers should be preserved or not.
In the case of the monolithic build, path_headers_preserve must be 'yes'.
Provide a new function fl_directory_create() to make it easy to create an entire directory tree.
Fake is now aware of this new 'path_headers_preserve', setting.
When supplied, it will make sure to preserve the directory tree, such as 'level_0/' in the monolithic build header file 'level_0/color.h'.
Both Fake and the bootstrap script should now behave the same in this respect.
The changes in this commit have been quickly thrown together.
This will need additional reviewing.
The NULL terminating character is not appended after each new header name.
This resulted in garbled header names due to existing content in the buffer.
Kevin Day [Wed, 4 Nov 2020 02:17:28 +0000 (20:17 -0600)]
Cleanup: default to monolithic build.
For simplicity purposes, I am just building and releasing the monolothic build of FLL.
It makes more sense to me then to change the default to use this monolithic build.