From: chrubis@suse.cz
To: Jan Stancek <jstancek@redhat.com>
Cc: ltp-list@lists.sourceforge.net
Subject: Re: [LTP] [PATCH v2 2/3] setns: add new syscall test setns01
Date: Tue, 12 Feb 2013 13:33:23 +0100 [thread overview]
Message-ID: <20130212123323.GA9378@rei> (raw)
In-Reply-To: <ea4d5250ff8316fa655eac37e5279a2fb611f23a.1360149841.git.jstancek@redhat.com>
Hi!
> +#define NS_MAX 5
> +static int ns_types[NS_MAX];
> +static int ns_fds[NS_MAX];
> +static int ns_total;
> +
> +static int get_ns_fd(int pid, const char *ns)
> +{
> + char tmp[PATH_MAX];
> + struct stat st;
> + int fd = -1;
> +
> + sprintf(tmp, "/proc/%d/%s", pid, ns);
> + if (stat(tmp, &st) == 0) {
> + fd = open(tmp, O_RDONLY);
> + if (fd == -1)
> + tst_brkm(TBROK|TERRNO, NULL, "failed to open %s", tmp);
> + } else {
> + if (errno != ENOENT)
> + tst_brkm(TBROK|TERRNO, NULL, "failed to stat %s", tmp);
> + }
> + return fd;
> +}
> +
> +static void init_available_ns()
Missing void in the function parameters.
> +{
> +#define INIT_NS_TYPE(clone_type, proc_name) \
> +{ \
> + int fd; \
> + fd = get_ns_fd(getpid(), "ns/"proc_name); \
> + if (fd != -1) { \
> + ns_types[ns_total] = clone_type; \
> + ns_fds[ns_total] = fd; \
> + tst_resm(TINFO, "ns_fds[%d]=%d, ns_types[%d]=0x%x", ns_total, \
> + fd, ns_total, clone_type); \
> + ns_total++; \
> + } \
> +}
I'm wondering why this is a macro and not regular function. The only
thing that I see and that wouldn't work is the string
concatenation, which should have been done before the function is
called. Or the get_ns_fd() could have additional parameter, since it
uses sprintf() anyway.
> +#if defined(CLONE_NEWIPC)
> + INIT_NS_TYPE(CLONE_NEWIPC, "ipc");
> +#endif
> +#if defined(CLONE_NEWNS)
> + INIT_NS_TYPE(CLONE_NEWNS, "mnt");
> +#endif
> +#if defined(CLONE_NEWNET)
> + INIT_NS_TYPE(CLONE_NEWNET, "net");
> +#endif
> +#if defined(CLONE_NEWPID)
> + INIT_NS_TYPE(CLONE_NEWPID, "pid");
> +#endif
> +#if defined(CLONE_NEWUTS)
> + INIT_NS_TYPE(CLONE_NEWUTS, "uts");
> +#endif
> +
> +#undef INIT_NS_TYPE
> +}
> +
> +static void close_ns_fds()
Here missing void as well.
> +{
> + int i;
> +
> + for (i = 0; i < ns_total; i++)
> + if (ns_fds[i] != -1)
> + close(ns_fds[i]);
> +}
--
Cyril Hrubis
chrubis@suse.cz
------------------------------------------------------------------------------
Free Next-Gen Firewall Hardware Offer
Buy your Sophos next-gen firewall before the end March 2013
and get the hardware for free! Learn more.
http://p.sf.net/sfu/sophos-d2d-feb
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list
next prev parent reply other threads:[~2013-02-12 12:32 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-02-06 11:55 [LTP] [PATCH v2 0/3] add new syscall test for setns(2) Jan Stancek
2013-02-06 11:55 ` [LTP] [PATCH v2 1/3] setns: setup directory at kernel/syscalls/setns Jan Stancek
2013-02-06 11:55 ` [LTP] [PATCH v2 2/3] setns: add new syscall test setns01 Jan Stancek
2013-02-12 12:33 ` chrubis [this message]
2013-02-06 11:55 ` [LTP] [PATCH v2 3/3] setns: add new syscall test setns02 Jan Stancek
2013-02-12 12:41 ` chrubis
[not found] ` <1704604395.1338521.1360674295147.JavaMail.root@redhat.com>
2013-02-12 13:09 ` chrubis
[not found] ` <1446382265.1343619.1360674762081.JavaMail.root@redhat.com>
2013-02-12 13:16 ` chrubis
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=20130212123323.GA9378@rei \
--to=chrubis@suse.cz \
--cc=jstancek@redhat.com \
--cc=ltp-list@lists.sourceforge.net \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.