Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

"Atomic batteries to power, turbines to speed." -- Robin, The Boy Wonder


computers / comp.os.vms / Re: Bizarre vfork() / exec() behavior in VMS V8.4-2L1 Alpha

SubjectAuthor
* Bizarre vfork() / exec() behavior in VMS V8.4-2L1 AlphaJake Hamby
+* Re: Bizarre vfork() / exec() behavior in VMS V8.4-2L1 AlphaCraig A. Berry
|`* Re: Bizarre vfork() / exec() behavior in VMS V8.4-2L1 AlphaJake Hamby
| +* Re: Bizarre vfork() / exec() behavior in VMS V8.4-2L1 AlphaCraig A. Berry
| |`- Re: Bizarre vfork() / exec() behavior in VMS V8.4-2L1 AlphaJake Hamby
| `- Re: Bizarre vfork() / exec() behavior in VMS V8.4-2L1 AlphaRoger Ivie
`- Re: Bizarre vfork() / exec() behavior in VMS V8.4-2L1 Alphagah4

1
Bizarre vfork() / exec() behavior in VMS V8.4-2L1 Alpha

<68cf2f4b-1eef-4f02-9b18-6304b1fab313n@googlegroups.com>

  copy mid

https://www.novabbs.com/computers/article-flat.php?id=22410&group=comp.os.vms#22410

  copy link   Newsgroups: comp.os.vms
X-Received: by 2002:a05:622a:2cb:b0:2f3:646b:54b6 with SMTP id a11-20020a05622a02cb00b002f3646b54b6mr18164481qtx.380.1651648785778;
Wed, 04 May 2022 00:19:45 -0700 (PDT)
X-Received: by 2002:a05:6214:27c6:b0:45a:b5f0:691d with SMTP id
ge6-20020a05621427c600b0045ab5f0691dmr788454qvb.9.1651648785357; Wed, 04 May
2022 00:19:45 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.os.vms
Date: Wed, 4 May 2022 00:19:45 -0700 (PDT)
Injection-Info: google-groups.googlegroups.com; posting-host=2600:1700:46b0:abc0:6a3:4625:c897:d245;
posting-account=OGFVHQoAAAASiNAamRQec8BtkuXxYFnQ
NNTP-Posting-Host: 2600:1700:46b0:abc0:6a3:4625:c897:d245
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <68cf2f4b-1eef-4f02-9b18-6304b1fab313n@googlegroups.com>
Subject: Bizarre vfork() / exec() behavior in VMS V8.4-2L1 Alpha
From: jake.ha...@gmail.com (Jake Hamby)
Injection-Date: Wed, 04 May 2022 07:19:45 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Lines: 46
 by: Jake Hamby - Wed, 4 May 2022 07:19 UTC

I recently got interested in the Rexx language as part of learning about IBM mainframes, and discovered that it's a good scripting language for other platforms as well. So why not port Regina (free Rexx interpreter) to VMS? After all, I've always been disappointed in DCL as a scripting language, and Rexx just seems like it'd be a good fit for VMS.

I discovered that Regina already *had* been ported to VMS, many years ago, and in fact had 3000+ lines of code to implement all of the useful F$ lexical functions from DCL directly as Rexx functions, which is pretty cool. I've been fixing bugs and updating it on my GitHub project page (link below), and I noticed some bizarre behavior in the vfork()/exec() implementation, at least in OpenVMS Alpha V8.4-2L1 (I'll try to test on Itanium as soon as I get access to my old boxes) that I wanted to ask the experts about. This is with VMS842L1A_RTL V3.0 installed.

My first issue was that vfork() doesn't preserve the file descriptors, unlike BSD or Linux vfork(), so I had to dup() the old stdin, stdout, and stderr before replacing them and calling vfork(), and then, in the parent path, reset everything the way it was before returning. That's annoying, but expected. The manual didn't say that the C RTL would preserve and restore the status of file descriptors that you dup2()'d or close()'d in the child.

But I think I've found an actual bug. When execvp() fails due to e.g. file not found, the manual, and traditional vfork() behavior, would have me call either _exit() or exit() in order to return to the parent. But if I do that, my process exits! As a workaround, I tried *returning* from my function, as the child, to see if the CRTL would jump back to the parent code path, and that actually works, but it feels really wrong to do something as hacky as returning from a function as the vfork child, rather than calling _exit().

I did try undefining _POSIX_EXIT, which I'd enabled, and that didn't make any difference. I've copied the vms_crtl_init.c file from GNV bash into the project to enable more UNIX behaviors, but didn't add anything unusual. Is this a known issue/bug in the V8.4-2L1 VMS CRTL?

This feels like a rather severe bug to be showing up suddenly in such core POSIX functionality, but if it's been this way for a long time, that's even more worrisome.

Thanks in advance for any thoughts/suggestions.

Link to my fork of Regina with VMS fixes: https://github.com/jhamby/vms-regina/tree/jhamby/vms-fixes

Regards,
Jake Hamby

Re: Bizarre vfork() / exec() behavior in VMS V8.4-2L1 Alpha

<t4tt3o$4ds$1@dont-email.me>

  copy mid

https://www.novabbs.com/computers/article-flat.php?id=22411&group=comp.os.vms#22411

  copy link   Newsgroups: comp.os.vms
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: craigbe...@nospam.mac.com (Craig A. Berry)
Newsgroups: comp.os.vms
Subject: Re: Bizarre vfork() / exec() behavior in VMS V8.4-2L1 Alpha
Date: Wed, 4 May 2022 07:55:18 -0500
Organization: A noiseless patient Spider
Lines: 21
Message-ID: <t4tt3o$4ds$1@dont-email.me>
References: <68cf2f4b-1eef-4f02-9b18-6304b1fab313n@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 4 May 2022 12:55:20 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="58228d791233c5d66881d98c0080b00d";
logging-data="4540"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/8J5nhECuTvr0TGW+PFKTzdbDOBALEyDQ="
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:91.0)
Gecko/20100101 Thunderbird/91.8.1
Cancel-Lock: sha1:PTAB6GfMRXhVoKldKv37cBkrOWU=
In-Reply-To: <68cf2f4b-1eef-4f02-9b18-6304b1fab313n@googlegroups.com>
Content-Language: en-US
 by: Craig A. Berry - Wed, 4 May 2022 12:55 UTC

On 5/4/22 2:19 AM, Jake Hamby wrote:
> My first issue was that vfork() doesn't preserve the file
> descriptors, unlike BSD or Linux vfork(), so I had to dup() the old stdin, stdout,
> and stderr before replacing them and calling vfork(), and then, in the
> parent path, reset everything the way it was before returning. That's
> annoying, but expected. The manual didn't say that the C RTL would
> preserve and restore the status of file descriptors that you dup2()'d or
> close()'d in the child.

You may want to look into decc$set_child_standard_streams and/or
decc$set_child_default_dir.

> But I think I've found an actual bug. When execvp() fails due to
> e.g. file not found, the manual, and traditional vfork() behavior, would have
> me call either _exit() or exit() in order to return to the parent. But
> if I do that, my process exits!

As far as I know, until the exec succeeds, you don't actually have a
child process. This is the documented behavior of vfork() on VMS, which
is really just a set-up routine comparable to setjmp(). So it makes
sense that exiting after a failed exec is actually exiting from the parent.

Re: Bizarre vfork() / exec() behavior in VMS V8.4-2L1 Alpha

<d0fdde59-6b38-4010-adac-6502b6d28d95n@googlegroups.com>

  copy mid

https://www.novabbs.com/computers/article-flat.php?id=22412&group=comp.os.vms#22412

  copy link   Newsgroups: comp.os.vms
X-Received: by 2002:a05:620a:472a:b0:6a0:23f0:6a64 with SMTP id bs42-20020a05620a472a00b006a023f06a64mr1663800qkb.534.1651688079672;
Wed, 04 May 2022 11:14:39 -0700 (PDT)
X-Received: by 2002:a37:a08d:0:b0:69f:ca79:fa1a with SMTP id
j135-20020a37a08d000000b0069fca79fa1amr14737349qke.739.1651688079446; Wed, 04
May 2022 11:14:39 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.os.vms
Date: Wed, 4 May 2022 11:14:39 -0700 (PDT)
In-Reply-To: <t4tt3o$4ds$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=2600:1700:46b0:abc0:3701:7875:7e47:aabc;
posting-account=OGFVHQoAAAASiNAamRQec8BtkuXxYFnQ
NNTP-Posting-Host: 2600:1700:46b0:abc0:3701:7875:7e47:aabc
References: <68cf2f4b-1eef-4f02-9b18-6304b1fab313n@googlegroups.com> <t4tt3o$4ds$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <d0fdde59-6b38-4010-adac-6502b6d28d95n@googlegroups.com>
Subject: Re: Bizarre vfork() / exec() behavior in VMS V8.4-2L1 Alpha
From: jake.ha...@gmail.com (Jake Hamby)
Injection-Date: Wed, 04 May 2022 18:14:39 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Lines: 25
 by: Jake Hamby - Wed, 4 May 2022 18:14 UTC

On Wednesday, May 4, 2022 at 5:55:23 AM UTC-7, Craig A. Berry wrote:
> You may want to look into decc$set_child_standard_streams and/or
> decc$set_child_default_dir.

I'll do that, thanks.

> As far as I know, until the exec succeeds, you don't actually have a
> child process. This is the documented behavior of vfork() on VMS, which
> is really just a set-up routine comparable to setjmp(). So it makes
> sense that exiting after a failed exec is actually exiting from the parent.

Yes, I'm aware of that, which is why the current behavior does make sense, but the problem is that the C RTL reference manual tells me specifically to call exit() or _exit() from the child in case of failure. Other vfork() man pages say _exit() is safer because it doesn't flush streams, so that's what I tried first, and I assumed there was a hook in both of those functions that would detect when it's being called by a vfork() "child" and handle it specially, because otherwise that means the C RTL reference manual is wrong and it needs to be updated to tell us what we're supposed to do in the child when the exec() fails, to return to the parent context. I'll return from the function for now, but it's not what I'm supposed to be doing according to the docs.

-Jake

Re: Bizarre vfork() / exec() behavior in VMS V8.4-2L1 Alpha

<t4umme$eig$1@dont-email.me>

  copy mid

https://www.novabbs.com/computers/article-flat.php?id=22413&group=comp.os.vms#22413

  copy link   Newsgroups: comp.os.vms
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: craigbe...@nospam.mac.com (Craig A. Berry)
Newsgroups: comp.os.vms
Subject: Re: Bizarre vfork() / exec() behavior in VMS V8.4-2L1 Alpha
Date: Wed, 4 May 2022 15:11:56 -0500
Organization: A noiseless patient Spider
Lines: 56
Message-ID: <t4umme$eig$1@dont-email.me>
References: <68cf2f4b-1eef-4f02-9b18-6304b1fab313n@googlegroups.com>
<t4tt3o$4ds$1@dont-email.me>
<d0fdde59-6b38-4010-adac-6502b6d28d95n@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 4 May 2022 20:11:58 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="58228d791233c5d66881d98c0080b00d";
logging-data="14928"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18Awrl4VRhaRV1uK8aMZflYZ/Dw8Q7ysJw="
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:91.0)
Gecko/20100101 Thunderbird/91.8.1
Cancel-Lock: sha1:WGVjCgnzs+3OEmuTwnyt2vHQY6I=
In-Reply-To: <d0fdde59-6b38-4010-adac-6502b6d28d95n@googlegroups.com>
Content-Language: en-US
 by: Craig A. Berry - Wed, 4 May 2022 20:11 UTC

On 5/4/22 1:14 PM, Jake Hamby wrote:
> On Wednesday, May 4, 2022 at 5:55:23 AM UTC-7, Craig A. Berry wrote:
>
>> As far as I know, until the exec succeeds, you don't actually have a
>> child process. This is the documented behavior of vfork() on VMS, which
>> is really just a set-up routine comparable to setjmp(). So it makes
>> sense that exiting after a failed exec is actually exiting from the parent.

> Yes, I'm aware of that, which is why the current behavior does make
> sense, but the problem is that the C RTL reference manual tells me
> specifically to call exit() or _exit() from the child in case of
> failure. Other vfork() man pages say _exit() is safer because it doesn't
> flush streams, so that's what I tried first, and I assumed there was a
> hook in both of those functions that would detect when it's being called
> by a vfork() "child" and handle it specially, because otherwise that
> means the C RTL reference manual is wrong and it needs to be updated to
> tell us what we're supposed to do in the child when the exec() fails, to
> return to the parent context. I'll return from the function for now, but
> it's not what I'm supposed to be doing according to the docs.

You're right. I hadn't noticed the docs said this, i.e., bottom of page
118 here:

https://vmssoftware.com/docs/VSI_CRTL_REF.pdf

However, in the reference section for exit(), page 307 of that manual,
it also says:

-----
Beginning with OpenVMS Version 8.3, C RTL contains a fix for the problem
in which a call to _exit after a failed execl really exits but must not.

In the OpenVMS implementation of vfork, a child process is not actually
started as it is started on most UNIX systems. However, the C RTL
creates some internal data structures intended to mimic child-process
functionality (called the "child context").

A bug occurred whereby after a vfork while in the child context, a call
to an exec function justifiably fails, then calls _exit. On UNIX
systems, after the failed exec call, the child process continues to
execute. A subsequent call to _exit terminates the child. In the OpenVMS
implementation, after the failed exec call, the child context
terminates. A subsequent call to _exit terminates the parent. The C RTL
fix is enabled by a feature logical switch, DECC$EXIT_AFTER_FAILED_EXEC.
Enabling this feature logical allows the child context to continue
execution.

With DECC$EXIT_AFTER_FAILED_EXEC disabled or not defined, the current
behavior remains the default.
----

So if you want to preserve some degree of portability, I guess you could
add DECC$EXIT_AFTER_FAILED_EXEC to your vms_crtl_init.c. Or you could
just not call exit after a failed exec.

Re: Bizarre vfork() / exec() behavior in VMS V8.4-2L1 Alpha

<b3ff515d-96f9-4065-8140-edf3cfd3df01n@googlegroups.com>

  copy mid

https://www.novabbs.com/computers/article-flat.php?id=22414&group=comp.os.vms#22414

  copy link   Newsgroups: comp.os.vms
X-Received: by 2002:a05:622a:3d3:b0:2f3:ba0b:ee5b with SMTP id k19-20020a05622a03d300b002f3ba0bee5bmr3042306qtx.365.1651718743771;
Wed, 04 May 2022 19:45:43 -0700 (PDT)
X-Received: by 2002:a05:622a:44e:b0:2f3:6941:a713 with SMTP id
o14-20020a05622a044e00b002f36941a713mr22286251qtx.146.1651718743619; Wed, 04
May 2022 19:45:43 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.os.vms
Date: Wed, 4 May 2022 19:45:43 -0700 (PDT)
In-Reply-To: <d0fdde59-6b38-4010-adac-6502b6d28d95n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=2604:2d80:f100:1600:0:0:0:2752;
posting-account=zvIpTQoAAABQJtJR1phhrQImju0wTmq2
NNTP-Posting-Host: 2604:2d80:f100:1600:0:0:0:2752
References: <68cf2f4b-1eef-4f02-9b18-6304b1fab313n@googlegroups.com>
<t4tt3o$4ds$1@dont-email.me> <d0fdde59-6b38-4010-adac-6502b6d28d95n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <b3ff515d-96f9-4065-8140-edf3cfd3df01n@googlegroups.com>
Subject: Re: Bizarre vfork() / exec() behavior in VMS V8.4-2L1 Alpha
From: roger.i...@gmail.com (Roger Ivie)
Injection-Date: Thu, 05 May 2022 02:45:43 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 7
 by: Roger Ivie - Thu, 5 May 2022 02:45 UTC

On Wednesday, May 4, 2022 at 11:14:41 AM UTC-7, jake....@gmail.com wrote:
> but the problem is that the C RTL reference manual tells me specifically to call exit() or _exit()
> from the child in case of failure.

yeah, well, the manual also says that sem_timedwait takes an absolute timeout. it doesn't.
--
roger ivie
roger.ivie@gmail.com

Re: Bizarre vfork() / exec() behavior in VMS V8.4-2L1 Alpha

<6e2ac8ed-6d69-4316-b3e2-37a5b2fd708an@googlegroups.com>

  copy mid

https://www.novabbs.com/computers/article-flat.php?id=22418&group=comp.os.vms#22418

  copy link   Newsgroups: comp.os.vms
X-Received: by 2002:a05:620a:4627:b0:69f:3328:71cc with SMTP id br39-20020a05620a462700b0069f332871ccmr167138qkb.689.1651784762708;
Thu, 05 May 2022 14:06:02 -0700 (PDT)
X-Received: by 2002:a05:622a:6114:b0:2f0:ffc8:53f8 with SMTP id
hg20-20020a05622a611400b002f0ffc853f8mr25749540qtb.681.1651784762520; Thu, 05
May 2022 14:06:02 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.os.vms
Date: Thu, 5 May 2022 14:06:02 -0700 (PDT)
In-Reply-To: <t4umme$eig$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=2600:1700:46b0:abc0:245c:a190:2a46:b4d8;
posting-account=OGFVHQoAAAASiNAamRQec8BtkuXxYFnQ
NNTP-Posting-Host: 2600:1700:46b0:abc0:245c:a190:2a46:b4d8
References: <68cf2f4b-1eef-4f02-9b18-6304b1fab313n@googlegroups.com>
<t4tt3o$4ds$1@dont-email.me> <d0fdde59-6b38-4010-adac-6502b6d28d95n@googlegroups.com>
<t4umme$eig$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <6e2ac8ed-6d69-4316-b3e2-37a5b2fd708an@googlegroups.com>
Subject: Re: Bizarre vfork() / exec() behavior in VMS V8.4-2L1 Alpha
From: jake.ha...@gmail.com (Jake Hamby)
Injection-Date: Thu, 05 May 2022 21:06:02 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 28
 by: Jake Hamby - Thu, 5 May 2022 21:06 UTC

On Wednesday, May 4, 2022 at 1:12:01 PM UTC-7, Craig A. Berry wrote:
>
> In the OpenVMS implementation of vfork, a child process is not actually
> started as it is started on most UNIX systems. However, the C RTL
> creates some internal data structures intended to mimic child-process
> functionality (called the "child context").
>
> A bug occurred whereby after a vfork while in the child context, a call
> to an exec function justifiably fails, then calls _exit. On UNIX
> systems, after the failed exec call, the child process continues to
> execute. A subsequent call to _exit terminates the child. In the OpenVMS
> implementation, after the failed exec call, the child context
> terminates. A subsequent call to _exit terminates the parent. The C RTL
> fix is enabled by a feature logical switch, DECC$EXIT_AFTER_FAILED_EXEC.
> Enabling this feature logical allows the child context to continue
> execution.
>
> With DECC$EXIT_AFTER_FAILED_EXEC disabled or not defined, the current
> behavior remains the default.
> ----
>
> So if you want to preserve some degree of portability, I guess you could
> add DECC$EXIT_AFTER_FAILED_EXEC to your vms_crtl_init.c. Or you could
> just not call exit after a failed exec.

Thanks, that's *exactly* what I was hoping to hear! I'll give it a try.

Cheers,
Jake

Re: Bizarre vfork() / exec() behavior in VMS V8.4-2L1 Alpha

<8eb81501-68b8-4f0b-aae0-d877ba62b035n@googlegroups.com>

  copy mid

https://www.novabbs.com/computers/article-flat.php?id=22474&group=comp.os.vms#22474

  copy link   Newsgroups: comp.os.vms
X-Received: by 2002:a0c:cc08:0:b0:45a:8f81:d8a8 with SMTP id r8-20020a0ccc08000000b0045a8f81d8a8mr12640421qvk.88.1652084054833;
Mon, 09 May 2022 01:14:14 -0700 (PDT)
X-Received: by 2002:a05:620a:1a07:b0:6a0:2601:6f57 with SMTP id
bk7-20020a05620a1a0700b006a026016f57mr10509259qkb.579.1652084054698; Mon, 09
May 2022 01:14:14 -0700 (PDT)
Path: i2pn2.org!i2pn.org!aioe.org!news.uzoreto.com!news-out.netnews.com!news.alt.net!fdc2.netnews.com!peer03.ams1!peer.ams1.xlned.com!news.xlned.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.os.vms
Date: Mon, 9 May 2022 01:14:14 -0700 (PDT)
In-Reply-To: <68cf2f4b-1eef-4f02-9b18-6304b1fab313n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=75.37.192.241; posting-account=gLDX1AkAAAA26M5HM-O3sVMAXdxK9FPA
NNTP-Posting-Host: 75.37.192.241
References: <68cf2f4b-1eef-4f02-9b18-6304b1fab313n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <8eb81501-68b8-4f0b-aae0-d877ba62b035n@googlegroups.com>
Subject: Re: Bizarre vfork() / exec() behavior in VMS V8.4-2L1 Alpha
From: gah...@u.washington.edu (gah4)
Injection-Date: Mon, 09 May 2022 08:14:14 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 3089
 by: gah4 - Mon, 9 May 2022 08:14 UTC

On Wednesday, May 4, 2022 at 12:19:46 AM UTC-7, jake....@gmail.com wrote:

(snip)

>
> My first issue was that vfork() doesn't preserve the file descriptors,
> unlike BSD or Linux vfork(), so I had to dup() the old stdin, stdout,
> and stderr before replacing them and calling vfork(), and then,
> in the parent path, reset everything the way it was before returning.
> That's annoying, but expected. The manual didn't say that the C RTL
> would preserve and restore the status of file descriptors that you
> dup2()'d or close()'d in the child.

From man vfork() on my system:

"vfork() can be used to create new processes without fully copying the address space of the old
process, which is horrendously inefficient in a paged environment. It is useful when the pur-
pose of fork(2) would have been to create a new system context for an execve. vfork() differs
from fork in that the child borrows the parent's memory and thread of control until a call to
execve(2) or an exit (either by a call to exit(2) or abnormally.) The parent process is sus-
pended while the child is using its resources.

vfork() returns 0 in the child's context and (later) the pid of the child in the parent's con-
text.

vfork() can normally be used just like fork. It does not work, however, to return while run-
ning in the childs context from the procedure that called vfork() since the eventual return
from vfork() would then return to a no longer existent stack frame. Be careful, also, to call
_exit rather than exit if you can't execve, since exit will flush and close standard I/O chan-
nels, and thereby mess up the parent processes standard I/O data structures. (Even with fork
it is wrong to call exit since buffered data would then be flushed twice.)"

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor