Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [RFA] save/restore environ in libiberty pex_unix_exec_child
@ 2009-12-07 17:26 Doug Evans
  2009-12-07 20:10 ` DJ Delorie
       [not found] ` <200912072009.nB7K9moj000406__858.220636337315$1260216617$gmane$org@greed.delorie.com>
  0 siblings, 2 replies; 6+ messages in thread
From: Doug Evans @ 2009-12-07 17:26 UTC (permalink / raw)
  To: gcc-patches; +Cc: gdb-patches

Hi.

I ran into this while using pex_run_in_environment in gdb.

Ok to check in?

2009-12-07  Doug Evans  <dje@google.com>

	* pex-unix.c (pex_unix_exec_child): Save/restore environ.

==== //depot2/gcctools/google_vendor_src_branch/gdb/gdb-7.0.x-prod/libiberty/pex-unix.c#1 - /usr/local/google/home/dje/ctools/gdb/7.0.x-prod/depot2/gcctools/google_vendor_src_branch/gdb/gdb-7.0.x-prod/libiberty/pex-unix.c ====
--- /tmp/g4-67641/cache/depot2/gcctools/google_vendor_src_branch/gdb/gdb-7.0.x-prod/libiberty/pex-unix.c#1	2009-12-06 12:30:36.000000000 -0800
+++ /usr/local/google/home/dje/ctools/gdb/7.0.x-prod/depot2/gcctools/google_vendor_src_branch/gdb/gdb-7.0.x-prod/libiberty/pex-unix.c	2009-12-06 12:27:46.000000000 -0800
@@ -397,6 +397,10 @@
   volatile int sleep_interval;
   volatile int retries;
 
+  /* We vfork and then set environ in the child before calling execvp.
+     This clobbers the parent's environ so we need to restore it.  */
+  char **save_environ = environ;
+
   sleep_interval = 1;
   pid = -1;
   for (retries = 0; retries < 4; ++retries)
@@ -468,6 +472,7 @@
 
     default:
       /* Parent process.  */
+      environ = save_environ;
       if (in != STDIN_FILE_NO)
 	{
 	  if (close (in) < 0)


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [RFA] save/restore environ in libiberty pex_unix_exec_child
  2009-12-07 17:26 [RFA] save/restore environ in libiberty pex_unix_exec_child Doug Evans
@ 2009-12-07 20:10 ` DJ Delorie
  2009-12-07 20:25   ` Doug Evans
       [not found] ` <200912072009.nB7K9moj000406__858.220636337315$1260216617$gmane$org@greed.delorie.com>
  1 sibling, 1 reply; 6+ messages in thread
From: DJ Delorie @ 2009-12-07 20:10 UTC (permalink / raw)
  To: Doug Evans; +Cc: gcc-patches, gdb-patches


If the child assignment truly clobbers the parent, won't the parent's
assignment clobber the child?

If it's portable enough, using exevpe/execve instead of execvp/execv
would be preferred.


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [RFA] save/restore environ in libiberty pex_unix_exec_child
  2009-12-07 20:10 ` DJ Delorie
@ 2009-12-07 20:25   ` Doug Evans
  2009-12-07 20:55     ` DJ Delorie
  0 siblings, 1 reply; 6+ messages in thread
From: Doug Evans @ 2009-12-07 20:25 UTC (permalink / raw)
  To: DJ Delorie; +Cc: gcc-patches, gdb-patches

On Mon, Dec 7, 2009 at 12:09 PM, DJ Delorie <dj@redhat.com> wrote:
>
> If the child assignment truly clobbers the parent, won't the parent's
> assignment clobber the child?
>
> If it's portable enough, using exevpe/execve instead of execvp/execv
> would be preferred.

The context is a child running under vfork.  While the linux man page
says one cannot assume, for example, that the parent is blocked until
the child execs/exits, it would be odd if in implementations where the
parent is not blocked that assignments in the parent clobbered the
child.  s/odd/broken/ even. :-)

[from man vfork]
CONFORMING TO
       4.3BSD,  POSIX.1-2001.  The requirements put on vfork() by the
standards are weaker than those put on fork(2), so an implementation
where the two are
       synonymous is compliant.  In particular, the programmer cannot
rely on the parent remaining blocked until a call of execve(2) or
_exit(2) and  cannot
       rely on any specific behavior with respect to shared memory.

I don't disagree re. execve, *if* it's portable enough.  I wasn't
prepared to investigate the full gamut of portability issues for this.
 Some thought may have gone into what's there now (maybe, maybe not,
but I err'd on the side of being cautious).  My patch seems like a
straightforward fix to what's there now.


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [RFA] save/restore environ in libiberty pex_unix_exec_child
       [not found] ` <200912072009.nB7K9moj000406__858.220636337315$1260216617$gmane$org@greed.delorie.com>
@ 2009-12-07 20:28   ` Tom Tromey
  0 siblings, 0 replies; 6+ messages in thread
From: Tom Tromey @ 2009-12-07 20:28 UTC (permalink / raw)
  To: DJ Delorie; +Cc: Doug Evans, gcc-patches, gdb-patches

>>>>> "DJ" == DJ Delorie <dj@redhat.com> writes:

DJ> If the child assignment truly clobbers the parent, won't the parent's
DJ> assignment clobber the child?

During a vfork, the parent is suspended until the child execs or dies.
So, this assignment won't affect the child.

Tom


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [RFA] save/restore environ in libiberty pex_unix_exec_child
  2009-12-07 20:25   ` Doug Evans
@ 2009-12-07 20:55     ` DJ Delorie
  2009-12-07 21:37       ` Doug Evans
  0 siblings, 1 reply; 6+ messages in thread
From: DJ Delorie @ 2009-12-07 20:55 UTC (permalink / raw)
  To: Doug Evans; +Cc: gcc-patches, gdb-patches


Hmm... my Linux doesn't even include execvpe().

Ok to check it in then, but *please* include a comment documenting the
assumption that the parent won't run until the child is done.


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [RFA] save/restore environ in libiberty pex_unix_exec_child
  2009-12-07 20:55     ` DJ Delorie
@ 2009-12-07 21:37       ` Doug Evans
  0 siblings, 0 replies; 6+ messages in thread
From: Doug Evans @ 2009-12-07 21:37 UTC (permalink / raw)
  To: DJ Delorie; +Cc: gcc-patches, gdb-patches

On Mon, Dec 7, 2009 at 12:55 PM, DJ Delorie <dj@redhat.com> wrote:
>
> Hmm... my Linux doesn't even include execvpe().
>
> Ok to check it in then, but *please* include a comment documenting the
> assumption that the parent won't run until the child is done.
>

Thanks.

I'm always for more comments explaining why things are the way they are.


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2009-12-07 21:37 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-12-07 17:26 [RFA] save/restore environ in libiberty pex_unix_exec_child Doug Evans
2009-12-07 20:10 ` DJ Delorie
2009-12-07 20:25   ` Doug Evans
2009-12-07 20:55     ` DJ Delorie
2009-12-07 21:37       ` Doug Evans
     [not found] ` <200912072009.nB7K9moj000406__858.220636337315$1260216617$gmane$org@greed.delorie.com>
2009-12-07 20:28   ` Tom Tromey

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox