Skip to contentSkip to conversation

cgroup simplify space stripping

RFC In review Paul Jackson 3 participants 4 messages Oct 24, 2007 – Oct 27, 2007

lore
Share & tools
lore
#0 lore raw

RFC 1/1 cgroup simplify space stripping

From: Paul Jackson <[email protected]>

Simplify the space stripping code in cgroup file write.

---

This patch applies after both:
Adrian Bunk's: [2.6 patch] kernel/cgroup.c: remove dead code pj's: [PATCH] cgroup brace coding style fix

 kernel/cgroup.c |   15 +++------------
 1 file changed, 3 insertions(+), 12 deletions(-)
kernel/cgroup.c +3 -12
@@ -1327,6 +1327,7 @@ static ssize_t cgroup_common_file_write(
 		goto out1;
 	}
 	buffer[nbytes] = 0;	/* nul-terminate */
+	strstrip(buffer);	/* strip -just- trailing whitespace */
 
 	mutex_lock(&cgroup_mutex);
 
@@ -1347,19 +1348,9 @@ static ssize_t cgroup_common_file_write(
 			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;
+		BUG_ON(sizeof(cgrp->root->release_agent_path) < PATH_MAX);
+		strcpy(cgrp->root->release_agent_path, buffer);
 		break;
-	}
 	default:
 		retval = -EINVAL;
 		goto out2;
Signature · 3 lines
                          I won't rest till it's the best ...
                          Programmer, Linux Scalability
                          Paul Jackson <[email protected]> 1.650.933.1373
Acked-by on v1 1/1
#1 lore raw
Quoted 5 lines · Paul Jackson

From: Paul Jackson <[email protected]>

Simplify the space stripping code in cgroup file write.

Quoted 48 lines

---

This patch applies after both:
Adrian Bunk's: [2.6 patch] kernel/cgroup.c: remove dead code pj's: [PATCH] cgroup brace coding style fix

 kernel/cgroup.c |   15 +++------------
 1 file changed, 3 insertions(+), 12 deletions(-)
kernel/cgroup.c 2007-10-24 10:29:08.355032464 -0700 renamed from kernel/cgroup.c 2007-10-24 10:03:11.847801501 -0700 +3 -13
@@ -1327,6 +1327,7 @@ static ssize_t cgroup_common_file_write(
                goto out1;
        }
        buffer[nbytes] = 0;     /* nul-terminate */
+       strstrip(buffer);       /* strip -just- trailing whitespace */
 
        mutex_lock(&cgroup_mutex);
 
@@ -1347,19 +1348,9 @@ static ssize_t cgroup_common_file_write(
                        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;
+               BUG_ON(sizeof(cgrp->root->release_agent_path) < PATH_MAX);
+               strcpy(cgrp->root->release_agent_path, buffer);
                break;
-       }
        default:
                retval = -EINVAL;
                goto out2;
 
--
                          I won't rest till it's the best ...
                          Programmer, Linux Scalability
                          Paul Jackson <[email protected]> 1.650.933.1373
#2 lore raw
In reply to Paul Jackson
Quoted 31 lines · Paul Jackson

From: Paul Jackson <[email protected]>

Simplify the space stripping code in cgroup file write.

---

This patch applies after both:
Adrian Bunk's: [2.6 patch] kernel/cgroup.c: remove dead code pj's: [PATCH] cgroup brace coding style fix

 kernel/cgroup.c |   15 +++------------
 1 file changed, 3 insertions(+), 12 deletions(-)
kernel/cgroup.c +1 -2
@@ -1327,6 +1327,7 @@ static ssize_t cgroup_common_file_write(
 		goto out1;
 	}
 	buffer[nbytes] = 0;	/* nul-terminate */
+	strstrip(buffer);	/* strip -just- trailing whitespace */
 
 	mutex_lock(&cgroup_mutex);
 
@@ -1347,19 +1348,9 @@ static ssize_t cgroup_common_file_write(
 			clear_bit(CGRP_NOTIFY_ON_RELEASE, &cgrp->flags);
 		break;
 	case FILE_RELEASE_AGENT:
-	{
-		struct cgroupfs_root *root = cgrp->root;

kernel/cgroup.c static ssize_t cgroup_common_file_write( · line 1351

Quoted 10 lines
kernel/cgroup.c +1 -9
-		/* 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;
+		BUG_ON(sizeof(cgrp->root->release_agent_path) < PATH_MAX);

Could be BUILD_BUG_ON, even.

Quoted 6 lines
kernel/cgroup.c +1 -1
+		strcpy(cgrp->root->release_agent_path, buffer);
 		break;
-	}
 	default:
 		retval = -EINVAL;
 		goto out2;
#3 lore raw
Quoted 1 line · Jason Uhlenkott

Could be BUILD_BUG_ON, even.

Oh, never mind -- I see you've reached that conclusion in the other thread.