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