diff --git a/libc/sock/pselect.c b/libc/calls/pselect.c
similarity index 100%
rename from libc/sock/pselect.c
rename to libc/calls/pselect.c
diff --git a/libc/sock/select-nt.c b/libc/calls/select-nt.c
similarity index 100%
rename from libc/sock/select-nt.c
rename to libc/calls/select-nt.c
diff --git a/libc/sock/select.c b/libc/calls/select.c
similarity index 100%
rename from libc/sock/select.c
rename to libc/calls/select.c
diff --git a/third_party/make/BUILD.mk b/third_party/make/BUILD.mk
index 99b840a65..85c96f690 100644
--- a/third_party/make/BUILD.mk
+++ b/third_party/make/BUILD.mk
@@ -3,84 +3,20 @@
PKGS += THIRD_PARTY_MAKE
-THIRD_PARTY_MAKE_COMS = \
- o/$(MODE)/third_party/make/make.com
+THIRD_PARTY_MAKE_A = o/$(MODE)/third_party/make/make.a
+THIRD_PARTY_MAKE_FILES := $(wildcard third_party/make/*)
+THIRD_PARTY_MAKE_HDRS = $(filter %.h,$(THIRD_PARTY_MAKE_FILES))
+THIRD_PARTY_MAKE_SRCS = $(filter %.c,$(THIRD_PARTY_MAKE_FILES))
+THIRD_PARTY_MAKE_OBJS = $(THIRD_PARTY_MAKE_SRCS:%.c=o/$(MODE)/%.o)
+THIRD_PARTY_MAKE_COMS = o/$(MODE)/third_party/make/make.com
+THIRD_PARTY_MAKE_CHECKS = $(THIRD_PARTY_MAKE_A).pkg
THIRD_PARTY_MAKE_BINS = \
$(THIRD_PARTY_MAKE_COMS) \
$(THIRD_PARTY_MAKE_COMS:%=%.dbg)
-THIRD_PARTY_MAKE_A = \
- o/$(MODE)/third_party/make/make.a
-
-THIRD_PARTY_MAKE_HDRS = \
- third_party/make/concat-filename.h \
- third_party/make/commands.h \
- third_party/make/glob.h \
- third_party/make/config.h \
- third_party/make/debug.h \
- third_party/make/dep.h \
- third_party/make/findprog.h \
- third_party/make/filedef.h \
- third_party/make/filename.h \
- third_party/make/getopt.h \
- third_party/make/gettext.h \
- third_party/make/gnumake.h \
- third_party/make/hash.h \
- third_party/make/job.h \
- third_party/make/makeint.h \
- third_party/make/mkconfig.h \
- third_party/make/mkcustom.h \
- third_party/make/os.h \
- third_party/make/output.h \
- third_party/make/rule.h \
- third_party/make/shuffle.h \
- third_party/make/variable.h
-
-THIRD_PARTY_MAKE_INCS = \
- third_party/make/makeint.h
-
-THIRD_PARTY_MAKE_CHECKS = \
- $(THIRD_PARTY_MAKE_A).pkg
-
-THIRD_PARTY_MAKE_SRCS = \
- third_party/make/glob.c \
- third_party/make/commands.c \
- third_party/make/default.c \
- third_party/make/dir.c \
- third_party/make/concat-filename.c \
- third_party/make/findprog-in.c \
- third_party/make/expand.c \
- third_party/make/file.c \
- third_party/make/function.c \
- third_party/make/getopt.c \
- third_party/make/getopt1.c \
- third_party/make/guile.c \
- third_party/make/hash.c \
- third_party/make/implicit.c \
- third_party/make/job.c \
- third_party/make/load.c \
- third_party/make/loadapi.c \
- third_party/make/main.c \
- third_party/make/misc.c \
- third_party/make/output.c \
- third_party/make/posixos.c \
- third_party/make/read.c \
- third_party/make/remake.c \
- third_party/make/remote-stub.c \
- third_party/make/rule.c \
- third_party/make/strcache.c \
- third_party/make/variable.c \
- third_party/make/version.c \
- third_party/make/shuffle.c \
- third_party/make/vpath.c
-
-THIRD_PARTY_MAKE_OBJS = \
- $(THIRD_PARTY_MAKE_SRCS:%.c=o/$(MODE)/%.o)
-
THIRD_PARTY_MAKE_DIRECTDEPS = \
LIBC_CALLS \
- LIBC_ELF \
LIBC_FMT \
LIBC_INTRIN \
LIBC_LOG \
@@ -90,16 +26,10 @@ THIRD_PARTY_MAKE_DIRECTDEPS = \
LIBC_RUNTIME \
LIBC_STDIO \
LIBC_STR \
- LIBC_SOCK \
- LIBC_NT_KERNEL32 \
LIBC_SYSV \
- LIBC_SYSV_CALLS \
LIBC_TIME \
LIBC_TINYMATH \
- LIBC_X \
- THIRD_PARTY_COMPILER_RT \
- THIRD_PARTY_MUSL \
- THIRD_PARTY_GDTOA
+ THIRD_PARTY_MUSL
THIRD_PARTY_MAKE_DEPS := \
$(call uniq,$(foreach x,$(THIRD_PARTY_MAKE_DIRECTDEPS),$($(x))))
@@ -122,14 +52,6 @@ o/$(MODE)/third_party/make/make.com.dbg: \
$(APE_NO_MODIFY_SELF)
@$(APELINK)
-o/$(MODE)/third_party/make/make.com: \
- o/$(MODE)/third_party/make/make.com.dbg \
- o/$(MODE)/third_party/zip/zip.com \
- o/$(MODE)/tool/build/symtab.com
- @$(MAKE_OBJCOPY)
- @$(MAKE_SYMTAB_CREATE)
- @$(MAKE_SYMTAB_ZIP)
-
o/$(MODE)/third_party/make/strcache.o \
o/$(MODE)/third_party/make/expand.o \
o/$(MODE)/third_party/make/read.o: private \
@@ -146,6 +68,8 @@ $(THIRD_PARTY_MAKE_OBJS): private \
-DNO_ARCHIVES \
-DHAVE_CONFIG_H
+$(THIRD_PARTY_MAKE_OBJS): third_party/make/BUILD.mk
+
.PHONY: o/$(MODE)/third_party/make
o/$(MODE)/third_party/make: \
$(THIRD_PARTY_MAKE_BINS) \
diff --git a/third_party/make/ar.c b/third_party/make/ar.c
deleted file mode 100644
index 73fc09566..000000000
--- a/third_party/make/ar.c
+++ /dev/null
@@ -1,332 +0,0 @@
-/* Interface to 'ar' archives for GNU Make.
-Copyright (C) 1988-2023 Free Software Foundation, Inc.
-
-This file is part of GNU Make.
-
-GNU Make is free software; you can redistribute it and/or modify it under the
-terms of the GNU General Public License as published by the Free Software
-Foundation; either version 3 of the License, or (at your option) any later
-version.
-
-GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY
-WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
-A PARTICULAR PURPOSE. See the GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License along with
-this program. If not, see . */
-
-#include "makeint.h"
-
-#ifndef NO_ARCHIVES
-
-#include "filedef.h"
-#include "dep.h"
-#include
-#include
-
-/* Return nonzero if NAME is an archive-member reference, zero if not. An
- archive-member reference is a name like 'lib(member)' where member is a
- non-empty string.
- If a name like 'lib((entry))' is used, a fatal error is signaled at
- the attempt to use this unsupported feature. */
-
-int
-ar_name (const char *name)
-{
- const char *p = strchr (name, '(');
- const char *end;
-
- if (p == NULL || p == name)
- return 0;
-
- end = p + strlen (p) - 1;
- if (*end != ')' || end == p + 1)
- return 0;
-
- if (p[1] == '(' && end[-1] == ')')
- OS (fatal, NILF, _("attempt to use unsupported feature: '%s'"), name);
-
- return 1;
-}
-
-
-/* Parse the archive-member reference NAME into the archive and member names.
- Creates one allocated string containing both names, pointed to by ARNAME_P.
- MEMNAME_P points to the member. */
-
-void
-ar_parse_name (const char *name, char **arname_p, char **memname_p)
-{
- char *p;
-
- *arname_p = xstrdup (name);
- p = strchr (*arname_p, '(');
- /* This is never called unless ar_name() is true so p cannot be NULL. */
- if (!p)
- OS (fatal, NILF, "Internal: ar_parse_name: bad name '%s'", *arname_p);
- *(p++) = '\0';
- p[strlen (p) - 1] = '\0';
- *memname_p = p;
-}
-
-
-/* This function is called by 'ar_scan' to find which member to look at. */
-
-/* ARGSUSED */
-static intmax_t
-ar_member_date_1 (int desc UNUSED, const char *mem, int truncated,
- long int hdrpos UNUSED, long int datapos UNUSED,
- long int size UNUSED, intmax_t date,
- int uid UNUSED, int gid UNUSED, unsigned int mode UNUSED,
- const void *name)
-{
- return ar_name_equal (name, mem, truncated) ? date : 0;
-}
-
-/* Return the modtime of NAME. */
-
-time_t
-ar_member_date (const char *name)
-{
- char *arname;
- char *memname;
- intmax_t val;
-
- ar_parse_name (name, &arname, &memname);
-
- /* Make sure we know the modtime of the archive itself because we are
- likely to be called just before commands to remake a member are run,
- and they will change the archive itself.
-
- But we must be careful not to enter_file the archive itself if it does
- not exist, because pattern_search assumes that files found in the data
- base exist or can be made. */
- {
- struct file *arfile;
- arfile = lookup_file (arname);
- if (arfile == 0 && file_exists_p (arname))
- arfile = enter_file (strcache_add (arname));
-
- if (arfile != 0)
- (void) f_mtime (arfile, 0);
- }
-
- val = ar_scan (arname, ar_member_date_1, memname);
-
- free (arname);
-
- return 0 < val && val <= TYPE_MAXIMUM (time_t) ? val : -1;
-}
-
-/* Set the archive-member NAME's modtime to now. */
-
-#ifdef VMS
-int
-ar_touch (const char *name)
-{
- O (error, NILF, _("touch archive member is not available on VMS"));
- return -1;
-}
-#else
-int
-ar_touch (const char *name)
-{
- char *arname, *memname;
- int val;
-
- ar_parse_name (name, &arname, &memname);
-
- /* Make sure we know the modtime of the archive itself before we
- touch the member, since this will change the archive modtime. */
- {
- struct file *arfile;
- arfile = enter_file (strcache_add (arname));
- f_mtime (arfile, 0);
- }
-
- val = 1;
- switch (ar_member_touch (arname, memname))
- {
- case -1:
- OS (error, NILF, _("touch: Archive '%s' does not exist"), arname);
- break;
- case -2:
- OS (error, NILF, _("touch: '%s' is not a valid archive"), arname);
- break;
- case -3:
- perror_with_name ("touch: ", arname);
- break;
- case 1:
- OSS (error, NILF,
- _("touch: Member '%s' does not exist in '%s'"), memname, arname);
- break;
- case 0:
- val = 0;
- break;
- default:
- OS (error, NILF,
- _("touch: Bad return code from ar_member_touch on '%s'"), name);
- }
-
- free (arname);
-
- return val;
-}
-#endif /* !VMS */
-
-/* State of an 'ar_glob' run, passed to 'ar_glob_match'. */
-
-/* On VMS, (object) modules in libraries do not have suffixes. That is, to
- find a match for a pattern, the pattern must not have any suffix. So the
- suffix of the pattern is saved and the pattern is stripped (ar_glob).
- If there is a match and the match, which is a module name, is added to
- the chain, the saved suffix is added back to construct a source filename
- (ar_glob_match). */
-
-struct ar_glob_state
- {
- const char *arname;
- const char *pattern;
-#ifdef VMS
- char *suffix;
-#endif
- size_t size;
- struct nameseq *chain;
- unsigned int n;
- };
-
-/* This function is called by 'ar_scan' to match one archive
- element against the pattern in STATE. */
-
-static intmax_t
-ar_glob_match (int desc UNUSED, const char *mem, int truncated UNUSED,
- long int hdrpos UNUSED, long int datapos UNUSED,
- long int size UNUSED, intmax_t date UNUSED, int uid UNUSED,
- int gid UNUSED, unsigned int mode UNUSED, const void *arg)
-{
- struct ar_glob_state *state = (struct ar_glob_state *)arg;
-
- if (fnmatch (state->pattern, mem, FNM_PATHNAME|FNM_PERIOD) == 0)
- {
- /* We have a match. Add it to the chain. */
- struct nameseq *new = xcalloc (state->size);
-#ifdef VMS
- if (state->suffix)
- new->name = strcache_add(
- concat(5, state->arname, "(", mem, state->suffix, ")"));
- else
-#endif
- new->name = strcache_add(concat(4, state->arname, "(", mem, ")"));
- new->next = state->chain;
- state->chain = new;
- ++state->n;
- }
-
- return 0;
-}
-
-/* Return nonzero if PATTERN contains any metacharacters.
- Metacharacters can be quoted with backslashes if QUOTE is nonzero. */
-static int
-ar_glob_pattern_p (const char *pattern, int quote)
-{
- const char *p;
- int opened = 0;
-
- for (p = pattern; *p != '\0'; ++p)
- switch (*p)
- {
- case '?':
- case '*':
- return 1;
-
- case '\\':
- if (quote)
- ++p;
- break;
-
- case '[':
- opened = 1;
- break;
-
- case ']':
- if (opened)
- return 1;
- break;
- }
-
- return 0;
-}
-
-/* Glob for MEMBER_PATTERN in archive ARNAME.
- Return a malloc'd chain of matching elements (or nil if none). */
-
-struct nameseq *
-ar_glob (const char *arname, const char *member_pattern, size_t size)
-{
- struct ar_glob_state state;
- struct nameseq *n;
- const char **names;
- unsigned int i;
-#ifdef VMS
- char *vms_member_pattern;
-#endif
- if (! ar_glob_pattern_p (member_pattern, 1))
- return 0;
-
- /* Scan the archive for matches.
- ar_glob_match will accumulate them in STATE.chain. */
- state.arname = arname;
- state.pattern = member_pattern;
-#ifdef VMS
- {
- /* In a copy of the pattern, find the suffix, save it and remove it from
- the pattern */
- char *lastdot;
- vms_member_pattern = xstrdup(member_pattern);
- lastdot = strrchr(vms_member_pattern, '.');
- state.suffix = lastdot;
- if (lastdot)
- {
- state.suffix = xstrdup(lastdot);
- *lastdot = 0;
- }
- state.pattern = vms_member_pattern;
- }
-#endif
- state.size = size;
- state.chain = 0;
- state.n = 0;
- ar_scan (arname, ar_glob_match, &state);
-
-#ifdef VMS
- /* Deallocate any duplicated string */
- free(vms_member_pattern);
- if (state.suffix)
- {
- free(state.suffix);
- }
-#endif
-
- if (state.chain == 0)
- return 0;
-
- /* Now put the names into a vector for sorting. */
- names = alloca (state.n * sizeof (const char *));
- i = 0;
- for (n = state.chain; n != 0; n = n->next)
- names[i++] = n->name;
-
- /* Sort them alphabetically. */
- /* MSVC erroneously warns without a cast here. */
- qsort ((void *)names, i, sizeof (*names), alpha_compare);
-
- /* Put them back into the chain in the sorted order. */
- i = 0;
- for (n = state.chain; n != 0; n = n->next)
- n->name = names[i++];
-
- return state.chain;
-}
-
-#endif /* Not NO_ARCHIVES. */
diff --git a/third_party/make/arscan.c b/third_party/make/arscan.c
deleted file mode 100644
index edd4070c3..000000000
--- a/third_party/make/arscan.c
+++ /dev/null
@@ -1,1013 +0,0 @@
-/* Library function for scanning an archive file.
-Copyright (C) 1987-2023 Free Software Foundation, Inc.
-This file is part of GNU Make.
-
-GNU Make is free software; you can redistribute it and/or modify it under the
-terms of the GNU General Public License as published by the Free Software
-Foundation; either version 3 of the License, or (at your option) any later
-version.
-
-GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY
-WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
-A PARTICULAR PURPOSE. See the GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License along with
-this program. If not, see . */
-
-#include "makeint.h"
-
-#ifdef TEST
-/* Hack, the real error() routine eventually pulls in die from main.c */
-#define error(a, b, c, d)
-#endif
-
-#ifdef HAVE_FCNTL_H
-#include
-#else
-#include
-#endif
-
-#ifndef NO_ARCHIVES
-
-#ifdef VMS
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-
-/* This symbol should be present in lbrdef.h. */
-#if !defined LBR$_HDRTRUNC
-#pragma extern_model save
-#pragma extern_model globalvalue
-extern unsigned int LBR$_HDRTRUNC;
-#pragma extern_model restore
-#endif
-
-#include
-#include
-
-const char *
-vmsify (const char *name, int type);
-
-/* Time conversion from VMS to Unix
- Conversion from local time (stored in library) to GMT (needed for gmake)
- Note: The tm_gmtoff element is a VMS extension to the ANSI standard. */
-static time_t
-vms_time_to_unix(void *vms_time)
-{
- struct tm *tmp;
- time_t unix_time;
-
- unix_time = decc$fix_time(vms_time);
- tmp = localtime(&unix_time);
- unix_time -= tmp->tm_gmtoff;
-
- return unix_time;
-}
-
-
-/* VMS library routines need static variables for callback */
-static void *VMS_lib_idx;
-
-static const void *VMS_saved_arg;
-
-static intmax_t (*VMS_function) ();
-
-static intmax_t VMS_function_ret;
-
-
-/* This is a callback procedure for lib$get_index */
-static int
-VMS_get_member_info(struct dsc$descriptor_s *module, unsigned long *rfa)
-{
- int status, i;
- const int truncated = 0; /* Member name may be truncated */
- time_t member_date; /* Member date */
- char *filename;
- unsigned int buffer_length; /* Actual buffer length */
-
- /* Unused constants - Make does not actually use most of these */
- const int file_desc = -1; /* archive file descriptor for reading the data */
- const int header_position = 0; /* Header position */
- const int data_position = 0; /* Data position in file */
- const int data_size = 0; /* Data size */
- const int uid = 0; /* member gid */
- const int gid = 0; /* member gid */
- const int mode = 0; /* member protection mode */
- /* End of unused constants */
-
- static struct dsc$descriptor_s bufdesc =
- { 0, DSC$K_DTYPE_T, DSC$K_CLASS_S, NULL };
-
- /* Only need the module definition */
- struct mhddef *mhd;
-
- /* If a previous callback is non-zero, just return that status */
- if (VMS_function_ret)
- {
- return SS$_NORMAL;
- }
-
- /* lbr_set_module returns more than just the module header. So allocate
- a buffer which is big enough: the maximum LBR$C_MAXHDRSIZ. That's at
- least bigger than the size of struct mhddef.
- If the request is too small, a buffer truncated warning is issued so
- it can be reissued with a larger buffer.
- We do not care if the buffer is truncated, so that is still a success. */
- mhd = xmalloc(LBR$C_MAXHDRSIZ);
- bufdesc.dsc$a_pointer = (char *) mhd;
- bufdesc.dsc$w_length = LBR$C_MAXHDRSIZ;
-
- status = lbr$set_module(&VMS_lib_idx, rfa, &bufdesc, &buffer_length, 0);
-
- if ((status != LBR$_HDRTRUNC) && !$VMS_STATUS_SUCCESS(status))
- {
- ON(error, NILF,
- _("lbr$set_module() failed to extract module info, status = %d"),
- status);
-
- lbr$close(&VMS_lib_idx);
-
- return status;
- }
-
-#ifdef TEST
- /* When testing this code, it is useful to know the length returned */
- printf ("Input length = %d, actual = %u\n",
- bufdesc.dsc$w_length, buffer_length);
-#endif
-
- /* Conversion from VMS time to C time.
- VMS defectlet - mhddef is sub-optimal, for the time, it has a 32 bit
- longword, mhd$l_datim, and a 32 bit fill instead of two longwords, or
- equivalent. */
- member_date = vms_time_to_unix(&mhd->mhd$l_datim);
- free(mhd);
-
- /* Here we have a problem. The module name on VMS does not have
- a file type, but the filename pattern in the "VMS_saved_arg"
- may have one.
- But only the method being called knows how to interpret the
- filename pattern.
- There are currently two different formats being used.
- This means that we need a VMS specific code in those methods
- to handle it. */
- filename = xmalloc(module->dsc$w_length + 1);
-
- /* TODO: We may need an option to preserve the case of the module
- For now force the module name to lower case */
- for (i = 0; i < module->dsc$w_length; i++)
- filename[i] = _tolower((unsigned char )module->dsc$a_pointer[i]);
-
- filename[i] = '\0';
-
- VMS_function_ret = (*VMS_function)(file_desc, filename, truncated,
- header_position, data_position, data_size, member_date, uid, gid, mode,
- VMS_saved_arg);
-
- free(filename);
- return SS$_NORMAL;
-}
-
-
-/* Takes three arguments ARCHIVE, FUNCTION and ARG.
-
- Open the archive named ARCHIVE, find its members one by one,
- and for each one call FUNCTION with the following arguments:
- archive file descriptor for reading the data,
- member name,
- member name might be truncated flag,
- member header position in file,
- member data position in file,
- member data size,
- member date,
- member uid,
- member gid,
- member protection mode,
- ARG.
-
- NOTE: on VMS systems, only name, date, and arg are meaningful!
-
- The descriptor is poised to read the data of the member
- when FUNCTION is called. It does not matter how much
- data FUNCTION reads.
-
- If FUNCTION returns nonzero, we immediately return
- what FUNCTION returned.
-
- Returns -1 if archive does not exist,
- Returns -2 if archive has invalid format.
- Returns 0 if have scanned successfully. */
-
-intmax_t
-ar_scan (const char *archive, ar_member_func_t function, const void *varg)
-{
- char *vms_archive;
-
- static struct dsc$descriptor_s libdesc =
- { 0, DSC$K_DTYPE_T, DSC$K_CLASS_S, NULL };
-
- const unsigned long func = LBR$C_READ;
- const unsigned long type = LBR$C_TYP_UNK;
- const unsigned long index = 1;
- unsigned long lib_idx;
- int status;
-
- VMS_saved_arg = varg;
-
- /* Null archive string can show up in test and cause an access violation */
- if (archive == NULL)
- {
- /* Null filenames do not exist */
- return -1;
- }
-
- /* archive path name must be in VMS format */
- vms_archive = (char *) vmsify(archive, 0);
-
- status = lbr$ini_control(&VMS_lib_idx, &func, &type, 0);
-
- if (!$VMS_STATUS_SUCCESS(status))
- {
- ON(error, NILF, _("lbr$ini_control() failed with status = %d"), status);
- return -2;
- }
-
- libdesc.dsc$a_pointer = vms_archive;
- libdesc.dsc$w_length = strlen(vms_archive);
-
- status = lbr$open(&VMS_lib_idx, &libdesc, 0, NULL, 0, NULL, 0);
-
- if (!$VMS_STATUS_SUCCESS(status))
- {
-
- /* TODO: A library format failure could mean that this is a file
- generated by the GNU AR utility and in that case, we need to
- take the UNIX codepath. This will also take a change to the
- GNV AR wrapper program. */
-
- switch (status)
- {
- case RMS$_FNF:
- /* Archive does not exist */
- return -1;
- default:
-#ifndef TEST
- OSN(error, NILF,
- _("unable to open library '%s' to lookup member status %d"),
- archive, status);
-#endif
- /* For library format errors, specification says to return -2 */
- return -2;
- }
- }
-
- VMS_function = function;
-
- /* Clear the return status, as we are supposed to stop calling the
- callback function if it becomes non-zero, and this is a static
- variable. */
- VMS_function_ret = 0;
-
- status = lbr$get_index(&VMS_lib_idx, &index, VMS_get_member_info, NULL, 0);
-
- lbr$close(&VMS_lib_idx);
-
- /* Unless a failure occurred in the lbr$ routines, return the
- the status from the 'function' routine. */
- if ($VMS_STATUS_SUCCESS(status))
- {
- return VMS_function_ret;
- }
-
- /* This must be something wrong with the library and an error
- message should already have been printed. */
- return -2;
-}
-
-#else /* !VMS */
-
-/* SCO Unix's compiler defines both of these. */
-#ifdef M_UNIX
-#undef M_XENIX
-#endif
-
-/* On the sun386i and in System V rel 3, ar.h defines two different archive
- formats depending upon whether you have defined PORTAR (normal) or PORT5AR
- (System V Release 1). There is no default, one or the other must be defined
- to have a nonzero value. */
-
-#if (!defined (PORTAR) || PORTAR == 0) && (!defined (PORT5AR) || PORT5AR == 0)
-#undef PORTAR
-#ifdef M_XENIX
-/* According to Jim Sievert , for SCO XENIX defining
- PORTAR to 1 gets the wrong archive format, and defining it to 0 gets the
- right one. */
-#define PORTAR 0
-#else
-#define PORTAR 1
-#endif
-#endif
-
-/* On AIX, define these symbols to be sure to get both archive formats.
- AIX 4.3 introduced the "big" archive format to support 64-bit object
- files, so on AIX 4.3 systems we need to support both the "normal" and
- "big" archive formats. An archive's format is indicated in the
- "fl_magic" field of the "FL_HDR" structure. For a normal archive,
- this field will be the string defined by the AIAMAG symbol. For a
- "big" archive, it will be the string defined by the AIAMAGBIG symbol
- (at least on AIX it works this way).
-
- Note: we'll define these symbols regardless of which AIX version
- we're compiling on, but this is okay since we'll use the new symbols
- only if they're present. */
-#ifdef _AIX
-# define __AR_SMALL__
-# define __AR_BIG__
-#endif
-
-#ifndef WINDOWS32
-# if !defined (__ANDROID__) && !defined (__BEOS__) && !defined(MK_OS_ZOS)
-# include
-# else
- /* These platforms don't have but have archives in the same format
- * as many other Unices. This was taken from GNU binutils for BeOS.
- */
-# define ARMAG "!\n" /* String that begins an archive file. */
-# define SARMAG 8 /* Size of that string. */
-# define ARFMAG "`\n" /* String in ar_fmag at end of each header. */
-struct ar_hdr
- {
- char ar_name[16]; /* Member file name, sometimes / terminated. */
- char ar_date[12]; /* File date, decimal seconds since Epoch. */
- char ar_uid[6], ar_gid[6]; /* User and group IDs, in ASCII decimal. */
- char ar_mode[8]; /* File mode, in ASCII octal. */
- char ar_size[10]; /* File size, in ASCII decimal. */
- char ar_fmag[2]; /* Always contains ARFMAG. */
- };
-# endif
-# define TOCHAR(_m) (_m)
-#else
-/* These should allow us to read Windows (VC++) libraries (according to Frank
- * Libbrecht )
- */
-# include
-# include
-# include
-# define ARMAG IMAGE_ARCHIVE_START
-# define SARMAG IMAGE_ARCHIVE_START_SIZE
-# define ar_hdr _IMAGE_ARCHIVE_MEMBER_HEADER
-# define ar_name Name
-# define ar_mode Mode
-# define ar_size Size
-# define ar_date Date
-# define ar_uid UserID
-# define ar_gid GroupID
-/* In Windows the member names have type BYTE so we must cast them. */
-# define TOCHAR(_m) ((char *)(_m))
-#endif
-
-/* Cray's apparently defines this. */
-#ifndef AR_HDR_SIZE
-# define AR_HDR_SIZE (sizeof (struct ar_hdr))
-#endif
-
-#include "intprops.h"
-
-#include "output.h"
-
-
-static uintmax_t
-parse_int (const char *ptr, const size_t len, const int base, uintmax_t max,
- const char *type, const char *archive, const char *name)
-{
- const char *const ep = ptr + len;
- const int maxchar = '0' + base - 1;
- uintmax_t val = 0;
-
- /* In all the versions I know of the spaces come last, but be safe. */
- while (ptr < ep && *ptr == ' ')
- ++ptr;
-
- while (ptr < ep && *ptr != ' ')
- {
- uintmax_t nv;
-
- if (*ptr < '0' || *ptr > maxchar)
- OSSS (fatal, NILF,
- _("Invalid %s for archive %s member %s"), type, archive, name);
- nv = (val * base) + (*ptr - '0');
- if (nv < val || nv > max)
- OSSS (fatal, NILF,
- _("Invalid %s for archive %s member %s"), type, archive, name);
- val = nv;
- ++ptr;
- }
-
- return val;
-}
-
-/* Takes three arguments ARCHIVE, FUNCTION and ARG.
-
- Open the archive named ARCHIVE, find its members one by one,
- and for each one call FUNCTION with the following arguments:
- archive file descriptor for reading the data,
- member name,
- member name might be truncated flag,
- member header position in file,
- member data position in file,
- member data size,
- member date,
- member uid,
- member gid,
- member protection mode,
- ARG.
-
- The descriptor is poised to read the data of the member
- when FUNCTION is called. It does not matter how much
- data FUNCTION reads.
-
- If FUNCTION returns nonzero, we immediately return
- what FUNCTION returned.
-
- Returns -1 if archive does not exist,
- Returns -2 if archive has invalid format.
- Returns 0 if have scanned successfully. */
-
-intmax_t
-ar_scan (const char *archive, ar_member_func_t function, const void *arg)
-{
-#ifdef AIAMAG
- FL_HDR fl_header;
-# ifdef AIAMAGBIG
- int big_archive = 0;
- FL_HDR_BIG fl_header_big;
-# endif
-#endif
- char *namemap = 0;
- unsigned int namemap_size = 0;
- int desc = open (archive, O_RDONLY, 0);
- if (desc < 0)
- return -1;
-
-#ifdef SARMAG
- {
- char buf[SARMAG];
- int nread;
- nread = readbuf (desc, buf, SARMAG);
- if (nread != SARMAG || memcmp (buf, ARMAG, SARMAG))
- goto invalid;
- }
-#else
-#ifdef AIAMAG
- {
- int nread;
- nread = readbuf (desc, &fl_header, FL_HSZ);
- if (nread != FL_HSZ)
- goto invalid;
-
-#ifdef AIAMAGBIG
- /* If this is a "big" archive, then set the flag and
- re-read the header into the "big" structure. */
- if (!memcmp (fl_header.fl_magic, AIAMAGBIG, SAIAMAG))
- {
- off_t o;
-
- big_archive = 1;
-
- /* seek back to beginning of archive */
- EINTRLOOP (o, lseek (desc, 0, 0));
- if (o < 0)
- goto invalid;
-
- /* re-read the header into the "big" structure */
- nread = readbuf (desc, &fl_header_big, FL_HSZ_BIG);
- if (nread != FL_HSZ_BIG)
- goto invalid;
- }
- else
-#endif
- /* Check to make sure this is a "normal" archive. */
- if (memcmp (fl_header.fl_magic, AIAMAG, SAIAMAG))
- goto invalid;
- }
-#else
- {
-#ifndef M_XENIX
- int buf;
-#else
- unsigned short int buf;
-#endif
- int nread;
- nread = readbuf (desc, &buf, sizeof (buf));
- if (nread != sizeof (buf) || buf != ARMAG)
- goto invalid;
- }
-#endif
-#endif
-
- /* Now find the members one by one. */
- {
-#ifdef SARMAG
- long int member_offset = SARMAG;
-#else
-#ifdef AIAMAG
- long int member_offset;
- long int last_member_offset;
-
-#ifdef AIAMAGBIG
- if ( big_archive )
- {
- sscanf (fl_header_big.fl_fstmoff, "%20ld", &member_offset);
- sscanf (fl_header_big.fl_lstmoff, "%20ld", &last_member_offset);
- }
- else
-#endif
- {
- sscanf (fl_header.fl_fstmoff, "%12ld", &member_offset);
- sscanf (fl_header.fl_lstmoff, "%12ld", &last_member_offset);
- }
-
- if (member_offset == 0)
- {
- /* Empty archive. */
- close (desc);
- return 0;
- }
-#else
-#ifndef M_XENIX
- long int member_offset = sizeof (int);
-#else /* Xenix. */
- long int member_offset = sizeof (unsigned short int);
-#endif /* Not Xenix. */
-#endif
-#endif
-
- while (1)
- {
- ssize_t nread;
- struct ar_hdr member_header;
-#ifdef AIAMAGBIG
- struct ar_hdr_big member_header_big;
-#endif
-#ifdef AIAMAG
-# define ARNAME_MAX 255
- char name[ARNAME_MAX + 1];
- int name_len;
- intmax_t dateval;
- int uidval, gidval;
- long int data_offset;
-#else
-# define ARNAME_MAX (int)sizeof(member_header.ar_name)
- char namebuf[ARNAME_MAX + 1];
- char *name;
- int is_namemap; /* Nonzero if this entry maps long names. */
- int long_name = 0;
-#endif
- long int eltsize;
- unsigned int eltmode;
- intmax_t eltdate;
- int eltuid, eltgid;
- intmax_t fnval;
- off_t o;
-
- memset(&member_header, '\0', sizeof (member_header));
-
- EINTRLOOP (o, lseek (desc, member_offset, 0));
- if (o < 0)
- goto invalid;
-
-#ifdef AIAMAG
-#define AR_MEMHDR_SZ(x) (sizeof(x) - sizeof (x._ar_name))
-
-#ifdef AIAMAGBIG
- if (big_archive)
- {
- nread = readbuf (desc, &member_header_big,
- AR_MEMHDR_SZ(member_header_big));
-
- if (nread != AR_MEMHDR_SZ(member_header_big))
- goto invalid;
-
- sscanf (member_header_big.ar_namlen, "%4d", &name_len);
- if (name_len < 1 || name_len > ARNAME_MAX)
- goto invalid;
-
- nread = readbuf (desc, name, name_len);
- if (nread != name_len)
- goto invalid;
-
- name[name_len] = '\0';
-
- sscanf (member_header_big.ar_date, "%12" SCNdMAX, &dateval);
- sscanf (member_header_big.ar_uid, "%12d", &uidval);
- sscanf (member_header_big.ar_gid, "%12d", &gidval);
- sscanf (member_header_big.ar_mode, "%12o", &eltmode);
- sscanf (member_header_big.ar_size, "%20ld", &eltsize);
-
- data_offset = (member_offset + AR_MEMHDR_SZ(member_header_big)
- + name_len + 2);
- }
- else
-#endif
- {
- nread = readbuf (desc, &member_header,
- AR_MEMHDR_SZ(member_header));
-
- if (nread != AR_MEMHDR_SZ(member_header))
- goto invalid;
-
- sscanf (member_header.ar_namlen, "%4d", &name_len);
- if (name_len < 1 || name_len > ARNAME_MAX)
- goto invalid;
-
- nread = readbuf (desc, name, name_len);
- if (nread != name_len)
- goto invalid;
-
- name[name_len] = '\0';
-
- sscanf (member_header.ar_date, "%12" SCNdMAX, &dateval);
- sscanf (member_header.ar_uid, "%12d", &uidval);
- sscanf (member_header.ar_gid, "%12d", &gidval);
- sscanf (member_header.ar_mode, "%12o", &eltmode);
- sscanf (member_header.ar_size, "%12ld", &eltsize);
-
- data_offset = (member_offset + AR_MEMHDR_SZ(member_header)
- + name_len + 2);
- }
- data_offset += data_offset % 2;
-
- fnval =
- (*function) (desc, name, 0,
- member_offset, data_offset, eltsize,
- dateval, uidval, gidval,
- eltmode, arg);
-
-#else /* Not AIAMAG. */
- nread = readbuf (desc, &member_header, AR_HDR_SIZE);
- if (nread == 0)
- /* No data left means end of file; that is OK. */
- break;
-
- if (nread != AR_HDR_SIZE
-#if defined(ARFMAG) || defined(ARFZMAG)
- || (
-# ifdef ARFMAG
- memcmp (member_header.ar_fmag, ARFMAG, 2)
-# else
- 1
-# endif
- &&
-# ifdef ARFZMAG
- memcmp (member_header.ar_fmag, ARFZMAG, 2)
-# else
- 1
-# endif
- )
-#endif
- )
- goto invalid;
-
- name = namebuf;
- memcpy (name, member_header.ar_name, sizeof member_header.ar_name);
- {
- char *p = name + sizeof member_header.ar_name;
- do
- *p = '\0';
- while (p > name && *--p == ' ');
-
-#ifndef AIAMAG
- /* If the member name is "//" or "ARFILENAMES/" this may be
- a list of file name mappings. The maximum file name
- length supported by the standard archive format is 14
- characters. This member will actually always be the
- first or second entry in the archive, but we don't check
- that. */
- is_namemap = (!strcmp (name, "//")
- || !strcmp (name, "ARFILENAMES/"));
-#endif /* Not AIAMAG. */
-
- /* On some systems, there is a slash after each member name. */
- if (*p == '/')
- *p = '\0';
-
-#ifndef AIAMAG
- /* If the member name starts with a space or a slash, this
- is an index into the file name mappings (used by GNU ar).
- Otherwise if the member name looks like #1/NUMBER the
- real member name appears in the element data (used by
- 4.4BSD). */
- if (! is_namemap
- && (name[0] == ' ' || name[0] == '/')
- && namemap != 0)
- {
- const char* err;
- unsigned int name_off = make_toui (name + 1, &err);
- size_t name_len;
-
- if (err|| name_off >= namemap_size)
- goto invalid;
-
- name = namemap + name_off;
- name_len = strlen (name);
- if (name_len < 1)
- goto invalid;
- long_name = 1;
- }
- else if (name[0] == '#'
- && name[1] == '1'
- && name[2] == '/')
- {
- const char* err;
- unsigned int name_len = make_toui (name + 3, &err);
-
- if (err || name_len == 0 || name_len >= MIN (PATH_MAX, INT_MAX))
- goto invalid;
-
- name = alloca (name_len + 1);
- nread = readbuf (desc, name, name_len);
- if (nread < 0 || (unsigned int) nread != name_len)
- goto invalid;
-
- name[name_len] = '\0';
-
- long_name = 1;
- }
-#endif /* Not AIAMAG. */
- }
-
-#ifndef M_XENIX
-#define PARSE_INT(_m, _t, _b, _n) \
- (_t) parse_int (TOCHAR (member_header._m), sizeof (member_header._m), \
- _b, TYPE_MAXIMUM (_t), _n, archive, name)
-
- eltmode = PARSE_INT (ar_mode, unsigned int, 8, "mode");
- eltsize = PARSE_INT (ar_size, long, 10, "size");
- eltdate = PARSE_INT (ar_date, intmax_t, 10, "date");
- eltuid = PARSE_INT (ar_uid, int, 10, "uid");
- eltgid = PARSE_INT (ar_gid, int, 10, "gid");
-#undef PARSE_INT
-#else /* Xenix. */
- eltmode = (unsigned short int) member_header.ar_mode;
- eltsize = member_header.ar_size;
-#endif /* Not Xenix. */
-
- fnval =
- (*function) (desc, name, ! long_name, member_offset,
- member_offset + AR_HDR_SIZE, eltsize,
-#ifndef M_XENIX
- eltdate, eltuid, eltgid,
-#else /* Xenix. */
- member_header.ar_date,
- member_header.ar_uid,
- member_header.ar_gid,
-#endif /* Not Xenix. */
- eltmode, arg);
-
-#endif /* AIAMAG. */
-
- if (fnval)
- {
- (void) close (desc);
- return fnval;
- }
-
-#ifdef AIAMAG
- if (member_offset == last_member_offset)
- /* End of the chain. */
- break;
-
-#ifdef AIAMAGBIG
- if (big_archive)
- sscanf (member_header_big.ar_nxtmem, "%20ld", &member_offset);
- else
-#endif
- sscanf (member_header.ar_nxtmem, "%12ld", &member_offset);
-
- if (lseek (desc, member_offset, 0) != member_offset)
- goto invalid;
-#else
-
- /* If this member maps archive names, we must read it in. The
- name map will always precede any members whose names must
- be mapped. */
- if (is_namemap)
- {
- char *clear;
- char *limit;
-
- if (eltsize > INT_MAX)
- goto invalid;
- namemap = alloca (eltsize + 1);
- nread = readbuf (desc, namemap, eltsize);
- if (nread != eltsize)
- goto invalid;
- namemap_size = eltsize;
-
- /* The names are separated by newlines. Some formats have
- a trailing slash. Null terminate the strings for
- convenience. */
- limit = namemap + eltsize;
- for (clear = namemap; clear < limit; clear++)
- {
- if (*clear == '\n')
- {
- *clear = '\0';
- if (clear[-1] == '/')
- clear[-1] = '\0';
- }
- }
- *limit = '\0';
-
- is_namemap = 0;
- }
-
- member_offset += AR_HDR_SIZE + eltsize;
- if (member_offset % 2 != 0)
- member_offset++;
-#endif
- }
- }
-
- close (desc);
- return 0;
-
- invalid:
- close (desc);
- return -2;
-}
-#endif /* !VMS */
-
-/* Return nonzero iff NAME matches MEM.
- If TRUNCATED is nonzero, MEM may be truncated to
- sizeof (struct ar_hdr.ar_name) - 1. */
-
-int
-ar_name_equal (const char *name, const char *mem, int truncated)
-{
- const char *p;
-
- p = strrchr (name, '/');
- if (p != 0)
- name = p + 1;
-
-#ifndef VMS
- if (truncated)
- {
-#ifdef AIAMAG
- /* TRUNCATED should never be set on this system. */
- abort ();
-#else
- struct ar_hdr hdr;
-#if !defined (__hpux) && !defined (cray)
- return strneq (name, mem, sizeof (hdr.ar_name) - 1);
-#else
- return strneq (name, mem, sizeof (hdr.ar_name) - 2);
-#endif /* !__hpux && !cray */
-#endif /* !AIAMAG */
- }
-
- return !strcmp (name, mem);
-#else
- /* VMS members do not have suffixes, but the filenames usually
- have.
- Do we need to strip VMS disk/directory format paths?
-
- Most VMS compilers etc. by default are case insensitive
- but produce uppercase external names, incl. module names.
- However the VMS librarian (ar) and the linker by default
- are case sensitive: they take what they get, usually
- uppercase names. So for the non-default settings of the
- compilers etc. there is a need to have a case sensitive
- mode. */
- {
- int len;
- len = strlen(mem);
- int match;
- char *dot;
- if ((dot=strrchr(name,'.')))
- match = (len == dot - name) && !strncasecmp(name, mem, len);
- else
- match = !strcasecmp (name, mem);
- return match;
- }
-#endif /* !VMS */
-}
-
-#ifndef VMS
-/* ARGSUSED */
-static intmax_t
-ar_member_pos (int desc UNUSED, const char *mem, int truncated,
- long int hdrpos, long int datapos UNUSED, long int size UNUSED,
- intmax_t date UNUSED, int uid UNUSED, int gid UNUSED,
- unsigned int mode UNUSED, const void *name)
-{
- if (!ar_name_equal (name, mem, truncated))
- return 0;
- return hdrpos;
-}
-
-/* Set date of member MEMNAME in archive ARNAME to current time.
- Returns 0 if successful,
- -1 if file ARNAME does not exist,
- -2 if not a valid archive,
- -3 if other random system call error (including file read-only),
- 1 if valid but member MEMNAME does not exist. */
-
-int
-ar_member_touch (const char *arname, const char *memname)
-{
- intmax_t pos = ar_scan (arname, ar_member_pos, memname);
- off_t opos;
- int fd;
- struct ar_hdr ar_hdr;
- off_t o;
- int r;
- int datelen;
- struct stat statbuf;
-
- if (pos < 0)
- return (int) pos;
- if (!pos)
- return 1;
-
- opos = (off_t) pos;
-
- EINTRLOOP (fd, open (arname, O_RDWR, 0666));
- if (fd < 0)
- return -3;
- /* Read in this member's header */
- EINTRLOOP (o, lseek (fd, opos, 0));
- if (o < 0)
- goto lose;
- r = readbuf (fd, &ar_hdr, AR_HDR_SIZE);
- if (r != AR_HDR_SIZE)
- goto lose;
- /* The file's mtime is the time we we want. */
- EINTRLOOP (r, fstat (fd, &statbuf));
- if (r < 0)
- goto lose;
- /* Advance member's time to that time */
-#if defined(ARFMAG) || defined(ARFZMAG) || defined(AIAMAG) || defined(WINDOWS32)
- datelen = snprintf (TOCHAR (ar_hdr.ar_date), sizeof ar_hdr.ar_date,
- "%" PRIdMAX, (intmax_t) statbuf.st_mtime);
- if (! (0 <= datelen && datelen < (int) sizeof ar_hdr.ar_date))
- goto lose;
- memset (ar_hdr.ar_date + datelen, ' ', sizeof ar_hdr.ar_date - datelen);
-#else
- ar_hdr.ar_date = statbuf.st_mtime;
-#endif
- /* Write back this member's header */
- EINTRLOOP (o, lseek (fd, opos, 0));
- if (o < 0)
- goto lose;
- r = writebuf (fd, &ar_hdr, AR_HDR_SIZE);
- if (r != AR_HDR_SIZE)
- goto lose;
- close (fd);
- return 0;
-
- lose:
- r = errno;
- close (fd);
- errno = r;
- return -3;
-}
-#endif
-
-#ifdef TEST
-
-intmax_t
-describe_member (int desc, const char *name, int truncated,
- long int hdrpos, long int datapos, long int size,
- intmax_t date, int uid, int gid, unsigned int mode,
- const void *arg)
-{
- extern char *ctime ();
- time_t d = date;
- char const *ds;
-
- printf (_("Member '%s'%s: %ld bytes at %ld (%ld).\n"),
- name, truncated ? _(" (name might be truncated)") : "",
- size, hdrpos, datapos);
- ds = ctime (&d);
- printf (_(" Date %s"), ds ? ds : "?");
- printf (_(" uid = %d, gid = %d, mode = 0%o.\n"), uid, gid, mode);
-
- return 0;
-}
-
-int
-main (int argc, char **argv)
-{
- ar_scan (argv[1], describe_member, NULL);
- return 0;
-}
-
-#endif /* TEST. */
-#endif /* NO_ARCHIVES. */
diff --git a/third_party/make/remote-cstms.c b/third_party/make/remote-cstms.c
deleted file mode 100644
index bc98a23be..000000000
--- a/third_party/make/remote-cstms.c
+++ /dev/null
@@ -1,297 +0,0 @@
-/* GNU Make remote job exportation interface to the Customs daemon.
- THIS CODE IS NOT SUPPORTED BY THE GNU PROJECT.
- Please do not send bug reports or questions about it to
- the Make maintainers.
-
-Copyright (C) 1988-2023 Free Software Foundation, Inc.
-This file is part of GNU Make.
-
-GNU Make is free software; you can redistribute it and/or modify it under the
-terms of the GNU General Public License as published by the Free Software
-Foundation; either version 3 of the License, or (at your option) any later
-version.
-
-GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY
-WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
-A PARTICULAR PURPOSE. See the GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License along with
-this program. If not, see . */
-
-#include "makeint.h"
-
-#include "filedef.h"
-#include "job.h"
-#include "commands.h"
-#include "debug.h"
-
-#if HAVE_SYS_TIME_H
-# include
-#endif
-#include
-
-#include "customs.h"
-
-char *remote_description = "Customs";
-
-/* File name of the Customs 'export' client command.
- A full path name can be used to avoid some path-searching overhead. */
-#define EXPORT_COMMAND "/usr/local/bin/export"
-
-/* ExportPermit gotten by start_remote_job_p, and used by start_remote_job. */
-static ExportPermit permit;
-
-/* Normalized path name of the current directory. */
-static char *normalized_cwd;
-
-/* Call once at startup even if no commands are run. */
-
-void
-remote_setup (void)
-{
-}
-
-/* Called before exit. */
-
-void
-remote_cleanup (void)
-{
-}
-
-/* Return nonzero if the next job should be done remotely. */
-
-int
-start_remote_job_p (int first_p)
-{
- static int inited = 0;
- int status;
- int njobs;
-
- if (!inited)
- {
- /* Allow the user to turn off job exportation (useful while he is
- debugging Customs, for example). */
- if (getenv ("GNU_MAKE_NO_CUSTOMS") != 0)
- {
- inited = -1;
- return 0;
- }
-
- if (ISDB (DB_JOBS))
- Rpc_Debug (1);
-
- /* Ping the daemon once to see if it is there. */
- inited = Customs_Ping () == RPC_SUCCESS ? 1 : -1;
-
- if (starting_directory == 0)
- /* main couldn't figure it out. */
- inited = -1;
- else
- {
- /* Normalize the current directory path name to something
- that should work on all machines exported to. */
-
- normalized_cwd = xmalloc (GET_PATH_MAX);
- strcpy (normalized_cwd, starting_directory);
- if (Customs_NormPath (normalized_cwd, GET_PATH_MAX) < 0)
- /* Path normalization failure means using Customs
- won't work, but it's not really an error. */
- inited = -1;
- }
- }
-
- if (inited < 0)
- return 0;
-
- njobs = job_slots_used;
- if (!first_p)
- njobs -= 1; /* correction for being called from reap_children() */
-
- /* the first job should run locally, or, if the -l flag is given, we use
- that as clue as to how many local jobs should be scheduled locally */
- if (max_load_average < 0 && njobs == 0 || njobs < max_load_average)
- return 0;
-
- status = Customs_Host (EXPORT_SAME, &permit);
- if (status != RPC_SUCCESS)
- {
- DB (DB_JOBS, (_("Customs won't export: %s\n"),
- Rpc_ErrorMessage (status)));
- return 0;
- }
-
- return !CUSTOMS_FAIL (&permit.addr);
-}
-
-/* Start a remote job running the command in ARGV, with environment from
- ENVP. It gets standard input from STDIN_FD. On failure, return
- nonzero. On success, return zero, and set *USED_STDIN to nonzero if it
- will actually use STDIN_FD, zero if not, set *ID_PTR to a unique
- identification, and set *IS_REMOTE to nonzero if the job is remote, zero
- if it is local (meaning *ID_PTR is a process ID). */
-
-int
-start_remote_job (char **argv, char **envp, int stdin_fd,
- int *is_remote, pid_t *id_ptr, int *used_stdin)
-{
- char waybill[MAX_DATA_SIZE], msg[128];
- struct hostent *host;
- struct timeval timeout;
- struct sockaddr_in sin;
- int len;
- int retsock, retport, sock;
- Rpc_Stat status;
- pid_t pid;
-
- /* Create the return socket. */
- retsock = Rpc_UdpCreate (True, 0);
- if (retsock < 0)
- {
- O (error, NILF, "exporting: Couldn't create return socket.");
- return 1;
- }
-
- /* Get the return socket's port number. */
- len = sizeof (sin);
- if (getsockname (retsock, (struct sockaddr *) &sin, &len) < 0)
- {
- (void) close (retsock);
- perror_with_name ("exporting: ", "getsockname");
- return 1;
- }
- retport = sin.sin_port;
-
- /* Create the TCP socket for talking to the remote child. */
- sock = Rpc_TcpCreate (False, 0);
-
- /* Create a WayBill to give to the server. */
- len = Customs_MakeWayBill (&permit, normalized_cwd, argv[0], argv,
- envp, retport, waybill);
-
- /* Modify the waybill for the child's uid/gid. */
- {
- WayBill *wb = (WayBill *) waybill;
- wb->ruid = wb->euid;
- wb->rgid = wb->egid;
- }
-
- /* Send the request to the server, timing out in 20 seconds. */
- timeout.tv_usec = 0;
- timeout.tv_sec = 20;
- sin.sin_family = AF_INET;
- sin.sin_port = htons (Customs_Port ());
- sin.sin_addr = permit.addr;
- status = Rpc_Call (sock, &sin, (Rpc_Proc) CUSTOMS_IMPORT,
- len, (Rpc_Opaque) waybill,
- sizeof (msg), (Rpc_Opaque) msg,
- 1, &timeout);
-
- host = gethostbyaddr ((char *)&permit.addr, sizeof(permit.addr), AF_INET);
-
- {
- const char *hnm = host ? host->h_name : inet_ntoa (permit.addr);
- size_t hlen = strlen (hnm);
-
- if (status != RPC_SUCCESS)
- {
- const char *err = Rpc_ErrorMessage (status);
- (void) close (retsock);
- (void) close (sock);
- error (NILF, hlen + strlen (err),
- "exporting to %s: %s", hnm, err);
- return 1;
- }
- else if (msg[0] != 'O' || msg[1] != 'k' || msg[2] != '\0')
- {
- (void) close (retsock);
- (void) close (sock);
- error (NILF, hlen + strlen (msg), "exporting to %s: %s", hnm, msg);
- return 1;
- }
- else
- {
- error (NILF, hlen + INTSTR_LENGTH,
- "*** exported to %s (id %u)", hnm, permit.id);
- }
-
- fflush (stdout);
- fflush (stderr);
- }
-
- pid = vfork ();
- if (pid < 0)
- {
- /* The fork failed! */
- perror_with_name ("fork", "");
- return 1;
- }
- else if (pid == 0)
- {
- /* Child side. Run 'export' to handle the connection. */
- static char sock_buf[INTSTR_LENGTH], retsock_buf[INTSTR_LENGTH];
- static char id_buf[INTSTR_LENGTH];
- static char *new_argv[6] =
- { EXPORT_COMMAND, "-id", sock_buf, retsock_buf, id_buf, 0 };
-
- /* Set up the arguments. */
- (void) sprintf (sock_buf, "%d", sock);
- (void) sprintf (retsock_buf, "%d", retsock);
- (void) sprintf (id_buf, "%x", permit.id);
-
- /* Get the right stdin. */
- if (stdin_fd != 0)
- (void) dup2 (stdin_fd, 0);
-
- /* Unblock signals in the child. */
- unblock_all_sigs ();
-
- /* Run the command. */
- exec_command (new_argv, envp);
- }
-
- /* Parent side. Return the 'export' process's ID. */
- (void) close (retsock);
- (void) close (sock);
- *is_remote = 0;
- *id_ptr = pid;
- *used_stdin = 1;
- return 0;
-}
-
-/* Get the status of a dead remote child. Block waiting for one to die
- if BLOCK is nonzero. Set *EXIT_CODE_PTR to the exit status, *SIGNAL_PTR
- to the termination signal or zero if it exited normally, and *COREDUMP_PTR
- nonzero if it dumped core. Return the ID of the child that died,
- 0 if we would have to block and !BLOCK, or < 0 if there were none. */
-
-int
-remote_status (int *exit_code_ptr, int *signal_ptr, int *coredump_ptr,
- int block)
-{
- return -1;
-}
-
-/* Block asynchronous notification of remote child death.
- If this notification is done by raising the child termination
- signal, do not block that signal. */
-void
-block_remote_children (void)
-{
- return;
-}
-
-/* Restore asynchronous notification of remote child death.
- If this is done by raising the child termination signal,
- do not unblock that signal. */
-void
-unblock_remote_children (void)
-{
- return;
-}
-
-/* Send signal SIG to child ID. Return 0 if successful, -1 if not. */
-int
-remote_kill (pid_t id, int sig)
-{
- return -1;
-}