xref: /dragonfly/usr.bin/dsynth/dsynth.h (revision 556932ec)
1 /*
2  * Copyright (c) 2019-2022 The DragonFly Project.  All rights reserved.
3  *
4  * This code is derived from software contributed to The DragonFly Project
5  * by Matthew Dillon <dillon@backplane.com>
6  *
7  * This code uses concepts and configuration based on 'synth', by
8  * John R. Marino <draco@marino.st>, which was written in ada.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  *
14  * 1. Redistributions of source code must retain the above copyright
15  *    notice, this list of conditions and the following disclaimer.
16  * 2. Redistributions in binary form must reproduce the above copyright
17  *    notice, this list of conditions and the following disclaimer in
18  *    the documentation and/or other materials provided with the
19  *    distribution.
20  * 3. Neither the name of The DragonFly Project nor the names of its
21  *    contributors may be used to endorse or promote products derived
22  *    from this software without specific, prior written permission.
23  *
24  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
27  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE
28  * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
29  * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
30  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
32  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
33  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
34  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35  * SUCH DAMAGE.
36  */
37 
38 #include <sys/types.h>
39 #include <sys/wait.h>
40 #include <sys/stat.h>
41 #include <sys/sysctl.h>
42 #include <sys/socket.h>
43 #include <sys/un.h>
44 #include <sys/mount.h>
45 #include <sys/procctl.h>
46 #include <sys/resource.h>	/* setpriority() */
47 #if defined(__DragonFly__)
48 #include <sys/vmmeter.h>
49 #endif
50 #include <stdio.h>
51 #include <stdlib.h>
52 #include <stddef.h>
53 #include <stdarg.h>
54 #include <unistd.h>
55 #include <string.h>
56 #include <fcntl.h>
57 #include <fts.h>
58 #include <ndbm.h>
59 #include <signal.h>
60 #include <poll.h>
61 #include <assert.h>
62 #include <errno.h>
63 #include <pthread.h>
64 #include <pthread_np.h>
65 #include <dirent.h>
66 #include <termios.h>
67 #include <time.h>
68 #include <ctype.h>
69 
70 /*
71  * More esoteric headers
72  */
73 #include <libutil.h>	/* forkpty() */
74 #include <arpa/inet.h>	/* ntohl() */
75 #include <elf.h>	/* try to get elf info */
76 
77 struct pkglink;
78 
79 #define DSYNTH_VERSION	"1.0.2"
80 #define MAXWORKERS	1024
81 #define MAXLOGLINES	1024
82 #define MAXJOBS		8192	/* just used for -j sanity */
83 #define MAXBULK		MAXWORKERS
84 
85 #define MAKE_BINARY		"/usr/bin/make"
86 #define PKG_BINARY		"/usr/local/sbin/pkg"
87 #define MOUNT_BINARY		"/sbin/mount"
88 #define UMOUNT_BINARY		"/sbin/umount"
89 
90 #define STATS_FILE		"monitor.dat"		/* under LogsPath */
91 #define STATS_LOCKFILE		"monitor.lk"		/* under LogsPath */
92 
93 #define ONEGB		(1024L * 1024 * 1024)
94 #define DISABLED_STR	"disabled"
95 
96 /*
97  * This can be ".tar", ".tgz", ".txz", ".tbz", "tzst".
98  *
99  * .tar	- very fast but you'll need 1TB+ of storage just for the package files.
100  * .txz - very compact but decompression speed is horrible.
101  * .tgz - reasonable compression, extremely fast decompression.  Roughly
102  *	  1.1x to 2.0x the size of a .txz, but decompresses 10x faster.
103  * .tbz - worse than .tgz generally
104  * .tzst - slightly worse compression ratio to .txz, decompresses 13x faster.
105  *
106  * NOTE: Decompression speed does effect bulk builds since each slot has
107  *	 to install pre-reqs before building any particular package.  Set
108  *	 the default to .txz to remain close to synth's default.
109  *
110  * NOTE: As of version 1.17 of pkg, all package files use the .pkg suffix
111  *	 regardless of the compression format.
112  */
113 #define USE_PKG_SUFX		".txz"
114 
115 /*
116  * Topology linkages
117  */
118 typedef struct pkglink {
119 	struct pkglink *next;
120 	struct pkglink *prev;
121 	struct pkg *pkg;
122 	int	dep_type;
123 } pkglink_t;
124 
125 #define DEP_TYPE_FETCH	1
126 #define DEP_TYPE_EXT	2
127 #define DEP_TYPE_PATCH	3
128 #define DEP_TYPE_BUILD	4
129 #define DEP_TYPE_LIB	5
130 #define DEP_TYPE_RUN	6
131 
132 /*
133  * Describes a [flavored] package
134  */
135 typedef struct pkg {
136 	struct pkg *build_next;	/* topology inversion build list */
137 	struct pkg *bnext;	/* linked list from bulk return */
138 	struct pkg *hnext1;	/* hash based on portdir */
139 	struct pkg *hnext2;	/* hash based on pkgfile */
140 	pkglink_t idepon_list;	/* I need these pkgs */
141 	pkglink_t deponi_list;	/* pkgs which depend on me */
142 	char *portdir;		/* origin name e.g. www/chromium[@flavor] */
143 	char *logfile;		/* relative logfile path */
144 	char *version;		/* PKGVERSION - e.g. 3.5.0_1		*/
145 	char *pkgfile;		/* PKGFILE    - e.g. flav-blah-3.5.0_1.txz */
146 	char *distfiles;	/* DISTFILES  - e.g. blah-68.0.source.tar.xz */
147 	char *distsubdir;	/* DIST_SUBDIR- e.g. cabal		*/
148 	char *ignore;		/* IGNORE (also covers BROKEN)		*/
149 	char *fetch_deps;	/* FETCH_DEPENDS			*/
150 	char *ext_deps;		/* EXTRACT_DEPENDS			*/
151 	char *patch_deps;	/* PATCH_DEPENDS			*/
152 	char *build_deps;	/* BUILD_DEPENDS			*/
153 	char *lib_deps;		/* LIB_DEPENDS				*/
154 	char *run_deps;		/* RUN_DEPENDS				*/
155 	char *pos_options;	/* SELECTED_OPTIONS			*/
156 	char *neg_options;	/* DESELECTED_OPTIONS			*/
157 	char *flavors;		/* FLAVORS    - e.g. py36 py27		*/
158 	char *uses;		/* USES (metaport test)			*/
159 	int make_jobs_number;	/* MAKE_JOBS_NUMBER			*/
160 	int use_linux;		/* USE_LINUX				*/
161 	int idep_count;		/* count recursive idepon build deps	*/
162 	int depi_count;		/* count recursive deponi build deps	*/
163 	int depi_depth;		/* tree depth who depends on me		*/
164 	int dsynth_install_flg;	/* locked with WorkerMutex	*/
165 	int flags;
166 	int rscan;		/* recursive scan flag (serialized use) */
167 	uint32_t crc32;		/* crc of port directory tree */
168 	size_t pkgfile_size;	/* size of pkgfile */
169 } pkg_t;
170 
171 #define PKGF_PACKAGED	0x00000001	/* has a repo package */
172 #define PKGF_DUMMY	0x00000002	/* generic root for flavors */
173 #define PKGF_NOTFOUND	0x00000004	/* dport not found */
174 #define PKGF_CORRUPT	0x00000008	/* dport corrupt */
175 #define PKGF_PLACEHOLD	0x00000010	/* pre-entered */
176 #define PKGF_BUILDLIST	0x00000020	/* on build_list */
177 #define PKGF_BUILDLOOP	0x00000040	/* traversal loop test */
178 #define PKGF_BUILDTRAV	0x00000080	/* traversal optimization */
179 #define PKGF_NOBUILD_D	0x00000100	/* can't build - dependency problem */
180 #define PKGF_NOBUILD_S	0x00000200	/* can't build - skipped */
181 #define PKGF_NOBUILD_F	0x00000400	/* can't build - failed */
182 #define PKGF_NOBUILD_I	0x00000800	/* can't build - ignored or broken */
183 #define PKGF_SUCCESS	0x00001000	/* build complete */
184 #define PKGF_FAILURE	0x00002000	/* build complete */
185 #define PKGF_RUNNING	0x00004000	/* build complete */
186 #define PKGF_PKGPKG	0x00008000	/* pkg/pkg-static special */
187 #define PKGF_NOTREADY	0x00010000	/* build_find_leaves() only */
188 #define PKGF_MANUALSEL	0x00020000	/* manually specified */
189 #define PKGF_META	0x00040000	/* USES contains 'metaport' */
190 #define PKGF_DEBUGSTOP	0x00080000	/* freeze slot on completion */
191 
192 #define PKGF_ERROR	(PKGF_PLACEHOLD | PKGF_CORRUPT | PKGF_NOTFOUND | \
193 			 PKGF_FAILURE)
194 #define PKGF_NOBUILD	(PKGF_NOBUILD_D | PKGF_NOBUILD_S | PKGF_NOBUILD_F | \
195 			 PKGF_NOBUILD_I)
196 
197 #define PKGLIST_EMPTY(pkglink)		((pkglink)->next == (pkglink))
198 #define PKGLIST_FOREACH(var, head)	\
199 	for (var = (head)->next; var != (head); var = (var)->next)
200 
201 typedef struct bulk {
202 	struct bulk *next;
203 	pthread_t td;
204 	int debug;
205 	int flags;
206 	enum { UNLISTED, ONSUBMIT, ONRUN, ISRUNNING, ONRESPONSE } state;
207 	char *s1;
208 	char *s2;
209 	char *s3;
210 	char *s4;
211 	char *r1;
212 	char *r2;
213 	char *r3;
214 	char *r4;
215 	pkg_t *list;		/* pkgs linked by bnext */
216 } bulk_t;
217 
218 /*
219  * Worker state (up to MAXWORKERS).  Each worker operates within a
220  * chroot or jail.  A system mirror is setup and the template
221  * is copied in.
222  *
223  * basedir		- tmpfs
224  * /bin			- nullfs (ro)
225  * /sbin		- nullfs (ro)
226  * /lib			- nullfs (ro)
227  * /libexec		- nullfs (ro)
228  * /usr/bin		- nullfs (ro)
229  * /usr/include		- nullfs (ro)
230  * /usr/lib		- nullfs (ro)
231  * /usr/libdata		- nullfs (ro)
232  * /usr/libexec		- nullfs (ro)
233  * /usr/sbin		- nullfs (ro)
234  * /usr/share		- nullfs (ro)
235  * /xports		- nullfs (ro)
236  * /options		- nullfs (ro)
237  * /packages		- nullfs (ro)
238  * /distfiles		- nullfs (ro)
239  * construction		- tmpfs
240  * /usr/local		- tmpfs
241  * /boot		- nullfs (ro)
242  * /boot/modules.local	- tmpfs
243  * /usr/games		- nullfs (ro)
244  * /usr/src		- nullfs (ro)
245  * /dev			- devfs
246  */
247 enum worker_state { WORKER_NONE, WORKER_IDLE, WORKER_PENDING,
248 		    WORKER_RUNNING, WORKER_DONE, WORKER_FAILED,
249 		    WORKER_FROZEN, WORKER_EXITING };
250 typedef enum worker_state worker_state_t;
251 
252 enum worker_phase { PHASE_PENDING,
253 		    PHASE_INSTALL_PKGS,
254 		    PHASE_CHECK_SANITY,
255 		    PHASE_PKG_DEPENDS,
256 		    PHASE_FETCH_DEPENDS,
257 		    PHASE_FETCH,
258 		    PHASE_CHECKSUM,
259 		    PHASE_EXTRACT_DEPENDS,
260 		    PHASE_EXTRACT,
261 		    PHASE_PATCH_DEPENDS,
262 		    PHASE_PATCH,
263 		    PHASE_BUILD_DEPENDS,
264 		    PHASE_LIB_DEPENDS,
265 		    PHASE_CONFIGURE,
266 		    PHASE_BUILD,
267 		    PHASE_RUN_DEPENDS,
268 		    PHASE_STAGE,
269 		    PHASE_TEST,
270 		    PHASE_CHECK_PLIST,
271 		    PHASE_PACKAGE,
272 		    PHASE_INSTALL,
273 		    PHASE_DEINSTALL,
274 		    PHASE_DUMP_ENV,
275 		    PHASE_DUMP_VAR,
276 		    PHASE_SHOW_CONFIG,
277 		    PHASE_DUMP_MAKECONF
278 		};
279 
280 typedef enum worker_phase worker_phase_t;
281 
282 /*
283  * Watchdog timeouts, in minutes, baseline, scales up with load/ncpus but
284  * does not scale down.
285  */
286 #define WDOG1	(5)
287 #define WDOG2	(10)
288 #define WDOG3	(15)
289 #define WDOG4	(30)
290 #define WDOG5	(60)
291 #define WDOG6	(60 + 30)
292 #define WDOG7	(60 * 2)
293 #define WDOG8	(60 * 2 + 30)
294 #define WDOG9	(60 * 3)
295 
296 typedef struct worker {
297 	int	index;		/* worker number 0..N-1 */
298 	int	flags;
299 	int	accum_error;	/* cumulative error */
300 	int	mount_error;	/* mount and unmount error */
301 	int	terminate : 1;	/* request sub-thread to terminate */
302 	char	*basedir;	/* base directory including id */
303 	char	*flavor;
304 	pthread_t td;		/* pthread */
305 	pthread_cond_t cond;	/* interlock cond (w/ WorkerMutex) */
306 	pkg_t	*pkg;
307 	worker_state_t state;	/* general worker state */
308 	worker_phase_t phase;	/* phase control in childBuilderThread */
309 	time_t	start_time;
310 	long	lines;
311 	long	memuse;
312 	pid_t	pid;
313 	int	fds[2];		/* forked environment process */
314 	char	status[64];
315 	size_t	pkg_dep_size;	/* pkg dependency size(s) */
316 } worker_t;
317 
318 #define WORKERF_STATUS_UPDATE	0x0001	/* display update */
319 #define WORKERF_SUCCESS		0x0002	/* completion flag */
320 #define WORKERF_FAILURE		0x0004	/* completion flag */
321 #define WORKERF_FREEZE		0x0008	/* freeze the worker */
322 
323 #define MOUNT_TYPE_MASK		0x000F
324 #define MOUNT_TYPE_TMPFS	0x0001
325 #define MOUNT_TYPE_NULLFS	0x0002
326 #define MOUNT_TYPE_DEVFS	0x0003
327 #define MOUNT_TYPE_PROCFS	0x0004
328 #define MOUNT_TYPE_RW		0x0010
329 #define MOUNT_TYPE_BIG		0x0020
330 #define MOUNT_TYPE_TMP		0x0040
331 #define MOUNT_TYPE_MED		0x0080
332 
333 #define NULLFS_RO		(MOUNT_TYPE_NULLFS)
334 #define NULLFS_RW		(MOUNT_TYPE_NULLFS | MOUNT_TYPE_RW)
335 #define PROCFS_RO		(MOUNT_TYPE_PROCFS)
336 #define TMPFS_RW		(MOUNT_TYPE_TMPFS | MOUNT_TYPE_RW)
337 #define TMPFS_RW_BIG		(MOUNT_TYPE_TMPFS | MOUNT_TYPE_RW |	\
338 				 MOUNT_TYPE_BIG)
339 #define TMPFS_RW_MED		(MOUNT_TYPE_TMPFS | MOUNT_TYPE_RW |	\
340 				 MOUNT_TYPE_MED)
341 #define DEVFS_RW		(MOUNT_TYPE_DEVFS | MOUNT_TYPE_RW)
342 
343 /*
344  * IPC messages between the worker support thread and the worker process.
345  */
346 typedef struct wmsg {
347 	int	cmd;
348 	int	status;
349 	long	lines;
350 	long	memuse;
351 	worker_phase_t phase;
352 } wmsg_t;
353 
354 #define WMSG_CMD_STATUS_UPDATE	0x0001
355 #define WMSG_CMD_SUCCESS	0x0002
356 #define WMSG_CMD_FAILURE	0x0003
357 #define WMSG_CMD_INSTALL_PKGS	0x0004
358 #define WMSG_RES_INSTALL_PKGS	0x0005
359 #define WMSG_CMD_FREEZEWORKER	0x0006
360 
361 /*
362  * Make variables and build environment
363  */
364 typedef struct buildenv {
365 	struct buildenv *next;
366 	const char *label;
367 	const char *data;
368 	char *a1;		/* allocations */
369 	char *a2;		/* allocations */
370 	int type;
371 } buildenv_t;
372 
373 /*
374  * Operating systems recognized by dsynth
375  */
376 enum os_id {
377 	OS_UNKNOWN, OS_DRAGONFLY, OS_FREEBSD, OS_NETBSD, OS_LINUX
378 };
379 
380 typedef enum os_id os_id_t;
381 
382 /*
383  * DLOG
384  */
385 #define DLOG_ALL	0	/* Usually stdout when curses disabled */
386 #define DLOG_SUCC	1	/* success_list.log		*/
387 #define DLOG_FAIL	2	/* failure_list.log		*/
388 #define DLOG_IGN	3	/* ignored_list.log		*/
389 #define DLOG_SKIP	4	/* skipped_list.log		*/
390 #define DLOG_ABN	5	/* abnormal_command_output	*/
391 #define DLOG_OBS	6	/* obsolete_packages.log	*/
392 #define DLOG_DEBUG	7	/* debug.log 			*/
393 #define DLOG_COUNT	8	/* total number of DLOGs	*/
394 #define DLOG_MASK	0x0FF
395 
396 #define DLOG_FILTER	0x100	/* Filter out of stdout in non-curses mode  */
397 #define DLOG_RED	0x200	/* Print in color */
398 #define DLOG_GRN	0x400	/* Print in color */
399 #define DLOG_STDOUT	0x800	/* And stdout */
400 
401 #define dassert(exp, fmt, ...)		\
402 	if (!(exp)) dpanic(fmt, ## __VA_ARGS__)
403 
404 #define ddassert(exp)			\
405 	dassert((exp), "\"%s\" line %d", __FILE__, __LINE__)
406 
407 #define dassert_errno(exp, fmt, ...)	\
408 	if (!(exp)) dpanic_errno(fmt, ## __VA_ARGS__)
409 
410 #define dlog_tab(which, tab, fmt, ...)	\
411 	_dlog(which, "%*.*s" fmt, (int)tab, (int)tab, "", ## __VA_ARGS__)
412 
413 #define dlog(which, fmt, ...)		\
414 	_dlog(which, fmt, ## __VA_ARGS__)
415 
416 #define dlog_tsnl(which, fmt, ...)	\
417 	_dlog(which, fmt, ## __VA_ARGS__)
418 
419 #define dfatal(fmt, ...)		\
420 	_dfatal(__FILE__, __LINE__, __func__, 0, fmt, ## __VA_ARGS__)
421 
422 #define dpanic(fmt, ...)		\
423 	_dfatal(__FILE__, __LINE__, __func__, 2, fmt, ## __VA_ARGS__)
424 
425 #define dfatal_errno(fmt, ...)		\
426 	_dfatal(__FILE__, __LINE__, __func__, 1, fmt, ## __VA_ARGS__)
427 
428 #define dpanic_errno(fmt, ...)		\
429 	_dfatal(__FILE__, __LINE__, __func__, 3, fmt, ## __VA_ARGS__)
430 
431 #define ddprintf(tab, fmt, ...)		\
432 	do {				\
433 	  if (DebugOpt == 1) dlog_tab(DLOG_DEBUG, tab, fmt, ## __VA_ARGS__); \
434 	     if (DebugOpt > 1) _ddprintf(tab, fmt, ## __VA_ARGS__);	     \
435 	} while(0)
436 
437 /*
438  * addbuildenv() types
439  */
440 #define BENV_ENVIRONMENT	1
441 #define BENV_MAKECONF		2
442 #define BENV_CMDMASK		0x000F
443 
444 #define BENV_PKGLIST		0x0010
445 
446 /*
447  * WORKER process flags
448  */
449 #define WORKER_PROC_DEBUGSTOP	0x0001
450 #define WORKER_PROC_DEVELOPER	0x0002
451 #define WORKER_PROC_CHECK_PLIST	0x0004
452 #define WORKER_PROC_INSTALL	0x0008
453 #define WORKER_PROC_DEINSTALL	0x0010
454 #define WORKER_PROC_PKGV17	0x0020
455 #define WORKER_PROC_FETCHONLY	0x0040
456 
457 /*
458  * Misc
459  */
460 #define DOSTRING(label)	#label
461 #define SCRIPTPATH(x)	DOSTRING(x)
462 #define MAXCAC		256
463 
464 /*
465  * RunStats satellite modules
466  */
467 typedef struct topinfo {
468 	int active;
469 	int pkgimpulse;
470 	int pkgrate;
471 	int noswap;
472 	int h;
473 	int m;
474 	int s;
475 	int total;
476 	int successful;
477 	int ignored;
478 	int remaining;
479 	int failed;
480 	int skipped;
481 	int meta;
482 	int dynmaxworkers;
483 	double dswap;
484 	double dload[3];
485 } topinfo_t;
486 
487 typedef struct runstats {
488 	struct runstats *next;
489 	void (*init)(void);
490 	void (*done)(void);
491 	void (*reset)(void);
492 	void (*update)(worker_t *work, const char *portdir);
493 	void (*updateTop)(topinfo_t *info);
494 	void (*updateLogs)(void);
495 	void (*updateCompletion)(worker_t *work, int dlogid, pkg_t *pkg,
496 				const char *reason, const char *skipbuf);
497 	void (*sync)(void);
498 } runstats_t;
499 
500 typedef struct monitorlog {
501 	off_t	offset;
502 	int	fd;
503 	int	buf_beg;
504 	int	buf_end;
505 	int	buf_scan;
506 	int	buf_discard_mode;
507 	char	buf[1024];
508 } monitorlog_t;
509 
510 extern runstats_t NCursesRunStats;
511 extern runstats_t MonitorRunStats;
512 extern runstats_t HtmlRunStats;
513 
514 extern int BuildCount;
515 extern int BuildTotal;
516 extern int BuildFailCount;
517 extern int BuildSkipCount;
518 extern int BuildIgnoreCount;
519 extern int BuildSuccessCount;
520 extern int BuildMissingCount;
521 extern int BuildMetaCount;
522 extern int DynamicMaxWorkers;
523 
524 extern buildenv_t *BuildEnv;
525 extern int WorkerProcFlags;
526 extern int DebugOpt;
527 extern int NiceOpt;
528 extern int MaskProbeAbort;
529 extern int ColorOpt;
530 extern int SlowStartOpt;
531 extern int ForceOpt;
532 extern int OverridePkgDeleteOpt;
533 extern int FetchOnlyOpt;
534 extern int YesOpt;
535 extern int NullStdinOpt;
536 extern int NumaSetSize;
537 extern int DeleteObsoletePkgs;
538 extern int UseCCache;
539 extern int UseUsrSrc;
540 extern int UseTmpfs;
541 extern int NumCores;
542 extern long PhysMem;
543 extern long PkgDepMemoryTarget;
544 extern long PkgDepScaleTarget;
545 extern int MaxBulk;
546 extern int MaxWorkers;
547 extern int MaxJobs;
548 extern int UseTmpfsWork;
549 extern int UseTmpfsBase;
550 extern int UseNCurses;
551 extern int LeveragePrebuilt;
552 extern char *DSynthExecPath;
553 extern char *ProfileOverrideOpt;
554 
555 extern const char *OperatingSystemName;
556 extern const char *ArchitectureName;
557 extern const char *MachineName;
558 extern const char *ReleaseName;
559 extern const char *VersionName;
560 extern const char *VersionOnlyName;
561 extern const char *VersionFromParamHeader;
562 
563 extern const char *ConfigBase1;
564 extern const char *ConfigBase2;
565 extern const char *ConfigBase;
566 extern const char *DPortsPath;
567 extern const char *CCachePath;
568 extern const char *PackagesPath;
569 extern const char *RepositoryPath;
570 extern const char *OptionsPath;
571 extern const char *DistFilesPath;
572 extern const char *BuildBase;
573 extern const char *LogsPath;
574 extern const char *SystemPath;
575 extern const char *UsePkgSufx;
576 extern const char *Profile;
577 extern int MetaVersion;
578 extern char *StatsBase;
579 extern char *StatsFilePath;
580 extern char *StatsLockPath;
581 
582 extern int UsingHooks;
583 extern const char *HookRunStart;
584 extern const char *HookRunEnd;
585 extern const char *HookPkgSuccess;
586 extern const char *HookPkgFailure;
587 extern const char *HookPkgIgnored;
588 extern const char *HookPkgSkipped;
589 
590 void _dfatal(const char *file, int line, const char *func, int do_errno,
591 	     const char *fmt, ...);
592 void _ddprintf(int tab, const char *fmt, ...);
593 void _dlog(int which, const char *fmt, ...);
594 char *strdup_or_null(char *str);
595 void dlogreset(void);
596 int dlog00_fd(void);
597 void addbuildenv(const char *label, const char *data, int type);
598 void delbuildenv(const char *label);
599 const char *getbuildenv(const char *label);
600 int readlogline(monitorlog_t *log, char **bufp);
601 uint32_t crcDirTree(const char *path);
602 
603 void initbulk(void (*func)(bulk_t *bulk), int jobs);
604 void queuebulk(const char *s1, const char *s2, const char *s3,
605 			const char *s4);
606 bulk_t *getbulk(void);
607 void donebulk(void);
608 void freebulk(bulk_t *bulk);
609 void freestrp(char **strp);
610 void dupstrp(char **strp);
611 int askyn(const char *ctl, ...);
612 double getswappct(int *noswapp);
613 FILE *dexec_open(const char *logid, const char **cav, int cac,
614 			pid_t *pidp, buildenv_t *xenv,
615 			int with_env, int with_mvars);
616 int dexec_close(FILE *fp, pid_t pid);
617 const char *getphasestr(worker_phase_t phase);
618 
619 void ParseConfiguration(int isworker);
620 pkg_t *ParsePackageList(int ac, char **av, int debugstop);
621 void FreePackageList(pkg_t *pkgs);
622 pkg_t *GetLocalPackageList(void);
623 pkg_t *GetFullPackageList(void);
624 pkg_t *GetPkgPkg(pkg_t **listp);
625 
626 void DoConfigure(void);
627 void DoStatus(pkg_t *pkgs);
628 void DoBuild(pkg_t *pkgs);
629 void DoInitBuild(int slot_override);
630 void DoCleanBuild(int resetlogs);
631 void OptimizeEnv(void);
632 void WorkerProcess(int ac, char **av);
633 
634 int DoCreateTemplate(int force);
635 void DoDestroyTemplate(void);
636 void DoWorkerMounts(worker_t *work);
637 void DoWorkerUnmounts(worker_t *work);
638 void DoRebuildRepo(int ask);
639 void DoUpgradePkgs(pkg_t *pkgs, int ask);
640 void RemovePackages(pkg_t *pkgs);
641 void PurgeDistfiles(pkg_t *pkgs);
642 
643 void RunStatsInit(void);
644 void RunStatsDone(void);
645 void RunStatsReset(void);
646 void RunStatsUpdate(worker_t *work, const char *portdir);
647 void RunStatsUpdateTop(int active);
648 void RunStatsUpdateLogs(void);
649 void RunStatsSync(void);
650 void RunStatsUpdateCompletion(worker_t *work, int logid, pkg_t *pkg,
651 			const char *reason, const char *skipbuf);
652 
653 void setNumaDomain(int slot);
654 
655 int copyfile(char *src, char *dst);
656 int ipcreadmsg(int fd, wmsg_t *msg);
657 int ipcwritemsg(int fd, wmsg_t *msg);
658 extern void MonitorDirective(const char *datfile, const char *lkfile);
659 
660 uint32_t iscsi_crc32(const void *buf, size_t size);
661 uint32_t iscsi_crc32_ext(const void *buf, size_t size, uint32_t ocrc);
662