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