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