From: Chris Wedgwood <cw@f00f.org>
To: Takashi Ikebe <ikebe.takashi@lab.ntt.co.jp>
Cc: Rik van Riel <riel@redhat.com>, Paul Jackson <pj@sgi.com>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH x86_64] Live Patching Function on 2.6.11.7
Date: Wed, 20 Apr 2005 01:26:55 -0700 [thread overview]
Message-ID: <20050420082655.GA2756@taniwha.stupidest.org> (raw)
In-Reply-To: <42660B6B.6040600@lab.ntt.co.jp>
[-- Attachment #1: Type: text/plain, Size: 407 bytes --]
On Wed, Apr 20, 2005 at 04:57:31PM +0900, Takashi Ikebe wrote:
> hmm.. most internet base services will use TCPv4 TCPv6 SCTP...
> AF_UNIX can not use as inter-nodes communication.
You can send file descriptors (the actually file descriptors
themselves, not their contents) to another process over a socket.
A nearly ten-year old example is attached (ie. this isn't new or
magical or specific to Linux).
[-- Attachment #2: sendfd.c --]
[-- Type: text/x-csrc, Size: 2160 bytes --]
/* sendfd.c - v. crude example of passing fds */
/*
* I tested this on HPUX10 using gcc -D_XOPEN_SOURCE_EXTENDED sendfd.c -lxnet
*
* Expected output is "hello world"
*/
#include <stdio.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/socket.h>
#include <sys/un.h>
/* Note: msg_control may be msg_accrights, etc. */
int sendfd(int conn, int fd)
{
size_t len = sizeof(struct cmsghdr) + sizeof(int);
struct cmsghdr *hdr = (struct cmsghdr *)malloc(len);
struct msghdr msg;
int rc;
hdr->cmsg_len = len;
hdr->cmsg_level = SOL_SOCKET;
hdr->cmsg_type = SCM_RIGHTS;
*(int *)CMSG_DATA(hdr) = fd;
msg.msg_name = NULL;
msg.msg_namelen = 0;
msg.msg_iov = NULL;
msg.msg_iovlen = 0;
msg.msg_control = hdr;
msg.msg_controllen = len;
rc = sendmsg(conn, &msg, 0);
free(hdr);
return rc;
}
int recvfd(int conn)
{
size_t len = sizeof(struct cmsghdr) + sizeof(int);
struct cmsghdr *hdr = (struct cmsghdr *)malloc(len);
struct msghdr msg;
int rc;
msg.msg_iov = NULL;
msg.msg_iovlen = 0;
msg.msg_control = hdr;
msg.msg_controllen = len;
rc = recvmsg(conn, &msg, 0);
if (rc >= 0
&& hdr->cmsg_len == len
&& hdr->cmsg_level == SOL_SOCKET
&& hdr->cmsg_type == SCM_RIGHTS)
{
int fd = *(int *)CMSG_DATA(hdr);
free(hdr);
return fd;
}
free(hdr);
return -1;
}
int main()
{
int fds[2];
int fd = -1;
int rc = socketpair(AF_UNIX, SOCK_STREAM, 0, fds);
pid_t pid;
if (rc)
{
perror("socketpair");
return 1;
}
/* punt */
system("echo hello world >testfile");
switch (pid = fork())
{
case 0:
// open this in the child proc
fd = open("testfile",O_RDONLY);
if (fd < 0)
perror("open(testfile)");
rc = sendfd(fds[1], fd);
if (rc)
perror("sendfd");
_exit(0);
case -1:
perror("fork");
return 1;
default:
waitpid(pid,NULL,0);
}
fd = recvfd(fds[0]);
if (fd < 0)
{
perror("recvfd");
return 1;
}
close(fds[0]);
close(fds[1]);
dup2(fd,0);
close(fd);
execl("/bin/cat","cat",NULL);
}
next prev parent reply other threads:[~2005-04-20 8:27 UTC|newest]
Thread overview: 59+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-04-18 3:19 Takashi Ikebe
2005-04-18 4:07 ` Chris Wedgwood
2005-04-18 4:19 ` Takashi Ikebe
2005-04-18 4:42 ` Daniel Jacobowitz
2005-04-18 4:55 ` Nicholas Miell
2005-04-18 5:01 ` Davide Libenzi
2005-04-18 5:41 ` Takashi Ikebe
2005-07-11 7:18 ` [PATCH] eventpoll : Suppress a short lived lock from struct file Eric Dumazet
2005-07-11 8:34 ` Peter Zijlstra
2005-07-11 9:29 ` Eric Dumazet
2005-07-11 14:00 ` Davide Libenzi
2005-07-11 15:20 ` Eric Dumazet
2005-04-18 5:00 ` [PATCH x86_64] Live Patching Function on 2.6.11.7 David S. Miller
2005-04-18 6:12 ` Chris Wedgwood
2005-04-18 6:35 ` Chris Friesen
2005-04-18 6:48 ` Chris Wedgwood
2005-04-18 10:03 ` James Courtier-Dutton
2005-04-18 9:10 ` Chris Wedgwood
2005-04-18 7:32 ` Takashi Ikebe
2005-04-18 7:56 ` Chris Wedgwood
2005-04-18 8:37 ` Takashi Ikebe
2005-04-18 8:59 ` Chris Wedgwood
2005-04-18 9:16 ` Paul Jackson
2005-04-18 9:25 ` Chris Wedgwood
2005-04-18 11:30 ` Rik van Riel
2005-04-18 12:52 ` Takashi Ikebe
2005-04-18 14:06 ` Rik van Riel
2005-04-19 2:14 ` Takashi Ikebe
2005-04-19 4:27 ` Chris Wedgwood
2005-04-19 5:19 ` Takashi Ikebe
2005-04-19 5:52 ` Chris Wedgwood
2005-04-20 4:18 ` Takashi Ikebe
2005-04-20 5:43 ` Chris Wedgwood
2005-04-20 7:35 ` Takashi Ikebe
2005-04-20 7:50 ` Chris Wedgwood
2005-04-20 7:57 ` Takashi Ikebe
2005-04-20 8:26 ` Chris Wedgwood [this message]
2005-04-20 8:45 ` Takashi Ikebe
2005-04-20 8:51 ` Chris Wedgwood
2005-04-20 11:19 ` Rik van Riel
2005-04-20 15:06 ` Chris Friesen
2005-04-20 8:34 ` Miquel van Smoorenburg
2005-04-19 5:57 ` Takashi Ikebe
2005-04-18 14:28 ` Paul Jackson
2005-04-20 13:10 ` Ralf Baechle
2005-04-20 15:08 ` Chris Friesen
2005-04-23 16:17 ` Andi Kleen
2005-04-25 2:11 ` Takashi Ikebe
2005-04-25 2:48 ` Kyle Moffett
2005-04-25 10:39 ` Takashi Ikebe
2005-04-25 11:15 ` Kyle Moffett
2005-04-25 15:09 ` Pavel Machek
2005-04-25 15:54 ` Andi Kleen
2005-04-25 16:36 ` Valdis.Kletnieks
2005-04-26 1:34 ` Takashi Ikebe
2005-04-26 2:15 ` Kyle Moffett
2005-04-26 9:36 ` Pavel Machek
2005-04-26 13:05 ` Andi Kleen
[not found] <3Uv7B-5lv-7@gated-at.bofh.it>
[not found] ` <3UvKd-5RT-1@gated-at.bofh.it>
[not found] ` <3Uw3y-65a-1@gated-at.bofh.it>
[not found] ` <3UwmX-6gm-5@gated-at.bofh.it>
[not found] ` <3UwwG-6lY-7@gated-at.bofh.it>
[not found] ` <3UwGk-6Cv-9@gated-at.bofh.it>
[not found] ` <3Uxj2-6YL-1@gated-at.bofh.it>
2005-04-18 10:59 ` Bodo Eggert <harvested.in.lkml@posting.7eggert.dyndns.org>
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=20050420082655.GA2756@taniwha.stupidest.org \
--to=cw@f00f.org \
--cc=ikebe.takashi@lab.ntt.co.jp \
--cc=linux-kernel@vger.kernel.org \
--cc=pj@sgi.com \
--cc=riel@redhat.com \
/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
all inboxes | Powered by JetHome®