This function returns a negative value on error.
*/
static int __pakfire_cgroup_open(struct pakfire_cgroup* cgroup) {
- int fd = -1;
+ int fd = -EBADF;
int r;
// Open file descriptor of the cgroup root
int rootfd = pakfire_cgroup_open_root(cgroup);
if (rootfd < 0)
- return -1;
+ return rootfd;
// Return the rootfd for the root group
if (pakfire_cgroup_is_root(cgroup))
ssize_t bytes_read = -1;
// Check if this cgroup has been destroyed already
- if (!cgroup->fd) {
+ if (cgroup->fd < 0) {
CTX_ERROR(cgroup->ctx, "Trying to read from destroyed cgroup\n");
return -1;
}
int r = 0;
// Check if this cgroup has been destroyed already
- if (!cgroup->fd) {
+ if (cgroup->fd < 0) {
CTX_ERROR(cgroup->ctx, "Trying to write to destroyed cgroup\n");
errno = EPERM;
return 1;
// Initialize reference counter
c->nrefs = 1;
+ // Initialize file descriptors
+ c->fd = c->devicesfd = -EBADF;
+
// Find the root
r = pakfire_cgroup_set_root(c);
if (r)
return r;
// Close the file descriptor
- if (cgroup->fd > 0) {
+ if (cgroup->fd >= 0) {
close(cgroup->fd);
- cgroup->fd = 0;
+ cgroup->fd = -EBADF;
}
// Open the root directory