-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
generate: generate clone operations for deep-copy #135
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
with this in place we can simplify crun as (and not have to manually keep the code in sync): diff --git a/src/libcrun/container.c b/src/libcrun/container.c
index be3c282..1bc20fb 100644
--- a/src/libcrun/container.c
+++ b/src/libcrun/container.c
@@ -554,31 +554,6 @@ make_container (runtime_spec_schema_config_schema *container_def, const char *pa
return container;
}
-runtime_spec_schema_config_schema_process_user *
-process_user_dup (const runtime_spec_schema_config_schema_process_user *const src)
-{
- runtime_spec_schema_config_schema_process_user *const dst = xmalloc0 (sizeof (runtime_spec_schema_config_schema_process_user));
-
- dst->uid = src->uid;
- dst->uid_present = src->uid_present;
- dst->gid = src->gid;
- dst->gid_present = src->gid_present;
- dst->umask = src->umask;
- dst->umask_present = src->umask_present;
-
- if (src->additional_gids)
- {
- dst->additional_gids_len = src->additional_gids_len;
- const size_t additional_gids_size = src->additional_gids_len * sizeof (gid_t);
- dst->additional_gids = xmalloc (additional_gids_size);
- memcpy (dst->additional_gids, src->additional_gids, additional_gids_size);
- }
-
- dst->username = xstrdup (src->username);
-
- return dst;
-}
-
libcrun_container_t *
libcrun_container_load_from_memory (const char *json, libcrun_error_t *err)
{
@@ -3662,7 +3637,11 @@ libcrun_container_exec_with_options (libcrun_context_t *context, const char *id,
process->apparmor_profile = xstrdup (container->container_def->process->apparmor_profile);
if (process->user == NULL && container->container_def->process->user)
- process->user = process_user_dup (container->container_def->process->user);
+ {
+ process->user = clone_runtime_spec_schema_config_schema_process_user (container->container_def->process->user);
+ if (process->user == NULL)
+ OOM ();
+ }
}
ret = initialize_security (process, err); @bduffany FYI |
for comparison, the generated code is: runtime_spec_schema_config_schema_process_user *
clone_runtime_spec_schema_config_schema_process_user (runtime_spec_schema_config_schema_process_user *src)
{
__auto_cleanup(free_runtime_spec_schema_config_schema_process_user) runtime_spec_schema_config_schema_process_user *ret = NULL;
ret = calloc (1, sizeof (*ret));
if (ret == NULL)
return NULL;
ret->uid = src->uid;
ret->uid_present = src->uid_present;
ret->gid = src->gid;
ret->gid_present = src->gid_present;
ret->umask = src->umask;
ret->umask_present = src->umask_present;
if (src->additional_gids)
{
ret->additional_gids_len = src->additional_gids_len;
ret->additional_gids = calloc (src->additional_gids_len + 1, sizeof (*ret->additional_gids));
if (ret->additional_gids == NULL)
return NULL;
for (size_t i = 0; i < src->additional_gids_len; i++)
{
ret->additional_gids[i] = src->additional_gids[i];
}
}
if (src->username)
{
ret->username = strdup (src->username);
if (ret->username == NULL)
return NULL;
}
return move_ptr (ret);
} |
giuseppe
force-pushed
the
generate-clone
branch
from
September 5, 2024 17:39
1fd47fc
to
37c2b65
Compare
flouthoc
approved these changes
Sep 5, 2024
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
giuseppe
force-pushed
the
generate-clone
branch
from
September 5, 2024 20:14
37c2b65
to
be36ade
Compare
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
giuseppe
force-pushed
the
generate-clone
branch
from
September 5, 2024 20:25
be36ade
to
3ec73ba
Compare
# for free
to join this conversation on GitHub.
Already have an account?
# to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
No description provided.