Hello Andrew,
This patch implements the sending of a message about the fork
connector's state (enabled or disabled). Now, when a user space
application asks the fork connector about its state, the fork connector
sends a message through the appropriate netlink interface.
Signed-off-by: [email protected]
---
drivers/connector/cn_fork.c | 37 +++++++++++++++++++++++++++++++++++--
include/linux/cn_fork.h | 20 +++++++++++++++-----
2 files changed, 50 insertions(+), 7 deletions(-)
Index: linux-2.6.12-rc4-mm2/drivers/connector/cn_fork.c
===================================================================
--- linux-2.6.12-rc4-mm2.orig/drivers/connector/cn_fork.c 2005-05-16 12:41:23.000000000 +0200
+++ linux-2.6.12-rc4-mm2/drivers/connector/cn_fork.c 2005-05-16 12:58:18.000000000 +0200
@@ -44,6 +44,16 @@ struct cb_id cb_fork_id = { CN_IDX_FORK,
/* fork_counts is used as the sequence number of the netlink message */
static DEFINE_PER_CPU(unsigned long, fork_counts);
+/**
+ * fork_connector - send information about fork through a connector
+ * @ppid: Parent process ID
+ * @ptid: Parent thread ID
+ * @cpid: Child process ID
+ * @ctid: Child thread ID
+ *
+ * It sends information to a user space application through the
+ * connector when a new process is created.
+ */
void fork_connector(pid_t ppid, pid_t ptid, pid_t cpid, pid_t ctid)
{
if (cn_fork_enable) {
@@ -60,6 +70,7 @@ void fork_connector(pid_t ppid, pid_t pt
msg->len = CN_FORK_INFO_SIZE;
forkmsg = (struct cn_fork_msg *)msg->data;
+ forkmsg->type = FORK_CN_MSG_P;
forkmsg->cpu = smp_processor_id();
forkmsg->ppid = ppid;
forkmsg->ptid = ptid;
@@ -73,10 +84,32 @@ void fork_connector(pid_t ppid, pid_t pt
}
}
+/**
+ * cn_fork_send_status - send a message with the status
+ *
+ * It sends information about the status of the fork connector
+ * to a user space application through the connector. The status
+ * is stored in the global variable "cn_fork_enable".
+ */
static inline void cn_fork_send_status(void)
{
- /* TODO: An informational line in log is maybe not enough... */
- printk(KERN_INFO "cn_fork_enable == %d\n", cn_fork_enable);
+ struct cn_msg *msg;
+ struct cn_fork_msg *forkmsg;
+ __u8 buffer[CN_FORK_MSG_SIZE];
+
+ msg = (struct cn_msg *)buffer;
+
+ memcpy(&msg->id, &cb_fork_id, sizeof(msg->id));
+
+ msg->ack = 0; /* not used */
+ msg->seq = 0; /* not used */
+
+ msg->len = CN_FORK_INFO_SIZE;
+ forkmsg = (struct cn_fork_msg *)msg->data;
+ forkmsg->type = FORK_CN_MSG_S;
+ forkmsg->status = cn_fork_enable;
+
+ cn_netlink_send(msg, CN_IDX_FORK, GFP_KERNEL);
}
/**
Index: linux-2.6.12-rc4-mm2/include/linux/cn_fork.h
===================================================================
--- linux-2.6.12-rc4-mm2.orig/include/linux/cn_fork.h 2005-05-16 12:41:38.000000000 +0200
+++ linux-2.6.12-rc4-mm2/include/linux/cn_fork.h 2005-05-17 08:07:35.000000000 +0200
@@ -29,6 +29,9 @@
#define FORK_CN_START 1
#define FORK_CN_STATUS 2
+#define FORK_CN_MSG_P 0 /* Message about processes */
+#define FORK_CN_MSG_S 1 /* Message about fork connector's state */
+
/*
* The fork connector sends information to a user-space
* application. From the user's point of view, the process
@@ -43,11 +46,18 @@
* child thread ID = child->pid
*/
struct cn_fork_msg {
- int cpu; /* ID of the cpu where the fork occured */
- pid_t ppid; /* parent process ID */
- pid_t ptid; /* parent thread ID */
- pid_t cpid; /* child process ID */
- pid_t ctid; /* child thread ID */
+ int type; /* 0: information about processes
+ 1: fork connector's state */
+ int cpu; /* ID of the cpu where the fork occurred */
+ union {
+ struct {
+ pid_t ppid; /* parent process ID */
+ pid_t ptid; /* parent thread ID */
+ pid_t cpid; /* child process ID */
+ pid_t ctid; /* child thread ID */
+ };
+ int status;
+ };
};
/* Code above is only inside the kernel */
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[Index of Archives]
[Kernel Newbies]
[Netfilter]
[Bugtraq]
[Photo]
[Stuff]
[Gimp]
[Yosemite News]
[MIPS Linux]
[ARM Linux]
[Linux Security]
[Linux RAID]
[Video 4 Linux]
[Linux for the blind]
[Linux Resources]