From: Guillaume Thouvenin Implement 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: guillaume.thouvenin@bull.net Signed-off-by: Andrew Morton --- drivers/connector/cn_fork.c | 37 +++++++++++++++++++++++++++++++++++-- include/linux/cn_fork.h | 20 +++++++++++++++----- 2 files changed, 50 insertions(+), 7 deletions(-) diff -puN drivers/connector/cn_fork.c~fork-connector-send-status-to-userspace drivers/connector/cn_fork.c --- 25/drivers/connector/cn_fork.c~fork-connector-send-status-to-userspace 2005-05-31 01:31:08.000000000 -0700 +++ 25-akpm/drivers/connector/cn_fork.c 2005-05-31 01:31:08.000000000 -0700 @@ -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); } /** diff -puN include/linux/cn_fork.h~fork-connector-send-status-to-userspace include/linux/cn_fork.h --- 25/include/linux/cn_fork.h~fork-connector-send-status-to-userspace 2005-05-31 01:31:08.000000000 -0700 +++ 25-akpm/include/linux/cn_fork.h 2005-05-31 01:31:08.000000000 -0700 @@ -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 */ _