linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Alexey Dobriyan <adobriyan@gmail.com>
To: linux-kernel@vger.kernel.org
Subject: [RFC] un petite hack: /proc/*/ctl
Date: Tue, 29 Nov 2005 03:28:02 +0300	[thread overview]
Message-ID: <20051129002801.GA9785@mipter.zuzino.mipt.ru> (raw)

echo kill >/proc/$PID/ctl
	send SIGKILL to process

echo term >/proc/$PID/ctl
	send SIGTERM to process

--- a/fs/proc/base.c
+++ b/fs/proc/base.c
@@ -71,6 +71,7 @@
 #include <linux/cpuset.h>
 #include <linux/audit.h>
 #include <linux/poll.h>
+#include <linux/syscalls.h>
 #include "internal.h"
 
 /*
@@ -125,6 +126,7 @@ enum pid_directory_inos {
 #endif
 	PROC_TGID_OOM_SCORE,
 	PROC_TGID_OOM_ADJUST,
+	PROC_TGID_CTL,
 	PROC_TID_INO,
 	PROC_TID_STATUS,
 	PROC_TID_MEM,
@@ -165,6 +167,7 @@ enum pid_directory_inos {
 #endif
 	PROC_TID_OOM_SCORE,
 	PROC_TID_OOM_ADJUST,
+	PROC_TID_CTL,
 
 	/* Add new entries before this */
 	PROC_TID_FD_DIR = 0x8000,	/* 0x8000-0xffff */
@@ -220,6 +223,7 @@ static struct pid_entry tgid_base_stuff[
 #ifdef CONFIG_AUDITSYSCALL
 	E(PROC_TGID_LOGINUID, "loginuid", S_IFREG|S_IWUSR|S_IRUGO),
 #endif
+	E(PROC_TGID_CTL,       "ctl",     S_IFREG|S_IWUSR),
 	{0,0,NULL,0}
 };
 static struct pid_entry tid_base_stuff[] = {
@@ -262,6 +266,7 @@ static struct pid_entry tid_base_stuff[]
 #ifdef CONFIG_AUDITSYSCALL
 	E(PROC_TID_LOGINUID, "loginuid", S_IFREG|S_IWUSR|S_IRUGO),
 #endif
+	E(PROC_TID_CTL,        "ctl",     S_IFREG|S_IWUSR),
 	{0,0,NULL,0}
 };
 
@@ -942,6 +947,42 @@ static struct file_operations proc_oom_a
 	.write		= oom_adjust_write,
 };
 
+static ssize_t ctl_write(struct file *file, const char __user *buf,
+			 size_t count, loff_t *ppos)
+{
+	char __buf[5];
+	struct task_struct *task;
+	int sig;
+
+	count = min(count, sizeof(__buf));
+	memset(__buf, 0, sizeof(__buf));
+	if (copy_from_user(__buf, buf, count))
+		return -EFAULT;
+	__buf[sizeof(__buf) - 1] = '\0';
+
+enum {
+	CONFIG_BOFH = 0,
+};
+
+	if (strcmp(__buf, "kill") == 0)
+		sig = SIGKILL;
+	else if (CONFIG_BOFH && strcmp(__buf, "FOAD") == 0)
+		sig = SIGKILL;
+	else if (strcmp(__buf, "term") == 0)
+		sig = SIGTERM;
+	else
+		goto exit;
+
+	task = proc_task(file->f_dentry->d_inode);
+	sys_kill(task->pid, sig);
+exit:
+	return count;
+}
+
+static struct file_operations proc_ctl_operations = {
+	.write		= ctl_write,
+};
+
 static struct inode_operations proc_mem_inode_operations = {
 	.permission	= proc_permission,
 };
@@ -1780,6 +1821,10 @@ static struct dentry *proc_pident_lookup
 		case PROC_TGID_OOM_ADJUST:
 			inode->i_fop = &proc_oom_adjust_operations;
 			break;
+		case PROC_TID_CTL:
+		case PROC_TGID_CTL:
+			inode->i_fop = &proc_ctl_operations;
+			break;
 #ifdef CONFIG_AUDITSYSCALL
 		case PROC_TID_LOGINUID:
 		case PROC_TGID_LOGINUID:


             reply	other threads:[~2005-11-29  0:13 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-11-29  0:28 Alexey Dobriyan [this message]
2005-11-29  0:23 ` [RFC] un petite hack: /proc/*/ctl Chris Boot
2005-11-29  1:33   ` Alexey Dobriyan
2005-11-29  5:48     ` Willy Tarreau
2005-11-29  5:53       ` Willy Tarreau
2005-11-29  7:26         ` Denis Vlasenko
2005-11-30 10:21       ` Folkert van Heusden
2005-11-30 21:23         ` Willy Tarreau
2005-12-09 14:24           ` Jan Engelhardt
2005-12-15  3:58             ` Kyle Moffett

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20051129002801.GA9785@mipter.zuzino.mipt.ru \
    --to=adobriyan@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).