Kevin Day [Wed, 15 Dec 2021 02:34:21 +0000 (20:34 -0600)]
Update: Don't bother checking, just always update pointer.
At this point the pointer has been allocated.
If the pointer addresses are the same, then there is no problem.
If they are different, then this properly replaces.
Assigning this just removes the extra step of checking.
Kevin Day [Sun, 12 Dec 2021 15:41:16 +0000 (09:41 -0600)]
Update: Restructure fake settings, moving examples into a new projects directory.
Create a projects directory to store some real replacements of other projects build systems.
The bzip2 build system was used as just an example and is now treated as a real use case.
I am planning on trying to use cmocka to provide unit tests for this project.
The cmocka uses that rather unpleasant cmake.
Provide a cmocka fake build setting file for building cmocka.
Kevin Day [Sun, 12 Dec 2021 05:59:06 +0000 (23:59 -0600)]
Update: Improve performance by removing redundant memset().
The calloc() program is supposed to guarantee 0 filled data.
Either the libc or the kernel know how to optimize this automatically using numerous tricks based on architecture or lack thereof.
This makes calloc() potentially faster than malloc()+memset().
Calling calloc()+memset() is just ridiculous.
Remove the calls to memset() that follow a calloc() call.
This is guaranteed to be a performance increase (but how much? I didn't bother trying to find out).
Kevin Day [Sun, 12 Dec 2021 05:50:23 +0000 (23:50 -0600)]
Update: Use C11's aligned_alloc() by default, but keep posix_memalign() via macro _f_memory_USE_posix_memalign_.
The C11 standard introduced aligned_alloc() making it better practice than posix_memalign().
In case the compiler being used doesn't have aligned_alloc() or the user compiling just wants to posix_memalign() this behavior is preserved via _f_memory_USE_posix_memalign_ macro.
I didn't actually test this beyond confirming that it compiles.
I'm flying blind here.
Kevin Day [Sun, 12 Dec 2021 01:14:05 +0000 (19:14 -0600)]
Cleanup: Utilize 'void' inside of function declarations.
It seems that by adding 'void' (without a parameter variable name) instructs the compiler that this function is not allowed to take arguments.
When the parameters are empty such as '()', the compiler simply disable checking what the parameters are.
By adding void this results in instructing the compiler to verify that there are no parameters.
This increases the code integrity.
This change may be a problem for older C compilers.
Kevin Day [Sat, 11 Dec 2021 22:31:08 +0000 (16:31 -0600)]
Update: Add documentation.
This is yet another reminder to me to try and avoid accidental commits.
I should have already had the documentation written up and be committed along with the initial commit.
Given that this project was accidentally committed before it was ready to, this left the project in less than ideal state.
As a reminder to myself to help encourage avoiding this mistake, I am constantly adding this oops notice to my commits.
With this documentation written, I once more believe that I have wrapped everything up that I need to consider this ready.
I previously thought this was the case, but as is seen by recent previous commits, this was not the case.
Going forward, I plan on investigating writing tests for this project and to use this project as an example of writing tests for the entire FLL probject.
This will hopefully allow me to find any remaining bugs and make this program production ready.
Kevin Day [Sat, 11 Dec 2021 22:06:37 +0000 (16:06 -0600)]
Feature: Support outputting width or combining state of characters.
The width is reported as one of: '0', '1', or '2'.
The following is used for unknown or invalid '?'.
The private use area is consider valid but unknown.
The combining state is reported as either 'C' or 'N'.
The 'N' can be considered either 'Not' or 'No' as the meaning is synonymous in this case.
The to_combining and to_width may be used together.
Now that I know how this is to be implemented, remove unneeded functions.
This is failing for two reasons:
1) Not using the original string data when printing detected invalid characters.
2) Performing the from codepoint check before checking the binary output check in the function utf8_print_character().
Also remove a redundant not zero check in the error print function utf8_print_character_invalid().
the function utf8_print_character_invalid() is a wrapper to utf8_print_character(), where that check is already performed.
Kevin Day [Sat, 11 Dec 2021 03:57:44 +0000 (21:57 -0600)]
Bugfix: Error handling should not exit for certain errors.
When a process signal is being received, F_signal is being set with the error bit.
This should not have the error bit set.
Move the conditional logic inside the appropriate printing functions.
Add utf8_print_character_invalid() for printing an error character.
Invalid UTF-8 fragments should not result in an exit on error.
Instead, these should be handled by either appropriate printing or by setting the is valid property on exit.
Kevin Day [Sat, 11 Dec 2021 03:36:42 +0000 (21:36 -0600)]
Bugfix: Raw formatted print sometimes prints trailing NULL.
A logic flaw is resulting in the last NULL after the max length is reached to be printed.
When the strnlen() calculates the length and the calculated length is the requested max length, the subsequent line attempts to print any NULLs.
This is normally fine, except that it needs to check to make sure that "i" is less than the requested max length.
Kevin Day [Fri, 10 Dec 2021 01:36:39 +0000 (19:36 -0600)]
Bugfix: Do not print leading zero's in large Unicode codepoints.
Also cleanup the code moving some generic print functions into utf8-specific print functions.
Use character rather than text to better communicate that the string is intended to represent a single Unicode character.
Kevin Day [Fri, 10 Dec 2021 01:17:43 +0000 (19:17 -0600)]
Bugfix: Codepoint to Binary is not working.
The wrong variable is being processed.
The codepoint (which is the Unicode representation, such as U+8C78 the codepoint is for the character '豸') is being width checked.
The binary character is what should be getting the width check.
A second situation where the codepoint is not being printed at all is with the files.
It seems that I forgot to finish writing this code (another problem caused by my original accidental commit of this project).
While investigating this I saw some opportunity for some cleanup.
- Move the width detection into a separate function utf8_process_text_width().
- Use character.string[0] instead of *character.string.
- Rename 'character' to 'current' to make more semantic sense (At the time I wasn't sure what to call it and 'text' was already unavailable).
- The 'text' in private-utf8_codepoint.c is now initialized in a simpler way.
Kevin Day [Thu, 9 Dec 2021 05:43:42 +0000 (23:43 -0600)]
Bugfix: Performance is slow due to process signal checks (more).
This is a follow up to the previous commit similarly named.
I forgot to hit the save button for the changes to FSS Basic List files in my editor.
The cost of the system call for checking if a signal is received is more expensive than I have previously imagined.
I also was not sure where I should handle the signals and I arbitrarily put them inside loops.
Reduce the number of checks.
Reduce the number of the system call to check the process signal using modulus math.
The performance difference is most notable when using the byte_dump program.
This focuses on solving the immediate performance bug.
I still have not done any extensive performance investigations and I expect this to still have significant room for improvement.
Kevin Day [Thu, 9 Dec 2021 05:21:57 +0000 (23:21 -0600)]
Bugfix: Performance is slow due to process signal checks.
The cost of the system call for checking if a signal is received is more expensive than I have previously imagined.
I also was not sure where I should handle the signals and I arbitrarily put them inside loops.
Reduce the number of checks.
Reduce the number of the system call to check the process signal using modulus math.
The performance difference is most notable when using the byte_dump program.
This focuses on solving the immediate performance bug.
I still have not done any extensive performance investigations and I expect this to still have significant room for improvement.
Kevin Day [Tue, 7 Dec 2021 03:51:02 +0000 (21:51 -0600)]
Update: Add missing function in f_utf needed for completeness and reduce repeated code.
As per my completeness principle, the f_utf_unicode_string_to() must have the f_utf_character_unicode_string_to() compliment.
This function only allows for ASCII characters to represent the number and returns errors as appropriate for non-ASCII values.
Unicode number values are not treated as the ASCII numbers for representing a Unicode code sequence.
The f_utf_character_unicode_to() and f_utf_unicode_to() now has code reduced by utilizing private_f_utf_character_unicode_to().
Kevin Day [Sat, 4 Dec 2021 23:03:56 +0000 (17:03 -0600)]
Update: Wrap up utf8 program.
This seems to be a good point to stop.
The program is only intended to be simple.
Complete the functionality and consider all future problems bugs.
Some of the parameters are not used correctly.
The strip-invalid is not being used.
The verify is being used as strip-invalid (this is likely the result of the previously incomplete code being accidentally committed).
Add a separate parameter to optionally separate by newlines when headers are not being printed.
The verify should disable printing.
The quiet verbosity should not hide printed headers as those are considered data.
Remove redundant newline being printed when headers parameter is used.
I had originally accidentally committed the utf8 program before it was ready.
I followed up with a cleanup after I noticed this.
It seems that there is still more work to finish.
Looking at what I need to do to finish this it has become clear to me that I was originally working on this and realized I should move functionality into the level_0 f_utf project.
When I did this, I probably noticed a Unicode bug and stopped what I was doing to fix it.
I then forgot to come back and fix this code, leaving it in this incomplete and broken state.
I also noticed that the f_utf_unicode_string_from() function is mis-named.
The is a "to" function rather than a "from" function because it is creating to a Unicode codepoint.
The "raw" print mode is now supported so use the fl_print_format() to print.
Move the printing of "append" to after the closing color context.
This makes more sense, but I have not bothered to check to see if the design logic is intended to be used this way.
Kevin Day [Fri, 3 Dec 2021 23:58:53 +0000 (17:58 -0600)]
Bugfix: f_utf_unicode_string_from() is not functioning correctly.
The code in this function is incomplete and incorrect.
I have a feeling I got distracted and came back later to work on it, forgetting what I was doing.
Use while loops rather than for loops for cases where the for loop would essentially have empty content.
It is clear that I intended to test for both upper case and lower case U but I didn't actually test against lower case.
The code is not incrementing after confirming there is a 'u' or 'U".
Kevin Day [Tue, 30 Nov 2021 04:14:00 +0000 (22:14 -0600)]
Update: More unicode improvements, byte_dump improvements.
Get rid of the use of declaring a byte_first, byte_second, byte_third, and byte_fourth variable.
The allocation of the variable is costly and consumes memory.
I am more recently of the opinion that the bitwise check is cheaper than defining a variable and then comparing.
Implement a significant portion of the blocks/planes for the unassigned detection function.
Have the byte_dump program treat unassigned as invalid.
This results in a cleaner display.
Kevin Day [Tue, 30 Nov 2021 02:42:06 +0000 (20:42 -0600)]
Update: Finish implementing combining character detection.
I consider this done.
There will be a pass sometime in the future where I review all of the codepoints before making the stable release.
I suspect, given the size of these kinds of changes, that there will be mistakes and oversights.
Kevin Day [Sat, 27 Nov 2021 05:06:30 +0000 (23:06 -0600)]
Progress: Major UTF-8 changes and optimization.
Add more combining characters.
As usual, with the UTF-8 codes I am focusing on getting it supported rather than getting it optimal.
Add wide character detection.
Any mistakes aside, this appears complete.
There are a lot of blocks within some sequence ranges, so I used ".." in the comments to designate that this is a range of blocks.
Update the byte_dump program to utilize both of these.
Kevin Day [Sat, 20 Nov 2021 03:26:18 +0000 (21:26 -0600)]
Progress: Major UTF-8 changes and optimization, begin updating byte_dump and utf8, and miscellaneous changes.
A previous commit accidentally include the utf8 level 3 program while it was being heavily developed.
As it is already committed, commit the latest changes.
The utf8 program is still not done.
While working on the utf program, I noticed that there are some things in the UTF-8 code that is not yet done or correct and is needed.
I also noticed that the byte_dump program needs to handle the narrow and wide widths to assure consistent column line ups.
Such a change requires new functionality in the UTF-8 code for processing the widths.
These two significant needs resulted in me finally getting around to some of the UTF-8 cleanup that I have been needing to do.
- Get rid of the width parameter, and calculate the width as needed (bitwise is chip and allocated a variable and then passing it along parameters is not as cheap).
- Swap some of the conditions to avoid using "!", saving a single operation though structural changes.
- Break out the utf string functions into its own utf_string.c, utf_string.h, private-utf_string.c, and private-utf_string.h.
- Numerous documentation comment cleanups and update (I think there is still more to do).
- Provide F_utf_fragment and F_utf_fragment_not for improved communication of UTF-8 fragments in error responses (rather than re-using F_utf).
- Provide f_utf_unicode_string_from() (I have not yet written a f_utf_unicode_string_to() but I plan to).
- Update endianess detection to use macros (I am include <endian.h>, but I may also provide custom macros to disable and explicitly designate endianess).
The UTF-8 is wide functions are drafted out, but there are a lot of wide character codes that I need to add.
This will be grunt work that will take a notable amount of time.
For now, just add a comment and I will get back to this.
The byte_dump program is depending on the is wide functions and so currently incompletely implements the narrow and wide support.
Try to use present tense in error message.
There are likely many more places, but this is a start.
Add F_first, F_first_not, F_last, F_last_not, F_next, F_next_not, F_previous, and F_previous_not for providing position return codes.
Fix a bug where width is being define by a uint8_t but the calculates are f_array_length_t.
How did this ever work before, by accident?
Kevin Day [Mon, 15 Nov 2021 23:34:06 +0000 (17:34 -0600)]
Regression: Previous byte_dump cleanup resulted in an extra space for one character.
The character 0xd89d is being handled in a special case.
This is previous code that is now identifiable as removable.
Stop handling this as a special case, avoiding the need to print extra spaces.
Kevin Day [Sun, 14 Nov 2021 04:39:06 +0000 (22:39 -0600)]
Update: Improve UTF-8 Control detecting, expanding to distinguish Control Code and Control Format.
There seem to be "Control Format".
Create functions for "Control Code" and "Control Format" (is_control_code and is_control_format functions).
The is_control functions now check for both.
Kevin Day [Sat, 13 Nov 2021 22:36:17 +0000 (16:36 -0600)]
Update: Implement double support in print functions and add missing functionality.
This implements the double support as a wrapper to the printf() functionality.
Future versions will ideally impliment this internally.
I observed that there is some incorrect logic with the "width" and the "precision".
The logic appears to be asserting that they are XOR to each other.
In actuality they are OR to each other and both can be provided.
Rename "output" to "stream".
This seems slightly more accurate to me.
I considered using "file" but that is heavily used by the f_file_t rather than the FILE *.
Kevin Day [Sat, 13 Nov 2021 16:07:53 +0000 (10:07 -0600)]
Bugfix: The print safely functions are not fully UTF-8 aware.
The f_print_character_safely_get() can only handle a single byte.
This makes it impossible to be UTF-8 aware.
Provide a new function f_print_safely_get() that accepts a string and a max width.
This string is intended to represent a single character, but can be multi-byte based on max width.
This function checks to see if the character is invalid or a control character, in which case it is replaced.
Kevin Day [Fri, 12 Nov 2021 05:04:37 +0000 (23:04 -0600)]
Update: Signal related updates, consistency improvements, and miscellaneous code cleanups.
Add support for setting the timeout via f_signal_read().
I am using both F_signal and F_interrupt.
The F_signal is more general and in this since is more accurate.
However, F_interrupt is more accurate to the intent in the design.
When an interrupt is received exit.
All signals being treated as an interrupt will need to exit, so just pass F_interrupt.
Provide a consistent reporting of handling the signals.
Setup all programs to catch and handle signals, allowing for a clean exit.
There are so many changes in this regard, I went for a quick approach.
In every loop that at glance look like it would be a good point to check for signal, the code now checks for signal.
There is likely a need for performance consideration in this.
There is likely a need for invetigating this further to make sure it is still responsive (as in, investigate to see if I need to add additional signal checks).
Programs like fake and controller already handle the signal.
These programs are update to be consistent with this newer design.
The "main" structure used in the programs is sometimes a constant variable and other times a pointer.
While there are performance and security reasons, I am finding that consistency is better at this point in time.
Pass all of the "main" structures as either a constant pointe or a pointer.
At some point in the future, I can see myself reviewing these and making performance improvements that might result in reverting some of this.
Having be more consistent will make the code a bit more mangeable during this highly active development and design period.
Miscellaneous syntax cleanups of any code that I happened to notice needs cleaning and can be easily cleaned on the spot.
When interrupting, flush the output and print a new line.
This is effective in properly cleaning the console (to some reasonable extent), which can be messy when exiting due to an interrupt.
I did not get a change to utilize the signal handling function callbacks in the FSS processing functions.
I will need to follow up this commit with such a change.
I need to see if the IKI processing functions also can do this and need to do this as well.
I haven't had a chance to really look at each of the programs after this change.
I will need to spend time making suring there are no regressions.
Kevin Day [Tue, 9 Nov 2021 02:36:22 +0000 (20:36 -0600)]
Update: Experimentall cast characters to uint8_t in UTF-8 processing code.
I've noticed with calls like printf("%d", string[0]) the printed number might be a negative huge number.
Explicitly casting it to uint8_t (rather than char) seems to be a way to avoid this and allow for the number to be better printed.
I am suspecting that this should be done in general rather than just to the print functions.
This is an experimental commit designed to make it so.
This also has an affect on bitwise operations because bitwise shifts respond differently between signed and unsigned integers.
Kevin Day [Tue, 9 Nov 2021 02:26:17 +0000 (20:26 -0600)]
Update: Fix print function bugs and add missing functions.
There are some cases where the logic is flawed and fails to print correctly.
Given a bash binary, passing it through the print functions and back to the disk in raw format resulted in a different binary.
The binary should be identical to the original and is not.
It seems that when I attempted to reduce the number of variables in the print function I failed to account for certain details.
This essentially reverts some of the previous logic and puts back the variables.
Many off these functions are almost identical but their differences result in requiring slightly different code.
This makes the code less manageable and easy to get lost in.
The code has been tweaked somewhat to be more consistent across the board, where possible.
This might come at a cost of some slight performance.
To make the code easier to read, separate the print functions into two groups:
1) The print functions that use file streams.
2) The print functions that use file descriptors.
This code is slightly different and while I could use macros to make this simpler, I opted to avoid macros at the cost of duplication.
Move these two groups into separate files, significantly improving code readability.
There is a mistake in the previous code where errno is being processed for file stream errors.
The libc file stream functions do not utilize errno.
Change the affected code to just return F_output with the error bit set.
I am unable to find a discrete list of error codes returned by ferror().
I will need to additional work to get these codes so I can properly map them to more verbose error codes.
The documentation is no longer out of sync.
There should be a file descriptor function equivalent for nearly every file stream function.
In this regard, several missing functions are now added.
This is an unplanned change that is rather large.
I am concerned with oversights and regressions.
Just keep an eye out for regressions and hope that there are none.
Kevin Day [Fri, 5 Nov 2021 01:53:17 +0000 (20:53 -0500)]
Bugfix: UTF-8 functions fail to properly handle ASCII.
This seems to be a problem where there are two ways of processing ASCII detection of UTF-8 code.
The macro_f_utf_byte_width() will return the width of 1 for ASCII.
The macro_f_utf_byte_width_is() will return a width of 0 for ASCII.
The affected code is assuming a width of 0, but some functions send a width of 1 for ASCII.
These are private functions, so it is relatively safe to just allow both.
Change the behavior to accept both 0 and 1 and treat them as ASCII.
Update comment about Unicode 12.1, setting it to 14.0.
Kevin Day [Thu, 4 Nov 2021 05:12:12 +0000 (00:12 -0500)]
Update: Add "success" color context and initialize color "set" in programs.
There is an "error" and a "warning" but no "success".
Make this complete by adding "success".
The programs aren't initializing the "set".
Attempting to use these always results in no color context.
Fix this by initializing these in each program.
The output context also needs to be initialized just like the error and warning.
Kevin Day [Tue, 2 Nov 2021 03:49:49 +0000 (22:49 -0500)]
Cleanup: Break apart controller sources.
The functions have gotten too large an are in a need of cleanup.
Create additional source files and move functions around as appropriate.
Do some function renaming as well.
Move the print functions into separate print source files.
This is done only for functions whose sole purpose is printing and is not nor should it be done for functions that happen to have printing within them.
The entry pre-process and process functions should be in the entry source files.
Fix the name of those functions to start with "controller_entry_" rather than starting with "controller_process_".
Move any structure construct and destruct functions into the common.h and common.c that are not already there.
Break out the build settings file settings into multiple lines.
I prefer not to have too many extra lines, but there is a point when the lines get absurdly too long.
The lines are broken up by some context or pattern.
Kevin Day [Sun, 31 Oct 2021 14:45:45 +0000 (09:45 -0500)]
Regression: Script and Utility are no longer working when using "Extended" rather than "Extended List" format.
At some point I changed how the actions array get incremented.
I failed to increment a valid script or utility (or accidentally removed the existing increment) when populating its actions.
I noticed a potential problem where the rerun is re-using "type".
Avoid any potential problems by refactoring this to "type_rerun".
I also noticed that the controller_rule_action_type_execute_* are starting at 0.
From off the top of my mind, I believe this starts at zero because it is being used as an index in a static array.
Otherwise this enum should start at 1.
Add a comment about this exceptional case.
Kevin Day [Sun, 31 Oct 2021 13:08:14 +0000 (08:08 -0500)]
Cleanup: Remove stale comment regarding sleep interrupts.
I updated this in the previous commit and completely failed to notice that its message is no longer correct.
The commit ad4a95d1b8a26e271d491320b627dbdea443a13c actually makes it possible for the sleep functions to receive the interrupts.
Kevin Day [Sun, 31 Oct 2021 13:00:17 +0000 (08:00 -0500)]
Update: Improve sleeping logic, also replacing sleep() with nanosleep().
The previous time-related regression fix introduced unblocking the signals as an immediate solution to its problem.
The preferred and intended design is to have the signal handling done by controller rather than done automatically.
Redesign the sleep functions to only unblock the signals for the sleep call.
Then re-lock the signal so that the intended design may be continued.
This then allows all appropriate cleanup functionality to operate as expected.
This can be confirmed with valgrind before/after and sending an interrupt during a validation process that utilizes a sleep (such as the example htop rule).
Create several functions to standardize some of the processes involved.
This also resolves a "todo" designating to replace sleep() with nanosleep().
Kevin Day [Sun, 31 Oct 2021 04:53:13 +0000 (23:53 -0500)]
Bugfix: Functions like nanosleep() are not receiving interrupt signals and similar.
When the thread is created, the signals are locked out so that they can be handled within the program.
The processes thread needs to be able to receive signals.
Allow the parent thread to receive all signals.
More work may be done in the future to fine tune this.
For now, the signals are just opened up entirely unless uninterruptible is designated,
This seems to allow for the thread to be cancelled even when nanosleep() is being called.
Also pass the specific signal received that is triggering a termination.
Kevin Day [Sun, 24 Oct 2021 20:42:27 +0000 (15:42 -0500)]
Bugfix: config.h shouldn't be installed.
The pre-generated config.h shouldn't be installed by default.
This fixes some mistakes in: "106c18c3 Feature: Enable config.h, config.c, and config.cpp support in package generation.".
The source files and any potential headers may still need changes to properly include the config.h as necessary.
Still, this is a step forward in making this project friendlier with some existing practices, even if it is only half a step.
Kevin Day [Sun, 24 Oct 2021 03:42:34 +0000 (22:42 -0500)]
Bugfix: Require is not properly triggering failure on error.
Get and handle the status code of controller_rule_wait_all().
Fix cases where "status" is being used where "status_lock" is better suited.
Remove unnecessary double assignment of status error.
In this case, only when F_lock is returned should the status be set.
This may need to be revisited and have the called function also set error on F_lock rather than handling here.
For asynchronous functions controller_rule_wait_all() is not properly handling the error.
This is happening because "required" is being incorrectly used.
For this function "required" is design to only wait for all required processes only and not limit the required validation.
Removing this fixing the problem so that when an asynchronous process that is required fails, the failure is propagated to the waiting process.
Add "require" in the htop example as a place for testing.
Add additional comments for clarifications and cleanup existing comments.
Kevin Day [Sat, 23 Oct 2021 21:45:55 +0000 (16:45 -0500)]
Update: Implement "session new" and "session same", improve documentation, update simulate and validate display.
The controller and init programs now support customizing their session as new or session as same state.
A setting global to the entry and exit files is defined as "session new" and "session same".
A setting specific to every rule item is appended to the "with" as either "session_new" or "session_same".
Update the documentation with these changes.
I noticed the documentation could use a little cleanup.
When passing both simulate and validate parameters, the entries and exits (with all related parts) are displayed.
The ordering can be more alphabetic.
It will not be fully alphabetic because there still exists logic that supersedes this, such as:
- "id", "name", and "type" values generally go first regardless of alphabetic ordering (and in that order).
- The simple data is displayed first (ones not using '{' and '}' to display), which are within themselves alphabetic.
- The complex data is displayed last, which are within themselves alphabetic.
- Within the complex data, the "item"s are displayed last.
Kevin Day [Sat, 23 Oct 2021 16:10:30 +0000 (11:10 -0500)]
Update: Improve terminal support in execute functions.
The init program calling bash results in "not a tty" error:
- "bash: cannot set terminal process group (-1): Not a tty"
- "bash: no job control in this shell"
This exposed me to the Process Group.
I have learned that I may need to set the Controlling Terminal in this case.
To that end, I have introduced FL_execute_parameter_option_session_d for setting this up.
I have also added an initial setup for FL_execute_parameter_option_terminal_d, but more investigation and research needs to be done.
I've added some basic execute terminal codes that I may or may not need.
I would rather have them now and remove them now rather than not have them and have to add them later.
The controller program needs to utilize this, at least when running as "init".
However, I believe that I should pass control over this to the user as new settings, such as "session new" and "session same".
Provide example to utilize "setsid" program for doing this same thing when directly calling bash.
Kevin Day [Thu, 21 Oct 2021 03:46:53 +0000 (22:46 -0500)]
Regression: Example bzip fakefile fails.
Empty strings end up getting passed to the programs, such as gcc.
The program gcc will throw an error claiming it cannot find file (displaying an empty sting for the filename).
This empty string doesn't show up in verbose, so the whole reason for failure is confusing because nothing is being displayed.
Fix this by not appending empty strings to the arguments.
At some point I added additional checks when loading the build settings file.
Because the fake make process uses the same function, it ends up failing because unrequired settings are now required.
Add a new variable "checks" to designate to perform these requirement checks or not.
The fake make process will then be setup to not perform these requirement checks.
In a recent commit, I added support for indexer_arguments.
It turns out I did more than necessary because this will already get loaded via the build settings loading code.
Remove the extra unnecessary processing of the indexer_arguments setting as it is already being processed later on.
The "compiler" and "indexer" should also be looked into.
Cleanup a print function.
Add a missing newline print at the end of the "print" operation.
Update the example fakefiles.
Add missing settings to the example build settings.
Kevin Day [Thu, 21 Oct 2021 00:41:31 +0000 (19:41 -0500)]
Update: Add support for indexer_arguments, update documentation, and fix printing bugs.
This is a step towards removing hardcoded defaults that I had initially added just to save time.
The indexer now has an indexer_arguments that will expect the arguments, such as "rcs".
Update the documentation, documenting this behavior, fix problems in the documentation, and do some cleanup of the documentation.
There are some places where "linker" is still used.
Replace this usage with "indexer".
Fix some cases with printing mistakes.
These mistakes are likely regressions resulting from the mass refactor to the fl_print_format() and fll_print_format().
I've noticed that there are some problems with the settings in the fakefile.
The custom settings, such as "compiler", "indexer", etc.., are being overwritten by the build settings.
It may also be a good idea to provide another iki parameter to expose some of these settings.
"flags_all" is now "flags".
"defines_all" is now "defines".
These are needed for the adding settings specific to shared or static state.
The "headers" related ones are added in case custom headers include static or shared specific code that should only be installed when using static or shared.
Note that the "headers" is for installation and is not needed in any way for compilation.
Other non-compilation related settings are not to have the "_shared" or "_static" added.
Kevin Day [Mon, 18 Oct 2021 02:04:56 +0000 (21:04 -0500)]
Refactor: Use the newer _s and _d define strategy.
This new strategy allows for the "const char *"s to be more directly the same as the "#define"s.
For example, "F_console_standard_short_dark_s" is the "#define" and "f_console_standard_short_dark_s" is the "const char *".
The use of uppercase is tolerated here as an exceptional case because F, FL, and FLL are sufficiently short enough to not be an eyesore.
No changes are made to exist "macro_*".
I will contemplate changing the "macro_XXX" to instead be "XXX_m" to match the "XXX_s" and "XXX_d" notations.
As an additional exception case, the length "#defines" that are directly coupled to a string, are of the fom "XXX_s_length" rather than "XXX_d".
This directly identifies that these only exist within direct relationship to the string "#define".
The "#define" will now have uppercase in the level 0, 1, and 2 projects.
Level 3, being programs, only conditionally follow to avoid using too many uppercase characters (ie: fss_basic_list_read_xxx vs FSS_BASIC_LIST_READ_xxx).
Kevin Day [Sun, 17 Oct 2021 03:43:57 +0000 (22:43 -0500)]
Refactor: Convert old f_file_t output strategy to the newer fl_print_t output strategy.
The "f_file_t output" should now be "fl_print_t output".
The output verbosity can now be used rather than the error verbosity for output verbosity.
This makes the code more readable and consistent.
The default fl_print_t_initialize is for normal output so also convert the error output initialization to use macro_fl_print_t_initialize_error().
Kevin Day [Sat, 16 Oct 2021 02:32:09 +0000 (21:32 -0500)]
Refactor: fll_error_print_t is now fl_print_t.
After using fll_error_print_t for a while now, I find that it is in practice superior to the regular print approach (such as with "f_file_t output;").
This made coding far easier than I imagined.
This refactor changes renames this from an error purpose print to a generic all-purpose print.
The existing "f_file_t output;" designs are not changed with this factor and will be changed in a later commit.
This refactor allows this to be moved from a level 2 project to a level 1 project.
In following with my completeness principle, I have added a "suffix" to compliment the "prefix".
I also added the "set" as a pointer to make it optional and to also not take up as much resources the full object rather than a pointer.
Having used fll_error_print_t for some time, I have found that I occasionally needed more than just the "context" and "notable".
While working on this, I realized I could improve my practice of handling "static" strings (such as fll_error_print_debug_s).
The practice is now to have the defines more closely match the names, but begin with the F_, FL_, etc.. in the same way that status codes are used.
This then allows:
| old | new |
----------------------------------------------
| fll_error_print_debug_s | fl_print_debug_s | <--- variable.
| fll_error_print_debug | FL_print_debug_s | <--- define/macro.
A future commit will convert all existing code that follows the old way.
Kevin Day [Fri, 15 Oct 2021 01:58:38 +0000 (20:58 -0500)]
Update: Execute changes and controller program changes.
Tweak some of the execute status codes.
I confused the errno parameters for what I was using F_execute_off for.
Change F_execute_off to F_execute_bad to more accurately reflect what the error code represents.
Add additional execute status codes.
Provide a F_format and F_format_not status codes.
Pass through non-negative, non-zero, exec return codes.
For negative return codes that is not -1, set the execute error code to F_execute_failure.
Improve error printing in controller program on child process failure.
Start to cleanup print functions.
There already is data being passed via the f_process_t, use those to better reduce the number of parameters passed to relevant functions.
There is much more work in this regards to do, but that is to be done at another time.
The controller program threads should exit with child code only if the child code is non-zero.
When the child code is zero, then the normal (and preferred) thread exit is allowed to perform.
Kevin Day [Wed, 13 Oct 2021 23:21:44 +0000 (18:21 -0500)]
Update: Implement "rerun" and properly get failed execute status codes.
Provide "rerun" support feature.
I discovered some problems with the execute functions after testing the "rerun" feature.
Specifically, when a child exits, the exit code is not properly propogating to the caller.
This makes it impossible to detect a failed execution.
It turns out that I need to call exit() with the appropriate failed code (which is only 8-bits).
The pthread_exit() is documented as always exit() with a value of 0.
This makes it impossible to communicate the failed state to the parent via an exit return code.
I am forced to call exit() here.
To do this, several significant changes are required.
Implement F_execute_codes enum and related functions to handle the 8-bit large status codes.
The limited set of codes are focused on possible failure states from the execute functions.
Functions to convert to and from regular status codes and these special limited execute status codes are now provided.
A union called f_execute_result_t is now provided as a way for the execute functions to return a pid_t for the parent process and an int for the child process.
The int in this case is intended to hold the special execute status codes.
An int is used rather than a more appropriate uint8_t because the standard POSIX functions use int.
Additional normal status codes F_too_large and F_too_small are now provided as generic too large and too small statuses.
Exit calls now directly use the execute status codes when calling exit().
The controller program child process now returns the exit status code either at the end of the appropraite threads or at the end of the main().
A new micro time conversion function is provided so that the deprecated usleep() can be avoided.
I may end up rewriting this to perform the sleep as well rather than just return a timespec.
Yet another htop rule is provided for testing "rerun".
Kevin Day [Mon, 11 Oct 2021 02:47:29 +0000 (21:47 -0500)]
Progress: Begin implementing re-run, fixing related problems.
To properly operate as an init (and improve the controller execution functionality), programs and services need to re-run after exiting.
A good example of this is the agetty program, which should re-run on both success and failure.
I attempted to take a simple approach with this design.
Example:
rerun start success delay 1000 reset
rerun start failure delay 5000 max 100
A "rerun" is applied to each Rule Action "start", "stop", "freeze", etc...
Each Rule Action has either a "success" or a "failure" state.
Each state may specify a delay, max, and a reset.
The delay provides how long to wait before re-running.
The max represents the maximum number of times to perform the re-run (setting to 0 results in no maximum).
The reset designates that the opposite return result (either success or failure) will have its counter reset.
That is, in the above example if failure is triggered 50 times and then success is triggered, the failure counter will be 0 again due to the reset on success.
Not specifying "rerun" will disable re-running.
This implements another array structure and the code is changed to perform the processing of the settings at an earlier point.
The previous design is a quick and simple but required additional looping before each execution.
The code now does the processing in the existing loops to avoid needing to loop later.
This requires adding new variables to the structure increasing memory footprint there but also decreases memory footprint in the actions array (and results in smaller actions array).
The "with" and "pid_file" are updated in this way as well.
The "user" and "group" have not yet been updated and need to be.
The configuration and validation of "rerun" is implemented, but the re-run functionality needs to be written.
The error checking, handling, and exiting will need to be reviewed after this work is complete.
Kevin Day [Fri, 8 Oct 2021 02:36:09 +0000 (21:36 -0500)]
Update: Implement timeout setting support, fix number handling, improve printing.
The timeout settings were never fully completed.
This implements the loading of the timeout settings but does not provide an usage of these settings.
Do some restructuring related to the timeout settings.
Fix detecting and processing of +/- as well as decimals.
Handle more errors returned by the number convert functions.
Cleanup the printing code.
Centralize some of the printing to functions, ideally reducing code size.
Add printing where it is not being done.
Fix debug vs verbose printing where debug isn't always including verbose printing messages.
Kevin Day [Thu, 7 Oct 2021 02:53:18 +0000 (21:53 -0500)]
Cleanup: The fl_conversion re-used functions should be within private files.
The practice is to maintain functional isolated even within a projects own sources.
The private sources are the method intended to re-use the functions within the same file.
Kevin Day [Thu, 7 Oct 2021 01:59:38 +0000 (20:59 -0500)]
Bugfix: The decimal '.' (0x2e) should not be considered a number.
The decimal may be a number character, but the conversion functions are for whole numbers only.
Consider the presence of decimals an error.
Use the F_number_decimal character to communicate this case.
Kevin Day [Sun, 3 Oct 2021 21:33:22 +0000 (16:33 -0500)]
Update: Support "pid" and "show" entry settings, and bug fixes.
The pid file may be created before the filesystem is ready and it may not be deleted when the system shuts down.
This then prevents the system from booting due to init failures.
Provide rule setting for fine tuning the control over how to handle the pid file.
Now, when running "as init", the pid entry setting by default designates to only utilize the pid file when "ready".
Previously, the pid file was always being checked for before the entry is even processed.
This prevented even waiting on the "ready" action because the entry is bailing out before even being processed.
There already is a "verbose" that prints the execution of programs.
This does not, however, start by default.
Provide a "show" setting for toggling this behavior to print some of the verbose messages when in "init" "show" mode.
Update the constant strings and related variables.
The ready behavior needs to be properly set.
As far as I can tell, the logic seemed odd, if not wrong.
Remove one of the ready checks and cleanup the ready check for the explicit ready action.
Update the prebuilt rules for terminals.
For now, there will be separate terminal files to execute.
There should be a variable substitution later on to not require multiple files.
For example, behavior is now:
"rule terminal one", found in rules/terminal/one.rule
"rule terminal two", found in rules/terminal/two.rule
This could better be something like:
"rule terminal tty/1", found in rules/terminal/tty.rule
"rule terminal tty/2", found in rules/terminal/tty.rule
Kevin Day [Sat, 2 Oct 2021 03:35:49 +0000 (22:35 -0500)]
Bugfix: Infinite loop on invalid entry file and related printing problems.
The loop is not properly handling the failure state and infinitely attempts to execute a rule that will always fail.
Make sure to copy over the rule failure code to the entry status.
Make sure to exit when rule execution fails when not simulating.
The related error printing bad logic in the conditionals.
Separate the simulate and related verbosity from the non-simulate and related verbosity.