On Thu, 2008-06-19 at 15:35 +0800, Li Zefan wrote:
> Hi,
>
> I've revised the patch according to your comments:
> - get it integrated with LTP-build
> - check if the user is root or not
> - prevent building if kernel version is below 2.6.15
>
> And also fixed issues which Matt pointed out.
>
> But still not run by default, as I explained in a previous mail.
>
> Signed-off-by: Li Zefan <[EMAIL PROTECTED]>
> ---
> runtest/connectors | 2
> testcases/kernel/Makefile | 2
> testcases/kernel/connectors/Makefile | 13
> testcases/kernel/connectors/pec/Makefile | 13
> testcases/kernel/connectors/pec/README | 48 +++
> testcases/kernel/connectors/pec/event_generator.c | 229 +++++++++++++++
> testcases/kernel/connectors/pec/pec_listener.c | 316
> ++++++++++++++++++++++
> testcases/kernel/connectors/pec/run_pec_test | 103 +++++++
> 8 files changed, 725 insertions(+), 1 deletion(-)
>
<snip> (I cut out parts of the patch irrelevant to my comment/question
below)
> diff -Nurp
> ltp-full-20080531.orig/testcases/kernel/connectors/pec/pec_listener.c
> ltp-full-20080531/testcases/kernel/connectors/pec/pec_listener.c
> --- ltp-full-20080531.orig/testcases/kernel/connectors/pec/pec_listener.c
> 1970-01-01 08:00:00.000000000 +0800
> +++ ltp-full-20080531/testcases/kernel/connectors/pec/pec_listener.c
> 2008-06-17 15:59:41.000000000 +0800
> @@ -0,0 +1,316 @@
> +/******************************************************************************/
> +/*
> */
> +/* Copyright (c) 2008 FUJITSU LIMITED
> */
> +/*
> */
> +/* This program is free software; you can redistribute it and/or modify
> */
> +/* it under the terms of the GNU General Public License as published by
> */
> +/* the Free Software Foundation; either version 2 of the License, or
> */
> +/* (at your option) any later version.
> */
> +/*
> */
> +/* This program is distributed in the hope that it will be useful,
> */
> +/* but WITHOUT ANY WARRANTY; without even the implied warranty of
> */
> +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
> */
> +/* the GNU General Public License for more details.
> */
> +/*
> */
> +/* You should have received a copy of the GNU General Public License
> */
> +/* along with this program; if not, write to the Free Software
> */
> +/* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
> */
> +/*
> */
> +/* Author: Li Zefan <[EMAIL PROTECTED]>
> */
> +/*
> */
> +/******************************************************************************/
> +
> +#include <unistd.h>
> +#include <stdio.h>
> +#include <stdlib.h>
> +#include <string.h>
> +#include <errno.h>
> +#include <signal.h>
> +#include <sys/socket.h>
> +#include <sys/poll.h>
> +
> +#include <linux/netlink.h>
> +#include <linux/connector.h>
> +#include <linux/cn_proc.h>
> +
> +#define PEC_MSG_SIZE (sizeof(struct cn_msg) + sizeof(struct proc_event))
> +#define PEC_CTRL_MSG_SIZE (sizeof(struct cn_msg) + sizeof(enum
> proc_cn_mcast_op))
> +
> +#define MAX_MSG_SIZE 256
> +
> +static __u32 seq;
> +
> +static int exit_flag;
> +static struct sigaction sigint_action;
> +
> +/*
> + * Handler for signal int. Set exit flag.
> + *
> + * @signo: the signal number, not used
> + */
> +static void sigint_handler(int __attribute__((unused)) signo)
> +{
> + exit_flag = 1;
> +}
> +
> +/*
> + * Send netlink package.
> + *
> + * @sd: socket descripor
> + * @to: the destination sockaddr
> + * @cnmsg: the pec control message
> + */
> +static int netlink_send(int sd, struct sockaddr_nl *to, struct cn_msg *cnmsg)
> +{
> + int ret;
> + char buf[MAX_MSG_SIZE];
> + struct nlmsghdr *nlhdr;
> + struct iovec iov;
> + struct msghdr msg;
> +
> + memset(buf, 0, MAX_MSG_SIZE);
> +
> + nlhdr = (struct nlmsghdr *)buf;
> +
> + nlhdr->nlmsg_seq = seq++;
> + nlhdr->nlmsg_pid = getpid();
> + nlhdr->nlmsg_type = NLMSG_DONE;
> + nlhdr->nlmsg_len = NLMSG_LENGTH(sizeof(*cnmsg) + cnmsg->len);
> + nlhdr->nlmsg_flags = 0;
> + memcpy(NLMSG_DATA(nlhdr), cnmsg, sizeof(*cnmsg) + cnmsg->len);
> +
> + memset(&iov, 0, sizeof(struct iovec));
> + iov.iov_base = (void *)nlhdr;
> + iov.iov_len = nlhdr->nlmsg_len;
> +
> + memset(&msg, 0, sizeof(struct msghdr));
> + msg.msg_name = (void *)to;
> + msg.msg_namelen = sizeof(*to);
> + msg.msg_iov = &iov;
> + msg.msg_iovlen = 1;
> +
> + ret = sendmsg(sd, &msg, 0);
> +
> + return ret;
> +}
> +
> +/*
> + * Receive package from netlink.
> + *
> + * @sd: socket descripor
> + * @from: source sockaddr
> + * @buf: buffer for storing the package
> + */
> +static int netlink_recv(int sd, struct sockaddr_nl *from, char *buf)
> +{
> + int ret;
> + struct nlmsghdr *nlhdr = (struct nlmsghdr *)buf;
> + struct iovec iov;
> + struct msghdr msg;
> +
> + memset(nlhdr, 0, NLMSG_SPACE(MAX_MSG_SIZE));
> + memset(&iov, 0, sizeof(iov));
> + memset(&msg, 0, sizeof(msg));
> +
> + iov.iov_base = (void *)nlhdr;
> + iov.iov_len = NLMSG_SPACE(MAX_MSG_SIZE);
> +
> + msg.msg_name = (void *)from;
> + msg.msg_namelen = sizeof(*from);
> + msg.msg_iov = &iov;
> + msg.msg_iovlen = 1;
> +
> + ret = recvmsg(sd, &msg, 0);
> +
> + return ret;
> +}
> +
> +/*
> + * Send control message to PEC.
> + *
> + * @sd: socket descriptor
> + * @to: the destination sockaddr
> + * @op: control flag
> + */
> +static int control_pec(int sd, struct sockaddr_nl *to, enum proc_cn_mcast_op
> op)
> +{
> + int ret;
> + char buf[PEC_CTRL_MSG_SIZE];
> + struct cn_msg *cnmsg;
> + enum proc_cn_mcast_op *pec_op;
> +
> + memset(buf, 0, sizeof(buf));
> +
> + cnmsg = (struct cn_msg *)buf;
> + cnmsg->id.idx = CN_IDX_PROC;
> + cnmsg->id.val = CN_VAL_PROC;
> + cnmsg->seq = seq++;
> + cnmsg->ack = 0;
> + cnmsg->len = sizeof(op);
> +
> + pec_op = (enum proc_cn_mcast_op *)cnmsg->data;
> + *pec_op = op;
> +
> + ret = netlink_send(sd, to, cnmsg);
> +
> + return ret;
> +}
> +
> +/*
> + * Process PEC event.
> + *
> + * @nlhdr: the netlinke pacakge
> + */
> +static void process_event(struct nlmsghdr *nlhdr)
> +{
> + struct cn_msg *msg;
> + struct proc_event *pe;
> +
> + msg = (struct cn_msg *)NLMSG_DATA(nlhdr);
> +
> + pe = (struct proc_event *)msg->data;
> +
> + switch (pe->what) {
> + case PROC_EVENT_NONE:
> + printf("none err: %u\n", pe->event_data.ack.err);
> + break;
> + case PROC_EVENT_FORK:
> + printf("fork parent: %d, child: %d\n",
> + pe->event_data.fork.parent_pid,
> + pe->event_data.fork.child_pid);
> + break;
> + case PROC_EVENT_EXEC:
> + printf("exec pid: %d\n",
> + pe->event_data.exec.process_pid);
> + break;
> + case PROC_EVENT_UID:
> + printf("uid pid: %d euid: %d ruid: %d\n",
> + pe->event_data.id.process_pid,
> + pe->event_data.id.e.euid,
> + pe->event_data.id.r.ruid);
> + break;
> + case PROC_EVENT_GID:
> + printf("gid pid: %d egid: %d rgid: %d\n",
> + pe->event_data.id.process_pid,
> + pe->event_data.id.e.egid,
> + pe->event_data.id.r.rgid);
> + break;
> + case PROC_EVENT_EXIT:
> + printf("exit pid: %d exit_code: %d exit_signal: %d\n",
> + pe->event_data.exit.process_pid,
> + pe->event_data.exit.exit_code,
> + pe->event_data.exit.exit_signal);
> + break;
> + default:
> + printf("unknown event\n");
> + break;
> + }
> +}
> +
> +int main(int argc, char **argv)
> +{
> + int ret;
> + int sd;
> + struct sockaddr_nl l_local;
> + struct sockaddr_nl src_addr;
> + char buf[MAX_MSG_SIZE];
> + struct pollfd pfd;
> +
> + sigint_action.sa_flags = SA_ONESHOT;
> + sigint_action.sa_handler = &sigint_handler;
> + sigaction(SIGINT, &sigint_action, NULL);
> +
> + /* Create and bind socket */
> + sd = socket(PF_NETLINK, SOCK_DGRAM, NETLINK_CONNECTOR);
> + if (sd == -1) {
> + fprintf(stderr, "failed to create socket\n");
> + exit(1);
> + }
> +
> + memset(&src_addr, 0, sizeof(src_addr));
> + src_addr.nl_family = AF_NETLINK;
> + src_addr.nl_pid = 0;
> + src_addr.nl_groups = 0;
> +
> + memset(&l_local, 0, sizeof(l_local));
> + l_local.nl_family = AF_NETLINK;
> + l_local.nl_pid = getpid();
> + l_local.nl_groups = CN_IDX_PROC;
> +
> + ret = bind(sd, (struct sockaddr *)&l_local,
> + sizeof(struct sockaddr_nl));
> + if (ret == -1) {
> + fprintf(stderr, "failed to bind socket\n");
> + exit(1);
> + }
In subsequent email echanges Li and Subrata wrote:
> Subrata Modak 写道:
> > Li,
> >
> > Will you be resending me a renewed patch that fixes those issues, so
> > that i can merge for the June 2008 LTP release ?
> >
>
> Will it be better to hold this until David Miller accepts my patch or
> Evgeniy Polyakov extends the connector core to allow querying of
> connector
> users ?
I'm not sure exactly what you're referring to.
Are you concerned that there's no way to test if the interfaces exist?
If so, couldn't you consider using main() of pec_listener.c up to the
point above as a test to determine if the kernel feature(s) needed for
the LTP tests exist? Then you can determine whether or not to run the
tests by default based on the result. You might need to check for
specific errno values and you might also need to test to be sure netlink
sockets have been configured into the kernel too, but I think that may
be do-able.
Either way, I think putting the tests in as they are would be nice. You
can always update the tests to reflect your patch or extensions by
Evgeniy, but in the meantime your useful tests would be available to LTP
users (even if not run by default).
That's just my 2 cents.
Cheers,
-Matt Helsley
-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list