xref: /dflybsd-src/usr.bin/dsynth/dsynth.h (revision 2b3f93ea6d1f70880f3e87f3c2cbe0dc0bfc9332)
18e25f19bSMatthew Dillon /*
23bd7e0a7SMatthew Dillon  * Copyright (c) 2019-2022 The DragonFly Project.  All rights reserved.
38e25f19bSMatthew Dillon  *
48e25f19bSMatthew Dillon  * This code is derived from software contributed to The DragonFly Project
58e25f19bSMatthew Dillon  * by Matthew Dillon <dillon@backplane.com>
68e25f19bSMatthew Dillon  *
78e25f19bSMatthew Dillon  * This code uses concepts and configuration based on 'synth', by
88e25f19bSMatthew Dillon  * John R. Marino <draco@marino.st>, which was written in ada.
98e25f19bSMatthew Dillon  *
108e25f19bSMatthew Dillon  * Redistribution and use in source and binary forms, with or without
118e25f19bSMatthew Dillon  * modification, are permitted provided that the following conditions
128e25f19bSMatthew Dillon  * are met:
138e25f19bSMatthew Dillon  *
148e25f19bSMatthew Dillon  * 1. Redistributions of source code must retain the above copyright
158e25f19bSMatthew Dillon  *    notice, this list of conditions and the following disclaimer.
168e25f19bSMatthew Dillon  * 2. Redistributions in binary form must reproduce the above copyright
178e25f19bSMatthew Dillon  *    notice, this list of conditions and the following disclaimer in
188e25f19bSMatthew Dillon  *    the documentation and/or other materials provided with the
198e25f19bSMatthew Dillon  *    distribution.
208e25f19bSMatthew Dillon  * 3. Neither the name of The DragonFly Project nor the names of its
218e25f19bSMatthew Dillon  *    contributors may be used to endorse or promote products derived
228e25f19bSMatthew Dillon  *    from this software without specific, prior written permission.
238e25f19bSMatthew Dillon  *
248e25f19bSMatthew Dillon  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
258e25f19bSMatthew Dillon  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
268e25f19bSMatthew Dillon  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
278e25f19bSMatthew Dillon  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE
288e25f19bSMatthew Dillon  * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
298e25f19bSMatthew Dillon  * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
308e25f19bSMatthew Dillon  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
318e25f19bSMatthew Dillon  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
328e25f19bSMatthew Dillon  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
338e25f19bSMatthew Dillon  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
348e25f19bSMatthew Dillon  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
358e25f19bSMatthew Dillon  * SUCH DAMAGE.
368e25f19bSMatthew Dillon  */
378e25f19bSMatthew Dillon 
388e25f19bSMatthew Dillon #include <sys/types.h>
398e25f19bSMatthew Dillon #include <sys/wait.h>
408e25f19bSMatthew Dillon #include <sys/stat.h>
418e25f19bSMatthew Dillon #include <sys/sysctl.h>
428e25f19bSMatthew Dillon #include <sys/socket.h>
43f9d29536SMatthew Dillon #include <sys/un.h>
448e25f19bSMatthew Dillon #include <sys/mount.h>
458e25f19bSMatthew Dillon #include <sys/procctl.h>
466d1478d9SMatthew Dillon #include <sys/resource.h>	/* setpriority() */
47*2b3f93eaSMatthew Dillon #include <sys/caps.h>
4832fc5bbfSMatthew Dillon #if defined(__DragonFly__)
4932fc5bbfSMatthew Dillon #include <sys/vmmeter.h>
5032fc5bbfSMatthew Dillon #endif
518e25f19bSMatthew Dillon #include <stdio.h>
528e25f19bSMatthew Dillon #include <stdlib.h>
538e25f19bSMatthew Dillon #include <stddef.h>
548e25f19bSMatthew Dillon #include <stdarg.h>
558e25f19bSMatthew Dillon #include <unistd.h>
568e25f19bSMatthew Dillon #include <string.h>
578e25f19bSMatthew Dillon #include <fcntl.h>
58b6bd007bSMatthew Dillon #include <fts.h>
59b6bd007bSMatthew Dillon #include <ndbm.h>
608e25f19bSMatthew Dillon #include <signal.h>
618e25f19bSMatthew Dillon #include <poll.h>
628e25f19bSMatthew Dillon #include <assert.h>
638e25f19bSMatthew Dillon #include <errno.h>
648e25f19bSMatthew Dillon #include <pthread.h>
653bd7e0a7SMatthew Dillon #include <pthread_np.h>
668e25f19bSMatthew Dillon #include <dirent.h>
678e25f19bSMatthew Dillon #include <termios.h>
688b485838SMatthew Dillon #include <time.h>
698e25f19bSMatthew Dillon #include <ctype.h>
708e25f19bSMatthew Dillon 
7168dc2eeaSMatthew Dillon /*
7268dc2eeaSMatthew Dillon  * More esoteric headers
7368dc2eeaSMatthew Dillon  */
7468dc2eeaSMatthew Dillon #include <libutil.h>	/* forkpty() */
7568dc2eeaSMatthew Dillon #include <arpa/inet.h>	/* ntohl() */
7668dc2eeaSMatthew Dillon #include <elf.h>	/* try to get elf info */
77a574cbf0SMatthew Dillon 
788e25f19bSMatthew Dillon struct pkglink;
798e25f19bSMatthew Dillon 
80a6fbec26SAntonio Huete Jimenez #define DSYNTH_VERSION	"1.0.2"
818e25f19bSMatthew Dillon #define MAXWORKERS	1024
82aac7a6d9SMatthew Dillon #define MAXLOGLINES	1024
838e25f19bSMatthew Dillon #define MAXJOBS		8192	/* just used for -j sanity */
848e25f19bSMatthew Dillon #define MAXBULK		MAXWORKERS
858e25f19bSMatthew Dillon 
868e25f19bSMatthew Dillon #define MAKE_BINARY		"/usr/bin/make"
878e25f19bSMatthew Dillon #define PKG_BINARY		"/usr/local/sbin/pkg"
888e25f19bSMatthew Dillon #define MOUNT_BINARY		"/sbin/mount"
898e25f19bSMatthew Dillon #define UMOUNT_BINARY		"/sbin/umount"
908e25f19bSMatthew Dillon 
91aac7a6d9SMatthew Dillon #define STATS_FILE		"monitor.dat"		/* under LogsPath */
92aac7a6d9SMatthew Dillon #define STATS_LOCKFILE		"monitor.lk"		/* under LogsPath */
93aac7a6d9SMatthew Dillon 
947f0eca56SMatthew Dillon #define ONEGB		(1024L * 1024 * 1024)
95f4094b20SMatthew Dillon #define DISABLED_STR	"disabled"
967f0eca56SMatthew Dillon 
978e25f19bSMatthew Dillon /*
98ef0c0bf5SKrzysztof Piecuch  * This can be ".tar", ".tgz", ".txz", ".tbz", "tzst".
99667fb2cbSMatthew Dillon  *
100667fb2cbSMatthew Dillon  * .tar	- very fast but you'll need 1TB+ of storage just for the package files.
101667fb2cbSMatthew Dillon  * .txz - very compact but decompression speed is horrible.
102667fb2cbSMatthew Dillon  * .tgz - reasonable compression, extremely fast decompression.  Roughly
103667fb2cbSMatthew Dillon  *	  1.1x to 2.0x the size of a .txz, but decompresses 10x faster.
104667fb2cbSMatthew Dillon  * .tbz - worse than .tgz generally
105ef0c0bf5SKrzysztof Piecuch  * .tzst - slightly worse compression ratio to .txz, decompresses 13x faster.
106f17a90cbSMatthew Dillon  *
107f17a90cbSMatthew Dillon  * NOTE: Decompression speed does effect bulk builds since each slot has
108f17a90cbSMatthew Dillon  *	 to install pre-reqs before building any particular package.  Set
109f17a90cbSMatthew Dillon  *	 the default to .txz to remain close to synth's default.
110753e4c44SMatthew Dillon  *
111753e4c44SMatthew Dillon  * NOTE: As of version 1.17 of pkg, all package files use the .pkg suffix
112753e4c44SMatthew Dillon  *	 regardless of the compression format.
113667fb2cbSMatthew Dillon  */
114f17a90cbSMatthew Dillon #define USE_PKG_SUFX		".txz"
115667fb2cbSMatthew Dillon 
116667fb2cbSMatthew Dillon /*
1178e25f19bSMatthew Dillon  * Topology linkages
1188e25f19bSMatthew Dillon  */
1198e25f19bSMatthew Dillon typedef struct pkglink {
1208e25f19bSMatthew Dillon 	struct pkglink *next;
1218e25f19bSMatthew Dillon 	struct pkglink *prev;
1228e25f19bSMatthew Dillon 	struct pkg *pkg;
12363fcce5bSMatthew Dillon 	int	dep_type;
1248e25f19bSMatthew Dillon } pkglink_t;
1258e25f19bSMatthew Dillon 
12663fcce5bSMatthew Dillon #define DEP_TYPE_FETCH	1
12763fcce5bSMatthew Dillon #define DEP_TYPE_EXT	2
12863fcce5bSMatthew Dillon #define DEP_TYPE_PATCH	3
12963fcce5bSMatthew Dillon #define DEP_TYPE_BUILD	4
13063fcce5bSMatthew Dillon #define DEP_TYPE_LIB	5
13163fcce5bSMatthew Dillon #define DEP_TYPE_RUN	6
13263fcce5bSMatthew Dillon 
1338e25f19bSMatthew Dillon /*
1348e25f19bSMatthew Dillon  * Describes a [flavored] package
1358e25f19bSMatthew Dillon  */
1368e25f19bSMatthew Dillon typedef struct pkg {
1378e25f19bSMatthew Dillon 	struct pkg *build_next;	/* topology inversion build list */
1388e25f19bSMatthew Dillon 	struct pkg *bnext;	/* linked list from bulk return */
1398e25f19bSMatthew Dillon 	struct pkg *hnext1;	/* hash based on portdir */
1408e25f19bSMatthew Dillon 	struct pkg *hnext2;	/* hash based on pkgfile */
1418e25f19bSMatthew Dillon 	pkglink_t idepon_list;	/* I need these pkgs */
1428e25f19bSMatthew Dillon 	pkglink_t deponi_list;	/* pkgs which depend on me */
1438e25f19bSMatthew Dillon 	char *portdir;		/* origin name e.g. www/chromium[@flavor] */
1448e25f19bSMatthew Dillon 	char *logfile;		/* relative logfile path */
1458e25f19bSMatthew Dillon 	char *version;		/* PKGVERSION - e.g. 3.5.0_1		*/
1468e25f19bSMatthew Dillon 	char *pkgfile;		/* PKGFILE    - e.g. flav-blah-3.5.0_1.txz */
1471645cafeSMatthew Dillon 	char *distfiles;	/* DISTFILES  - e.g. blah-68.0.source.tar.xz */
1481645cafeSMatthew Dillon 	char *distsubdir;	/* DIST_SUBDIR- e.g. cabal		*/
14987017ac4SMatthew Dillon 	char *ignore;		/* IGNORE (also covers BROKEN)		*/
1508e25f19bSMatthew Dillon 	char *fetch_deps;	/* FETCH_DEPENDS			*/
1518e25f19bSMatthew Dillon 	char *ext_deps;		/* EXTRACT_DEPENDS			*/
1528e25f19bSMatthew Dillon 	char *patch_deps;	/* PATCH_DEPENDS			*/
1538e25f19bSMatthew Dillon 	char *build_deps;	/* BUILD_DEPENDS			*/
1548e25f19bSMatthew Dillon 	char *lib_deps;		/* LIB_DEPENDS				*/
1558e25f19bSMatthew Dillon 	char *run_deps;		/* RUN_DEPENDS				*/
1568e25f19bSMatthew Dillon 	char *pos_options;	/* SELECTED_OPTIONS			*/
1578e25f19bSMatthew Dillon 	char *neg_options;	/* DESELECTED_OPTIONS			*/
1588e25f19bSMatthew Dillon 	char *flavors;		/* FLAVORS    - e.g. py36 py27		*/
159f4094b20SMatthew Dillon 	char *uses;		/* USES (metaport test)			*/
1608e25f19bSMatthew Dillon 	int make_jobs_number;	/* MAKE_JOBS_NUMBER			*/
1618e25f19bSMatthew Dillon 	int use_linux;		/* USE_LINUX				*/
1628e25f19bSMatthew Dillon 	int idep_count;		/* count recursive idepon build deps	*/
1638e25f19bSMatthew Dillon 	int depi_count;		/* count recursive deponi build deps	*/
16488c24d72SMatthew Dillon 	int depi_depth;		/* tree depth who depends on me		*/
1658e25f19bSMatthew Dillon 	int dsynth_install_flg;	/* locked with WorkerMutex	*/
1668e25f19bSMatthew Dillon 	int flags;
1673dd48cfaSMatthew Dillon 	int rscan;		/* recursive scan flag (serialized use) */
168b6bd007bSMatthew Dillon 	uint32_t crc32;		/* crc of port directory tree */
169fef2fc63SMatthew Dillon 	size_t pkgfile_size;	/* size of pkgfile */
1708e25f19bSMatthew Dillon } pkg_t;
1718e25f19bSMatthew Dillon 
1728e25f19bSMatthew Dillon #define PKGF_PACKAGED	0x00000001	/* has a repo package */
1738e25f19bSMatthew Dillon #define PKGF_DUMMY	0x00000002	/* generic root for flavors */
1748e25f19bSMatthew Dillon #define PKGF_NOTFOUND	0x00000004	/* dport not found */
1758e25f19bSMatthew Dillon #define PKGF_CORRUPT	0x00000008	/* dport corrupt */
1768e25f19bSMatthew Dillon #define PKGF_PLACEHOLD	0x00000010	/* pre-entered */
1778e25f19bSMatthew Dillon #define PKGF_BUILDLIST	0x00000020	/* on build_list */
1788e25f19bSMatthew Dillon #define PKGF_BUILDLOOP	0x00000040	/* traversal loop test */
1798e25f19bSMatthew Dillon #define PKGF_BUILDTRAV	0x00000080	/* traversal optimization */
1808e25f19bSMatthew Dillon #define PKGF_NOBUILD_D	0x00000100	/* can't build - dependency problem */
1818e25f19bSMatthew Dillon #define PKGF_NOBUILD_S	0x00000200	/* can't build - skipped */
1828e25f19bSMatthew Dillon #define PKGF_NOBUILD_F	0x00000400	/* can't build - failed */
18387017ac4SMatthew Dillon #define PKGF_NOBUILD_I	0x00000800	/* can't build - ignored or broken */
18487017ac4SMatthew Dillon #define PKGF_SUCCESS	0x00001000	/* build complete */
18587017ac4SMatthew Dillon #define PKGF_FAILURE	0x00002000	/* build complete */
18687017ac4SMatthew Dillon #define PKGF_RUNNING	0x00004000	/* build complete */
18787017ac4SMatthew Dillon #define PKGF_PKGPKG	0x00008000	/* pkg/pkg-static special */
18887017ac4SMatthew Dillon #define PKGF_NOTREADY	0x00010000	/* build_find_leaves() only */
189f4094b20SMatthew Dillon #define PKGF_MANUALSEL	0x00020000	/* manually specified */
190f4094b20SMatthew Dillon #define PKGF_META	0x00040000	/* USES contains 'metaport' */
191710838f7SMatthew Dillon #define PKGF_DEBUGSTOP	0x00080000	/* freeze slot on completion */
192710838f7SMatthew Dillon 
1938e25f19bSMatthew Dillon #define PKGF_ERROR	(PKGF_PLACEHOLD | PKGF_CORRUPT | PKGF_NOTFOUND | \
1948e25f19bSMatthew Dillon 			 PKGF_FAILURE)
19587017ac4SMatthew Dillon #define PKGF_NOBUILD	(PKGF_NOBUILD_D | PKGF_NOBUILD_S | PKGF_NOBUILD_F | \
19687017ac4SMatthew Dillon 			 PKGF_NOBUILD_I)
1978e25f19bSMatthew Dillon 
1988e25f19bSMatthew Dillon #define PKGLIST_EMPTY(pkglink)		((pkglink)->next == (pkglink))
1998e25f19bSMatthew Dillon #define PKGLIST_FOREACH(var, head)	\
2008e25f19bSMatthew Dillon 	for (var = (head)->next; var != (head); var = (var)->next)
2018e25f19bSMatthew Dillon 
2028e25f19bSMatthew Dillon typedef struct bulk {
2038e25f19bSMatthew Dillon 	struct bulk *next;
2048e25f19bSMatthew Dillon 	pthread_t td;
2058e25f19bSMatthew Dillon 	int debug;
2068e25f19bSMatthew Dillon 	int flags;
2078e25f19bSMatthew Dillon 	enum { UNLISTED, ONSUBMIT, ONRUN, ISRUNNING, ONRESPONSE } state;
2088e25f19bSMatthew Dillon 	char *s1;
2098e25f19bSMatthew Dillon 	char *s2;
2108e25f19bSMatthew Dillon 	char *s3;
2118e25f19bSMatthew Dillon 	char *s4;
2128e25f19bSMatthew Dillon 	char *r1;
2138e25f19bSMatthew Dillon 	char *r2;
2148e25f19bSMatthew Dillon 	char *r3;
2158e25f19bSMatthew Dillon 	char *r4;
2168e25f19bSMatthew Dillon 	pkg_t *list;		/* pkgs linked by bnext */
2178e25f19bSMatthew Dillon } bulk_t;
2188e25f19bSMatthew Dillon 
2198e25f19bSMatthew Dillon /*
2208e25f19bSMatthew Dillon  * Worker state (up to MAXWORKERS).  Each worker operates within a
2218e25f19bSMatthew Dillon  * chroot or jail.  A system mirror is setup and the template
2228e25f19bSMatthew Dillon  * is copied in.
2238e25f19bSMatthew Dillon  *
2248e25f19bSMatthew Dillon  * basedir		- tmpfs
2258e25f19bSMatthew Dillon  * /bin			- nullfs (ro)
2268e25f19bSMatthew Dillon  * /sbin		- nullfs (ro)
2278e25f19bSMatthew Dillon  * /lib			- nullfs (ro)
2288e25f19bSMatthew Dillon  * /libexec		- nullfs (ro)
2298e25f19bSMatthew Dillon  * /usr/bin		- nullfs (ro)
2308e25f19bSMatthew Dillon  * /usr/include		- nullfs (ro)
2318e25f19bSMatthew Dillon  * /usr/lib		- nullfs (ro)
2328e25f19bSMatthew Dillon  * /usr/libdata		- nullfs (ro)
2338e25f19bSMatthew Dillon  * /usr/libexec		- nullfs (ro)
2348e25f19bSMatthew Dillon  * /usr/sbin		- nullfs (ro)
2358e25f19bSMatthew Dillon  * /usr/share		- nullfs (ro)
2368e25f19bSMatthew Dillon  * /xports		- nullfs (ro)
2378e25f19bSMatthew Dillon  * /options		- nullfs (ro)
2388e25f19bSMatthew Dillon  * /packages		- nullfs (ro)
2398e25f19bSMatthew Dillon  * /distfiles		- nullfs (ro)
2408e25f19bSMatthew Dillon  * construction		- tmpfs
2418e25f19bSMatthew Dillon  * /usr/local		- tmpfs
2428e25f19bSMatthew Dillon  * /boot		- nullfs (ro)
2438e25f19bSMatthew Dillon  * /boot/modules.local	- tmpfs
2448e25f19bSMatthew Dillon  * /usr/games		- nullfs (ro)
2458e25f19bSMatthew Dillon  * /usr/src		- nullfs (ro)
2468e25f19bSMatthew Dillon  * /dev			- devfs
2478e25f19bSMatthew Dillon  */
2488e25f19bSMatthew Dillon enum worker_state { WORKER_NONE, WORKER_IDLE, WORKER_PENDING,
2498e25f19bSMatthew Dillon 		    WORKER_RUNNING, WORKER_DONE, WORKER_FAILED,
2508ec23ca1SMatthew Dillon 		    WORKER_FROZEN, WORKER_EXITING };
2518e25f19bSMatthew Dillon typedef enum worker_state worker_state_t;
2528e25f19bSMatthew Dillon 
2538e25f19bSMatthew Dillon enum worker_phase { PHASE_PENDING,
2548e25f19bSMatthew Dillon 		    PHASE_INSTALL_PKGS,
2558e25f19bSMatthew Dillon 		    PHASE_CHECK_SANITY,
2568e25f19bSMatthew Dillon 		    PHASE_PKG_DEPENDS,
2578e25f19bSMatthew Dillon 		    PHASE_FETCH_DEPENDS,
2588e25f19bSMatthew Dillon 		    PHASE_FETCH,
2598e25f19bSMatthew Dillon 		    PHASE_CHECKSUM,
2608e25f19bSMatthew Dillon 		    PHASE_EXTRACT_DEPENDS,
2618e25f19bSMatthew Dillon 		    PHASE_EXTRACT,
2628e25f19bSMatthew Dillon 		    PHASE_PATCH_DEPENDS,
2638e25f19bSMatthew Dillon 		    PHASE_PATCH,
2648e25f19bSMatthew Dillon 		    PHASE_BUILD_DEPENDS,
2658e25f19bSMatthew Dillon 		    PHASE_LIB_DEPENDS,
2668e25f19bSMatthew Dillon 		    PHASE_CONFIGURE,
2678e25f19bSMatthew Dillon 		    PHASE_BUILD,
2688e25f19bSMatthew Dillon 		    PHASE_RUN_DEPENDS,
2698e25f19bSMatthew Dillon 		    PHASE_STAGE,
2708e25f19bSMatthew Dillon 		    PHASE_TEST,
2718e25f19bSMatthew Dillon 		    PHASE_CHECK_PLIST,
2728e25f19bSMatthew Dillon 		    PHASE_PACKAGE,
2738e25f19bSMatthew Dillon 		    PHASE_INSTALL,
2749fdb3f28SAntonio Huete Jimenez 		    PHASE_DEINSTALL,
2759fdb3f28SAntonio Huete Jimenez 		    PHASE_DUMP_ENV,
2769fdb3f28SAntonio Huete Jimenez 		    PHASE_DUMP_VAR,
2779fdb3f28SAntonio Huete Jimenez 		    PHASE_SHOW_CONFIG,
2789fdb3f28SAntonio Huete Jimenez 		    PHASE_DUMP_MAKECONF
2798e25f19bSMatthew Dillon 		};
2808e25f19bSMatthew Dillon 
2818e25f19bSMatthew Dillon typedef enum worker_phase worker_phase_t;
2828e25f19bSMatthew Dillon 
2838e25f19bSMatthew Dillon /*
2848e25f19bSMatthew Dillon  * Watchdog timeouts, in minutes, baseline, scales up with load/ncpus but
2858e25f19bSMatthew Dillon  * does not scale down.
2868e25f19bSMatthew Dillon  */
2878e25f19bSMatthew Dillon #define WDOG1	(5)
2888e25f19bSMatthew Dillon #define WDOG2	(10)
2898e25f19bSMatthew Dillon #define WDOG3	(15)
2908e25f19bSMatthew Dillon #define WDOG4	(30)
2918e25f19bSMatthew Dillon #define WDOG5	(60)
2928e25f19bSMatthew Dillon #define WDOG6	(60 + 30)
2938e25f19bSMatthew Dillon #define WDOG7	(60 * 2)
2948e25f19bSMatthew Dillon #define WDOG8	(60 * 2 + 30)
2958e25f19bSMatthew Dillon #define WDOG9	(60 * 3)
2968e25f19bSMatthew Dillon 
2978e25f19bSMatthew Dillon typedef struct worker {
2988e25f19bSMatthew Dillon 	int	index;		/* worker number 0..N-1 */
2998e25f19bSMatthew Dillon 	int	flags;
3008e25f19bSMatthew Dillon 	int	accum_error;	/* cumulative error */
3018e25f19bSMatthew Dillon 	int	mount_error;	/* mount and unmount error */
3028e25f19bSMatthew Dillon 	int	terminate : 1;	/* request sub-thread to terminate */
3038e25f19bSMatthew Dillon 	char	*basedir;	/* base directory including id */
3048e25f19bSMatthew Dillon 	char	*flavor;
3058e25f19bSMatthew Dillon 	pthread_t td;		/* pthread */
3068e25f19bSMatthew Dillon 	pthread_cond_t cond;	/* interlock cond (w/ WorkerMutex) */
3078e25f19bSMatthew Dillon 	pkg_t	*pkg;
3088e25f19bSMatthew Dillon 	worker_state_t state;	/* general worker state */
3098e25f19bSMatthew Dillon 	worker_phase_t phase;	/* phase control in childBuilderThread */
3108e25f19bSMatthew Dillon 	time_t	start_time;
3118e25f19bSMatthew Dillon 	long	lines;
312516819d9SMatthew Dillon 	long	memuse;
3138e25f19bSMatthew Dillon 	pid_t	pid;
3148e25f19bSMatthew Dillon 	int	fds[2];		/* forked environment process */
3158e25f19bSMatthew Dillon 	char	status[64];
316fef2fc63SMatthew Dillon 	size_t	pkg_dep_size;	/* pkg dependency size(s) */
3178e25f19bSMatthew Dillon } worker_t;
3188e25f19bSMatthew Dillon 
3198e25f19bSMatthew Dillon #define WORKERF_STATUS_UPDATE	0x0001	/* display update */
3208e25f19bSMatthew Dillon #define WORKERF_SUCCESS		0x0002	/* completion flag */
3218e25f19bSMatthew Dillon #define WORKERF_FAILURE		0x0004	/* completion flag */
3228ec23ca1SMatthew Dillon #define WORKERF_FREEZE		0x0008	/* freeze the worker */
3238e25f19bSMatthew Dillon 
3248e25f19bSMatthew Dillon #define MOUNT_TYPE_MASK		0x000F
3258e25f19bSMatthew Dillon #define MOUNT_TYPE_TMPFS	0x0001
3268e25f19bSMatthew Dillon #define MOUNT_TYPE_NULLFS	0x0002
3278e25f19bSMatthew Dillon #define MOUNT_TYPE_DEVFS	0x0003
3288ec23ca1SMatthew Dillon #define MOUNT_TYPE_PROCFS	0x0004
3298e25f19bSMatthew Dillon #define MOUNT_TYPE_RW		0x0010
3308e25f19bSMatthew Dillon #define MOUNT_TYPE_BIG		0x0020
3318e25f19bSMatthew Dillon #define MOUNT_TYPE_TMP		0x0040
332a6361508SMatthew Dillon #define MOUNT_TYPE_MED		0x0080
3338e25f19bSMatthew Dillon 
3348e25f19bSMatthew Dillon #define NULLFS_RO		(MOUNT_TYPE_NULLFS)
3358e25f19bSMatthew Dillon #define NULLFS_RW		(MOUNT_TYPE_NULLFS | MOUNT_TYPE_RW)
3368ec23ca1SMatthew Dillon #define PROCFS_RO		(MOUNT_TYPE_PROCFS)
3378e25f19bSMatthew Dillon #define TMPFS_RW		(MOUNT_TYPE_TMPFS | MOUNT_TYPE_RW)
3388e25f19bSMatthew Dillon #define TMPFS_RW_BIG		(MOUNT_TYPE_TMPFS | MOUNT_TYPE_RW |	\
3398e25f19bSMatthew Dillon 				 MOUNT_TYPE_BIG)
340a6361508SMatthew Dillon #define TMPFS_RW_MED		(MOUNT_TYPE_TMPFS | MOUNT_TYPE_RW |	\
341a6361508SMatthew Dillon 				 MOUNT_TYPE_MED)
3428e25f19bSMatthew Dillon #define DEVFS_RW		(MOUNT_TYPE_DEVFS | MOUNT_TYPE_RW)
3438e25f19bSMatthew Dillon 
3448e25f19bSMatthew Dillon /*
3458e25f19bSMatthew Dillon  * IPC messages between the worker support thread and the worker process.
3468e25f19bSMatthew Dillon  */
3478e25f19bSMatthew Dillon typedef struct wmsg {
3488e25f19bSMatthew Dillon 	int	cmd;
3498e25f19bSMatthew Dillon 	int	status;
3508e25f19bSMatthew Dillon 	long	lines;
351516819d9SMatthew Dillon 	long	memuse;
3528e25f19bSMatthew Dillon 	worker_phase_t phase;
3538e25f19bSMatthew Dillon } wmsg_t;
3548e25f19bSMatthew Dillon 
3558e25f19bSMatthew Dillon #define WMSG_CMD_STATUS_UPDATE	0x0001
3568e25f19bSMatthew Dillon #define WMSG_CMD_SUCCESS	0x0002
3578e25f19bSMatthew Dillon #define WMSG_CMD_FAILURE	0x0003
3588e25f19bSMatthew Dillon #define WMSG_CMD_INSTALL_PKGS	0x0004
3598e25f19bSMatthew Dillon #define WMSG_RES_INSTALL_PKGS	0x0005
3608ec23ca1SMatthew Dillon #define WMSG_CMD_FREEZEWORKER	0x0006
3618e25f19bSMatthew Dillon 
3628e25f19bSMatthew Dillon /*
3638e25f19bSMatthew Dillon  * Make variables and build environment
3648e25f19bSMatthew Dillon  */
3658e25f19bSMatthew Dillon typedef struct buildenv {
3668e25f19bSMatthew Dillon 	struct buildenv *next;
36768dc2eeaSMatthew Dillon 	const char *label;
36868dc2eeaSMatthew Dillon 	const char *data;
36968dc2eeaSMatthew Dillon 	char *a1;		/* allocations */
37068dc2eeaSMatthew Dillon 	char *a2;		/* allocations */
3716fd67931SMatthew Dillon 	int type;
3728e25f19bSMatthew Dillon } buildenv_t;
3738e25f19bSMatthew Dillon 
3748e25f19bSMatthew Dillon /*
3758e25f19bSMatthew Dillon  * Operating systems recognized by dsynth
3768e25f19bSMatthew Dillon  */
3778e25f19bSMatthew Dillon enum os_id {
3788e25f19bSMatthew Dillon 	OS_UNKNOWN, OS_DRAGONFLY, OS_FREEBSD, OS_NETBSD, OS_LINUX
3798e25f19bSMatthew Dillon };
3808e25f19bSMatthew Dillon 
3818e25f19bSMatthew Dillon typedef enum os_id os_id_t;
3828e25f19bSMatthew Dillon 
3838e25f19bSMatthew Dillon /*
3848e25f19bSMatthew Dillon  * DLOG
3858e25f19bSMatthew Dillon  */
3868e25f19bSMatthew Dillon #define DLOG_ALL	0	/* Usually stdout when curses disabled */
3878e25f19bSMatthew Dillon #define DLOG_SUCC	1	/* success_list.log		*/
3888e25f19bSMatthew Dillon #define DLOG_FAIL	2	/* failure_list.log		*/
3898e25f19bSMatthew Dillon #define DLOG_IGN	3	/* ignored_list.log		*/
3908e25f19bSMatthew Dillon #define DLOG_SKIP	4	/* skipped_list.log		*/
3918e25f19bSMatthew Dillon #define DLOG_ABN	5	/* abnormal_command_output	*/
3928e25f19bSMatthew Dillon #define DLOG_OBS	6	/* obsolete_packages.log	*/
393349e3a76SMatthew Dillon #define DLOG_DEBUG	7	/* debug.log 			*/
394349e3a76SMatthew Dillon #define DLOG_COUNT	8	/* total number of DLOGs	*/
395a574cbf0SMatthew Dillon #define DLOG_MASK	0x0FF
396a574cbf0SMatthew Dillon 
397a574cbf0SMatthew Dillon #define DLOG_FILTER	0x100	/* Filter out of stdout in non-curses mode  */
398a574cbf0SMatthew Dillon #define DLOG_RED	0x200	/* Print in color */
399a574cbf0SMatthew Dillon #define DLOG_GRN	0x400	/* Print in color */
40033170e2dSMatthew Dillon #define DLOG_STDOUT	0x800	/* And stdout */
4018e25f19bSMatthew Dillon 
4028e25f19bSMatthew Dillon #define dassert(exp, fmt, ...)		\
4038e25f19bSMatthew Dillon 	if (!(exp)) dpanic(fmt, ## __VA_ARGS__)
4048e25f19bSMatthew Dillon 
4058e25f19bSMatthew Dillon #define ddassert(exp)			\
4068e25f19bSMatthew Dillon 	dassert((exp), "\"%s\" line %d", __FILE__, __LINE__)
4078e25f19bSMatthew Dillon 
4088e25f19bSMatthew Dillon #define dassert_errno(exp, fmt, ...)	\
4099c4c701fSMatthew Dillon 	if (!(exp)) dpanic_errno(fmt, ## __VA_ARGS__)
4108e25f19bSMatthew Dillon 
411349e3a76SMatthew Dillon #define dlog_tab(which, tab, fmt, ...)	\
412349e3a76SMatthew Dillon 	_dlog(which, "%*.*s" fmt, (int)tab, (int)tab, "", ## __VA_ARGS__)
413349e3a76SMatthew Dillon 
4148e25f19bSMatthew Dillon #define dlog(which, fmt, ...)		\
4158e25f19bSMatthew Dillon 	_dlog(which, fmt, ## __VA_ARGS__)
4168e25f19bSMatthew Dillon 
417a574cbf0SMatthew Dillon #define dlog_tsnl(which, fmt, ...)	\
418a574cbf0SMatthew Dillon 	_dlog(which, fmt, ## __VA_ARGS__)
419a574cbf0SMatthew Dillon 
4208e25f19bSMatthew Dillon #define dfatal(fmt, ...)		\
4218e25f19bSMatthew Dillon 	_dfatal(__FILE__, __LINE__, __func__, 0, fmt, ## __VA_ARGS__)
4228e25f19bSMatthew Dillon 
4238e25f19bSMatthew Dillon #define dpanic(fmt, ...)		\
4248e25f19bSMatthew Dillon 	_dfatal(__FILE__, __LINE__, __func__, 2, fmt, ## __VA_ARGS__)
4258e25f19bSMatthew Dillon 
4268e25f19bSMatthew Dillon #define dfatal_errno(fmt, ...)		\
4278e25f19bSMatthew Dillon 	_dfatal(__FILE__, __LINE__, __func__, 1, fmt, ## __VA_ARGS__)
4288e25f19bSMatthew Dillon 
4298e25f19bSMatthew Dillon #define dpanic_errno(fmt, ...)		\
4308e25f19bSMatthew Dillon 	_dfatal(__FILE__, __LINE__, __func__, 3, fmt, ## __VA_ARGS__)
4318e25f19bSMatthew Dillon 
4328e25f19bSMatthew Dillon #define ddprintf(tab, fmt, ...)		\
433349e3a76SMatthew Dillon 	do {				\
434349e3a76SMatthew Dillon 	  if (DebugOpt == 1) dlog_tab(DLOG_DEBUG, tab, fmt, ## __VA_ARGS__); \
435349e3a76SMatthew Dillon 	     if (DebugOpt > 1) _ddprintf(tab, fmt, ## __VA_ARGS__);	     \
436349e3a76SMatthew Dillon 	} while(0)
4378e25f19bSMatthew Dillon 
4386fd67931SMatthew Dillon /*
4396fd67931SMatthew Dillon  * addbuildenv() types
4406fd67931SMatthew Dillon  */
4416fd67931SMatthew Dillon #define BENV_ENVIRONMENT	1
4426fd67931SMatthew Dillon #define BENV_MAKECONF		2
44331f2ea22SMatthew Dillon #define BENV_CMDMASK		0x000F
44431f2ea22SMatthew Dillon 
44531f2ea22SMatthew Dillon #define BENV_PKGLIST		0x0010
4466fd67931SMatthew Dillon 
4476fd67931SMatthew Dillon /*
4486fd67931SMatthew Dillon  * WORKER process flags
4496fd67931SMatthew Dillon  */
4506fd67931SMatthew Dillon #define WORKER_PROC_DEBUGSTOP	0x0001
4516fd67931SMatthew Dillon #define WORKER_PROC_DEVELOPER	0x0002
45232f62172SMatthew Dillon #define WORKER_PROC_CHECK_PLIST	0x0004
45329d8adfcSAntonio Huete Jimenez #define WORKER_PROC_INSTALL	0x0008
45429d8adfcSAntonio Huete Jimenez #define WORKER_PROC_DEINSTALL	0x0010
455dca89e44SMatthew Dillon #define WORKER_PROC_PKGV17	0x0020
456325ef124SMatthew Dillon #define WORKER_PROC_FETCHONLY	0x0040
4576fd67931SMatthew Dillon 
4586fd67931SMatthew Dillon /*
4596fd67931SMatthew Dillon  * Misc
4606fd67931SMatthew Dillon  */
4618e25f19bSMatthew Dillon #define DOSTRING(label)	#label
4628e25f19bSMatthew Dillon #define SCRIPTPATH(x)	DOSTRING(x)
4636fd67931SMatthew Dillon #define MAXCAC		256
4648e25f19bSMatthew Dillon 
465ea37671dSMatthew Dillon /*
466ea37671dSMatthew Dillon  * RunStats satellite modules
467ea37671dSMatthew Dillon  */
468ea37671dSMatthew Dillon typedef struct topinfo {
4698b485838SMatthew Dillon 	int active;
470ea37671dSMatthew Dillon 	int pkgimpulse;
471ea37671dSMatthew Dillon 	int pkgrate;
472ea37671dSMatthew Dillon 	int noswap;
473ea37671dSMatthew Dillon 	int h;
474ea37671dSMatthew Dillon 	int m;
475ea37671dSMatthew Dillon 	int s;
476ea37671dSMatthew Dillon 	int total;
477ea37671dSMatthew Dillon 	int successful;
478ea37671dSMatthew Dillon 	int ignored;
479ea37671dSMatthew Dillon 	int remaining;
480ea37671dSMatthew Dillon 	int failed;
481ea37671dSMatthew Dillon 	int skipped;
48251705b28SAntonio Huete Jimenez 	int meta;
483aac7a6d9SMatthew Dillon 	int dynmaxworkers;
484ea37671dSMatthew Dillon 	double dswap;
485ea37671dSMatthew Dillon 	double dload[3];
486ea37671dSMatthew Dillon } topinfo_t;
487ea37671dSMatthew Dillon 
488ea37671dSMatthew Dillon typedef struct runstats {
489ea37671dSMatthew Dillon 	struct runstats *next;
490ea37671dSMatthew Dillon 	void (*init)(void);
491ea37671dSMatthew Dillon 	void (*done)(void);
492ea37671dSMatthew Dillon 	void (*reset)(void);
493aac7a6d9SMatthew Dillon 	void (*update)(worker_t *work, const char *portdir);
494ea37671dSMatthew Dillon 	void (*updateTop)(topinfo_t *info);
495ea37671dSMatthew Dillon 	void (*updateLogs)(void);
49664b61b2eSMatthew Dillon 	void (*updateCompletion)(worker_t *work, int dlogid, pkg_t *pkg,
49764b61b2eSMatthew Dillon 				const char *reason, const char *skipbuf);
498ea37671dSMatthew Dillon 	void (*sync)(void);
499ea37671dSMatthew Dillon } runstats_t;
500ea37671dSMatthew Dillon 
501aac7a6d9SMatthew Dillon typedef struct monitorlog {
502aac7a6d9SMatthew Dillon 	off_t	offset;
503aac7a6d9SMatthew Dillon 	int	fd;
504aac7a6d9SMatthew Dillon 	int	buf_beg;
505aac7a6d9SMatthew Dillon 	int	buf_end;
506aac7a6d9SMatthew Dillon 	int	buf_scan;
507aac7a6d9SMatthew Dillon 	int	buf_discard_mode;
508aac7a6d9SMatthew Dillon 	char	buf[1024];
509aac7a6d9SMatthew Dillon } monitorlog_t;
510aac7a6d9SMatthew Dillon 
511ea37671dSMatthew Dillon extern runstats_t NCursesRunStats;
512ea37671dSMatthew Dillon extern runstats_t MonitorRunStats;
513ea37671dSMatthew Dillon extern runstats_t HtmlRunStats;
514ea37671dSMatthew Dillon 
5158e25f19bSMatthew Dillon extern int BuildCount;
5168e25f19bSMatthew Dillon extern int BuildTotal;
5178e25f19bSMatthew Dillon extern int BuildFailCount;
5188e25f19bSMatthew Dillon extern int BuildSkipCount;
51987017ac4SMatthew Dillon extern int BuildIgnoreCount;
5208e25f19bSMatthew Dillon extern int BuildSuccessCount;
521549987f1SMatthew Dillon extern int BuildMissingCount;
52251705b28SAntonio Huete Jimenez extern int BuildMetaCount;
523f7f25838SMatthew Dillon extern int DynamicMaxWorkers;
5248e25f19bSMatthew Dillon 
5258e25f19bSMatthew Dillon extern buildenv_t *BuildEnv;
5266fd67931SMatthew Dillon extern int WorkerProcFlags;
5278e25f19bSMatthew Dillon extern int DebugOpt;
5286d1478d9SMatthew Dillon extern int NiceOpt;
529*2b3f93eaSMatthew Dillon extern int CapabilityRestrictions;
530927e4e3eSMatthew Dillon extern int MaskProbeAbort;
531a574cbf0SMatthew Dillon extern int ColorOpt;
532f7f25838SMatthew Dillon extern int SlowStartOpt;
5332c5f241eSMatthew Dillon extern int ForceOpt;
534b6bd007bSMatthew Dillon extern int OverridePkgDeleteOpt;
535325ef124SMatthew Dillon extern int FetchOnlyOpt;
5361645cafeSMatthew Dillon extern int YesOpt;
5379c4c701fSMatthew Dillon extern int NullStdinOpt;
5383bd7e0a7SMatthew Dillon extern int NumaSetSize;
539dc46751bSMatthew Dillon extern int DeleteObsoletePkgs;
5408e25f19bSMatthew Dillon extern int UseCCache;
541f4094b20SMatthew Dillon extern int UseUsrSrc;
5428e25f19bSMatthew Dillon extern int UseTmpfs;
5438e25f19bSMatthew Dillon extern int NumCores;
5447f0eca56SMatthew Dillon extern long PhysMem;
5457f0eca56SMatthew Dillon extern long PkgDepMemoryTarget;
5464ad2f7b8SMatthew Dillon extern long PkgDepScaleTarget;
5478e25f19bSMatthew Dillon extern int MaxBulk;
5488e25f19bSMatthew Dillon extern int MaxWorkers;
5498e25f19bSMatthew Dillon extern int MaxJobs;
5508e25f19bSMatthew Dillon extern int UseTmpfsWork;
5518e25f19bSMatthew Dillon extern int UseTmpfsBase;
5528e25f19bSMatthew Dillon extern int UseNCurses;
5538e25f19bSMatthew Dillon extern int LeveragePrebuilt;
5548e25f19bSMatthew Dillon extern char *DSynthExecPath;
5559e1d0b12SMatthew Dillon extern char *ProfileOverrideOpt;
556a67bf8dbSMatthew Dillon 
5578e25f19bSMatthew Dillon extern const char *OperatingSystemName;
5588e25f19bSMatthew Dillon extern const char *ArchitectureName;
5598e25f19bSMatthew Dillon extern const char *MachineName;
5608e25f19bSMatthew Dillon extern const char *ReleaseName;
5618e25f19bSMatthew Dillon extern const char *VersionName;
5620df5ec4eSMatthew Dillon extern const char *VersionOnlyName;
5630df5ec4eSMatthew Dillon extern const char *VersionFromParamHeader;
5648e25f19bSMatthew Dillon 
56568dc2eeaSMatthew Dillon extern const char *ConfigBase1;
56668dc2eeaSMatthew Dillon extern const char *ConfigBase2;
5678ec23ca1SMatthew Dillon extern const char *ConfigBase;
5688e25f19bSMatthew Dillon extern const char *DPortsPath;
5698e25f19bSMatthew Dillon extern const char *CCachePath;
5708e25f19bSMatthew Dillon extern const char *PackagesPath;
5718e25f19bSMatthew Dillon extern const char *RepositoryPath;
5728e25f19bSMatthew Dillon extern const char *OptionsPath;
5738e25f19bSMatthew Dillon extern const char *DistFilesPath;
5748e25f19bSMatthew Dillon extern const char *BuildBase;
5758e25f19bSMatthew Dillon extern const char *LogsPath;
5768e25f19bSMatthew Dillon extern const char *SystemPath;
577483dbac9SMatthew Dillon extern const char *UsePkgSufx;
57868dc2eeaSMatthew Dillon extern const char *Profile;
5796a7ba689SMatthew Dillon extern int MetaVersion;
580aac7a6d9SMatthew Dillon extern char *StatsBase;
581aac7a6d9SMatthew Dillon extern char *StatsFilePath;
582aac7a6d9SMatthew Dillon extern char *StatsLockPath;
58368dc2eeaSMatthew Dillon 
58468dc2eeaSMatthew Dillon extern int UsingHooks;
58568dc2eeaSMatthew Dillon extern const char *HookRunStart;
58668dc2eeaSMatthew Dillon extern const char *HookRunEnd;
58768dc2eeaSMatthew Dillon extern const char *HookPkgSuccess;
58868dc2eeaSMatthew Dillon extern const char *HookPkgFailure;
58968dc2eeaSMatthew Dillon extern const char *HookPkgIgnored;
59068dc2eeaSMatthew Dillon extern const char *HookPkgSkipped;
5918e25f19bSMatthew Dillon 
5928e25f19bSMatthew Dillon void _dfatal(const char *file, int line, const char *func, int do_errno,
5938e25f19bSMatthew Dillon 	     const char *fmt, ...);
5948e25f19bSMatthew Dillon void _ddprintf(int tab, const char *fmt, ...);
5958e25f19bSMatthew Dillon void _dlog(int which, const char *fmt, ...);
5964ea2ee4dSMatthew Dillon char *strdup_or_null(char *str);
5978e25f19bSMatthew Dillon void dlogreset(void);
59854f2fefcSMatthew Dillon int dlog00_fd(void);
5996fd67931SMatthew Dillon void addbuildenv(const char *label, const char *data, int type);
600a67bf8dbSMatthew Dillon void delbuildenv(const char *label);
601aeecca07SMatthew Dillon const char *getbuildenv(const char *label);
602aac7a6d9SMatthew Dillon int readlogline(monitorlog_t *log, char **bufp);
603b6bd007bSMatthew Dillon uint32_t crcDirTree(const char *path);
6048e25f19bSMatthew Dillon 
6058e25f19bSMatthew Dillon void initbulk(void (*func)(bulk_t *bulk), int jobs);
6067f0eca56SMatthew Dillon void queuebulk(const char *s1, const char *s2, const char *s3,
6078e25f19bSMatthew Dillon 			const char *s4);
6088e25f19bSMatthew Dillon bulk_t *getbulk(void);
6098e25f19bSMatthew Dillon void donebulk(void);
6108e25f19bSMatthew Dillon void freebulk(bulk_t *bulk);
6118e25f19bSMatthew Dillon void freestrp(char **strp);
6128e25f19bSMatthew Dillon void dupstrp(char **strp);
6131645cafeSMatthew Dillon int askyn(const char *ctl, ...);
6143699ee09SMatthew Dillon double getswappct(int *noswapp);
615f9d29536SMatthew Dillon FILE *dexec_open(const char *logid, const char **cav, int cac,
616f9d29536SMatthew Dillon 			pid_t *pidp, buildenv_t *xenv,
6176fd67931SMatthew Dillon 			int with_env, int with_mvars);
6186fd67931SMatthew Dillon int dexec_close(FILE *fp, pid_t pid);
6193cebe4a8SMatthew Dillon const char *getphasestr(worker_phase_t phase);
620*2b3f93eaSMatthew Dillon void set_capability_restrictions(void);
6218e25f19bSMatthew Dillon 
6228e25f19bSMatthew Dillon void ParseConfiguration(int isworker);
623710838f7SMatthew Dillon pkg_t *ParsePackageList(int ac, char **av, int debugstop);
6248e25f19bSMatthew Dillon void FreePackageList(pkg_t *pkgs);
6258e25f19bSMatthew Dillon pkg_t *GetLocalPackageList(void);
6268e25f19bSMatthew Dillon pkg_t *GetFullPackageList(void);
627549987f1SMatthew Dillon pkg_t *GetPkgPkg(pkg_t **listp);
6288e25f19bSMatthew Dillon 
6298e25f19bSMatthew Dillon void DoConfigure(void);
6301645cafeSMatthew Dillon void DoStatus(pkg_t *pkgs);
6318e25f19bSMatthew Dillon void DoBuild(pkg_t *pkgs);
6328e25f19bSMatthew Dillon void DoInitBuild(int slot_override);
63387017ac4SMatthew Dillon void DoCleanBuild(int resetlogs);
634a67bf8dbSMatthew Dillon void OptimizeEnv(void);
6358e25f19bSMatthew Dillon void WorkerProcess(int ac, char **av);
6368e25f19bSMatthew Dillon 
6371d6e00cdSMatthew Dillon int DoCreateTemplate(int force);
6388e25f19bSMatthew Dillon void DoDestroyTemplate(void);
6398e25f19bSMatthew Dillon void DoWorkerMounts(worker_t *work);
6408e25f19bSMatthew Dillon void DoWorkerUnmounts(worker_t *work);
6418e25f19bSMatthew Dillon void DoRebuildRepo(int ask);
6428e25f19bSMatthew Dillon void DoUpgradePkgs(pkg_t *pkgs, int ask);
6438e25f19bSMatthew Dillon void RemovePackages(pkg_t *pkgs);
6448e25f19bSMatthew Dillon void PurgeDistfiles(pkg_t *pkgs);
6458e25f19bSMatthew Dillon 
646ea37671dSMatthew Dillon void RunStatsInit(void);
647ea37671dSMatthew Dillon void RunStatsDone(void);
648ea37671dSMatthew Dillon void RunStatsReset(void);
649aac7a6d9SMatthew Dillon void RunStatsUpdate(worker_t *work, const char *portdir);
6508b485838SMatthew Dillon void RunStatsUpdateTop(int active);
651ea37671dSMatthew Dillon void RunStatsUpdateLogs(void);
652ea37671dSMatthew Dillon void RunStatsSync(void);
65364b61b2eSMatthew Dillon void RunStatsUpdateCompletion(worker_t *work, int logid, pkg_t *pkg,
65464b61b2eSMatthew Dillon 			const char *reason, const char *skipbuf);
6558e25f19bSMatthew Dillon 
6563bd7e0a7SMatthew Dillon void setNumaDomain(int slot);
6573bd7e0a7SMatthew Dillon 
6588b485838SMatthew Dillon int copyfile(char *src, char *dst);
6598e25f19bSMatthew Dillon int ipcreadmsg(int fd, wmsg_t *msg);
6608e25f19bSMatthew Dillon int ipcwritemsg(int fd, wmsg_t *msg);
661aac7a6d9SMatthew Dillon extern void MonitorDirective(const char *datfile, const char *lkfile);
662b6bd007bSMatthew Dillon 
663b6bd007bSMatthew Dillon uint32_t iscsi_crc32(const void *buf, size_t size);
664b6bd007bSMatthew Dillon uint32_t iscsi_crc32_ext(const void *buf, size_t size, uint32_t ocrc);
665