mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [RFC] cgroup simplify space stripping
@ 2007-10-24 17:36 Paul Jackson
  2007-10-26  1:14 ` Paul Menage
  2007-10-27  5:50 ` Jason Uhlenkott
  0 siblings, 2 replies; 4+ messages in thread
From: Paul Jackson @ 2007-10-24 17:36 UTC (permalink / raw)
  To: Paul Menage; +Cc: Paul Jackson, Adrian Bunk, linux-kernel

From: Paul Jackson <pj@sgi.com>

Simplify the space stripping code in cgroup file write.

Signed-off-by: Paul Jackson <pj@sgi.com>

---

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(-)

--- 2.6.23-mm1.orig/kernel/cgroup.c	2007-10-24 10:03:11.847801501 -0700
+++ 2.6.23-mm1/kernel/cgroup.c	2007-10-24 10:29:08.355032464 -0700
@@ -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 <pj@sgi.com> 1.650.933.1373

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [RFC] cgroup simplify space stripping
  2007-10-24 17:36 [RFC] cgroup simplify space stripping Paul Jackson
@ 2007-10-26  1:14 ` Paul Menage
  2007-10-27  5:50 ` Jason Uhlenkott
  1 sibling, 0 replies; 4+ messages in thread
From: Paul Menage @ 2007-10-26  1:14 UTC (permalink / raw)
  To: Paul Jackson; +Cc: Adrian Bunk, linux-kernel, Andrew Morton

On 10/24/07, Paul Jackson <pj@sgi.com> wrote:
> From: Paul Jackson <pj@sgi.com>
>
> Simplify the space stripping code in cgroup file write.
>
> Signed-off-by: Paul Jackson <pj@sgi.com>

Acked-by: Paul Menage <menage@google.com>

>
> ---
>
> 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(-)
>
> --- 2.6.23-mm1.orig/kernel/cgroup.c     2007-10-24 10:03:11.847801501 -0700
> +++ 2.6.23-mm1/kernel/cgroup.c  2007-10-24 10:29:08.355032464 -0700
> @@ -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 <pj@sgi.com> 1.650.933.1373
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [RFC] cgroup simplify space stripping
  2007-10-24 17:36 [RFC] cgroup simplify space stripping Paul Jackson
  2007-10-26  1:14 ` Paul Menage
@ 2007-10-27  5:50 ` Jason Uhlenkott
  2007-10-27  6:00   ` Jason Uhlenkott
  1 sibling, 1 reply; 4+ messages in thread
From: Jason Uhlenkott @ 2007-10-27  5:50 UTC (permalink / raw)
  To: Paul Jackson; +Cc: Paul Menage, Adrian Bunk, linux-kernel

On Wed, Oct 24, 2007 at 10:36:21 -0700, Paul Jackson wrote:
> From: Paul Jackson <pj@sgi.com>
> 
> Simplify the space stripping code in cgroup file write.
> 
> Signed-off-by: Paul Jackson <pj@sgi.com>
> 
> ---
> 
> 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(-)
> 
> --- 2.6.23-mm1.orig/kernel/cgroup.c	2007-10-24 10:03:11.847801501 -0700
> +++ 2.6.23-mm1/kernel/cgroup.c	2007-10-24 10:29:08.355032464 -0700
> @@ -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);

Could be BUILD_BUG_ON, even.


> +		strcpy(cgrp->root->release_agent_path, buffer);
>  		break;
> -	}
>  	default:
>  		retval = -EINVAL;
>  		goto out2;

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [RFC] cgroup simplify space stripping
  2007-10-27  5:50 ` Jason Uhlenkott
@ 2007-10-27  6:00   ` Jason Uhlenkott
  0 siblings, 0 replies; 4+ messages in thread
From: Jason Uhlenkott @ 2007-10-27  6:00 UTC (permalink / raw)
  To: Paul Jackson; +Cc: Paul Menage, Adrian Bunk, linux-kernel

On Fri, Oct 26, 2007 at 22:50:45 -0700, Jason Uhlenkott wrote:
> Could be BUILD_BUG_ON, even.

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2007-10-27  6:00 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-10-24 17:36 [RFC] cgroup simplify space stripping Paul Jackson
2007-10-26  1:14 ` Paul Menage
2007-10-27  5:50 ` Jason Uhlenkott
2007-10-27  6:00   ` Jason Uhlenkott

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome