/* * Read a symbolic link */ static int pfs_readlink(struct vop_readlink_args *va) { struct vnode *vn = va->a_vp; struct pfs_vdata *pvd = vn->v_data; struct pfs_node *pn = pvd->pvd_pn; struct uio *uio = va->a_uio; struct proc *proc = NULL; struct thread *td = curthread; char buf[PATH_MAX]; struct sbuf sb; int error, locked; PFS_TRACE(("%s", pn->pn_name)); pfs_assert_not_owned(pn); if (vn->v_type != VLNK) PFS_RETURN (EINVAL); KASSERT_PN_IS_LINK(pn); if (pn->pn_fill == NULL) PFS_RETURN (EIO); if (pvd->pvd_pid != NO_PID) { if ((proc = pfind(pvd->pvd_pid)) == NULL) PFS_RETURN (EIO); if (proc->p_flag & P_WEXIT) { PROC_UNLOCK(proc); PFS_RETURN (EIO); } _PHOLD(proc); PROC_UNLOCK(proc); } vhold(vn); locked = VOP_ISLOCKED(vn, td); VOP_UNLOCK(vn, 0, td); /* sbuf_new() can't fail with a static buffer */ sbuf_new(&sb, buf, sizeof buf, 0); error = pn_fill(td, proc, pn, &sb, NULL); if (proc != NULL) PRELE(proc); vn_lock(vn, locked | LK_RETRY, td); vdrop(vn); if (error) { sbuf_delete(&sb); PFS_RETURN (error); } sbuf_finish(&sb); error = uiomove_frombuf(sbuf_data(&sb), sbuf_len(&sb), uio); sbuf_delete(&sb); PFS_RETURN (error); }
struct pkgdb_it * pkgdb_rquery_provide(struct pkgdb *db, const char *provide, const char *repo) { sqlite3_stmt *stmt; struct sbuf *sql = NULL; const char *reponame = NULL; int ret; const char basesql[] = "" "SELECT p.id, p.origin, p.name, p.version, p.comment, " "p.name || '~' || p.origin as uniqueid, " "p.prefix, p.desc, p.arch, p.maintainer, p.www, " "p.licenselogic, p.flatsize, p.pkgsize, " "p.cksum, p.manifestdigest, p.path AS repopath, '%1$s' AS dbname " "FROM '%1$s'.packages AS p, '%1$s'.pkg_provides AS pp, " "'%1$s'.provides AS pr " "WHERE p.id = pp.package_id " "AND pp.provide_id = pr.id " "AND pr.name = ?1;"; assert(db != NULL); reponame = pkgdb_get_reponame(db, repo); sql = sbuf_new_auto(); /* * Working on multiple remote repositories */ if (reponame == NULL) { /* duplicate the query via UNION for all the attached * databases */ ret = pkgdb_sql_all_attached(db->sqlite, sql, basesql, " UNION ALL "); if (ret != EPKG_OK) { sbuf_delete(sql); return (NULL); } } else sbuf_printf(sql, basesql, reponame); sbuf_finish(sql); pkg_debug(4, "Pkgdb: running '%s'", sbuf_get(sql)); ret = sqlite3_prepare_v2(db->sqlite, sbuf_get(sql), -1, &stmt, NULL); if (ret != SQLITE_OK) { ERROR_SQLITE(db->sqlite, sbuf_get(sql)); sbuf_delete(sql); return (NULL); } sbuf_delete(sql); sqlite3_bind_text(stmt, 1, provide, -1, SQLITE_TRANSIENT); return (pkgdb_it_new(db, stmt, PKG_REMOTE, PKGDB_IT_FLAG_ONCE)); }
void vfs_mountroot(void) { struct mount *mp; struct sbuf *sb; struct thread *td; time_t timebase; int error; td = curthread; vfs_mountroot_wait(); sb = sbuf_new_auto(); vfs_mountroot_conf0(sb); sbuf_finish(sb); error = vfs_mountroot_devfs(td, &mp); while (!error) { error = vfs_mountroot_parse(sb, mp); if (!error) { error = vfs_mountroot_shuffle(td, mp); if (!error) { sbuf_clear(sb); error = vfs_mountroot_readconf(td, sb); sbuf_finish(sb); } } } sbuf_delete(sb); /* * Iterate over all currently mounted file systems and use * the time stamp found to check and/or initialize the RTC. * Call inittodr() only once and pass it the largest of the * timestamps we encounter. */ timebase = 0; mtx_lock(&mountlist_mtx); mp = TAILQ_FIRST(&mountlist); while (mp != NULL) { if (mp->mnt_time > timebase) timebase = mp->mnt_time; mp = TAILQ_NEXT(mp, mnt_list); } mtx_unlock(&mountlist_mtx); inittodr(timebase); /* Keep prison0's root in sync with the global rootvnode. */ mtx_lock(&prison0.pr_mtx); prison0.pr_root = rootvnode; vref(prison0.pr_root); mtx_unlock(&prison0.pr_mtx); mtx_lock(&mountlist_mtx); atomic_store_rel_int(&root_mount_complete, 1); wakeup(&root_mount_complete); mtx_unlock(&mountlist_mtx); }
static void khttpd_ktr_logging_main(void *arg) { struct sbuf *sbuf; struct thread *td; int error; KHTTPD_ASSERT_CURPROC_IS_KHTTPD(); td = curthread; khttpd_ktr_logging_idx = ktr_idx; error = kern_openat(td, AT_FDCWD, KHTTPD_KTR_FILE, UIO_SYSSPACE, O_CREAT | O_TRUNC | O_WRONLY, 0666); if (error != 0) { log(LOG_WARNING, "khttpd: failed to open ktr file '%s' " "(error %d)", KHTTPD_KTR_FILE, error); goto quit; } kern_close(td, td->td_retval[0]); sbuf = sbuf_new_auto(); while (!khttpd_ktr_logging_shutdown) { khttpd_ktr_logging(sbuf); pause("khttpd-ktr-flush", hz); } sbuf_delete(sbuf); quit: khttpd_ktr_logging_thread = NULL; kthread_exit(); }
/* construct path to node->name */ static char * mtree_file_path(fsnode *node) { fsnode *pnode; struct sbuf *sb; char *res, *rp[MAKEFS_MAX_TREE_DEPTH]; int depth; depth = 0; rp[depth] = node->name; for (pnode = node->parent; pnode && depth < MAKEFS_MAX_TREE_DEPTH; pnode = pnode->parent) { if (strcmp(pnode->name, ".") == 0) break; rp[++depth] = pnode->name; } sb = sbuf_new_auto(); if (sb == NULL) { errno = ENOMEM; return (NULL); } while (depth > 0) { sbuf_cat(sb, rp[depth--]); sbuf_putc(sb, '/'); } sbuf_cat(sb, rp[depth]); sbuf_finish(sb); res = strdup(sbuf_data(sb)); sbuf_delete(sb); if (res == NULL) errno = ENOMEM; return res; }
static int acpi_cpu_usage_sysctl(SYSCTL_HANDLER_ARGS) { struct acpi_cpu_softc *sc; struct sbuf sb; char buf[128]; int i; uintmax_t fract, sum, whole; sc = (struct acpi_cpu_softc *) arg1; sum = 0; for (i = 0; i < sc->cpu_cx_count; i++) sum += sc->cpu_cx_stats[i]; sbuf_new(&sb, buf, sizeof(buf), SBUF_FIXEDLEN); for (i = 0; i < sc->cpu_cx_count; i++) { if (sum > 0) { whole = (uintmax_t)sc->cpu_cx_stats[i] * 100; fract = (whole % sum) * 100; sbuf_printf(&sb, "%u.%02u%% ", (u_int)(whole / sum), (u_int)(fract / sum)); } else sbuf_printf(&sb, "0.00%% "); } sbuf_printf(&sb, "last %dus", sc->cpu_prev_sleep); sbuf_trim(&sb); sbuf_finish(&sb); sysctl_handle_string(oidp, sbuf_data(&sb), sbuf_len(&sb), req); sbuf_delete(&sb); return (0); }
static int sysctl_handle_dpi(SYSCTL_HANDLER_ARGS) { struct ioat_softc *ioat; struct sbuf sb; #define PRECISION "1" const uintmax_t factor = 10; uintmax_t rate; int error; ioat = arg1; sbuf_new_for_sysctl(&sb, NULL, 16, req); if (ioat->stats.interrupts == 0) { sbuf_printf(&sb, "NaN"); goto out; } rate = ioat->stats.descriptors_processed * factor / ioat->stats.interrupts; sbuf_printf(&sb, "%ju.%." PRECISION "ju", rate / factor, rate % factor); #undef PRECISION out: error = sbuf_finish(&sb); sbuf_delete(&sb); if (error != 0 || req->newptr == NULL) return (error); return (EINVAL); }
static int sysctl_debug_ddb_scripting_scripts(SYSCTL_HANDLER_ARGS) { struct sbuf sb; int error, i, len; char *buffer; /* * Make space to include a maximum-length name, = symbol, * maximum-length script, and carriage return for every script that * may be defined. */ len = DB_MAXSCRIPTS * (DB_MAXSCRIPTNAME + 1 + DB_MAXSCRIPTLEN + 1); buffer = malloc(len, M_TEMP, M_WAITOK); (void)sbuf_new(&sb, buffer, len, SBUF_FIXEDLEN); mtx_lock(&db_script_mtx); for (i = 0; i < DB_MAXSCRIPTS; i++) { if (strlen(db_script_table[i].ds_scriptname) == 0) continue; (void)sbuf_printf(&sb, "%s=%s\n", db_script_table[i].ds_scriptname, db_script_table[i].ds_script); } mtx_unlock(&db_script_mtx); sbuf_finish(&sb); error = SYSCTL_OUT(req, sbuf_data(&sb), sbuf_len(&sb) + 1); sbuf_delete(&sb); free(buffer, M_TEMP); return (error); }
/* * Create an sbuf with uio data */ struct sbuf * sbuf_uionew(struct sbuf *s, struct uio *uio, int *error) { KASSERT(uio != NULL, ("%s called with NULL uio pointer", __func__)); KASSERT(error != NULL, ("%s called with NULL error pointer", __func__)); s = sbuf_new(s, NULL, uio->uio_resid + 1, 0); if (s == NULL) { *error = ENOMEM; return (NULL); } *error = uiomove(s->s_buf, uio->uio_resid, uio); if (*error != 0) { sbuf_delete(s); return (NULL); } s->s_len = s->s_size - 1; if (SBUF_ISSECTION(s)) s->s_sect_len = s->s_size - 1; *error = 0; return (s); }
void virtio_describe(device_t dev, const char *msg, uint64_t features, struct virtio_feature_desc *feature_desc) { struct sbuf sb; uint64_t val; char *buf; const char *name; int n; if ((buf = malloc(512, M_TEMP, M_NOWAIT)) == NULL) { device_printf(dev, "%s features: 0x%"PRIx64"\n", msg, features); return; } sbuf_new(&sb, buf, 512, SBUF_FIXEDLEN); sbuf_printf(&sb, "%s features: 0x%"PRIx64, msg, features); for (n = 0, val = 1ULL << 63; val != 0; val >>= 1) { /* * BAD_FEATURE is used to detect broken Linux clients * and therefore is not applicable to FreeBSD. */ if (((features & val) == 0) || val == VIRTIO_F_BAD_FEATURE) continue; if (n++ == 0) sbuf_cat(&sb, " <"); else sbuf_cat(&sb, ","); name = NULL; if (feature_desc != NULL) name = virtio_feature_name(val, feature_desc); if (name == NULL) name = virtio_feature_name(val, virtio_common_feature_desc); if (name == NULL) sbuf_printf(&sb, "0x%"PRIx64, val); else sbuf_cat(&sb, name); } if (n > 0) sbuf_cat(&sb, ">"); #if __FreeBSD_version < 900020 sbuf_finish(&sb); if (sbuf_overflowed(&sb) == 0) #else if (sbuf_finish(&sb) == 0) #endif device_printf(dev, "%s\n", sbuf_data(&sb)); sbuf_delete(&sb); free(buf, M_TEMP); }
int sysctl_l2t(SYSCTL_HANDLER_ARGS) { struct adapter *sc = arg1; struct l2t_data *l2t = sc->l2t; struct l2t_entry *e; struct sbuf *sb; int rc, i, header = 0; char ip[INET6_ADDRSTRLEN]; if (l2t == NULL) return (ENXIO); rc = sysctl_wire_old_buffer(req, 0); if (rc != 0) return (rc); sb = sbuf_new_for_sysctl(NULL, NULL, 4096, req); if (sb == NULL) return (ENOMEM); e = &l2t->l2tab[0]; for (i = 0; i < l2t->l2t_size; i++, e++) { mtx_lock(&e->lock); if (e->state == L2T_STATE_UNUSED) goto skip; if (header == 0) { sbuf_printf(sb, " Idx IP address " "Ethernet address VLAN/P LP State Users Port"); header = 1; } if (e->state == L2T_STATE_SWITCHING) ip[0] = 0; else { inet_ntop(e->ipv6 ? AF_INET6 : AF_INET, &e->addr[0], &ip[0], sizeof(ip)); } /* * XXX: e->ifp may not be around. * XXX: IPv6 addresses may not align properly in the output. */ sbuf_printf(sb, "\n%4u %-15s %02x:%02x:%02x:%02x:%02x:%02x %4d" " %u %2u %c %5u %s", e->idx, ip, e->dmac[0], e->dmac[1], e->dmac[2], e->dmac[3], e->dmac[4], e->dmac[5], e->vlan & 0xfff, vlan_prio(e), e->lport, l2e_state(e), atomic_load_acq_int(&e->refcnt), e->ifp->if_xname); skip: mtx_unlock(&e->lock); } rc = sbuf_finish(sb); sbuf_delete(sb); return (rc); }
static void print_status_end(struct sbuf *msg) { sbuf_finish(msg); printf("%s", sbuf_data(msg)); /*printf("\033]0; %s\007", sbuf_data(msg));*/ sbuf_delete(msg); }
static void print_and_set_term_title(struct sbuf *msg) { sbuf_finish(msg); printf("%s", sbuf_data(msg)); /*printf("\033]0; %s\007", sbuf_data(msg));*/ sbuf_delete(msg); }
int pkg_script_run(struct pkg *pkg, pkg_script_t type) { struct pkg_script *script = NULL; pkg_script_t stype; struct sbuf *script_cmd = sbuf_new_auto(); size_t i; struct { const char *arg; const pkg_script_t b; const pkg_script_t a; } const map[] = { /* a implies b with argument arg */ {"PRE-INSTALL", PKG_SCRIPT_INSTALL, PKG_SCRIPT_PRE_INSTALL}, {"POST-INSTALL", PKG_SCRIPT_INSTALL, PKG_SCRIPT_POST_INSTALL}, {"PRE-UPGRADE", PKG_SCRIPT_UPGRADE, PKG_SCRIPT_PRE_UPGRADE}, {"POST-UPGRADE", PKG_SCRIPT_UPGRADE, PKG_SCRIPT_POST_UPGRADE}, {"DEINSTALL", PKG_SCRIPT_DEINSTALL, PKG_SCRIPT_PRE_DEINSTALL}, {"POST-DEINSTALL", PKG_SCRIPT_DEINSTALL, PKG_SCRIPT_POST_DEINSTALL}, }; for (i = 0; i < sizeof(map) / sizeof(map[0]); i++) { if (map[i].a == type) break; } if (map[i].a != type) return (ERROR_BAD_ARG("type")); while (pkg_scripts(pkg, &script) == EPKG_OK) { stype = pkg_script_type(script); if (stype == map[i].a || stype == map[i].b) { sbuf_reset(script_cmd); sbuf_printf(script_cmd, "PKG_PREFIX=%s\nset -- %s-%s", pkg_get(pkg, PKG_PREFIX), pkg_get(pkg, PKG_NAME), pkg_get(pkg, PKG_VERSION)); if (stype == map[i].b) { /* add arg **/ sbuf_cat(script_cmd, " "); sbuf_cat(script_cmd, map[i].arg); } sbuf_cat(script_cmd, "\n"); sbuf_cat(script_cmd, pkg_script_data(script)); sbuf_finish(script_cmd); system(sbuf_data(script_cmd)); } } sbuf_delete(script_cmd); return (EPKG_OK); }
/** * \brief Enumerate all devices of the given type on this bus. * * \param dev NewBus device_t for this XenBus backend bus instance. * \param type String indicating the device sub-tree (e.g. "vfb", "vif") * to enumerate. * * \return On success, 0. Otherwise an errno value indicating the * type of failure. * * Devices that are found are entered into the NewBus hierarchy via * xenbusb_add_device(). xenbusb_add_device() ignores duplicate detects * and ignores duplicate devices, so it can be called unconditionally * for any device found in the XenStore. * * The backend XenStore hierarchy has the following format: * * backend/<device type>/<frontend vm id>/<device id> * */ static int xenbusb_back_enumerate_type(device_t dev, const char *type) { struct xenbusb_softc *xbs; const char **vms; u_int vm_idx; u_int vm_count; int error; xbs = device_get_softc(dev); error = xs_directory(XST_NIL, xbs->xbs_node, type, &vm_count, &vms); if (error) return (error); for (vm_idx = 0; vm_idx < vm_count; vm_idx++) { struct sbuf *vm_path; const char *vm; const char **devs; u_int dev_idx; u_int dev_count; vm = vms[vm_idx]; vm_path = xs_join(type, vm); error = xs_directory(XST_NIL, xbs->xbs_node, sbuf_data(vm_path), &dev_count, &devs); sbuf_delete(vm_path); if (error) break; for (dev_idx = 0; dev_idx < dev_count; dev_idx++) { const char *dev_num; struct sbuf *id; dev_num = devs[dev_idx]; id = xs_join(vm, dev_num); xenbusb_add_device(dev, type, sbuf_data(id)); sbuf_delete(id); } free(devs, M_XENSTORE); } free(vms, M_XENSTORE); return (0); }
struct pkg_repo_it * pkg_repo_binary_query(struct pkg_repo *repo, const char *pattern, match_t match) { sqlite3 *sqlite = PRIV_GET(repo); sqlite3_stmt *stmt = NULL; struct sbuf *sql = NULL; const char *comp = NULL; int ret; char basesql[BUFSIZ] = "" "SELECT id, origin, name, name as uniqueid, version, comment, " "prefix, desc, arch, maintainer, www, " "licenselogic, flatsize, pkgsize, " "cksum, manifestdigest, path AS repopath, '%s' AS dbname " "FROM packages AS p"; if (match != MATCH_ALL && (pattern == NULL || pattern[0] == '\0')) return (NULL); sql = sbuf_new_auto(); comp = pkgdb_get_pattern_query(pattern, match); if (comp && comp[0]) strlcat(basesql, comp, sizeof(basesql)); sbuf_printf(sql, basesql, repo->name); sbuf_cat(sql, " ORDER BY name;"); sbuf_finish(sql); pkg_debug(4, "Pkgdb: running '%s' query for %s", sbuf_data(sql), pattern == NULL ? "all": pattern); ret = sqlite3_prepare_v2(sqlite, sbuf_data(sql), sbuf_len(sql), &stmt, NULL); if (ret != SQLITE_OK) { ERROR_SQLITE(sqlite, sbuf_data(sql)); sbuf_delete(sql); return (NULL); } sbuf_delete(sql); if (match != MATCH_ALL && match != MATCH_CONDITION) sqlite3_bind_text(stmt, 1, pattern, -1, SQLITE_TRANSIENT); return (pkg_repo_binary_it_new(repo, stmt, PKGDB_IT_FLAG_ONCE)); }
int exec_add(int argc, char **argv) { struct pkgdb *db = NULL; struct sbuf *failedpkgs = sbuf_new_auto(); char path[MAXPATHLEN + 1]; char *file; int retcode = EPKG_OK; int i; int failedpkgcount = 0; struct pkg *p = NULL; if (argc < 2) { usage_add(); return (EX_USAGE); } if (geteuid() != 0) { warnx("adding packages can only be done as root"); return (EX_NOPERM); } if (pkgdb_open(&db, PKGDB_DEFAULT) != EPKG_OK) { return (EX_IOERR); } for (i = 1; i < argc; i++) { if (is_url(argv[i]) == EPKG_OK) { snprintf(path, sizeof(path), "./%s", basename(argv[i])); if ((retcode = pkg_fetch_file(argv[i], path)) != EPKG_OK) break; file = path; } else file = argv[i]; pkg_open(&p, file, NULL); if ((retcode = pkg_add(db, file, 0)) != EPKG_OK) { sbuf_cat(failedpkgs, argv[i]); if (i != argc - 1) sbuf_printf(failedpkgs, ", "); failedpkgcount++; } } pkgdb_close(db); if(failedpkgcount > 0) { sbuf_finish(failedpkgs); printf("Failed to install the following %d package(s): %s.\n", failedpkgcount, sbuf_data(failedpkgs)); } sbuf_delete(failedpkgs); return (retcode == EPKG_OK ? EX_OK : EX_SOFTWARE); }
/* * Write to a file */ static int pfs_write(struct vop_write_args *va) { struct vnode *vn = va->a_vp; struct pfs_vdata *pvd = vn->v_data; struct pfs_node *pn = pvd->pvd_pn; struct uio *uio = va->a_uio; struct proc *proc; struct sbuf sb; int error; PFS_TRACE(("%s", pn->pn_name)); pfs_assert_not_owned(pn); if (vn->v_type != VREG) PFS_RETURN (EINVAL); KASSERT_PN_IS_FILE(pn); if (!(pn->pn_flags & PFS_WR)) PFS_RETURN (EBADF); if (pn->pn_fill == NULL) PFS_RETURN (EIO); /* * This is necessary because either process' privileges may * have changed since the open() call. */ if (!pfs_visible(curthread, pn, pvd->pvd_pid, &proc)) PFS_RETURN (EIO); if (proc != NULL) { _PHOLD(proc); PROC_UNLOCK(proc); } if (pn->pn_flags & PFS_RAWWR) { error = pn_fill(curthread, proc, pn, NULL, uio); if (proc != NULL) PRELE(proc); PFS_RETURN (error); } sbuf_uionew(&sb, uio, &error); if (error) { if (proc != NULL) PRELE(proc); PFS_RETURN (error); } error = pn_fill(curthread, proc, pn, &sb, uio); sbuf_delete(&sb); if (proc != NULL) PRELE(proc); PFS_RETURN (error); }
int linux_sysctl(struct thread *td, struct linux_sysctl_args *args) { struct l___sysctl_args la; struct sbuf *sb; l_int *mib; int error, i; error = copyin(args->args, &la, sizeof(la)); if (error) return (error); if (la.nlen <= 0 || la.nlen > LINUX_CTL_MAXNAME) return (ENOTDIR); mib = malloc(la.nlen * sizeof(l_int), M_TEMP, M_WAITOK); error = copyin(PTRIN(la.name), mib, la.nlen * sizeof(l_int)); if (error) { free(mib, M_TEMP); return (error); } switch (mib[0]) { case LINUX_CTL_KERN: if (la.nlen < 2) break; switch (mib[1]) { case LINUX_KERN_VERSION: error = handle_string(&la, version); free(mib, M_TEMP); return (error); default: break; } break; default: break; } sb = sbuf_new(NULL, NULL, 20 + la.nlen * 5, SBUF_AUTOEXTEND); if (sb == NULL) { linux_msg(td, "sysctl is not implemented"); } else { sbuf_printf(sb, "sysctl "); for (i = 0; i < la.nlen; i++) sbuf_printf(sb, "%c%d", (i) ? ',' : '{', mib[i]); sbuf_printf(sb, "} is not implemented"); sbuf_finish(sb); linux_msg(td, "%s", sbuf_data(sb)); sbuf_delete(sb); } free(mib, M_TEMP); return (ENOTDIR); }
struct pkg_repo_it * pkg_repo_binary_search(struct pkg_repo *repo, const char *pattern, match_t match, pkgdb_field field, pkgdb_field sort) { sqlite3 *sqlite = PRIV_GET(repo); sqlite3_stmt *stmt = NULL; struct sbuf *sql = NULL; int ret; const char *multireposql = "" "SELECT id, origin, name, version, comment, " "prefix, desc, arch, maintainer, www, " "licenselogic, flatsize, pkgsize, " "cksum, path AS repopath, '%1$s' AS dbname, '%2$s' AS repourl " "FROM packages "; if (pattern == NULL || pattern[0] == '\0') return (NULL); sql = sbuf_new_auto(); sbuf_printf(sql, multireposql, repo->name, repo->url); /* close the UNIONs and build the search query */ sbuf_cat(sql, "WHERE "); pkg_repo_binary_build_search_query(sql, match, field, sort); sbuf_cat(sql, ";"); sbuf_finish(sql); pkg_debug(4, "Pkgdb: running '%s'", sbuf_data(sql)); ret = sqlite3_prepare_v2(sqlite, sbuf_data(sql), -1, &stmt, NULL); if (ret != SQLITE_OK) { ERROR_SQLITE(sqlite, sbuf_data(sql)); sbuf_delete(sql); return (NULL); } sbuf_delete(sql); sqlite3_bind_text(stmt, 1, pattern, -1, SQLITE_TRANSIENT); return (pkg_repo_binary_it_new(repo, stmt, PKGDB_IT_FLAG_ONCE)); }
struct pkg_repo_it * pkg_repo_binary_shlib_require(struct pkg_repo *repo, const char *provide) { sqlite3_stmt *stmt; sqlite3 *sqlite = PRIV_GET(repo); struct sbuf *sql = NULL; int ret; const char basesql[] = "" "SELECT p.id, p.origin, p.name, p.version, p.comment, " "p.name as uniqueid, " "p.prefix, p.desc, p.arch, p.maintainer, p.www, " "p.licenselogic, p.flatsize, p.pkgsize, " "p.cksum, p.manifestdigest, p.path AS repopath, '%s' AS dbname " "FROM packages AS p INNER JOIN pkg_shlibs_required AS ps ON " "p.id = ps.package_id " "WHERE ps.shlib_id = (SELECT id FROM shlibs WHERE name=?1);"; sql = sbuf_new_auto(); sbuf_printf(sql, basesql, repo->name); sbuf_finish(sql); pkg_debug(4, "Pkgdb: running '%s'", sbuf_data(sql)); ret = sqlite3_prepare_v2(sqlite, sbuf_data(sql), -1, &stmt, NULL); if (ret != SQLITE_OK) { ERROR_SQLITE(sqlite, sbuf_data(sql)); sbuf_delete(sql); return (NULL); } sbuf_delete(sql); pkg_debug(1, "> loading provides"); sqlite3_bind_text(stmt, 1, provide, -1, SQLITE_TRANSIENT); return (pkg_repo_binary_it_new(repo, stmt, PKGDB_IT_FLAG_ONCE)); }
char * epg_to_m3u(const list_s *channels, enum epg_m3u_format format) { sbuf_s *buffer = sbuf_new(); error_if(buffer == NULL, error, "Error Allocating sbuf_s"); error_if(channels == NULL, error, "Params Error"); trace("There are %zu channels", list_count(channels)); list_apply_with_state_cb func = (format == epg_m3u_format_simpletv) ? _gen_m3u_simpletv : _gen_m3u_tvheadend; list_walk_with_state((list_s *)channels, func, (void *)buffer); char *s = sbuf_detach(buffer); sbuf_delete(buffer); return s; error: if (buffer) sbuf_delete(buffer); return NULL; }
void khttpd_ktr_logging_fini(void) { struct sbuf *sbuf; KHTTPD_ASSERT_CURPROC_IS_KHTTPD(); khttpd_ktr_logging_shutdown = TRUE; while (khttpd_ktr_logging_thread != NULL) pause("khttpd-ktr-flush-fini", hz); sbuf = sbuf_new_auto(); khttpd_ktr_logging(sbuf); sbuf_delete(sbuf); }
/* ARGSUSED */ static int random_print_harvestmask(SYSCTL_HANDLER_ARGS) { struct sbuf sbuf; int error, i; error = sysctl_wire_old_buffer(req, 0); if (error == 0) { sbuf_new_for_sysctl(&sbuf, NULL, 128, req); for (i = RANDOM_ENVIRONMENTAL_END; i >= 0; i--) sbuf_cat(&sbuf, (harvest_context.hc_source_mask & (1 << i)) ? "1" : "0"); error = sbuf_finish(&sbuf); sbuf_delete(&sbuf); } return (error); }
static int kdb_sysctl_available(SYSCTL_HANDLER_ARGS) { struct kdb_dbbe **iter; struct sbuf sbuf; int error; sbuf_new_for_sysctl(&sbuf, NULL, 64, req); SET_FOREACH(iter, kdb_dbbe_set) { if ((*iter)->dbbe_active == 0) sbuf_printf(&sbuf, "%s ", (*iter)->dbbe_name); } error = sbuf_finish(&sbuf); sbuf_delete(&sbuf); return (error); }
static int pkg_set_files_from_object(struct pkg *pkg, ucl_object_t *obj) { ucl_object_t *cur; ucl_object_iter_t it = NULL; const char *sum = NULL; const char *uname = NULL; const char *gname = NULL; void *set = NULL; mode_t perm = 0; struct sbuf *fname = NULL; const char *key, *okey; okey = ucl_object_key(obj); if (okey == NULL) return (EPKG_FATAL); urldecode(okey, &fname); while ((cur = ucl_iterate_object(obj, &it, true))) { key = ucl_object_key(cur); if (key == NULL) continue; if (!strcasecmp(key, "uname") && cur->type == UCL_STRING) uname = ucl_object_tostring(cur); else if (!strcasecmp(key, "gname") && cur->type == UCL_STRING) gname = ucl_object_tostring(cur); else if (!strcasecmp(key, "sum") && cur->type == UCL_STRING && strlen(ucl_object_tostring(cur)) == 64) sum = ucl_object_tostring(cur); else if (!strcasecmp(key, "perm") && (cur->type == UCL_STRING || cur->type == UCL_INT)) { if ((set = setmode(ucl_object_tostring_forced(cur))) == NULL) pkg_emit_error("Not a valid mode: %s", ucl_object_tostring(cur)); else perm = getmode(set, 0); } else { pkg_emit_error("Skipping unknown key for file(%s): %s", sbuf_data(fname), ucl_object_tostring(cur)); } } pkg_addfile_attr(pkg, sbuf_data(fname), sum, uname, gname, perm, false); sbuf_delete(fname); return (EPKG_OK); }
/* * Create an sbuf with uio data */ struct sbuf * sbuf_uionew(struct sbuf *s, struct uio *uio, int *error) { KASSERT(uio != NULL); KASSERT(error != NULL); s = sbuf_new(s, NULL, uio->uio_resid + 1, 0); if (s == NULL) { *error = ENOMEM; return (NULL); } *error = uiomove(s->s_buf, uio->uio_resid, uio); if (*error != 0) { sbuf_delete(s); return (NULL); } s->s_len = s->s_size - 1; *error = 0; return (s); }
/* List available sysclocks. */ static int sysctl_kern_sysclock_available(SYSCTL_HANDLER_ARGS) { struct sbuf *s; int clk, error; s = sbuf_new_for_sysctl(NULL, NULL, MAX_SYSCLOCK_NAME_LEN * NUM_SYSCLOCKS, req); if (s == NULL) return (ENOMEM); for (clk = 0; clk < NUM_SYSCLOCKS; clk++) { sbuf_cat(s, sysclocks[clk]); if (clk + 1 < NUM_SYSCLOCKS) sbuf_cat(s, " "); } error = sbuf_finish(s); sbuf_delete(s); return (error); }
static int sysctl_handle_chansts(SYSCTL_HANDLER_ARGS) { struct ioat_softc *ioat; struct sbuf sb; uint64_t status; int error; ioat = arg1; status = ioat_get_chansts(ioat) & IOAT_CHANSTS_STATUS; sbuf_new_for_sysctl(&sb, NULL, 256, req); switch (status) { case IOAT_CHANSTS_ACTIVE: sbuf_printf(&sb, "ACTIVE"); break; case IOAT_CHANSTS_IDLE: sbuf_printf(&sb, "IDLE"); break; case IOAT_CHANSTS_SUSPENDED: sbuf_printf(&sb, "SUSPENDED"); break; case IOAT_CHANSTS_HALTED: sbuf_printf(&sb, "HALTED"); break; case IOAT_CHANSTS_ARMED: sbuf_printf(&sb, "ARMED"); break; default: sbuf_printf(&sb, "UNKNOWN"); break; } error = sbuf_finish(&sb); sbuf_delete(&sb); if (error != 0 || req->newptr == NULL) return (error); return (EINVAL); }
struct sbuf * exec_buf(const char *cmd) { FILE *fp; char buf[BUFSIZ]; struct sbuf *res; if ((fp = popen(cmd, "r")) == NULL) return (NULL); res = sbuf_new_auto(); while (fgets(buf, BUFSIZ, fp) != NULL) sbuf_cat(res, buf); pclose(fp); if (sbuf_len(res) == 0) { sbuf_delete(res); return (NULL); } sbuf_finish(res); return (res); }