Linux Container Development
 help / color / mirror / Atom feed
From: Dan Smith <danms-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
To: Oren Laadan <orenl-eQaUEPhvms7ENvBUuze7eA@public.gmane.org>
Cc: containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org,
	Dave Hansen
	<dave-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
Subject: Re: [RFC cr-pipe-v13][PATCH 3/3] Restore open pipes
Date: Mon, 02 Feb 2009 09:43:01 -0800	[thread overview]
Message-ID: <87k5887n16.fsf@caffeine.danplanet.com> (raw)
In-Reply-To: <1233091395-24582-5-git-send-email-orenl-eQaUEPhvms7ENvBUuze7eA@public.gmane.org> (Oren Laadan's message of "Tue, 27 Jan 2009 16:23:15 -0500")

OL> +/* restore a pipe */
OL> +static int
OL> +cr_read_fd_pipe(struct cr_ctx *ctx, struct cr_hdr_fd_data *hh, int rparent)
OL> +{
OL> +	struct file *file;
OL> +	int fds[2], which, ret;
OL> +
OL> +	file = cr_obj_get_by_ref(ctx, hh->fd_objref, CR_OBJ_FILE);
OL> +	if (IS_ERR(file))
OL> +		return PTR_ERR(file);
OL> +	else if (file)
OL> +		return cr_attach_get_file(file);
OL> +
OL> +	/* first encounter of this pipe: create it */
OL> +	ret = do_pipe(fds);
OL> +	if (ret < 0)
OL> +		return ret;
OL> +
OL> +	which = (hh->f_flags & O_WRONLY ? 1 : 0);
OL> +
OL> +	/*
OL> +	 * Below we return the fd corersponding to one side of the pipe
OL> +	 * for our caller to use. Now register the other side of the pipe
OL> +	 * in the hash, to be picked up when that side is to be restored.
OL> +	 */
OL> +	file = cr_obj_add_file(ctx, fds[1-which], hh->fd_objref);
OL> +	if (IS_ERR(file)) {
OL> +		ret = PTR_ERR(file);
OL> +		goto out;
OL> +	}
OL> +
OL> +	ret = cr_read_pipe(ctx, fds[which]);
OL> + out:
OL> +	sys_close(fds[1-which]);	/* this side isn't used anymore */

This isn't always a valid thing to do, right?  I can think of two
scenarios off the top of my head that will break here:

1. The process has called pipe() but has not yet fork()'d
2. The process is using both sides of a pipe for a select()-based
   event loop

I worked up a quick test for #1, and it dies immediately on restart
with a SIGPIPE.

I'll see if I can work up and post a patch to fix this if I can come
up with something I think is reasonable.

Thanks!

-- 
Dan Smith
IBM Linux Technology Center
email: danms-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org

  parent reply	other threads:[~2009-02-02 17:43 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-01-27 21:23 [RFC cr-pipe-v13][PATCH 0/3] c/r of open pipes Oren Laadan
     [not found] ` <1233091395-24582-1-git-send-email-orenl-eQaUEPhvms7ENvBUuze7eA@public.gmane.org>
2009-01-27 21:23   ` Oren Laadan
2009-01-27 21:23   ` [RFC cr-pipe-v13][PATCH 1/3] A new file type (CR_FD_OBJREF) for a file descriptor already setup Oren Laadan
2009-01-27 21:23   ` [RFC cr-pipe-v13][PATCH 2/3] Checkpoint open pipes Oren Laadan
     [not found]     ` <1233091395-24582-4-git-send-email-orenl-eQaUEPhvms7ENvBUuze7eA@public.gmane.org>
2009-02-05  9:45       ` Cedric Le Goater
     [not found]         ` <498AB553.3090902-NmTC/0ZBporQT0dZR+AlfA@public.gmane.org>
2009-02-06  2:26           ` Nathan Lynch
     [not found]             ` <20090205202637.4d4f4a29-4v5LP+xe+1byhTdZtsIeww@public.gmane.org>
2009-02-06 13:05               ` Cedric Le Goater
2009-02-06 17:11               ` Dave Hansen
2009-02-06 17:20                 ` Cedric Le Goater
     [not found]                   ` <498C715B.4050303-NmTC/0ZBporQT0dZR+AlfA@public.gmane.org>
2009-02-06 17:24                     ` Dave Hansen
2009-02-07 12:54                       ` Cedric Le Goater
     [not found]                         ` <498D8489.6090904-NmTC/0ZBporQT0dZR+AlfA@public.gmane.org>
2009-02-09 14:39                           ` Cedric Le Goater
2009-01-27 21:23   ` [RFC cr-pipe-v13][PATCH 3/3] Restore " Oren Laadan
     [not found]     ` <1233091395-24582-5-git-send-email-orenl-eQaUEPhvms7ENvBUuze7eA@public.gmane.org>
2009-02-02 17:43       ` Dan Smith [this message]
     [not found]         ` <87k5887n16.fsf-FLMGYpZoEPULwtHQx/6qkW3U47Q5hpJU@public.gmane.org>
2009-02-03  0:02           ` Oren Laadan
     [not found]             ` <498789B1.80601-eQaUEPhvms7ENvBUuze7eA@public.gmane.org>
2009-02-03 16:23               ` Dan Smith
2009-01-27 21:29   ` [RFC cr-pipe-v13][PATCH 0/3] c/r of " Oren Laadan

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=87k5887n16.fsf@caffeine.danplanet.com \
    --to=danms-r/jw6+rmf7hqt0dzr+alfa@public.gmane.org \
    --cc=containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org \
    --cc=dave-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org \
    --cc=orenl-eQaUEPhvms7ENvBUuze7eA@public.gmane.org \
    /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