int exec_check(int argc, char **argv) { struct pkg *pkg = NULL; struct pkgdb_it *it = NULL; struct pkgdb *db = NULL; struct sbuf *msg = NULL; match_t match = MATCH_EXACT; int flags = PKG_LOAD_BASIC; int ret, rc = EX_OK; int ch; bool dcheck = false; bool checksums = false; bool recompute = false; bool reanalyse_shlibs = false; bool noinstall = false; int nbpkgs = 0; int i, processed, total = 0; int verbose = 0; struct option longopts[] = { { "all", no_argument, NULL, 'a' }, { "shlibs", no_argument, NULL, 'B' }, { "case-sensitive", no_argument, NULL, 'C' }, { "dependencies", no_argument, NULL, 'd' }, { "glob", no_argument, NULL, 'g' }, { "case-insensitive", no_argument, NULL, 'i' }, { "dry-run", no_argument, NULL, 'n' }, { "recompute", no_argument, NULL, 'r' }, { "checksums", no_argument, NULL, 's' }, { "verbose", no_argument, NULL, 'v' }, { "regex", no_argument, NULL, 'x' }, { "yes", no_argument, NULL, 'y' }, { NULL, 0, NULL, 0 }, }; struct deps_head dh = STAILQ_HEAD_INITIALIZER(dh); processed = 0; while ((ch = getopt_long(argc, argv, "+aBCdginrsvxy", longopts, NULL)) != -1) { switch (ch) { case 'a': match = MATCH_ALL; break; case 'B': reanalyse_shlibs = true; flags |= PKG_LOAD_FILES; break; case 'C': pkgdb_set_case_sensitivity(true); break; case 'd': dcheck = true; flags |= PKG_LOAD_DEPS; break; case 'g': match = MATCH_GLOB; break; case 'i': pkgdb_set_case_sensitivity(false); break; case 'n': noinstall = true; break; case 'r': recompute = true; flags |= PKG_LOAD_FILES; break; case 's': checksums = true; flags |= PKG_LOAD_FILES; break; case 'v': verbose = 1; break; case 'x': match = MATCH_REGEX; break; case 'y': yes = true; break; default: usage_check(); return (EX_USAGE); } } argc -= optind; argv += optind; /* Default to all packages if no pkg provided */ if (argc == 0 && (dcheck || checksums || recompute || reanalyse_shlibs)) { match = MATCH_ALL; } else if ((argc == 0 && match != MATCH_ALL) || !(dcheck || checksums || recompute || reanalyse_shlibs)) { usage_check(); return (EX_USAGE); } if (recompute || reanalyse_shlibs) ret = pkgdb_access(PKGDB_MODE_READ|PKGDB_MODE_WRITE, PKGDB_DB_LOCAL); else ret = pkgdb_access(PKGDB_MODE_READ, PKGDB_DB_LOCAL); if (ret == EPKG_ENODB) { warnx("No packages installed. Nothing to do!"); return (EX_OK); } else if (ret == EPKG_ENOACCESS) { warnx("Insufficient privileges to access the package database"); return (EX_NOPERM); } else if (ret != EPKG_OK) { warnx("Error accessing the package database"); return (EX_SOFTWARE); } ret = pkgdb_open(&db, PKGDB_DEFAULT); if (ret != EPKG_OK) return (EX_IOERR); if (pkgdb_obtain_lock(db, PKGDB_LOCK_ADVISORY) != EPKG_OK) { pkgdb_close(db); warnx("Cannot get an advisory lock on a database, it is locked by another process"); return (EX_TEMPFAIL); } i = 0; nbdone = 0; do { /* XXX: This is really quirky, it would be cleaner to pass * in multiple matches and only run this top-loop once. */ if ((it = pkgdb_query(db, argv[i], match)) == NULL) { rc = EX_IOERR; goto cleanup; } if (msg == NULL) msg = sbuf_new_auto(); if (!verbose) { if (match == MATCH_ALL) progressbar_start("Checking all packages"); else { sbuf_printf(msg, "Checking %s", argv[i]); sbuf_finish(msg); progressbar_start(sbuf_data(msg)); } processed = 0; total = pkgdb_it_count(it); } else { if (match == MATCH_ALL) nbactions = pkgdb_it_count(it); else nbactions = argc; } while (pkgdb_it_next(it, &pkg, flags) == EPKG_OK) { if (!verbose) progressbar_tick(processed, total); else { ++nbdone; job_status_begin(msg); pkg_sbuf_printf(msg, "Checking %n-%v:", pkg, pkg); sbuf_flush(msg); } /* check for missing dependencies */ if (dcheck) { if (verbose) printf(" dependencies..."); nbpkgs += check_deps(db, pkg, &dh, noinstall); if (noinstall && nbpkgs > 0) { rc = EX_UNAVAILABLE; } } if (checksums) { if (verbose) printf(" checksums..."); if (pkg_test_filesum(pkg) != EPKG_OK) { rc = EX_DATAERR; } } if (recompute) { if (pkgdb_upgrade_lock(db, PKGDB_LOCK_ADVISORY, PKGDB_LOCK_EXCLUSIVE) == EPKG_OK) { if (verbose) printf(" recomputing..."); if (pkg_recompute(db, pkg) != EPKG_OK) { rc = EX_DATAERR; } pkgdb_downgrade_lock(db, PKGDB_LOCK_EXCLUSIVE, PKGDB_LOCK_ADVISORY); } else { rc = EX_TEMPFAIL; } } if (reanalyse_shlibs) { if (pkgdb_upgrade_lock(db, PKGDB_LOCK_ADVISORY, PKGDB_LOCK_EXCLUSIVE) == EPKG_OK) { if (verbose) printf(" shared libraries..."); if (pkgdb_reanalyse_shlibs(db, pkg) != EPKG_OK) { pkg_fprintf(stderr, "Failed to " "reanalyse for shlibs: " "%n-%v\n", pkg, pkg); rc = EX_UNAVAILABLE; } pkgdb_downgrade_lock(db, PKGDB_LOCK_EXCLUSIVE, PKGDB_LOCK_ADVISORY); } else { rc = EX_TEMPFAIL; } } if (!verbose) ++processed; else printf(" done\n"); } if (!verbose) progressbar_tick(processed, total); if (msg != NULL) { sbuf_delete(msg); msg = NULL; } if (dcheck && nbpkgs > 0 && !noinstall) { printf("\n>>> Missing package dependencies were detected.\n"); printf(">>> Found %d issue(s) in the package database.\n\n", nbpkgs); if (pkgdb_upgrade_lock(db, PKGDB_LOCK_ADVISORY, PKGDB_LOCK_EXCLUSIVE) == EPKG_OK) { ret = fix_deps(db, &dh, nbpkgs, yes); if (ret == EPKG_OK) check_summary(db, &dh); else if (ret == EPKG_ENODB) { db = NULL; rc = EX_IOERR; } pkgdb_downgrade_lock(db, PKGDB_LOCK_EXCLUSIVE, PKGDB_LOCK_ADVISORY); if (rc == EX_IOERR) goto cleanup; } else { rc = EX_TEMPFAIL; goto cleanup; } } pkgdb_it_free(it); i++; } while (i < argc); cleanup: if (!verbose) progressbar_stop(); if (msg != NULL) sbuf_delete(msg); deps_free(&dh); pkg_free(pkg); pkgdb_release_lock(db, PKGDB_LOCK_ADVISORY); pkgdb_close(db); return (rc); }
*/ struct fs_map_entry { int32_t hrIndex; /* used for fs_entry::index */ u_char *a_name; /* map key same as fs_entry::mountPoint */ /* may be NULL if the respective hrFSTblEntry is (temporally) gone */ struct fs_entry *entry; STAILQ_ENTRY(fs_map_entry) link; }; STAILQ_HEAD(fs_map, fs_map_entry); /* head of the list with hrFSTable's entries */ static struct fs_tbl fs_tbl = TAILQ_HEAD_INITIALIZER(fs_tbl); /* for consistent table indexing */ static struct fs_map fs_map = STAILQ_HEAD_INITIALIZER(fs_map); /* next index available for hrFSTable */ static uint32_t next_fs_index = 1; /* last tick when hrFSTable was updated */ static uint64_t fs_tick; /* maximum number of ticks between refreshs */ uint32_t fs_tbl_refresh = HR_FS_TBL_REFRESH * 100; /* some constants */ static const struct asn_oid OIDX_hrFSBerkeleyFFS_c = OIDX_hrFSBerkeleyFFS; static const struct asn_oid OIDX_hrFSiso9660_c = OIDX_hrFSiso9660; static const struct asn_oid OIDX_hrFSNFS_c = OIDX_hrFSNFS; static const struct asn_oid OIDX_hrFSLinuxExt2_c = OIDX_hrFSLinuxExt2;
struct xenbus_device *xdev; int unit; int evtchn; int gnt_ref; /* Lock this when doing any operations in sh_info */ struct mtx sh_info_lock; struct xen_pci_sharedinfo *sh_info; device_t ndev; int ref_cnt; }; static STAILQ_HEAD(pcifront_dlist, pcifront_device) pdev_list = STAILQ_HEAD_INITIALIZER(pdev_list); struct xpcib_softc { int domain; int bus; struct pcifront_device *pdev; }; /* Allocate a PCI device structure */ static struct pcifront_device * alloc_pdev(struct xenbus_device *xdev) { struct pcifront_device *pdev = NULL; int err, unit; err = sscanf(xdev->nodename, "device/pci/%d", &unit);
} SYSINIT(mbuf, SI_SUB_MBUF, SI_ORDER_FIRST, mbuf_init, NULL); #ifdef NETDUMP /* * netdump makes use of a pre-allocated pool of mbufs and clusters. When * netdump is configured, we initialize a set of UMA cache zones which return * items from this pool. At panic-time, the regular UMA zone pointers are * overwritten with those of the cache zones so that drivers may allocate and * free mbufs and clusters without attempting to allocate physical memory. * * We keep mbufs and clusters in a pair of mbuf queues. In particular, for * the purpose of caching clusters, we treat them as mbufs. */ static struct mbufq nd_mbufq = { STAILQ_HEAD_INITIALIZER(nd_mbufq.mq_head), 0, INT_MAX }; static struct mbufq nd_clustq = { STAILQ_HEAD_INITIALIZER(nd_clustq.mq_head), 0, INT_MAX }; static int nd_clsize; static uma_zone_t nd_zone_mbuf; static uma_zone_t nd_zone_clust; static uma_zone_t nd_zone_pack; static int nd_buf_import(void *arg, void **store, int count, int domain __unused, int flags) { struct mbufq *q; struct mbuf *m; int i;
#include <machine/cpu.h> #include <machine/clock.h> static MALLOC_DEFINE(M_TTYCONS, "tty console", "tty console handling"); struct cn_device { STAILQ_ENTRY(cn_device) cnd_next; struct consdev *cnd_cn; }; #define CNDEVPATHMAX 32 #define CNDEVTAB_SIZE 4 static struct cn_device cn_devtab[CNDEVTAB_SIZE]; static STAILQ_HEAD(, cn_device) cn_devlist = STAILQ_HEAD_INITIALIZER(cn_devlist); int cons_avail_mask = 0; /* Bit mask. Each registered low level console * which is currently unavailable for inpit * (i.e., if it is in graphics mode) will have * this bit cleared. */ static int cn_mute; static char *consbuf; /* buffer used by `consmsgbuf' */ static struct callout conscallout; /* callout for outputting to constty */ struct msgbuf consmsgbuf; /* message buffer for console tty */ static u_char console_pausing; /* pause after each line during probe */ static char *console_pausestr= "<pause; press any key to proceed to next line or '.' to end pause mode>"; struct tty *constty; /* pointer to console "window" tty */ static struct mtx cnputs_mtx; /* Mutex for cnputs(). */
} memcpy(str + prelen, path, len); /* includes zero */ return (str); } /* * Pattern lists for include / exclude processing */ struct pattern { STAILQ_ENTRY(pattern) link; char pattern[]; }; STAILQ_HEAD(pattern_list, pattern); static struct pattern_list include = STAILQ_HEAD_INITIALIZER(include); static struct pattern_list exclude = STAILQ_HEAD_INITIALIZER(exclude); /* * Add an entry to a pattern list */ static void add_pattern(struct pattern_list *list, const char *pattern) { struct pattern *entry; size_t len; debug("adding pattern '%s'\n", pattern); len = strlen(pattern); if ((entry = malloc(sizeof *entry + len + 1)) == NULL) { errno = ENOMEM;
/* * next may be NULL if the respective storage_entry * is (temporally) gone */ struct storage_entry *entry; STAILQ_ENTRY(storage_map_entry) link; }; STAILQ_HEAD(storage_map, storage_map_entry); /* the head of the list with table's entries */ static struct storage_tbl storage_tbl = TAILQ_HEAD_INITIALIZER(storage_tbl); /*for consistent table indexing*/ static struct storage_map storage_map = STAILQ_HEAD_INITIALIZER(storage_map); /* last (agent) tick when hrStorageTable was updated */ static uint64_t storage_tick; /* maximum number of ticks between two refreshs */ uint32_t storage_tbl_refresh = HR_STORAGE_TBL_REFRESH * 100; /* for kvm_getswapinfo, malloc'd */ static struct kvm_swap *swap_devs; static size_t swap_devs_len; /* item count for swap_devs */ /* for getfsstat, malloc'd */ static struct statfs *fs_buf; static size_t fs_buf_count; /* item count for fs_buf */
void bios_getsmap(void) { struct smap_buf buf; STAILQ_HEAD(smap_head, smap_buf) head = STAILQ_HEAD_INITIALIZER(head); struct smap_buf *cur, *next; u_int n, x; STAILQ_INIT(&head); n = 0; x = 0; v86.ebx = 0; do { v86.ctl = V86_FLAGS; v86.addr = 0x15; v86.eax = 0xe820; /* int 0x15 function 0xe820 */ v86.ecx = SMAP_BUFSIZE; v86.edx = SMAP_SIG; v86.es = VTOPSEG(&buf); v86.edi = VTOPOFF(&buf); v86int(); if (V86_CY(v86.efl) || v86.eax != SMAP_SIG || v86.ecx < sizeof(buf.smap) || v86.ecx > SMAP_BUFSIZE) break; next = malloc(sizeof(*next)); if (next == NULL) break; next->smap = buf.smap; if (v86.ecx == SMAP_BUFSIZE) { next->xattr = buf.xattr; x++; } STAILQ_INSERT_TAIL(&head, next, bufs); n++; } while (v86.ebx != 0); smaplen = n; if (smaplen > 0) { smapbase = malloc(smaplen * sizeof(*smapbase)); if (smapbase != NULL) { n = 0; STAILQ_FOREACH(cur, &head, bufs) smapbase[n++] = cur->smap; } if (smaplen == x) { smapattr = malloc(smaplen * sizeof(*smapattr)); if (smapattr != NULL) { n = 0; STAILQ_FOREACH(cur, &head, bufs) smapattr[n++] = cur->xattr & SMAP_XATTR_MASK; } } else smapattr = NULL; cur = STAILQ_FIRST(&head); while (cur != NULL) { next = STAILQ_NEXT(cur, bufs); free(cur); cur = next; } } }
#include <unistd.h> #include <fetch.h> #include <pthread.h> #include "pkg.h" #include "private/event.h" #include "private/pkg.h" #include "private/utils.h" struct http_mirror { struct url *url; STAILQ_ENTRY(http_mirror) next; }; static struct dns_srvinfo *srv_mirrors = NULL; static STAILQ_HEAD(,http_mirror) http_mirrors = STAILQ_HEAD_INITIALIZER(http_mirrors); static void gethttpmirrors(const char *url) { FILE *f; char *line = NULL; size_t linecap = 0; ssize_t linelen; struct http_mirror *m; struct url *u; if ((f = fetchGetURL(url, "")) == NULL) return; while ((linelen = getline(&line, &linecap, f)) > 0) { if (strncmp(line, "URL:", 4) == 0) {
int exec_check(int argc, char **argv) { struct pkg *pkg = NULL; struct pkgdb_it *it = NULL; struct pkgdb *db = NULL; match_t match = MATCH_EXACT; int flags = PKG_LOAD_BASIC; int ret, rc = EX_OK; int ch; bool yes; bool dcheck = false; bool checksums = false; bool recompute = false; bool reanalyse_shlibs = false; bool noinstall = false; int nbpkgs = 0; int i; int verbose = 0; pkg_config_bool(PKG_CONFIG_ASSUME_ALWAYS_YES, &yes); struct deps_head dh = STAILQ_HEAD_INITIALIZER(dh); while ((ch = getopt(argc, argv, "yagidnBxsrv")) != -1) { switch (ch) { case 'a': match = MATCH_ALL; break; case 'B': reanalyse_shlibs = true; flags |= PKG_LOAD_FILES; break; case 'd': dcheck = true; flags |= PKG_LOAD_DEPS; break; case 'g': match = MATCH_GLOB; break; case 'i': pkgdb_set_case_sensitivity(false); break; case 'n': noinstall = true; break; case 'r': recompute = true; flags |= PKG_LOAD_FILES; break; case 's': checksums = true; flags |= PKG_LOAD_FILES; break; case 'v': verbose = 1; break; case 'x': match = MATCH_REGEX; break; case 'y': yes = true; break; default: usage_check(); return (EX_USAGE); } } argc -= optind; argv += optind; /* Default to all packages if no pkg provided */ if (argc == 0 && (dcheck || checksums || recompute || reanalyse_shlibs)) { match = MATCH_ALL; } else if ((argc == 0 && match != MATCH_ALL) || !(dcheck || checksums || recompute || reanalyse_shlibs)) { usage_check(); return (EX_USAGE); } if (recompute || reanalyse_shlibs) ret = pkgdb_access(PKGDB_MODE_READ|PKGDB_MODE_WRITE, PKGDB_DB_LOCAL); else ret = pkgdb_access(PKGDB_MODE_READ, PKGDB_DB_LOCAL); if (ret == EPKG_ENODB) { warnx("No packages installed. Nothing to do!"); return (EX_OK); } else if (ret == EPKG_ENOACCESS) { warnx("Insufficient privileges to access the package database"); return (EX_NOPERM); } else if (ret != EPKG_OK) { warnx("Error accessing the package database"); return (EX_SOFTWARE); } ret = pkgdb_open(&db, PKGDB_DEFAULT); if (ret != EPKG_OK) return (EX_IOERR); i = 0; do { if ((it = pkgdb_query(db, argv[i], match)) == NULL) { pkgdb_close(db); return (EX_IOERR); } while (pkgdb_it_next(it, &pkg, flags) == EPKG_OK) { /* check for missing dependencies */ if (dcheck) { if (verbose) pkg_printf("Checking dependencies: %n\n", pkg); nbpkgs += check_deps(db, pkg, &dh, noinstall); if (noinstall && nbpkgs > 0) { rc = EX_UNAVAILABLE; } } if (checksums) { if (verbose) pkg_printf("Checking checksums: %n\n", pkg); if (pkg_test_filesum(pkg) != EPKG_OK) { rc = EX_DATAERR; } } if (recompute) { if (verbose) pkg_printf("Recomputing size and checksums: %n\n", pkg); if (pkg_recompute(db, pkg) != EPKG_OK) { rc = EX_DATAERR; } } if (reanalyse_shlibs) { if (verbose) pkg_printf("Reanalyzing files for shlibs: %n\n", pkg); if (pkgdb_reanalyse_shlibs(db, pkg) != EPKG_OK) { pkg_printf("Failed to reanalyse for shlibs: %n\n", pkg); rc = EX_UNAVAILABLE; } } } if (dcheck && nbpkgs > 0 && !noinstall) { printf("\n>>> Missing package dependencies were detected.\n"); printf(">>> Found %d issue(s) in the package database.\n\n", nbpkgs); ret = fix_deps(db, &dh, nbpkgs, yes); if (ret == EPKG_OK) check_summary(db, &dh); else if (ret == EPKG_ENODB) { db = NULL; return (EX_IOERR); } } pkgdb_it_free(it); i++; } while (i < argc); deps_free(&dh); pkg_free(pkg); pkgdb_close(db); return (rc); }
} static int riscv64_fetch_retval(struct trussinfo *trussinfo, long *retval, int *errorp) { struct reg regs; lwpid_t tid; tid = trussinfo->curthread->tid; if (ptrace(PT_GETREGS, tid, (caddr_t)®s, 0) < 0) { fprintf(trussinfo->outfile, "-- CANNOT READ REGISTERS --\n"); return (-1); } retval[0] = regs.a[0]; retval[1] = regs.a[1]; *errorp = !!(regs.t[0]); return (0); } static struct procabi riscv64_freebsd = { "FreeBSD ELF64", SYSDECODE_ABI_FREEBSD, riscv64_fetch_args, riscv64_fetch_retval, STAILQ_HEAD_INITIALIZER(riscv64_freebsd.extra_syscalls), { NULL } }; PROCABI(riscv64_freebsd);
#include "format.h" #include "mkimg.h" #include "scheme.h" #define LONGOPT_FORMATS 0x01000001 #define LONGOPT_SCHEMES 0x01000002 #define LONGOPT_VERSION 0x01000003 static struct option longopts[] = { { "formats", no_argument, NULL, LONGOPT_FORMATS }, { "schemes", no_argument, NULL, LONGOPT_SCHEMES }, { "version", no_argument, NULL, LONGOPT_VERSION }, { NULL, 0, NULL, 0 } }; struct partlisthead partlist = STAILQ_HEAD_INITIALIZER(partlist); u_int nparts = 0; u_int unit_testing; u_int verbose; u_int ncyls = 0; u_int nheads = 1; u_int nsecs = 1; u_int secsz = 512; u_int blksz = 0; static void print_formats(int usage) { struct mkimg_format *f, **f_iter;
#define PMCC_ENABLE_DISABLE 3 #define PMCC_SHOW_STATISTICS 4 #define PMCC_CPU_ALL -1 #define PMCC_CPU_WILDCARD '*' #define PMCC_PMC_ALL -1 #define PMCC_PMC_WILDCARD '*' #define PMCC_OP_IGNORE 0 #define PMCC_OP_DISABLE 1 #define PMCC_OP_ENABLE 2 #define PMCC_PROGRAM_NAME "pmccontrol" static STAILQ_HEAD(pmcc_op_list, pmcc_op) head = STAILQ_HEAD_INITIALIZER(head); struct pmcc_op { char op_cpu; char op_pmc; char op_op; STAILQ_ENTRY(pmcc_op) op_next; }; /* Function Prototypes */ #if DEBUG static void pmcc_init_debug(void); #endif static int pmcc_do_list_state(void); static int pmcc_do_enable_disable(struct pmcc_op_list *);
struct swins_map_entry { int32_t index; /* swins_entry::index */ u_char *name; /* map key,a copy of swins_entry::name*/ /* * next may be NULL if the respective hrSWInstalledTblEntry * is (temporally) gone */ struct swins_entry *entry; STAILQ_ENTRY(swins_map_entry) link; }; STAILQ_HEAD(swins_map, swins_map_entry); /* map for consistent indexing */ static struct swins_map swins_map = STAILQ_HEAD_INITIALIZER(swins_map); /* the head of the list with hrSWInstalledTable's entries */ static struct swins_tbl swins_tbl = TAILQ_HEAD_INITIALIZER(swins_tbl); /* next int available for indexing the hrSWInstalledTable */ static uint32_t next_swins_index = 1; /* last (agent) tick when hrSWInstalledTable was updated */ static uint64_t swins_tick; /* maximum number of ticks between updates of network table */ uint32_t swins_tbl_refresh = HR_SWINS_TBL_REFRESH * 100; /* package directory */ u_char *pkg_dir;
const char *str; }; struct cap_iface { STAILQ_ENTRY(cap_iface) entries; const char *name; const char *filter; pcap_t *pcap; int fd; const struct linkhdr *linkhdr; struct local_ips local_ips; }; static STAILQ_HEAD(cli_ifnames_head, strnode) cli_ifnames = STAILQ_HEAD_INITIALIZER(cli_ifnames); static STAILQ_HEAD(cli_filters_head, strnode) cli_filters = STAILQ_HEAD_INITIALIZER(cli_filters); static STAILQ_HEAD(cap_ifs_head, cap_iface) cap_ifs = STAILQ_HEAD_INITIALIZER(cap_ifs); /* The read timeout passed to pcap_open_live() */ #define CAP_TIMEOUT_MSEC 500 void cap_add_ifname(const char *ifname) { struct strnode *n = xmalloc(sizeof(*n)); n->str = ifname; STAILQ_INSERT_TAIL(&cli_ifnames, n, entries); }
static u_int timeout = 1000; static u_int debug_level; /* number of microseconds per clock tick */ static struct clockinfo clockinfo; /* Csock buffers. Communication on the csock is asynchronuous. This means * if we wait for a specific response, we may get other messages. Put these * into a queue and execute them when we are idle. */ struct csock_buf { STAILQ_ENTRY(csock_buf) link; struct ng_mesg *mesg; char path[NG_PATHSIZ]; }; static STAILQ_HEAD(, csock_buf) csock_bufs = STAILQ_HEAD_INITIALIZER(csock_bufs); /* * We dispatch unsolicieted messages by node cookies and ids. * So we must keep a list of hook names and dispatch functions. */ struct msgreg { u_int32_t cookie; ng_ID_t id; ng_cookie_f *func; void *arg; const struct lmodule *mod; SLIST_ENTRY(msgreg) link; }; static SLIST_HEAD(, msgreg) msgreg_list = SLIST_HEAD_INITIALIZER(msgreg_list);
//#include <special_includes/sys/sysctl.h> //#include <special_includes/sys/un.h> //#include <special_includes/sys/unpcb.h> //#include <special_includes/sys/file.h> //#include <special_includes/sys/filedesc.h> //#include <special_includes/sys/kauth.h> #include <special_includes/sys/syslog.h> MALLOC_DECLARE(M_SOCKADDR); MALLOC_DEFINE(M_SOCKADDR, "sockaddr", "socket endpoints"); void pffasttimo(void *); void pfslowtimo(void *); struct domainhead domains = STAILQ_HEAD_INITIALIZER(domains); static struct domain *domain_array[AF_MAX]; callout_t pffasttimo_ch, pfslowtimo_ch; /* * Current time values for fast and slow timeouts. We can use u_int * relatively safely. The fast timer will roll over in 27 years and * the slow timer in 68 years. */ u_int pfslowtimo_now; u_int pffasttimo_now; //static struct sysctllog *domain_sysctllog; //static void sysctl_net_setup(void); extern struct domain inetdomain;
*/ #include <ec.h> #include <ec_ui.h> #include <stdarg.h> #include <pthread.h> /* globals */ struct ui_message { char *message; STAILQ_ENTRY(ui_message) next; }; static STAILQ_HEAD(, ui_message) messages_queue = STAILQ_HEAD_INITIALIZER(messages_queue); /* global mutex on interface */ static pthread_mutex_t ui_msg_mutex = PTHREAD_MUTEX_INITIALIZER; #define UI_MSG_LOCK do{ pthread_mutex_lock(&ui_msg_mutex); }while(0) #define UI_MSG_UNLOCK do{ pthread_mutex_unlock(&ui_msg_mutex); }while(0) /* protos... */ void ui_init(void); void ui_start(void); void ui_cleanup(void); void ui_msg(const char *fmt, ...); void ui_error(const char *fmt, ...); void ui_fatal_error(const char *msg);
static int pkg_create_matches(int argc, char **argv, match_t match, pkg_formats fmt, const char * const outdir, const char * const rootdir, bool overwrite) { int i, ret = EPKG_OK, retcode = EPKG_OK; const char *name, *version; struct pkg *pkg = NULL; struct pkgdb *db = NULL; struct pkgdb_it *it = NULL; int query_flags = PKG_LOAD_DEPS | PKG_LOAD_FILES | PKG_LOAD_CATEGORIES | PKG_LOAD_DIRS | PKG_LOAD_SCRIPTS | PKG_LOAD_OPTIONS | PKG_LOAD_MTREE | PKG_LOAD_LICENSES | PKG_LOAD_USERS | PKG_LOAD_GROUPS | PKG_LOAD_SHLIBS; struct pkg_head head = STAILQ_HEAD_INITIALIZER(head); struct pkg_entry *e = NULL; char pkgpath[MAXPATHLEN]; const char *format = NULL; bool foundone; if (pkgdb_open(&db, PKGDB_DEFAULT) != EPKG_OK) { pkgdb_close(db); return (EX_IOERR); } switch (fmt) { case TXZ: format = "txz"; break; case TBZ: format = "tbz"; break; case TGZ: format = "tgz"; break; case TAR: format = "tar"; break; } for (i = 0; i < argc || match == MATCH_ALL; i++) { if (match == MATCH_ALL) { printf("Loading package list...\n"); if ((it = pkgdb_query(db, NULL, match)) == NULL) goto cleanup; match = !MATCH_ALL; } else if ((it = pkgdb_query(db, argv[i], match)) == NULL) goto cleanup; foundone = false; while ((ret = pkgdb_it_next(it, &pkg, query_flags)) == EPKG_OK) { if ((e = malloc(sizeof(struct pkg_entry))) == NULL) err(1, "malloc(pkg_entry)"); e->pkg = pkg; pkg = NULL; STAILQ_INSERT_TAIL(&head, e, next); foundone = true; } if (!foundone) warnx("No installed package matching \"%s\" found\n", argv[i]); pkgdb_it_free(it); if (ret != EPKG_END) retcode++; } while (!STAILQ_EMPTY(&head)) { e = STAILQ_FIRST(&head); STAILQ_REMOVE_HEAD(&head, next); pkg_get(e->pkg, PKG_NAME, &name, PKG_VERSION, &version); if (!overwrite) { snprintf(pkgpath, MAXPATHLEN, "%s/%s-%s.%s", outdir, name, version, format); if (access(pkgpath, F_OK) == 0) { printf("%s-%s already packaged, skipping...\n", name, version); pkg_free(e->pkg); free(e); continue; } } printf("Creating package for %s-%s\n", name, version); if (pkg_create_installed(outdir, fmt, rootdir, e->pkg) != EPKG_OK) retcode++; pkg_free(e->pkg); free(e); } cleanup: pkgdb_close(db); return (retcode); }
#include <sys/sysctl.h> #include <sys/ucred.h> #include <err.h> #include <errno.h> #include <stddef.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include "ps.h" static struct varent *makevarent(const char *); static int vcmp(const void *, const void *); struct varent_head var_head = STAILQ_HEAD_INITIALIZER(var_head); #ifdef NOTINUSE int utime(), stime(), ixrss(), idrss(), isrss(); {{"utime"}, "UTIME", USER, utime, NULL, 4}, {{"stime"}, "STIME", USER, stime, NULL, 4}, {{"ixrss"}, "IXRSS", USER, ixrss, NULL, 4}, {{"idrss"}, "IDRSS", USER, idrss, NULL, 4}, {{"isrss"}, "ISRSS", USER, isrss, NULL, 4}, #endif /* Compute offset in common structures. */ #define POFF(x) offsetof(struct kinfo_proc, kp_##x) #define LPOFF(x) offsetof(struct kinfo_lwp, kl_##x) #define ROFF(x) offsetof(struct rusage, x)
int exec_check(int argc, char **argv) { struct pkg *pkg = NULL; struct pkgdb_it *it = NULL; struct pkgdb *db = NULL; match_t match = MATCH_EXACT; int flags = PKG_LOAD_BASIC; int ret; int ch; bool yes = false; bool dcheck = false; bool checksums = false; bool recompute = false; bool reanalyse_shlibs = false; bool shlibs; int nbpkgs = 0; int i; int verbose = 0; struct deps_head dh = STAILQ_HEAD_INITIALIZER(dh); while ((ch = getopt(argc, argv, "yagdBxsrv")) != -1) { switch (ch) { case 'a': match = MATCH_ALL; break; case 'x': match = MATCH_REGEX; break; case 'g': match = MATCH_GLOB; break; case 'y': yes = true; break; case 'd': dcheck = true; flags |= PKG_LOAD_DEPS; break; case 'B': pkg_config_bool(PKG_CONFIG_SHLIBS, &shlibs); if (!shlibs) errx(EX_USAGE, "reanalyzing shlibs requires SHLIBS" " in pkg.conf."); reanalyse_shlibs = true; flags |= PKG_LOAD_FILES; break; case 's': checksums = true; flags |= PKG_LOAD_FILES; break; case 'r': recompute = true; flags |= PKG_LOAD_FILES; if (geteuid() != 0) errx(EX_USAGE, "recomputing the checksums" " and size can only be done as root"); break; case 'v': verbose = 1; break; default: usage_check(); return (EX_USAGE); } } argc -= optind; argv += optind; /* Default to all packages if no pkg provided */ if (argc == 0 && (dcheck || checksums || recompute || reanalyse_shlibs)) { match = MATCH_ALL; } else if ((argc == 0 && match != MATCH_ALL) || !(dcheck || checksums || recompute || reanalyse_shlibs)) { usage_check(); return (EX_USAGE); } ret = pkgdb_open(&db, PKGDB_DEFAULT); if (ret == EPKG_ENODB) { if (geteuid() == 0) return (EX_IOERR); return (EX_OK); } if (ret != EPKG_OK) return (EX_IOERR); i = 0; do { if ((it = pkgdb_query(db, argv[i], match)) == NULL) { pkgdb_close(db); return (EX_IOERR); } while (pkgdb_it_next(it, &pkg, flags) == EPKG_OK) { const char *pkgname = NULL; pkg_get(pkg, PKG_NAME, &pkgname); /* check for missing dependencies */ if (dcheck) { if (verbose) printf("Checking dependencies: %s\n", pkgname); nbpkgs += check_deps(db, pkg, &dh); } if (checksums) { if (verbose) printf("Checking checksums: %s\n", pkgname); pkg_test_filesum(pkg); } if (recompute) { if (verbose) printf("Recomputing size and checksums: %s\n", pkgname); pkg_recompute(db, pkg); } if (reanalyse_shlibs) { if (verbose) printf("Reanalyzing files for shlibs: %s\n", pkgname); if (pkgdb_reanalyse_shlibs(db, pkg) != EPKG_OK) printf("Failed to reanalyse for shlibs: %s\n", pkgname); } } if (geteuid() == 0 && nbpkgs > 0) { if (yes == false) pkg_config_bool(PKG_CONFIG_ASSUME_ALWAYS_YES, &yes); printf("\n>>> Missing package dependencies were detected.\n"); printf(">>> Found %d issue(s) in total with your package database.\n\n", nbpkgs); ret = fix_deps(db, &dh, nbpkgs, yes); if (ret == EPKG_OK) check_summary(db, &dh); else if (ret == EPKG_ENODB) { db = NULL; return (EX_IOERR); } } pkgdb_it_free(it); i++; } while (i < argc); deps_free(&dh); pkg_free(pkg); pkgdb_close(db); return (EX_OK); }
int exec_clean(int argc, char **argv) { struct pkgdb *db = NULL; struct pkgdb_it *it = NULL; struct pkg *p = NULL; struct sumlist *sumlist = NULL, *s, *t; FTS *fts = NULL; FTSENT *ent = NULL; struct dl_head dl = STAILQ_HEAD_INITIALIZER(dl); const char *cachedir, *sum, *name; char *paths[2], csum[PKG_FILE_CKSUM_CHARS + 1], link_buf[MAXPATHLEN]; bool all = false; bool sumloaded = false; int retcode; int ch, cnt = 0; size_t total = 0, slen; ssize_t link_len; char size[7]; struct pkg_manifest_key *keys = NULL; struct option longopts[] = { { "all", no_argument, NULL, 'a' }, { "dry-run", no_argument, NULL, 'n' }, { "quiet", no_argument, NULL, 'q' }, { "yes", no_argument, NULL, 'y' }, { NULL, 0, NULL, 0 }, }; while ((ch = getopt_long(argc, argv, "+anqy", longopts, NULL)) != -1) { switch (ch) { case 'a': all = true; break; case 'n': dry_run = true; break; case 'q': quiet = true; break; case 'y': yes = true; break; default: usage_clean(); return (EX_USAGE); } } argc -= optind; argv += optind; cachedir = pkg_object_string(pkg_config_get("PKG_CACHEDIR")); paths[0] = __DECONST(char*, cachedir); paths[1] = NULL; retcode = pkgdb_access(PKGDB_MODE_READ, PKGDB_DB_REPO); if (retcode == EPKG_ENOACCESS) { warnx("Insufficient privileges to clean old packages"); return (EX_NOPERM); } else if (retcode == EPKG_ENODB) { warnx("No package database installed. Nothing to do!"); return (EX_OK); } else if (retcode != EPKG_OK) { warnx("Error accessing the package database"); return (EX_SOFTWARE); } retcode = EX_SOFTWARE; if (pkgdb_open(&db, PKGDB_REMOTE) != EPKG_OK) return (EX_IOERR); if (pkgdb_obtain_lock(db, PKGDB_LOCK_READONLY) != EPKG_OK) { pkgdb_close(db); warnx("Cannot get a read lock on a database, it is locked by another process"); return (EX_TEMPFAIL); } if ((fts = fts_open(paths, FTS_PHYSICAL, NULL)) == NULL) { warn("fts_open(%s)", cachedir); goto cleanup; } /* Build the list of out-of-date or obsolete packages */ pkg_manifest_keys_new(&keys); while ((ent = fts_read(fts)) != NULL) { if (ent->fts_info != FTS_F && ent->fts_info != FTS_SL) continue; if (all) { retcode = add_to_dellist(&dl, ent->fts_path); if (retcode == EPKG_OK) { total += ent->fts_statp->st_size; ++cnt; } continue; } if (sumlist == NULL && !sumloaded) { it = pkgdb_repo_search(db, "*", MATCH_GLOB, FIELD_NAME, FIELD_NONE, NULL); while (pkgdb_it_next(it, &p, PKG_LOAD_BASIC) == EPKG_OK) { pkg_get(p, PKG_CKSUM, &sum); slen = MIN(strlen(sum), PKG_FILE_CKSUM_CHARS); s = calloc(1, sizeof(struct sumlist)); memcpy(s->sum, sum, slen); s->sum[slen] = '\0'; HASH_ADD_STR(sumlist, sum, s); } } if (ent->fts_info == FTS_SL) { /* Dereference the symlink and check it for being * recognized checksum file, or delete the symlink * later. */ if ((link_len = readlink(ent->fts_name, link_buf, sizeof(link_buf))) == -1) continue; link_buf[link_len] = '\0'; name = link_buf; } else name = ent->fts_name; s = NULL; if (extract_filename_sum(name, csum)) HASH_FIND_STR(sumlist, csum, s); if (s == NULL) { retcode = add_to_dellist(&dl, ent->fts_path); if (retcode == EPKG_OK) { total += ent->fts_statp->st_size; ++cnt; } continue; } } HASH_ITER(hh, sumlist, s, t) { HASH_DEL(sumlist, s); free(s); }
__FBSDID("$FreeBSD: release/9.0.0/usr.bin/grep/queue.c 220422 2011-04-07 13:03:35Z gabor $"); #include <sys/param.h> #include <sys/queue.h> #include <stdlib.h> #include <string.h> #include "grep.h" struct qentry { STAILQ_ENTRY(qentry) list; struct str data; }; static STAILQ_HEAD(, qentry) queue = STAILQ_HEAD_INITIALIZER(queue); static unsigned long long count; static struct qentry *dequeue(void); void enqueue(struct str *x) { struct qentry *item; item = grep_malloc(sizeof(struct qentry)); item->data.dat = grep_malloc(sizeof(char) * x->len); item->data.len = x->len; item->data.line_no = x->line_no; item->data.off = x->off; memcpy(item->data.dat, x->dat, x->len);
void efi_getsmap(void) { UINTN size, desc_size, key; EFI_MEMORY_DESCRIPTOR *efi_mmap, *p; EFI_PHYSICAL_ADDRESS addr; EFI_STATUS status; STAILQ_HEAD(smap_head, smap_buf) head = STAILQ_HEAD_INITIALIZER(head); struct smap_buf *cur, *next; int i, n, ndesc; int type = -1; size = 0; efi_mmap = NULL; status = BS->GetMemoryMap(&size, efi_mmap, &key, &desc_size, NULL); efi_mmap = malloc(size); status = BS->GetMemoryMap(&size, efi_mmap, &key, &desc_size, NULL); if (EFI_ERROR(status)) { printf("GetMemoryMap: error %lu\n", EFI_ERROR_CODE(status)); free(efi_mmap); return; } STAILQ_INIT(&head); n = 0; i = 0; p = efi_mmap; next = NULL; ndesc = size / desc_size; while (i < ndesc) { if (next == NULL) { next = malloc(sizeof(*next)); if (next == NULL) break; next->sb_smap.base = p->PhysicalStart; next->sb_smap.length = p->NumberOfPages << EFI_PAGE_SHIFT; /* * ACPI 6.1 tells the lower memory should be * reported as normal memory, so we enforce * page 0 type even as vmware maps it as * acpi reclaimable. */ if (next->sb_smap.base == 0) type = SMAP_TYPE_MEMORY; else type = smap_type(p->Type); next->sb_smap.type = type; STAILQ_INSERT_TAIL(&head, next, sb_bufs); n++; p = NextMemoryDescriptor(p, desc_size); i++; continue; } addr = next->sb_smap.base + next->sb_smap.length; if ((smap_type(p->Type) == type) && (p->PhysicalStart == addr)) { next->sb_smap.length += (p->NumberOfPages << EFI_PAGE_SHIFT); p = NextMemoryDescriptor(p, desc_size); i++; } else next = NULL; } smaplen = n; if (smaplen > 0) { smapbase = malloc(smaplen * sizeof(*smapbase)); if (smapbase != NULL) { n = 0; STAILQ_FOREACH(cur, &head, sb_bufs) smapbase[n++] = cur->sb_smap; } cur = STAILQ_FIRST(&head); while (cur != NULL) { next = STAILQ_NEXT(cur, sb_bufs); free(cur); cur = next; } } free(efi_mmap); }
int main(int argc, char *argv[]) { FILE *in, *out; char *str; int i; size_t len; char *strp; char *modules[MAXMODULES]; int num_modules = 0; STAILQ_HEAD(includehead, include) includes = STAILQ_HEAD_INITIALIZER(includes); include *inc; int isam = 0; int linecont = 0; if (argc != 3) { fprintf(stderr, "Usage: %s <module.in> <Makefile[.am]>\n", argv[0]); return EXIT_FAILURE; } str = malloc(MAXLINE); /* Starting with initial input Makefile, look for include <file> or * YASM_MODULES += <module>. Note this currently doesn't handle * a relative starting path. */ len = strlen(argv[2]); inc = malloc(sizeof(include)); inc->filename = malloc(len+1); strcpy(inc->filename, argv[2]); STAILQ_INSERT_TAIL(&includes, inc, link); isam = argv[2][len-2] == 'a' && argv[2][len-1] == 'm'; while (!STAILQ_EMPTY(&includes)) { inc = STAILQ_FIRST(&includes); STAILQ_REMOVE_HEAD(&includes, link); in = fopen(inc->filename, "rt"); if (!in) { fprintf(stderr, "Could not open `%s'.\n", inc->filename); return EXIT_FAILURE; } free(inc->filename); free(inc); while (fgets(str, MAXLINE, in)) { /* Strip off any trailing whitespace */ len = strlen(str); if (len > 0) { strp = &str[len-1]; while (len > 0 && isspace(*strp)) { *strp-- = '\0'; len--; } } strp = str; /* Skip whitespace */ while (isspace(*strp)) strp++; /* Skip comments */ if (*strp == '#') continue; /* If line continuation, skip to continue copy */ if (linecont) goto keepgoing; /* Check for include if original input is .am file */ if (isam && strncmp(strp, "include", 7) == 0 && isspace(strp[7])) { strp += 7; while (isspace(*strp)) strp++; /* Build new include and add to end of list */ inc = malloc(sizeof(include)); inc->filename = malloc(strlen(strp)+1); strcpy(inc->filename, strp); STAILQ_INSERT_TAIL(&includes, inc, link); continue; } /* Check for YASM_MODULES = or += */ if (strncmp(strp, "YASM_MODULES", 12) != 0) continue; strp += 12; while (isspace(*strp)) strp++; if (strncmp(strp, "+=", 2) != 0 && *strp != '=') continue; if (*strp == '+') strp++; strp++; while (isspace(*strp)) strp++; keepgoing: /* Check for continuation */ if (len > 0 && str[len-1] == '\\') { str[len-1] = '\0'; while (isspace(*strp)) *strp-- = '\0'; linecont = 1; } else linecont = 0; while (*strp != '\0') { /* Copy module name */ modules[num_modules] = malloc(MAXNAME); len = 0; while (*strp != '\0' && !isspace(*strp)) modules[num_modules][len++] = *strp++; modules[num_modules][len] = '\0'; num_modules++; while (isspace(*strp)) strp++; } } fclose(in); } out = fopen(OUTPUT, "wt"); if (!out) { fprintf(stderr, "Could not open `%s'.\n", OUTPUT); return EXIT_FAILURE; } fprintf(out, "/* This file auto-generated by genmodule.c" " - don't edit it */\n\n"); in = fopen(argv[1], "rt"); if (!in) { fprintf(stderr, "Could not open `%s'.\n", argv[1]); fclose(out); remove(OUTPUT); return EXIT_FAILURE; } len = 0; while (fgets(str, MAXLINE, in)) { if (strncmp(str, "MODULES_", 8) == 0) { len = 0; strp = str+8; while (*strp != '\0' && *strp != '_') { len++; strp++; } *strp = '\0'; for (i=0; i<num_modules; i++) { if (strncmp(modules[i], str+8, len) == 0) { fprintf(out, " {\"%s\", &yasm_%s_LTX_%s},\n", modules[i]+len+1, modules[i]+len+1, str+8); } } } else if (strncmp(str, "EXTERN_LIST", 11) == 0) { for (i=0; i<num_modules; i++) { strcpy(str, modules[i]); strp = str; while (*strp != '\0' && *strp != '_') strp++; *strp++ = '\0'; fprintf(out, "extern yasm_%s_module yasm_%s_LTX_%s;\n", str, strp, str); } } else fputs(str, out); } fclose(in); fclose(out); for (i=0; i<num_modules; i++) free(modules[i]); free(str); return EXIT_SUCCESS; }
*/ #include <ec.h> #include <ec_threads.h> #include <ec_hook.h> #include <ec_stats.h> #include <time.h> /* this is the PO queue from bottom to top half */ struct po_queue_entry { struct packet_object *po; STAILQ_ENTRY(po_queue_entry) next; }; static STAILQ_HEAD(, po_queue_entry) po_queue = STAILQ_HEAD_INITIALIZER(po_queue); /* global mutex on interface */ static pthread_mutex_t po_mutex = PTHREAD_MUTEX_INITIALIZER; #define PO_QUEUE_LOCK do{ pthread_mutex_lock(&po_mutex); }while(0) #define PO_QUEUE_UNLOCK do{ pthread_mutex_unlock(&po_mutex); }while(0) /* proto */ void top_half_queue_add(struct packet_object *po); EC_THREAD_FUNC(top_half); /*******************************************/ /*
static u_int udpmib_reg; static u_int ipForward_reg; /*****************************/ /* list of all IP addresses */ struct mibifa_list mibifa_list = TAILQ_HEAD_INITIALIZER(mibifa_list); /* list of all interfaces */ struct mibif_list mibif_list = TAILQ_HEAD_INITIALIZER(mibif_list); /* list of dynamic interface names */ struct mibdynif_list mibdynif_list = SLIST_HEAD_INITIALIZER(mibdynif_list); /* list of all interface index mappings */ struct mibindexmap_list mibindexmap_list = STAILQ_HEAD_INITIALIZER(mibindexmap_list); /* list of all stacking entries */ struct mibifstack_list mibifstack_list = TAILQ_HEAD_INITIALIZER(mibifstack_list); /* list of all receive addresses */ struct mibrcvaddr_list mibrcvaddr_list = TAILQ_HEAD_INITIALIZER(mibrcvaddr_list); /* list of all NetToMedia entries */ struct mibarp_list mibarp_list = TAILQ_HEAD_INITIALIZER(mibarp_list); /* number of interfaces */ int32_t mib_if_number; /* last change of table */ uint64_t mib_iftable_last_change;
/* * isdigit takes an `int', but expects values in the range of unsigned char. * This wrapper ensures that values from a 'char' end up in the correct range. */ #define isdigitch(Anychar) isdigit((u_char)(Anychar)) int cflag; /* -c */ int eval; /* Exit value */ time_t now; /* Current time(3) value */ int rawcpu; /* -C */ int sumrusage; /* -S */ int termwidth; /* Width of the screen (0 == infinity). */ int totwidth; /* Calculated-width of requested variables. */ struct velisthead varlist = STAILQ_HEAD_INITIALIZER(varlist); #ifndef __APPLE__ static int forceuread = DEF_UREAD; /* Do extra work to get u-area. */ static kvm_t *kd; #endif /* !__APPLE__ */ static KINFO *kinfo; static int needcomm; /* -o "command" */ static int needenv; /* -e */ static int needuser; /* -o "user" */ static int optfatal; /* Fatal error parsing some list-option. */ static enum sort { DEFAULT, SORTMEM, SORTCPU } sortby = DEFAULT; struct listinfo; typedef int addelem_rtn(struct listinfo *_inf, const char *_elem);
static const char *hash_colors[] = { SB_GREEN, SB_BLUE, SB_CYAN }; #define N_HASH_COLORS 3 #define MAX_SANDBOXES 129 static char *hash_names[MAX_SANDBOXES]; static char *proto_names[MAX_SANDBOXES]; static struct cheri_tcpdump_control _ctdc; static volatile struct cheri_tcpdump_control *ctdc; static struct tcpdump_sandbox_list sandboxes = STAILQ_HEAD_INITIALIZER(sandboxes); static struct tcpdump_sandbox *default_sandbox; static struct sandbox_class *tcpdump_classp; static void handle_alarm(int sig, siginfo_t *info __unused, void *vuap) { assert(sig == SIGALRM); cheri_stack_unwind(vuap, SANDBOX_STACK_UNWOUND, 0); } static void set_color_default(void)
int exec_clean(int argc, char **argv) { struct pkgdb *db = NULL; struct pkgdb_it *it = NULL; struct pkg *pkg = NULL; struct pkg *p = NULL; FTS *fts = NULL; FTSENT *ent = NULL; struct dl_head dl = STAILQ_HEAD_INITIALIZER(dl); const char *cachedir; char *paths[2]; char *repopath; bool dry_run = false; bool yes; int retcode = EX_SOFTWARE; int ret; int ch; pkg_config_bool(PKG_CONFIG_ASSUME_ALWAYS_YES, &yes); while ((ch = getopt(argc, argv, "nqy")) != -1) { switch (ch) { case 'n': dry_run = true; break; case 'q': quiet = true; break; case 'y': yes = true; break; default: usage_clean(); return (EX_USAGE); } } argc -= optind; argv += optind; if (pkg_config_string(PKG_CONFIG_CACHEDIR, &cachedir) != EPKG_OK) { warnx("Cannot get cachedir config entry"); return 1; } paths[0] = __DECONST(char*, cachedir); paths[1] = NULL; if (pkgdb_open(&db, PKGDB_REMOTE) != EPKG_OK) { goto cleanup; } if ((fts = fts_open(paths, FTS_PHYSICAL, NULL)) == NULL) { warn("fts_open(%s)", cachedir); goto cleanup; } /* Build the list of out-of-date or obsolete packages */ while ((ent = fts_read(fts)) != NULL) { const char *origin, *pkgrepopath; if (ent->fts_info != FTS_F) continue; repopath = ent->fts_path + strlen(cachedir); if (repopath[0] == '/') repopath++; if (pkg_open(&pkg, ent->fts_path) != EPKG_OK) { if (!quiet) warnx("skipping %s", ent->fts_path); continue; } pkg_get(pkg, PKG_ORIGIN, &origin); it = pkgdb_search(db, origin, MATCH_EXACT, FIELD_ORIGIN, FIELD_NONE, NULL); if (it == NULL) { if (!quiet) warnx("skipping %s", ent->fts_path); continue; } if ((ret = pkgdb_it_next(it, &p, PKG_LOAD_BASIC)) == EPKG_FATAL) { if (!quiet) warnx("skipping %s", ent->fts_path); continue; } pkg_get(p, PKG_REPOPATH, &pkgrepopath); if (ret == EPKG_END) { ret = add_to_dellist(&dl, REMOVED, ent->fts_path, origin, NULL, NULL); } else if (strcmp(repopath, pkgrepopath)) { const char *newname; const char *newversion; pkg_get(p, PKG_NAME, &newname, PKG_VERSION, &newversion); ret = add_to_dellist(&dl, OUT_OF_DATE, ent->fts_path, origin, newname, newversion); } else { char local_cksum[SHA256_DIGEST_LENGTH * 2 +1]; const char *cksum; pkg_get(p, PKG_CKSUM, &cksum); if (hash_file(ent->fts_path, local_cksum) == EPKG_OK) { if (strcmp(cksum, local_cksum) != 0) { ret = add_to_dellist(&dl, CKSUM_MISMATCH, ent->fts_path, origin, NULL, NULL); } } } if (ret != EPKG_OK && ret != EPKG_END) { retcode = EX_OSERR; /* out of memory */ goto cleanup; } pkgdb_it_free(it); } if (STAILQ_EMPTY(&dl)) { if (!quiet) printf("Nothing to do.\n"); retcode = EX_OK; goto cleanup; } if (dry_run || !yes || !quiet) display_dellist(&dl, cachedir); if (!dry_run) { if (!yes) yes = query_yesno( "\nProceed with cleaning cache [y/N]: "); if (yes) retcode = delete_dellist(&dl); } else retcode = EX_OK; cleanup: free_dellist(&dl); pkg_free(pkg); pkg_free(p); if (fts != NULL) fts_close(fts); if (db != NULL) pkgdb_close(db); return (retcode); }