cgroups/cgfsng: replace logging functions

parent 6d9a9f08
...@@ -1941,7 +1941,7 @@ static bool cg_legacy_freeze(struct cgroup_ops *ops) ...@@ -1941,7 +1941,7 @@ static bool cg_legacy_freeze(struct cgroup_ops *ops)
h = get_hierarchy(ops, "freezer"); h = get_hierarchy(ops, "freezer");
if (!h) if (!h)
return minus_one_set_errno(ENOENT); return ret_set_errno(-1, ENOENT);
path = must_make_path(h->container_full_path, "freezer.state", NULL); path = must_make_path(h->container_full_path, "freezer.state", NULL);
return lxc_write_to_file(path, "FROZEN", STRLITERALLEN("FROZEN"), false, 0666); return lxc_write_to_file(path, "FROZEN", STRLITERALLEN("FROZEN"), false, 0666);
...@@ -1992,10 +1992,10 @@ static int cg_unified_freeze(struct cgroup_ops *ops, int timeout) ...@@ -1992,10 +1992,10 @@ static int cg_unified_freeze(struct cgroup_ops *ops, int timeout)
h = ops->unified; h = ops->unified;
if (!h) if (!h)
return minus_one_set_errno(ENOENT); return ret_set_errno(-1, ENOENT);
if (!h->container_full_path) if (!h->container_full_path)
return minus_one_set_errno(EEXIST); return ret_set_errno(-1, EEXIST);
if (timeout != 0) { if (timeout != 0) {
__do_free char *events_file = NULL; __do_free char *events_file = NULL;
...@@ -2003,27 +2003,27 @@ static int cg_unified_freeze(struct cgroup_ops *ops, int timeout) ...@@ -2003,27 +2003,27 @@ static int cg_unified_freeze(struct cgroup_ops *ops, int timeout)
events_file = must_make_path(h->container_full_path, "cgroup.events", NULL); events_file = must_make_path(h->container_full_path, "cgroup.events", NULL);
fd = open(events_file, O_RDONLY | O_CLOEXEC); fd = open(events_file, O_RDONLY | O_CLOEXEC);
if (fd < 0) if (fd < 0)
return error_log_errno(errno, "Failed to open cgroup.events file"); return log_error_errno(-1, errno, "Failed to open cgroup.events file");
ret = lxc_mainloop_open(&descr); ret = lxc_mainloop_open(&descr);
if (ret) if (ret)
return error_log_errno(errno, "Failed to create epoll instance to wait for container freeze"); return log_error_errno(-1, errno, "Failed to create epoll instance to wait for container freeze");
/* automatically cleaned up now */ /* automatically cleaned up now */
descr_ptr = &descr; descr_ptr = &descr;
ret = lxc_mainloop_add_handler(&descr, fd, freezer_cgroup_events_cb, INT_TO_PTR((int){1})); ret = lxc_mainloop_add_handler(&descr, fd, freezer_cgroup_events_cb, INT_TO_PTR((int){1}));
if (ret < 0) if (ret < 0)
return error_log_errno(errno, "Failed to add cgroup.events fd handler to mainloop"); return log_error_errno(-1, errno, "Failed to add cgroup.events fd handler to mainloop");
} }
path = must_make_path(h->container_full_path, "cgroup.freeze", NULL); path = must_make_path(h->container_full_path, "cgroup.freeze", NULL);
ret = lxc_write_to_file(path, "1", 1, false, 0666); ret = lxc_write_to_file(path, "1", 1, false, 0666);
if (ret < 0) if (ret < 0)
return error_log_errno(errno, "Failed to open cgroup.freeze file"); return log_error_errno(-1, errno, "Failed to open cgroup.freeze file");
if (timeout != 0 && lxc_mainloop(&descr, timeout)) if (timeout != 0 && lxc_mainloop(&descr, timeout))
return error_log_errno(errno, "Failed to wait for container to be frozen"); return log_error_errno(-1, errno, "Failed to wait for container to be frozen");
return 0; return 0;
} }
...@@ -2031,7 +2031,7 @@ static int cg_unified_freeze(struct cgroup_ops *ops, int timeout) ...@@ -2031,7 +2031,7 @@ static int cg_unified_freeze(struct cgroup_ops *ops, int timeout)
__cgfsng_ops static int cgfsng_freeze(struct cgroup_ops *ops, int timeout) __cgfsng_ops static int cgfsng_freeze(struct cgroup_ops *ops, int timeout)
{ {
if (!ops->hierarchies) if (!ops->hierarchies)
return minus_one_set_errno(ENOENT); return ret_set_errno(-1, ENOENT);
if (ops->cgroup_layout != CGROUP_LAYOUT_UNIFIED) if (ops->cgroup_layout != CGROUP_LAYOUT_UNIFIED)
return cg_legacy_freeze(ops); return cg_legacy_freeze(ops);
...@@ -2046,7 +2046,7 @@ static int cg_legacy_unfreeze(struct cgroup_ops *ops) ...@@ -2046,7 +2046,7 @@ static int cg_legacy_unfreeze(struct cgroup_ops *ops)
h = get_hierarchy(ops, "freezer"); h = get_hierarchy(ops, "freezer");
if (!h) if (!h)
return minus_one_set_errno(ENOENT); return ret_set_errno(-1, ENOENT);
path = must_make_path(h->container_full_path, "freezer.state", NULL); path = must_make_path(h->container_full_path, "freezer.state", NULL);
return lxc_write_to_file(path, "THAWED", STRLITERALLEN("THAWED"), false, 0666); return lxc_write_to_file(path, "THAWED", STRLITERALLEN("THAWED"), false, 0666);
...@@ -2063,10 +2063,10 @@ static int cg_unified_unfreeze(struct cgroup_ops *ops, int timeout) ...@@ -2063,10 +2063,10 @@ static int cg_unified_unfreeze(struct cgroup_ops *ops, int timeout)
h = ops->unified; h = ops->unified;
if (!h) if (!h)
return minus_one_set_errno(ENOENT); return ret_set_errno(-1, ENOENT);
if (!h->container_full_path) if (!h->container_full_path)
return minus_one_set_errno(EEXIST); return ret_set_errno(-1, EEXIST);
if (timeout != 0) { if (timeout != 0) {
__do_free char *events_file = NULL; __do_free char *events_file = NULL;
...@@ -2074,27 +2074,27 @@ static int cg_unified_unfreeze(struct cgroup_ops *ops, int timeout) ...@@ -2074,27 +2074,27 @@ static int cg_unified_unfreeze(struct cgroup_ops *ops, int timeout)
events_file = must_make_path(h->container_full_path, "cgroup.events", NULL); events_file = must_make_path(h->container_full_path, "cgroup.events", NULL);
fd = open(events_file, O_RDONLY | O_CLOEXEC); fd = open(events_file, O_RDONLY | O_CLOEXEC);
if (fd < 0) if (fd < 0)
return error_log_errno(errno, "Failed to open cgroup.events file"); return log_error_errno(-1, errno, "Failed to open cgroup.events file");
ret = lxc_mainloop_open(&descr); ret = lxc_mainloop_open(&descr);
if (ret) if (ret)
return error_log_errno(errno, "Failed to create epoll instance to wait for container unfreeze"); return log_error_errno(-1, errno, "Failed to create epoll instance to wait for container unfreeze");
/* automatically cleaned up now */ /* automatically cleaned up now */
descr_ptr = &descr; descr_ptr = &descr;
ret = lxc_mainloop_add_handler(&descr, fd, freezer_cgroup_events_cb, INT_TO_PTR((int){0})); ret = lxc_mainloop_add_handler(&descr, fd, freezer_cgroup_events_cb, INT_TO_PTR((int){0}));
if (ret < 0) if (ret < 0)
return error_log_errno(errno, "Failed to add cgroup.events fd handler to mainloop"); return log_error_errno(-1, errno, "Failed to add cgroup.events fd handler to mainloop");
} }
path = must_make_path(h->container_full_path, "cgroup.freeze", NULL); path = must_make_path(h->container_full_path, "cgroup.freeze", NULL);
ret = lxc_write_to_file(path, "0", 1, false, 0666); ret = lxc_write_to_file(path, "0", 1, false, 0666);
if (ret < 0) if (ret < 0)
return error_log_errno(errno, "Failed to open cgroup.freeze file"); return log_error_errno(-1, errno, "Failed to open cgroup.freeze file");
if (timeout != 0 && lxc_mainloop(&descr, timeout)) if (timeout != 0 && lxc_mainloop(&descr, timeout))
return error_log_errno(errno, "Failed to wait for container to be unfrozen"); return log_error_errno(-1, errno, "Failed to wait for container to be unfrozen");
return 0; return 0;
} }
...@@ -2102,7 +2102,7 @@ static int cg_unified_unfreeze(struct cgroup_ops *ops, int timeout) ...@@ -2102,7 +2102,7 @@ static int cg_unified_unfreeze(struct cgroup_ops *ops, int timeout)
__cgfsng_ops static int cgfsng_unfreeze(struct cgroup_ops *ops, int timeout) __cgfsng_ops static int cgfsng_unfreeze(struct cgroup_ops *ops, int timeout)
{ {
if (!ops->hierarchies) if (!ops->hierarchies)
return minus_one_set_errno(ENOENT); return ret_set_errno(-1, ENOENT);
if (ops->cgroup_layout != CGROUP_LAYOUT_UNIFIED) if (ops->cgroup_layout != CGROUP_LAYOUT_UNIFIED)
return cg_legacy_unfreeze(ops); return cg_legacy_unfreeze(ops);
...@@ -2148,7 +2148,7 @@ static int cgroup_attach_leaf(int unified_fd, int64_t pid) ...@@ -2148,7 +2148,7 @@ static int cgroup_attach_leaf(int unified_fd, int64_t pid)
return 0; return 0;
/* this is a non-leaf node */ /* this is a non-leaf node */
if (errno != EBUSY) if (errno != EBUSY)
return error_log_errno(errno, "Failed to attach to unified cgroup"); return log_error_errno(-1, errno, "Failed to attach to unified cgroup");
do { do {
char *slash; char *slash;
...@@ -2167,7 +2167,7 @@ static int cgroup_attach_leaf(int unified_fd, int64_t pid) ...@@ -2167,7 +2167,7 @@ static int cgroup_attach_leaf(int unified_fd, int64_t pid)
*slash = '\0'; *slash = '\0';
ret = mkdirat(unified_fd, attach_cgroup, 0755); ret = mkdirat(unified_fd, attach_cgroup, 0755);
if (ret < 0 && errno != EEXIST) if (ret < 0 && errno != EEXIST)
return error_log_errno(errno, "Failed to create cgroup %s", attach_cgroup); return log_error_errno(-1, errno, "Failed to create cgroup %s", attach_cgroup);
*slash = '/'; *slash = '/';
ret = lxc_writeat(unified_fd, attach_cgroup, pidstr, pidstr_len); ret = lxc_writeat(unified_fd, attach_cgroup, pidstr, pidstr_len);
...@@ -2176,7 +2176,7 @@ static int cgroup_attach_leaf(int unified_fd, int64_t pid) ...@@ -2176,7 +2176,7 @@ static int cgroup_attach_leaf(int unified_fd, int64_t pid)
/* this is a non-leaf node */ /* this is a non-leaf node */
if (errno != EBUSY) if (errno != EBUSY)
return error_log_errno(errno, "Failed to attach to unified cgroup"); return log_error_errno(-1, errno, "Failed to attach to unified cgroup");
idx++; idx++;
} while (idx < 1000); } while (idx < 1000);
...@@ -2435,7 +2435,7 @@ __cgfsng_ops static int cgfsng_set(struct cgroup_ops *ops, ...@@ -2435,7 +2435,7 @@ __cgfsng_ops static int cgfsng_set(struct cgroup_ops *ops,
ret = device_cgroup_rule_parse(&device, key, value); ret = device_cgroup_rule_parse(&device, key, value);
if (ret < 0) if (ret < 0)
return error_log_errno(EINVAL, "Failed to parse device string %s=%s", return log_error_errno(-1, EINVAL, "Failed to parse device string %s=%s",
key, value); key, value);
ret = lxc_cmd_add_bpf_device_cgroup(name, lxcpath, &device); ret = lxc_cmd_add_bpf_device_cgroup(name, lxcpath, &device);
...@@ -2644,7 +2644,7 @@ static int bpf_device_cgroup_prepare(struct cgroup_ops *ops, ...@@ -2644,7 +2644,7 @@ static int bpf_device_cgroup_prepare(struct cgroup_ops *ops,
ret = device_cgroup_rule_parse(&device_item, key, val); ret = device_cgroup_rule_parse(&device_item, key, val);
if (ret < 0) if (ret < 0)
return error_log_errno(EINVAL, return log_error_errno(-1, EINVAL,
"Failed to parse device string %s=%s", "Failed to parse device string %s=%s",
key, val); key, val);
...@@ -3072,14 +3072,14 @@ static int cg_unified_init(struct cgroup_ops *ops, bool relative, ...@@ -3072,14 +3072,14 @@ static int cg_unified_init(struct cgroup_ops *ops, bool relative,
ret = unified_cgroup_hierarchy(); ret = unified_cgroup_hierarchy();
if (ret == -ENOMEDIUM) if (ret == -ENOMEDIUM)
return -ENOMEDIUM; return ret_errno(ENOMEDIUM);
if (ret != CGROUP2_SUPER_MAGIC) if (ret != CGROUP2_SUPER_MAGIC)
return 0; return 0;
base_cgroup = cg_unified_get_current_cgroup(relative); base_cgroup = cg_unified_get_current_cgroup(relative);
if (!base_cgroup) if (!base_cgroup)
return -EINVAL; return ret_errno(EINVAL);
if (!relative) if (!relative)
prune_init_scope(base_cgroup); prune_init_scope(base_cgroup);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment