From 3b0f34c7cd55686cf18f65efbdc0be8a84f13e3e Mon Sep 17 00:00:00 2001 From: zhongtao Date: Mon, 20 May 2024 17:54:04 +1400 Subject: [PATCH 090/108] modify the user error log to be the same as before Signed-off-by: zhongtao --- src/daemon/common/id_name_manager.c | 4 +-- .../executor/container_cb/execution_create.c | 26 +++++++++++-------- .../container_cb/execution_information.c | 4 ++- 3 files changed, 20 insertions(+), 14 deletions(-) diff --git a/src/daemon/common/id_name_manager.c b/src/daemon/common/id_name_manager.c index 263a584d..f64094b9 100644 --- a/src/daemon/common/id_name_manager.c +++ b/src/daemon/common/id_name_manager.c @@ -242,7 +242,7 @@ static bool try_add_name(const char *name) } if (!util_valid_container_name(name)) { - ERROR("Failed to add invalid name: %s", name); + ERROR("Invalid container name (%s), only [a-zA-Z0-9][a-zA-Z0-9_.-]+$ are allowed.", name); return false; } @@ -262,7 +262,7 @@ static bool try_remove_name(const char *name) } if (!util_valid_container_name(name)) { - ERROR("Failed to remove invalid name: %s", name); + ERROR("Invalid container name (%s), only [a-zA-Z0-9][a-zA-Z0-9_.-]+$ are allowed.", name); return false; } diff --git a/src/daemon/executor/container_cb/execution_create.c b/src/daemon/executor/container_cb/execution_create.c index 785b4e27..041089dd 100644 --- a/src/daemon/executor/container_cb/execution_create.c +++ b/src/daemon/executor/container_cb/execution_create.c @@ -761,8 +761,17 @@ static int maintain_container_id(const container_create_request *request, char * #endif if (!nret) { - ERROR("Failed to add entry to id name manager with new id and name"); - isulad_set_error_message("Failed to add entry to id name manager with new id and name"); + __isula_auto_free char *used_id = NULL; + used_id = container_name_index_get(name); + if(used_id != NULL) { + ERROR("Name %s is in use by container %s", name, used_id); + isulad_set_error_message("Conflict. The name \"%s\" is already in use by container %s. " + "You have to remove (or rename) that container to be able to reuse that name.", + name, used_id); + } else { + ERROR("Failed to add entry to id name manager with new id and name"); + isulad_set_error_message("Failed to add entry to id name manager with new id and name"); + } ret = -1; goto out; } @@ -775,19 +784,14 @@ static int maintain_container_id(const container_create_request *request, char * goto out; } - char *used_id = NULL; - used_id = container_name_index_get(name); - ERROR("Name %s is in use by container %s", name, used_id); - isulad_set_error_message("Conflict. The name \"%s\" is already in use by container %s. " - "You have to remove (or rename) that container to be able to reuse that name.", - name, used_id); - free(used_id); - used_id = NULL; - ret = -1; if (!skip_id_name_manage && !id_name_manager_remove_entry(id, name)) { WARN("Failed to remove %s and %s from id name manager", id, name); } + ERROR("Failed to add %s to container name index", name); + isulad_set_error_message("Failed to add %s to container name index", name); + ret = -1; + out: *out_id = id; *out_name = name; diff --git a/src/daemon/executor/container_cb/execution_information.c b/src/daemon/executor/container_cb/execution_information.c index c02cc830..58924257 100644 --- a/src/daemon/executor/container_cb/execution_information.c +++ b/src/daemon/executor/container_cb/execution_information.c @@ -1149,7 +1149,9 @@ static int container_rename(container_t *cont, const char *new_name) if (!id_name_manager_rename(new_name, old_name)) { ERROR("Failed to rename %s to %s in id-name manager", old_name, new_name); - isulad_set_error_message("Failed to rename %s to %s in id-name manager", old_name, new_name); + isulad_set_error_message("Conflict. The name \"%s\" is already in use by container %s. " + "You have to remove (or rename) that container to be able to reuse that name.", + new_name, new_name); ret = -1; goto out; } -- 2.25.1