HomeClusterLabs Projects

Refactor: remoted: Clean up load_env_vars()
81b51044ac06Unpublished

Unpublished Commit ยท Learn More

Not On Permanent Ref: This commit is not an ancestor of any permanent ref.
This commit no longer exists in the repository. It may have been part of a branch which was deleted.This commit has been deleted in the repository: it is no longer reachable from any branch, tag, or ref.

Description

Refactor: remoted: Clean up load_env_vars()

The changes in this commit involve using (gchar *) strings and some
dynamic allocation to make load_env_vars() easier to reason about.

Previously, we tried to be as efficient as possible by reading a line
into a buffer, iterating over it with multiple pointers, dividing
it into name and value by insertion of a null terminator, etc.

This is premature optimization. This function is not called along a path
of execution where performance is so critical as to require this. In my
opinion, clarity is more important.

  • Use pcmk__scan_nvpair() to separate the line on the equal sign.
  • Simplify name validation since we now have name as a separate string (before the equal sign) and don't need to return first and last pointers.
  • Use an is_quoted boolean variable, so that we can limit the quote character to the inner block and compare to the value instead of maintaining a pointer to the quote character.
  • Skip the leading quote by converting it to a space and calling g_strchug() to memmove() value up by one position. This ensures that value still points to the beginning of the buffer, which simplifies freeing it later.

Signed-off-by: Reid Wahl <nrwahl@protonmail.com>

Details

Provenance
nrwahl2Authored on Mar 6 2025, 6:32 AM

Event Timeline

Commit No Longer Exists

This commit no longer exists in the repository.