static void pmt_callback(int status, struct tssp_section_listener *listener, struct tssp_section *section, void *userdata) { struct tssp_pmt *pmt; struct tssp_pmt_es *es; #if 0 printf("#### %s() called\n", __FUNCTION__); #endif pmt = tssp_pmt_parse(section); tssp_section_destroy(section); if (pmt == NULL) return; printf("PMT: program_number(0x%04x), version(%d), current_next(%d)\n", pmt->program_number, pmt->version, pmt->current_next); STAILQ_FOREACH(es, &pmt->es_list, entry) printf(" type(0x%02x), pid(0x%04x)\n", es->type, es->pid); tssp_pmt_destroy(pmt); }
static int fix_deps(struct pkgdb *db, struct deps_head *dh, int nbpkgs, bool yes) { struct pkg_jobs *jobs = NULL; struct deps_entry *e = NULL; char **pkgs = NULL; int i = 0; pkg_flags f = PKG_FLAG_AUTOMATIC; assert(db != NULL); assert(nbpkgs > 0); if ((pkgs = calloc(nbpkgs, MAXPATHLEN + 1)) == NULL) err(1, "calloc()"); STAILQ_FOREACH(e, dh, next) pkgs[i++] = e->origin; if (pkgdb_open(&db, PKGDB_REMOTE) != EPKG_OK) { free(pkgs); return (EPKG_ENODB); } if (pkg_jobs_new(&jobs, PKG_JOBS_INSTALL, db) != EPKG_OK) { free(pkgs); return (EPKG_FATAL); } pkg_jobs_set_flags(jobs, f); if (pkg_jobs_add(jobs, MATCH_EXACT, pkgs, nbpkgs) == EPKG_FATAL) { pkg_jobs_free(jobs); return (EPKG_FATAL); } if (pkg_jobs_solve(jobs) != EPKG_OK) { pkg_jobs_free(jobs); return (EPKG_FATAL); } if (pkg_jobs_count(jobs) == 0) { printf("\nUnable to find packages for installation.\n\n"); pkg_jobs_free(jobs); return (EPKG_FATAL); } /* print a summary before applying the jobs */ print_jobs_summary(jobs, "The following packages will be installed:\n\n"); if (yes == false) yes = query_yesno("\n>>> Try to fix the missing dependencies [y/N]: "); if (yes == true) pkg_jobs_apply(jobs); free(pkgs); pkg_jobs_free(jobs); return (EPKG_OK); }
static void dump_descriptors(struct tssp_descriptors *descriptors, int depth) { struct tssp_descriptor *desc; STAILQ_FOREACH(desc, descriptors, entry) dump_descriptor(desc, depth); }
static int fix_deps(struct pkgdb *db, struct deps_head *dh, int nbpkgs, bool yes) { struct pkg *pkg = NULL; struct pkgdb_it *it = NULL; struct pkg_jobs *jobs = NULL; struct deps_entry *e = NULL; char **pkgs = NULL; int i = 0; assert(db != NULL); assert(nbpkgs > 0); if ((pkgs = calloc(nbpkgs, MAXPATHLEN + 1)) == NULL) err(1, "calloc()"); STAILQ_FOREACH(e, dh, next) pkgs[i++] = e->origin; if (pkgdb_open(&db, PKGDB_REMOTE) != EPKG_OK) return (EPKG_ENODB); if (pkg_jobs_new(&jobs, PKG_JOBS_INSTALL, db) != EPKG_OK) free(pkgs); if ((it = pkgdb_query_installs(db, MATCH_EXACT, nbpkgs, pkgs, NULL, false)) == NULL) { free(pkgs); pkg_jobs_free(jobs); } while (pkgdb_it_next(it, &pkg, PKG_LOAD_BASIC|PKG_LOAD_DEPS) == EPKG_OK) { pkg_jobs_add(jobs, pkg); pkg = NULL; } if (pkg_jobs_is_empty(jobs)) { printf("\n>>> Unable to find packages for installation.\n\n"); return (EPKG_FATAL); } /* print a summary before applying the jobs */ pkg = NULL; print_jobs_summary(jobs, PKG_JOBS_INSTALL, "The following packages will be installed:\n\n"); if (yes == false) yes = query_yesno("\n>>> Try to fix the missing dependencies [y/N]: "); if (yes == true) pkg_jobs_apply(jobs, 0); free(pkgs); pkg_free(pkg); pkg_jobs_free(jobs); pkgdb_it_free(it); return (EPKG_OK); }
void notify(RECOVERY_STATUS status, int error, const char *msg) { struct notify_elem *elem; STAILQ_FOREACH(elem, &clients, next) (elem->client)(status, error, msg); }
static void snmp_dump_enumpairs(struct enum_pairs *headp) { struct enum_pair *entry; if (headp == NULL) return; fprintf(stderr,"enums: "); STAILQ_FOREACH(entry, headp, link) fprintf(stderr,"%d - %s, ", entry->enum_val, (entry->enum_str == NULL)?"NULL":entry->enum_str); fprintf(stderr,"; "); }
static void status() { spa_t *spa; spa = STAILQ_FIRST(&zfs_pools); if (spa == NULL) { printf("%s found no pools\n", zfs_module.name); return; } printf("%s found the following pools:", zfs_module.name); STAILQ_FOREACH(spa, &zfs_pools, spa_link) printf(" %s", spa->spa_name); printf("\n"); }
void wifi_scan_done(void *arg, STATUS status) { if (status == OK) { STAILQ_HEAD(, bss_info) *info = arg; struct bss_info *p; const char **ssids; int n = 0; STAILQ_FOREACH(p, info, next) n++; ssids = calloc(n + 1, sizeof(*ssids)); if (ssids == NULL) { LOG(LL_ERROR, ("Out of memory")); return; } n = 0; STAILQ_FOREACH(p, info, next) { int i; /* Remove duplicates */ for (i = 0; i < n; i++) { if (strcmp(ssids[i], (const char *) p->ssid) == 0) break; } if (i == n) ssids[n++] = (const char *) p->ssid; }
void init_table(struct Table *table) { struct Backend *iter; STAILQ_FOREACH(iter, &table->backends, entries) init_backend(iter); }
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); }
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; } } }
static int fix_deps(struct pkgdb *db, struct deps_head *dh, int nbpkgs, bool yes) { struct pkg_jobs *jobs = NULL; struct deps_entry *e = NULL; char **pkgs = NULL; int i = 0; bool rc; pkg_flags f = PKG_FLAG_AUTOMATIC; assert(db != NULL); assert(nbpkgs > 0); if ((pkgs = calloc(nbpkgs, sizeof (char *))) == NULL) err(1, "calloc()"); STAILQ_FOREACH(e, dh, next) pkgs[i++] = e->origin; if (pkgdb_open(&db, PKGDB_REMOTE) != EPKG_OK) { free(pkgs); return (EPKG_ENODB); } if (pkg_jobs_new(&jobs, PKG_JOBS_INSTALL, db) != EPKG_OK) { goto cleanup; } pkg_jobs_set_flags(jobs, f); if (pkg_jobs_add(jobs, MATCH_EXACT, pkgs, nbpkgs) == EPKG_FATAL) { goto cleanup; } if (pkg_jobs_solve(jobs) != EPKG_OK) { goto cleanup; } if (pkg_jobs_count(jobs) == 0) { printf("\nUnable to find packages for installation.\n\n"); goto cleanup; } /* print a summary before applying the jobs */ print_jobs_summary(jobs, "The following packages will be installed:\n\n"); rc = query_yesno(false, "\n>>> Try to fix the missing dependencies? [y/N]: "); if (rc) { if (pkgdb_access(PKGDB_MODE_WRITE, PKGDB_DB_LOCAL) == EPKG_ENOACCESS) { warnx("Insufficient privileges to modify the package " "database"); goto cleanup; } pkg_jobs_apply(jobs); } cleanup: free(pkgs); if (jobs != NULL) pkg_jobs_free(jobs); return (EPKG_OK); }
void wifi_changed_cb(System_Event_t *evt) { enum sj_wifi_status sj_ev = -1; /* TODO(rojer): Share this logic between platforms. */ if (wifi_setting_up && #ifndef RTOS_SDK evt->event == EVENT_STAMODE_GOT_IP #else evt->event_id == EVENT_STAMODE_GOT_IP #endif ) { struct station_config config; v7_val_t res; v7_val_t conf = v7_get(v7, v7_get_global_object(v7), "conf", ~0); v7_val_t known, wifi; if (v7_is_undefined(conf)) { fprintf(stderr, "cannot save conf, no conf object\n"); return; } wifi = v7_get(v7, conf, "wifi", ~0); if (v7_is_undefined(wifi)) { wifi = v7_create_object(v7); v7_set(v7, conf, "wifi", ~0, 0, wifi); } known = v7_get(v7, conf, "known", ~0); if (v7_is_undefined(known)) { known = v7_create_object(v7); v7_set(v7, wifi, "known", ~0, 0, known); } wifi_station_get_config(&config); v7_set(v7, known, (const char *) config.ssid, ~0, 0, v7_create_string(v7, (const char *) config.password, strlen((const char *) config.password), 1)); v7_exec(v7, "conf.save()", &res); wifi_setting_up = 0; } #ifndef RTOS_SDK switch (evt->event) { #else switch (evt->event_id) { #endif case EVENT_STAMODE_DISCONNECTED: sj_ev = SJ_WIFI_DISCONNECTED; break; case EVENT_STAMODE_CONNECTED: sj_ev = SJ_WIFI_CONNECTED; break; case EVENT_STAMODE_GOT_IP: sj_ev = SJ_WIFI_IP_ACQUIRED; break; } if (sj_ev >= 0) sj_wifi_on_change_callback(sj_ev); } char *sj_wifi_get_connected_ssid() { struct station_config conf; if (!wifi_station_get_config(&conf)) return NULL; return strdup((const char *) conf.ssid); } char *sj_wifi_get_sta_ip() { struct ip_info info; char *ip; if (!wifi_get_ip_info(0, &info) || info.ip.addr == 0) return NULL; if (asprintf(&ip, IPSTR, IP2STR(&info.ip)) < 0) { return NULL; } return ip; } void wifi_scan_done(void *arg, STATUS status) { if (status == OK) { STAILQ_HEAD(, bss_info) *info = arg; struct bss_info *p; const char **ssids; int n = 0; STAILQ_FOREACH(p, info, next) n++; ssids = calloc(n + 1, sizeof(*ssids)); n = 0; STAILQ_FOREACH(p, info, next) { ssids[n++] = (const char *) p->ssid; } wifi_scan_cb(ssids); free(ssids); } else {