From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI autolearn=ham autolearn_force=no version=3.4.4 Received: from minnie.tuhs.org (minnie.tuhs.org [50.116.15.146]) by inbox.vuxu.org (Postfix) with ESMTP id 2288622229 for ; Mon, 13 May 2024 15:22:04 +0200 (CEST) Received: from minnie.tuhs.org (localhost [IPv6:::1]) by minnie.tuhs.org (Postfix) with ESMTP id 19B2C43658; Mon, 13 May 2024 23:22:00 +1000 (AEST) Received: from mcvoy.com (mcvoy.com [192.169.23.250]) by minnie.tuhs.org (Postfix) with ESMTPS id AE67A435E5 for ; Mon, 13 May 2024 23:21:55 +1000 (AEST) Received: by mcvoy.com (Postfix, from userid 3546) id F2A5D35E4CE; Mon, 13 May 2024 06:21:54 -0700 (PDT) Date: Mon, 13 May 2024 06:21:54 -0700 From: Larry McVoy To: Dave Horsfall Message-ID: <20240513132154.GN9216@mcvoy.com> References: <20240512194707.GL9216@mcvoy.com> <20240512201349.0DB6A8A9D055@ary.qy> <20240512233454.GM9216@mcvoy.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.24 (2015-08-30) Message-ID-Hash: DHAHQKDKM45JWOYUXUB54JEVXDP4GPI3 X-Message-ID-Hash: DHAHQKDKM45JWOYUXUB54JEVXDP4GPI3 X-MailFrom: lm@mcvoy.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: The Eunuchs Hysterical Society X-Mailman-Version: 3.3.6b1 Precedence: list Subject: [TUHS] Re: forking, Re: [COFF] Re: On Bloat and the Idea of Small Specialized Tools List-Id: The Unix Heritage Society mailing list Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: On Mon, May 13, 2024 at 11:34:38AM +1000, Dave Horsfall wrote: > On Sun, 12 May 2024, Larry McVoy wrote: > > > Our spawnvp() implmentation is 40 lines of code. Worked fine everywhere. > > I can post it if you like. > > Pretty please... > > -- Dave /* * Copyright 1999-2002,2004-2006,2015-2016 BitMover, Inc * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "system.h" void (*spawn_preHook)(int flags, char *av[]) = 0; #ifndef WIN32 pid_t bk_spawnvp(int flags, char *cmdname, char *av[]) { int fd, status; pid_t pid; char *exec; /* Tell the calling process right away if there is no such program */ unless (exec = which((char*)cmdname)) return (-1); if (spawn_preHook) spawn_preHook(flags, av); if (pid = fork()) { /* parent */ free(exec); if (pid == -1) return (pid); unless (flags & (_P_DETACH|_P_NOWAIT)) { if (waitpid(pid, &status, 0) != pid) status = -1; return (status); } return (pid); } else { /* child */ /* * See win32/uwtlib/wapi_intf.c:spawnvp_ex() * We leave nothing open on a detach, but leave * in/out/err open on a normal fork/exec. */ if (flags & _P_DETACH) { unless (getenv("_NO_SETSID")) setsid(); /* close everything to match winblows */ for (fd = 0; fd < 100; fd++) (close)(fd); } else { /* * Emulate having everything except in/out/err * as being marked as close on exec to match winblows. */ for (fd = 3; fd < 100; fd++) (close)(fd); } execv(exec, av); perror(exec); _exit(19); } } #else /* ======== WIN32 ======== */ pid_t bk_spawnvp(int flags, char *cmdname, char *av[]) { pid_t pid; char *exec; /* Tell the calling process right away if there is no such program */ unless (exec = which((char*)cmdname)) return (-1); if (spawn_preHook) spawn_preHook(flags, av); /* * We use our own version of spawn in uwtlib * because the NT spawn() does not work well with tcl */ pid = _spawnvp_ex(flags, exec, av, 1); free(exec); return (pid); } #endif /* WIN32 */