]> git.hungrycats.org Git - linux/commitdiff
[PATCH] Add prctl to modify current->comm
authorAndi Kleen <ak@suse.de>
Tue, 14 Sep 2004 00:48:01 +0000 (17:48 -0700)
committerLinus Torvalds <torvalds@ppc970.osdl.org>
Tue, 14 Sep 2004 00:48:01 +0000 (17:48 -0700)
This patch adds a prctl to modify current->comm as shown in /proc.  This
feature was requested by KDE developers.  In KDE most programs are started by
forking from a kdeinit program that already has the libraries loaded and some
other state.

Problem is to give these forked programs the proper name.  It already writes
the command line in the environment (as seen in ps), but top uses a different
field in /proc/pid/status that reports current->comm.  And that was always
"kdeinit" instead of the real command name.  So you ended up with lots of
kdeinits in your top listing, which was not very useful.

This patch adds a new prctl PR_SET_NAME to allow a program to change its comm
field.

I considered the potential security issues of a program obscuring itself with
this interface, but I don't think it matters much because a program can
already obscure itself when the admin uses ps instead of top.  In case of a
KDE desktop calling everything kdeinit is much more obfuscation than the
alternative.

Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
include/linux/prctl.h
kernel/sys.c

index c8b69670e2d6a9b2c2267a2959e246699eb4de76..54333c98e53237a3b4fc618e8950fd5d16866336 100644 (file)
@@ -50,4 +50,6 @@
                                                    process timing */
 
 
+#define PR_SET_NAME    15              /* Set process name */
+
 #endif /* _LINUX_PRCTL_H */
index 8e9a88dadab1fc5ac9c3bf0c2ca49048d85819fb..59def31398749675da116154370bdf6c767936d1 100644 (file)
@@ -1729,6 +1729,17 @@ asmlinkage long sys_prctl(int option, unsigned long arg2, unsigned long arg3,
                        }
                        current->keep_capabilities = arg2;
                        break;
+               case PR_SET_NAME: {
+                       struct task_struct *me = current;
+                       unsigned char ncomm[sizeof(me->comm)];
+
+                       ncomm[sizeof(me->comm)-1] = 0;
+                       if (strncpy_from_user(ncomm, (char *)arg2,
+                                               sizeof(me->comm)-1) < 0)
+                               return -EFAULT;
+                       set_task_comm(me, ncomm);
+                       return 0;
+               }
                default:
                        error = -EINVAL;
                        break;