Skip to content

Commit

Permalink
cgroup simplify space stripping
Browse files Browse the repository at this point in the history
Simplify the space stripping code in cgroup file write.

[akpm@linux-foundation.org: s/BUG_ON/BUILD_BUG_ON/]
Signed-off-by: Paul Jackson <pj@sgi.com>
Acked-by: Paul Menage <menage@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
  • Loading branch information
Paul Jackson authored and Linus Torvalds committed Feb 7, 2008
1 parent e18f631 commit 622d42c
Showing 1 changed file with 3 additions and 14 deletions.
17 changes: 3 additions & 14 deletions kernel/cgroup.c
Original file line number Diff line number Diff line change
Expand Up @@ -1326,6 +1326,7 @@ static ssize_t cgroup_common_file_write(struct cgroup *cgrp,
goto out1;
}
buffer[nbytes] = 0; /* nul-terminate */
strstrip(buffer); /* strip -just- trailing whitespace */

mutex_lock(&cgroup_mutex);

Expand All @@ -1346,21 +1347,9 @@ static ssize_t cgroup_common_file_write(struct cgroup *cgrp,
clear_bit(CGRP_NOTIFY_ON_RELEASE, &cgrp->flags);
break;
case FILE_RELEASE_AGENT:
{
struct cgroupfs_root *root = cgrp->root;
/* Strip trailing newline */
if (nbytes && (buffer[nbytes-1] == '\n'))
buffer[nbytes-1] = 0;

/* We never write anything other than '\0'
* into the last char of release_agent_path,
* so it always remains a NUL-terminated
* string */
strncpy(root->release_agent_path, buffer, nbytes);
root->release_agent_path[nbytes] = 0;

BUILD_BUG_ON(sizeof(cgrp->root->release_agent_path) < PATH_MAX);
strcpy(cgrp->root->release_agent_path, buffer);
break;
}
default:
retval = -EINVAL;
goto out2;
Expand Down

0 comments on commit 622d42c

Please sign in to comment.