{
int ret = 0;
const char *filename = fts->fts_path;
- dbg("seeing file %s\n", filename);
+ cgroup_dbg("seeing file %s\n", filename);
switch (ent->fts_info) {
case FTS_ERR:
errno = ent->fts_errno;
static int cg_chown_recursive(char **path, uid_t owner, gid_t group)
{
int ret = 0;
- dbg("path is %s\n", *path);
+ cgroup_dbg("path is %s\n", *path);
FTS *fts = fts_open(path, FTS_PHYSICAL | FTS_NOCHDIR |
FTS_NOSTAT, NULL);
while (1) {
FTSENT *ent;
ent = fts_read(fts);
if (!ent) {
- dbg("fts_read failed\n");
+ cgroup_dbg("fts_read failed\n");
break;
}
ret = cg_chown_file(fts, ent, owner, group);
/* Make sure our rule is not NULL, first. */
if (!r) {
- dbg("Warning: Attempted to free NULL rule.\n");
+ cgroup_dbg("Warning: Attempted to free NULL rule.\n");
return;
}
/* Make sure we're not freeing NULL memory! */
if (!(rl->head)) {
- dbg("Warning: Attempted to free NULL list.\n");
+ cgroup_dbg("Warning: Attempted to free NULL list.\n");
return;
}
pthread_rwlock_wrlock(&rl_lock);
fp = fopen(CGRULES_CONF_FILE, "r");
if (!fp) {
- dbg("Failed to open configuration file %s with"
+ cgroup_dbg("Failed to open configuration file %s with"
" error: %s\n", CGRULES_CONF_FILE,
strerror(errno));
last_errno = errno;
buff = calloc(CGROUP_RULE_MAXLINE, sizeof(char));
if (!buff) {
- dbg("Out of memory? Error: %s\n", strerror(errno));
+ cgroup_dbg("Out of memory? Error: %s\n", strerror(errno));
last_errno = errno;
ret = ECGOTHER;
goto close_unlock;
cgroup_free_rule_list(lst);
/* Now, parse the configuration file one line at a time. */
- dbg("Parsing configuration file.\n");
+ cgroup_dbg("Parsing configuration file.\n");
while ((itr = fgets(buff, CGROUP_RULE_MAXLINE, fp)) != NULL) {
linenum++;
* of it (begins with %), then we should skip this rule too.
*/
if (skipped && *itr == '%') {
- dbg("Warning: Skipped child of invalid rule,"
+ cgroup_dbg("Warning: Skipped child of invalid rule,"
" line %d.\n", linenum);
memset(buff, '\0', CGROUP_RULE_MAXLINE);
continue;
memset(destination, '\0', FILENAME_MAX);
i = sscanf(itr, "%s%s%s", user, controllers, destination);
if (i != 3) {
- dbg("Failed to parse configuration file on"
+ cgroup_dbg("Failed to parse configuration file on"
" line %d.\n", linenum);
goto parsefail;
}
*/
if ((!cache) && matched && (strncmp(user, "%", 1) != 0)) {
/* If we make it here, we finished (non-cache). */
- dbg("Parsing of configuration file complete.\n\n");
+ cgroup_dbg("Parsing of configuration file"
+ " complete.\n\n");
ret = -1;
goto cleanup;
}
uid = CGRULE_INVALID;
gid = grp->gr_gid;
} else {
- dbg("Warning: Entry for %s not"
+ cgroup_dbg("Warning: Entry for %s not"
"found. Skipping rule on line"
" %d.\n", itr, linenum);
memset(buff, '\0', CGROUP_RULE_MAXLINE);
uid = pwd->pw_uid;
gid = CGRULE_INVALID;
} else {
- dbg("Warning: Entry for %s not"
+ cgroup_dbg("Warning: Entry for %s not"
"found. Skipping rule on line"
" %d.\n", user, linenum);
memset(buff, '\0', CGROUP_RULE_MAXLINE);
*/
newrule = calloc(1, sizeof(struct cgroup_rule));
if (!newrule) {
- dbg("Out of memory? Error: %s\n", strerror(errno));
+ cgroup_dbg("Out of memory? Error: %s\n",
+ strerror(errno));
last_errno = errno;
ret = ECGOTHER;
goto cleanup;
/* Parse the controller list, and add that to newrule too. */
stok_buff = strtok(controllers, ",");
if (!stok_buff) {
- dbg("Failed to parse controllers on line"
+ cgroup_dbg("Failed to parse controllers on line"
" %d\n", linenum);
goto destroyrule;
}
i = 0;
do {
if (i >= MAX_MNT_ELEMENTS) {
- dbg("Too many controllers listed"
+ cgroup_dbg("Too many controllers listed"
" on line %d\n", linenum);
goto destroyrule;
}
newrule->controllers[i] = strndup(stok_buff,
strlen(stok_buff) + 1);
if (!(newrule->controllers[i])) {
- dbg("Out of memory? Error was: %s\n",
+ cgroup_dbg("Out of memory? Error was: %s\n",
strerror(errno));
goto destroyrule;
}
lst->tail = newrule;
}
- dbg("Added rule %s (UID: %d, GID: %d) -> %s for controllers:",
- lst->tail->name, lst->tail->uid, lst->tail->gid,
- lst->tail->destination);
+ cgroup_dbg("Added rule %s (UID: %d, GID: %d) -> %s for"
+ " controllers:", lst->tail->name, lst->tail->uid,
+ lst->tail->gid, lst->tail->destination);
for (i = 0; lst->tail->controllers[i]; i++) {
- dbg(" %s", lst->tail->controllers[i]);
+ cgroup_dbg(" %s", lst->tail->controllers[i]);
}
- dbg("\n");
+ cgroup_dbg("\n");
/* Finally, clear the buffer. */
memset(buff, '\0', CGROUP_RULE_MAXLINE);
}
/* If we make it here, there were no errors. */
- dbg("Parsing of configuration file complete.\n\n");
+ cgroup_dbg("Parsing of configuration file complete.\n\n");
ret = (matched && !cache) ? -1 : 0;
goto cleanup;
mntopt = strtok_r(mntopt, ",", &strtok_buffer);
if (strcmp(mntopt, controllers[i]) == 0) {
- dbg("matched %s:%s\n", mntopt,
+ cgroup_dbg("matched %s:%s\n", mntopt,
controllers[i]);
strcpy(cg_mount_table[found_mnt].name,
controllers[i]);
strcpy(cg_mount_table[found_mnt].path,
ent->mnt_dir);
- dbg("Found cgroup option %s, "
+ cgroup_dbg("Found cgroup option %s, "
" count %d\n",
ent->mnt_opts, found_mnt);
found_mnt++;
int i, ret = 0;
if (!cgroup_initialized) {
- dbg ("libcgroup is not initialized\n");
+ cgroup_dbg("libcgroup is not initialized\n");
return ECGROUPNOTINITIALIZED;
}
if(!cgroup)
}
ret = fprintf(tasks, "%d", tid);
if (ret < 0) {
- dbg("Error writing tid %d to %s:%s\n",
+ cgroup_dbg("Error writing tid %d to %s:%s\n",
tid, path, strerror(errno));
fclose(tasks);
last_errno = errno;
ret = fflush(tasks);
if (ret) {
last_errno = errno;
- dbg("Error writing tid %d to %s:%s\n",
+ cgroup_dbg("Error writing tid %d to %s:%s\n",
tid, path, strerror(errno));
fclose(tasks);
return ECGOTHER;
} else {
for (i = 0; i < cgroup->index; i++) {
if (!cgroup_test_subsys_mounted(cgroup->controller[i]->name)) {
- dbg("subsystem %s is not mounted\n",
+ cgroup_dbg("subsystem %s is not mounted\n",
cgroup->controller[i]->name);
return ECGROUPSUBSYSNOTMOUNTED;
}
tasks = fopen(path, "w");
if (!tasks) {
- dbg("fopen failed for %s:%s", path,
+ cgroup_dbg("fopen failed for %s:%s", path,
strerror(errno));
switch (errno) {
ret = fprintf(tasks, "%d", tid);
if (ret < 0) {
last_errno = errno;
- dbg("Error writing tid %d to %s:%s\n",
+ cgroup_dbg("Error writing tid %d to %s:%s\n",
tid, path, strerror(errno));
fclose(tasks);
return ECGOTHER;
ret = fflush(tasks);
if (ret) {
last_errno = errno;
- dbg("Error writing tid %d to %s:%s\n",
+ cgroup_dbg("Error writing tid %d to %s:%s\n",
tid, path, strerror(errno));
fclose(tasks);
return ECGOTHER;
i = j;
ret = chdir(wd);
if (ret) {
- dbg("could not chdir to child directory (%s)\n", wd);
+ cgroup_dbg("could not chdir to child directory (%s)\n",
+ wd);
break;
}
free(wd);
if (ret) {
last_errno = errno;
ret = ECGOTHER;
- dbg("could not go back to old directory (%s)\n", cwd);
+ cgroup_dbg("could not go back to old directory (%s)\n", cwd);
}
done:
for (i = 0; i < cgroup->index; i++) {
if (!cgroup_test_subsys_mounted(cgroup->controller[i]->name)) {
- dbg("subsystem %s is not mounted\n",
+ cgroup_dbg("subsystem %s is not mounted\n",
cgroup->controller[i]->name);
return ECGROUPSUBSYSNOTMOUNTED;
}
}
if (!ignore_ownership) {
- dbg("Changing ownership of %s\n", fts_path[0]);
+ cgroup_dbg("Changing ownership of %s\n", fts_path[0]);
error = cg_chown_recursive(fts_path,
cgroup->control_uid, cgroup->control_gid);
}
for (j = 0; j < cgroup->controller[k]->index; j++) {
ret = snprintf(path, FILENAME_MAX, "%s%s", base,
cgroup->controller[k]->values[j]->name);
- dbg("setting %s to %s, error %d\n", path,
+ cgroup_dbg("setting %s to %s, error %d\n", path,
cgroup->controller[k]->values[j]->name, ret);
if (ret < 0 || ret >= FILENAME_MAX) {
last_errno = errno;
}
pthread_rwlock_unlock(&cg_mount_table_lock);
- dbg("path is %s\n", child);
+ cgroup_dbg("path is %s\n", child);
dir = dirname(child);
- dbg("directory name is %s\n", dir);
+ cgroup_dbg("directory name is %s\n", dir);
if (asprintf(&parent, "%s/..", dir) < 0)
return NULL;
- dbg("parent's name is %s\n", parent);
+ cgroup_dbg("parent's name is %s\n", parent);
if (stat(dir, &stat_child) < 0)
goto free_parent;
* Is the specified "name" a mount point?
*/
if (stat_parent.st_dev != stat_child.st_dev) {
- dbg("parent is a mount point\n");
+ cgroup_dbg("parent is a mount point\n");
strcpy(parent, ".");
} else {
dir = strdup(name);
if (!parent)
return ret;
- dbg("parent is %s\n", parent);
+ cgroup_dbg("parent is %s\n", parent);
parent_cgroup = cgroup_new_cgroup(parent);
if (!parent_cgroup)
goto err_nomem;
if (cgroup_get_cgroup(parent_cgroup))
goto err_parent;
- dbg("got parent group for %s\n", parent_cgroup->name);
+ cgroup_dbg("got parent group for %s\n", parent_cgroup->name);
ret = cgroup_copy_cgroup(cgroup, parent_cgroup);
if (ret)
goto err_parent;
- dbg("copied parent group %s to %s\n", parent_cgroup->name,
+ cgroup_dbg("copied parent group %s to %s\n", parent_cgroup->name,
cgroup->name);
ret = cgroup_create_cgroup(cgroup, ignore_ownership);
struct cgroup_controller *cptr = NULL;
/* Fill in cgroup details. */
- dbg("Will move pid %d to cgroup '%s'\n", pid, dest);
+ cgroup_dbg("Will move pid %d to cgroup '%s'\n", pid, dest);
strcpy(cgroup->name, dest);
pthread_rwlock_rdlock(&cg_mount_table_lock);
for (i = 0; i < CG_CONTROLLER_MAX &&
cg_mount_table[i].name[0] != '\0'; i++) {
- dbg("Adding controller %s\n",
+ cgroup_dbg("Adding controller %s\n",
cg_mount_table[i].name);
cptr = cgroup_add_controller(cgroup,
cg_mount_table[i].name);
if (!cptr) {
- dbg("Adding controller '%s' failed\n",
+ cgroup_dbg("Adding controller '%s'"
+ " failed\n",
cg_mount_table[i].name);
pthread_rwlock_unlock(&cg_mount_table_lock);
return ECGROUPNOTALLOWED;
}
/* it is individual controller names and not "*" */
- dbg("Adding controller %s\n", controller);
+ cgroup_dbg("Adding controller %s\n", controller);
cptr = cgroup_add_controller(cgroup, controller);
if (!cptr) {
- dbg("Adding controller '%s' failed\n", controller);
+ cgroup_dbg("Adding controller '%s' failed\n",
+ controller);
return ECGROUPNOTALLOWED;
}
}
/* We need to check this before doing anything else! */
if (!cgroup_initialized) {
- dbg("libcgroup is not initialized\n");
+ cgroup_dbg("libcgroup is not initialized\n");
ret = ECGROUPNOTINITIALIZED;
goto finished;
}
* find the first match in the cached list (rl).
*/
if (!(flags & CGFLAG_USECACHE)) {
- dbg("Not using cached rules for PID %d.\n", pid);
+ cgroup_dbg("Not using cached rules for PID %d.\n", pid);
ret = cgroup_parse_rules(false, uid, gid);
/* The configuration file has an error! We must exit now. */
if (ret != -1 && ret != 0) {
- dbg("Failed to parse the configuration rules.\n");
+ cgroup_dbg("Failed to parse the configuration"
+ " rules.\n");
goto finished;
}
/* We did not find a matching rule, so we're done. */
if (ret == 0) {
- dbg("No rule found to match PID: %d, UID: %d, "
+ cgroup_dbg("No rule found to match PID: %d, UID: %d, "
"GID: %d\n", pid, uid, gid);
goto finished;
}
/* Find the first matching rule in the cached list. */
tmp = cgroup_find_matching_rule_uid_gid(uid, gid);
if (!tmp) {
- dbg("No rule found to match PID: %d, UID: %d, "
+ cgroup_dbg("No rule found to match PID: %d, UID: %d, "
"GID: %d\n", pid, uid, gid);
ret = 0;
goto finished;
}
}
- dbg("Found matching rule %s for PID: %d, UID: %d, GID: %d\n",
+ cgroup_dbg("Found matching rule %s for PID: %d, UID: %d, GID: %d\n",
tmp->name, pid, uid, gid);
/* If we are here, then we found a matching rule, so execute it. */
do {
- dbg("Executing rule %s for PID %d... ", tmp->name, pid);
+ cgroup_dbg("Executing rule %s for PID %d... ", tmp->name, pid);
ret = cgroup_change_cgroup_path(tmp->destination,
pid, tmp->controllers);
if (ret) {
- dbg("FAILED! (Error Code: %d)\n", ret);
+ cgroup_dbg("FAILED! (Error Code: %d)\n", ret);
goto finished;
}
- dbg("OK!\n");
+ cgroup_dbg("OK!\n");
/* Now, check for multi-line rules. As long as the "next"
* rule starts with '%', it's actually part of the rule that
struct cgroup cgroup;
if (!cgroup_initialized) {
- dbg("libcgroup is not initialized\n");
+ cgroup_dbg("libcgroup is not initialized\n");
return ECGROUPNOTINITIALIZED;
}
memset(&cgroup, 0, sizeof(struct cgroup));
/* Add task to cgroup */
ret = cgroup_attach_task_pid(&cgroup, pid);
if (ret) {
- dbg("cgroup_attach_task_pid failed:%d\n", ret);
+ cgroup_dbg("cgroup_attach_task_pid failed:%d\n", ret);
return ret;
}
return 0;
/* Return codes */
int ret = 0;
- dbg("Reloading cached rules from %s.\n", CGRULES_CONF_FILE);
+ cgroup_dbg("Reloading cached rules from %s.\n", CGRULES_CONF_FILE);
if ((ret = cgroup_parse_rules(true, CGRULE_INVALID, CGRULE_INVALID))) {
- dbg("Error parsing configuration file \"%s\": %d.\n",
+ cgroup_dbg("Error parsing configuration file \"%s\": %d.\n",
CGRULES_CONF_FILE, ret);
ret = ECGROUPPARSEFAIL;
goto finished;
/* Attempt to read the configuration file and cache the rules. */
ret = cgroup_parse_rules(true, CGRULE_INVALID, CGRULE_INVALID);
if (ret) {
- dbg("Could not initialize rule cache, error was: %d\n", ret);
+ cgroup_dbg("Could not initialize rule cache, error was: %d\n",
+ ret);
cgroup_rules_loaded = false;
} else {
cgroup_rules_loaded = true;
return ECGOTHER;
if (!cgroup_initialized) {
- dbg("libcgroup is not initialized\n");
+ cgroup_dbg("libcgroup is not initialized\n");
return ECGROUPNOTINITIALIZED;
}
ret = asprintf(&path, "/proc/%d/cgroup", pid);
if (ret <= 0) {
- dbg("cannot allocate memory (/proc/pid/cgroup) ret %d\n", ret);
+ cgroup_dbg("cannot allocate memory (/proc/pid/cgroup) ret %d\n",
+ ret);
return ret;
}
* disappear :)
*/
if (ret != 3 || ret == EOF) {
- dbg("read failed for pid_cgroup_fd ret %d\n", ret);
+ cgroup_dbg("read failed for pid_cgroup_fd ret %d\n",
+ ret);
last_errno = errno;
ret = ECGOTHER;
goto done;