void free_chunks (struct surface *srf) { int component_index; long n_freed; char message[MAXLINE]; struct chunk *head_chunk; struct chunk *this_chunk, *next_chunk; struct component *cmp_ptr; n_freed = 0; for (component_index = 0; component_index < srf -> n_component; component_index++) { cmp_ptr = get_component_ptr (srf, component_index+1); if (cmp_ptr == NULL) continue; head_chunk = cmp_ptr -> head_chunk; next_chunk = NULL; for (this_chunk = head_chunk; this_chunk != NULL; this_chunk = next_chunk) { next_chunk = this_chunk -> next[1]; free_chunk (this_chunk); n_freed++; } /* end of chunk loop */ } /* end of component loop */ sprintf (message,"%8ld chunks freed", n_freed); informd(message); free_cache (CHUNK); }
static errcode_t unix_close(io_channel channel) { struct unix_private_data *data; errcode_t retval = 0; EXT2_CHECK_MAGIC(channel, EXT2_ET_MAGIC_IO_CHANNEL); data = (struct unix_private_data *) channel->private_data; EXT2_CHECK_MAGIC(data, EXT2_ET_MAGIC_UNIX_IO_CHANNEL); if (--channel->refcount > 0) return 0; #ifndef NO_IO_CACHE retval = flush_cached_blocks(channel, data, 0); #endif if (close(data->dev) < 0) retval = errno; free_cache(data); ext2fs_free_mem(&channel->private_data); if (channel->name) ext2fs_free_mem(&channel->name); ext2fs_free_mem(&channel); return retval; }
/* * rcm_mod_fini() * * Destroy the cache. */ int rcm_mod_fini(void) { free_cache(); (void) mutex_destroy(&cache_lock); dladm_close(dld_handle); return (RCM_SUCCESS); }
int freeST (struct Plex *plex) { long ne, np; char message[MAXLINE]; ne = freeSubEdges (plex); if (ne == 0) return (0); sprintf (message, "%8ld subedges freed", ne); inform (message); free_pointers (SUBEDGE, (short *) (plex -> subedges)); plex -> subedges = NULL; np = freeSubPolygons (plex); if (np == 0) return (0); sprintf (message, "%8ld subpolygons freed", np); inform (message); free_pointers (SUBPOLYGON, (short *) (plex -> subpolygons)); plex -> subpolygons = NULL; free_cache (SUBEDGE); free_cache (SUBPOLYGON); return (1); }
int main(int argc, char *argv[]) { int i; init_cache(); i = argc; while (i>1) printf("%d\n", collatz(atoi(argv[--i]))); free_cache(); return 0; }
void clear_consumer() { free_hashmap(&savedRequests); free_hashmap(&wb_cl_map); free_hashmap(&cl_req_map); free_cache(cache); free_queue(&queue_clients); free_queue(&queue_webservers); pthread_attr_destroy(&attr); pthread_cond_destroy(&queue_cond); pthread_mutex_destroy(&queue_mutex); pthread_mutex_destroy(&wb_cl_map_mutex); pthread_mutex_destroy(&savedReq_map_mutex); }
void free_centrals (struct surface *this_srf) { struct central *central_ptr, *next_ptr; if (this_srf -> n_central > 0) { next_ptr = NULL; for (central_ptr = this_srf -> head_central; central_ptr != NULL; central_ptr = next_ptr) { next_ptr = central_ptr -> next; free_central (central_ptr); } } this_srf -> head_central = (struct central *) NULL; this_srf -> tail_central = (struct central *) NULL; this_srf -> n_central = 0; free_cache(CENTRAL); }
/** * Close the LRU page cache. */ void lru_close(DBM *db) { struct lru_cache *cache = db->cache; if (cache) { if (!db->is_volatile) flush_dirtypag(db); if (common_stats) log_lrustats(db); free_cache(cache); WFREE(cache); } db->cache = NULL; }
/** * Close (i.e. free) the LRU page cache. * * @attention * This does not attempt to flush any remaining dirty pages. */ void lru_close(DBM *db) { struct lru_cache *cache = db->cache; if (cache) { sdbm_lru_check(cache); if (common_stats) log_lrustats(db); free_cache(cache); cache->magic = 0; WFREE(cache); } db->cache = NULL; }
void read_file(Cache *cache){ FILE *pFile; pFile = fopen(read_in_file,"r"); char identifier; int address; int size; // Reading lines like " M 20,1" or "L 19,3" while(fscanf(pFile," %c %x,%d",&identifier,&address,&size) > 0){ if(identifier == 'I'){ //Ignore instruction I } else { //Operation according to identifier operate_cache(cache,identifier,address,size); } } free_cache(cache); fclose(pFile); }
int huffman_encode_memory(const unsigned char *bufin, unsigned int bufinlen, unsigned char **pbufout, unsigned int *pbufoutlen) { SymbolFrequencies sf; SymbolEncoder *se; huffman_node *root = NULL; int rc; unsigned int symbol_count; buf_cache cache; /* Ensure the arguments are valid. */ if(!pbufout || !pbufoutlen) return 1; if(init_cache(&cache, CACHE_SIZE, pbufout, pbufoutlen)) return 1; /* Get the frequency of each symbol in the input memory. */ symbol_count = get_symbol_frequencies_from_memory(&sf, bufin, bufinlen); /* Build an optimal table from the symbolCount. */ se = calculate_huffman_codes(&sf); root = sf[0]; /* Scan the memory again and, using the table previously built, encode it into the output memory. */ rc = write_code_table_to_memory(&cache, se, symbol_count); if(rc == 0) rc = do_memory_encode(&cache, bufin, bufinlen, se); /* Flush the cache. */ flush_cache(&cache); /* Free the Huffman tree. */ free_huffman_tree(root); free_encoder(se); free_cache(&cache); return rc; }
/** * Close the LRU page cache. */ void lru_close(DBM *db) { struct lru_cache *cache = db->cache; if (cache) { sdbm_lru_check(cache); if (!db->is_volatile && !(db->flags & DBM_BROKEN)) flush_dirtypag(db); if (common_stats) log_lrustats(db); free_cache(cache); cache->magic = 0; WFREE(cache); } db->cache = NULL; }
static errcode_t unix_set_blksize(io_channel channel, int blksize) { struct unix_private_data *data; errcode_t retval; EXT2_CHECK_MAGIC(channel, EXT2_ET_MAGIC_IO_CHANNEL); data = (struct unix_private_data *) channel->private_data; EXT2_CHECK_MAGIC(data, EXT2_ET_MAGIC_UNIX_IO_CHANNEL); if (channel->block_size != blksize) { #ifndef NO_IO_CACHE if ((retval = flush_cached_blocks(channel, data, 0))) return retval; #endif channel->block_size = blksize; free_cache(data); if ((retval = alloc_cache(channel, data))) return retval; } return 0; }
static errcode_t unix_open(const char *name, int flags, io_channel *channel) { io_channel io = NULL; struct unix_private_data *data = NULL; errcode_t retval; int open_flags, zeroes = 0; int f_nocache = 0; ext2fs_struct_stat st; #ifdef __linux__ struct utsname ut; #endif if (name == 0) return EXT2_ET_BAD_DEVICE_NAME; retval = ext2fs_get_mem(sizeof(struct struct_io_channel), &io); if (retval) goto cleanup; memset(io, 0, sizeof(struct struct_io_channel)); io->magic = EXT2_ET_MAGIC_IO_CHANNEL; retval = ext2fs_get_mem(sizeof(struct unix_private_data), &data); if (retval) goto cleanup; io->manager = unix_io_manager; retval = ext2fs_get_mem(strlen(name)+1, &io->name); if (retval) goto cleanup; strcpy(io->name, name); io->private_data = data; io->block_size = 1024; io->read_error = 0; io->write_error = 0; io->refcount = 1; memset(data, 0, sizeof(struct unix_private_data)); data->magic = EXT2_ET_MAGIC_UNIX_IO_CHANNEL; data->io_stats.num_fields = 2; open_flags = (flags & IO_FLAG_RW) ? O_RDWR : O_RDONLY; if (flags & IO_FLAG_EXCLUSIVE) open_flags |= O_EXCL; #if defined(O_DIRECT) if (flags & IO_FLAG_DIRECT_IO) { open_flags |= O_DIRECT; io->align = ext2fs_get_dio_alignment(data->dev); } #elif defined(F_NOCACHE) if (flags & IO_FLAG_DIRECT_IO) { f_nocache = F_NOCACHE; io->align = 4096; } #endif data->flags = flags; data->dev = ext2fs_open_file(io->name, open_flags, 0); if (data->dev < 0) { retval = errno; goto cleanup; } if (f_nocache) { if (fcntl(data->dev, f_nocache, 1) < 0) { retval = errno; goto cleanup; } } /* * If the device is really a block device, then set the * appropriate flag, otherwise we can set DISCARD_ZEROES flag * because we are going to use punch hole instead of discard * and if it succeed, subsequent read from sparse area returns * zero. */ if (ext2fs_stat(io->name, &st) == 0) { if (S_ISBLK(st.st_mode)) io->flags |= CHANNEL_FLAGS_BLOCK_DEVICE; else io->flags |= CHANNEL_FLAGS_DISCARD_ZEROES; } #ifdef BLKDISCARDZEROES ioctl(data->dev, BLKDISCARDZEROES, &zeroes); if (zeroes) io->flags |= CHANNEL_FLAGS_DISCARD_ZEROES; #endif #if defined(__CYGWIN__) || defined(__FreeBSD__) || defined(__FreeBSD_kernel__) /* * Some operating systems require that the buffers be aligned, * regardless of O_DIRECT */ if (!io->align) io->align = 512; #endif if ((retval = alloc_cache(io, data))) goto cleanup; #ifdef BLKROGET if (flags & IO_FLAG_RW) { int error; int readonly = 0; /* Is the block device actually writable? */ error = ioctl(data->dev, BLKROGET, &readonly); if (!error && readonly) { close(data->dev); retval = EPERM; goto cleanup; } } #endif #ifdef __linux__ #undef RLIM_INFINITY #if (defined(__alpha__) || ((defined(__sparc__) || defined(__mips__)) && (SIZEOF_LONG == 4))) #define RLIM_INFINITY ((unsigned long)(~0UL>>1)) #else #define RLIM_INFINITY (~0UL) #endif /* * Work around a bug in 2.4.10-2.4.18 kernels where writes to * block devices are wrongly getting hit by the filesize * limit. This workaround isn't perfect, since it won't work * if glibc wasn't built against 2.2 header files. (Sigh.) * */ if ((flags & IO_FLAG_RW) && (uname(&ut) == 0) && ((ut.release[0] == '2') && (ut.release[1] == '.') && (ut.release[2] == '4') && (ut.release[3] == '.') && (ut.release[4] == '1') && (ut.release[5] >= '0') && (ut.release[5] < '8')) && (ext2fs_stat(io->name, &st) == 0) && (S_ISBLK(st.st_mode))) { struct rlimit rlim; rlim.rlim_cur = rlim.rlim_max = (unsigned long) RLIM_INFINITY; setrlimit(RLIMIT_FSIZE, &rlim); getrlimit(RLIMIT_FSIZE, &rlim); if (((unsigned long) rlim.rlim_cur) < ((unsigned long) rlim.rlim_max)) { rlim.rlim_cur = rlim.rlim_max; setrlimit(RLIMIT_FSIZE, &rlim); } } #endif *channel = io; return 0; cleanup: if (data) { free_cache(data); ext2fs_free_mem(&data); } if (io) ext2fs_free_mem(&io); return retval; }
static errcode_t unix_open(const char *name, int flags, io_channel *channel) { io_channel io = NULL; struct unix_private_data *data = NULL; errcode_t retval; int open_flags; struct stat st; #ifdef __linux__ struct utsname ut; #endif if (name == 0) return EXT2_ET_BAD_DEVICE_NAME; retval = ext2fs_get_mem(sizeof(struct struct_io_channel), &io); if (retval) return retval; memset(io, 0, sizeof(struct struct_io_channel)); io->magic = EXT2_ET_MAGIC_IO_CHANNEL; retval = ext2fs_get_mem(sizeof(struct unix_private_data), &data); if (retval) goto cleanup; io->manager = unix_io_manager; retval = ext2fs_get_mem(strlen(name)+1, &io->name); if (retval) goto cleanup; strcpy(io->name, name); io->private_data = data; io->block_size = 1024; io->read_error = 0; io->write_error = 0; io->refcount = 1; memset(data, 0, sizeof(struct unix_private_data)); data->magic = EXT2_ET_MAGIC_UNIX_IO_CHANNEL; data->io_stats.num_fields = 2; if ((retval = alloc_cache(io, data))) goto cleanup; open_flags = (flags & IO_FLAG_RW) ? O_RDWR : O_RDONLY; if (flags & IO_FLAG_EXCLUSIVE) open_flags |= O_EXCL; #ifdef HAVE_OPEN64 data->dev = open64(io->name, open_flags); #else data->dev = open(io->name, open_flags); #endif if (data->dev < 0) { retval = errno; goto cleanup; } #ifdef BLKROGET if (flags & IO_FLAG_RW) { int error; int readonly = 0; /* Is the block device actually writable? */ error = ioctl(data->dev, BLKROGET, &readonly); if (!error && readonly) { close(data->dev); retval = EPERM; goto cleanup; } } #endif #ifdef __linux__ #undef RLIM_INFINITY #if (defined(__alpha__) || ((defined(__sparc__) || defined(__mips__)) && (SIZEOF_LONG == 4))) #define RLIM_INFINITY ((unsigned long)(~0UL>>1)) #else #define RLIM_INFINITY (~0UL) #endif /* * Work around a bug in 2.4.10-2.4.18 kernels where writes to * block devices are wrongly getting hit by the filesize * limit. This workaround isn't perfect, since it won't work * if glibc wasn't built against 2.2 header files. (Sigh.) * */ if ((flags & IO_FLAG_RW) && (uname(&ut) == 0) && ((ut.release[0] == '2') && (ut.release[1] == '.') && (ut.release[2] == '4') && (ut.release[3] == '.') && (ut.release[4] == '1') && (ut.release[5] >= '0') && (ut.release[5] < '8')) && (fstat(data->dev, &st) == 0) && (S_ISBLK(st.st_mode))) { struct rlimit rlim; rlim.rlim_cur = rlim.rlim_max = (unsigned long) RLIM_INFINITY; setrlimit(RLIMIT_FSIZE, &rlim); getrlimit(RLIMIT_FSIZE, &rlim); if (((unsigned long) rlim.rlim_cur) < ((unsigned long) rlim.rlim_max)) { rlim.rlim_cur = rlim.rlim_max; setrlimit(RLIMIT_FSIZE, &rlim); } } #endif *channel = io; return 0; cleanup: if (data) { free_cache(data); ext2fs_free_mem(&data); } if (io) ext2fs_free_mem(&io); return retval; }
static errcode_t unix_open(const char *name, int flags, io_channel *channel) { io_channel io = NULL; struct unix_private_data *data = NULL; errcode_t retval; int open_flags; struct stat st; #ifdef __linux__ struct utsname ut; #endif if (name == 0) return EXT2_ET_BAD_DEVICE_NAME; retval = ext2fs_get_mem(sizeof(struct struct_io_channel), &io); if (retval) return retval; memset(io, 0, sizeof(struct struct_io_channel)); io->magic = EXT2_ET_MAGIC_IO_CHANNEL; retval = ext2fs_get_mem(sizeof(struct unix_private_data), &data); if (retval) goto cleanup; io->manager = unix_io_manager; retval = ext2fs_get_mem(strlen(name)+1, &io->name); if (retval) goto cleanup; strcpy(io->name, name); io->private_data = data; io->block_size = 1024; io->read_error = 0; io->write_error = 0; io->refcount = 1; memset(data, 0, sizeof(struct unix_private_data)); data->magic = EXT2_ET_MAGIC_UNIX_IO_CHANNEL; if ((retval = alloc_cache(io, data))) goto cleanup; open_flags = (flags & IO_FLAG_RW) ? O_RDWR : O_RDONLY; #ifdef CONFIG_LFS data->dev = open64(io->name, open_flags); #else data->dev = open(io->name, open_flags); #endif if (data->dev < 0) { retval = errno; goto cleanup; } #ifdef __linux__ #undef RLIM_INFINITY #if (defined(__alpha__) || ((defined(__sparc__) || defined(__mips__)) && (SIZEOF_LONG \ == 4))) #define RLIM_INFINITY ((unsigned long)(~0UL>>1)) #else #define RLIM_INFINITY (~0UL) #endif if ((flags & IO_FLAG_RW) && (uname(&ut) == 0) && ((ut.release[0] == '2') && (ut.release[1] == '.') && (ut.release[2] == '4') && (ut.release[3] == '.') && (ut.release[4] == '1') && (ut.release[5] >= '0') && (ut.release[5] < '8')) && (fstat(data->dev, &st) == 0) && (S_ISBLK(st.st_mode))) { struct rlimit rlim; rlim.rlim_cur = rlim.rlim_max = (unsigned long) RLIM_INFINITY; setrlimit(RLIMIT_FSIZE, &rlim); getrlimit(RLIMIT_FSIZE, &rlim); if (((unsigned long) rlim.rlim_cur) < ((unsigned long) rlim.rlim_max)) { rlim.rlim_cur = rlim.rlim_max; setrlimit(RLIMIT_FSIZE, &rlim); } } #endif *channel = io; return 0; cleanup: if (data) { free_cache(data); ext2fs_free_mem(&data); } ext2fs_free_mem(&io); return retval; }
int /* O - Exit status */ main(int argc, /* I - Number of command-line arguments (6 or 7) */ char *argv[]) /* I - Command-line arguments */ { int ipv4, /* SNMP IPv4 socket */ ipv6; /* SNMP IPv6 socket */ #if defined(HAVE_SIGACTION) && !defined(HAVE_SIGSET) struct sigaction action; /* Actions for POSIX signals */ #endif /* HAVE_SIGACTION && !HAVE_SIGSET */ /* * Check command-line options... */ if (argc > 2) { _cupsLangPuts(stderr, _("Usage: snmp [host-or-ip-address]")); return (1); } /* * Set the password callback for IPP operations... */ cupsSetPasswordCB(password_cb); /* * Catch SIGALRM signals... */ #ifdef HAVE_SIGSET sigset(SIGALRM, alarm_handler); #elif defined(HAVE_SIGACTION) memset(&action, 0, sizeof(action)); sigemptyset(&action.sa_mask); sigaddset(&action.sa_mask, SIGALRM); action.sa_handler = alarm_handler; sigaction(SIGALRM, &action, NULL); #else signal(SIGALRM, alarm_handler); #endif /* HAVE_SIGSET */ /* * Open the SNMP socket... */ if ((ipv4 = _cupsSNMPOpen(AF_INET)) < 0) return (1); #ifdef AF_INET6 if ((ipv6 = _cupsSNMPOpen(AF_INET6)) < 0) perror("DEBUG: Unable to create IPv6 socket"); #else ipv6 = -1; #endif /* AF_INET6 */ /* * Read the configuration file and any cache data... */ read_snmp_conf(argv[1]); _cupsSNMPSetDebug(DebugLevel); Devices = cupsArrayNew((cups_array_func_t)compare_cache, NULL); /* * Scan for devices... */ scan_devices(ipv4, ipv6); /* * Close, free, and return with no errors... */ _cupsSNMPClose(ipv4); if (ipv6 >= 0) _cupsSNMPClose(ipv6); free_array(Addresses); free_array(Communities); free_cache(); return (0); }
int main(int argc, char *argv[]) { char *env; int i, verify = 0, clean = 0; while ((i = getopt(argc, argv, "cd:hi:kl:p:t:vCT:V")) != -1) switch ((char)i) { case 'c': clean = 1; break; case 'd': comics_dir = must_strdup(optarg); break; case 'h': usage(0); case 'i': add_index_dir(optarg); break; case 'k': unlink_index = 0; break; case 'l': links_only = fopen(optarg, "w"); if (!links_only) { my_perror(optarg); exit(1); } break; case 'p': set_proxy(optarg); break; case 't': thread_limit = strtol(optarg, NULL, 0); threads_set = 1; break; case 'v': verbose++; break; case 'C': #ifdef WANT_SSL openssl_list_ciphers(); #else puts("-C not supported."); #endif exit(0); case 'T': read_timeout = strtol(optarg, NULL, 0); break; case 'V': verify = 1; break; default: usage(1); } if (optind < argc) while (optind < argc) { if (read_config(argv[optind])) { printf("Fatal error in config file\n"); exit(1); } ++optind; } else if (read_config(NULL)) { printf("Fatal error in config file\n"); exit(1); } if (verify) { printf("Comics: %u Skipped today: %u\n", n_comics + skipped, skipped); if (verbose) dump_outstanding(0); return 0; } /* set_proxy will not use this if proxy already set */ env = getenv("COMICS_PROXY"); if (env) set_proxy(env); if (thread_limit == 0) { printf("You must allow at least one thread\n"); exit(1); } if (thread_limit > n_comics) thread_limit = n_comics; cd_comics_dir(clean); #ifdef _WIN32 win32_init(); #else signal(SIGTERM, dump_outstanding); signal(SIGHUP, dump_outstanding); signal(SIGPIPE, sigpipe); #endif if (links_only) fclose(links_only); want_extensions = 1; main_loop(); out_results(comics, skipped); #ifdef WIN32 printf("Hit return to exit"); getchar(); #endif free_cache(); /* for valgrind */ free_comics(); /* for valgrind */ if (debug_fp) fclose(debug_fp); return 0; }
int main(int argc, char *argv[]) { static char buff[16384]; struct cpio _cpio; /* Allocated on stack. */ struct cpio *cpio; const char *errmsg; int uid, gid; int opt; cpio = &_cpio; memset(cpio, 0, sizeof(*cpio)); cpio->buff = buff; cpio->buff_size = sizeof(buff); /* Need lafe_progname before calling lafe_warnc. */ if (*argv == NULL) lafe_progname = "bsdcpio"; else { #if defined(_WIN32) && !defined(__CYGWIN__) lafe_progname = strrchr(*argv, '\\'); #else lafe_progname = strrchr(*argv, '/'); #endif if (lafe_progname != NULL) lafe_progname++; else lafe_progname = *argv; } cpio->uid_override = -1; cpio->gid_override = -1; cpio->argv = argv; cpio->argc = argc; cpio->mode = '\0'; cpio->verbose = 0; cpio->compress = '\0'; cpio->extract_flags = ARCHIVE_EXTRACT_NO_AUTODIR; cpio->extract_flags |= ARCHIVE_EXTRACT_NO_OVERWRITE_NEWER; cpio->extract_flags |= ARCHIVE_EXTRACT_SECURE_SYMLINKS; cpio->extract_flags |= ARCHIVE_EXTRACT_SECURE_NODOTDOT; cpio->extract_flags |= ARCHIVE_EXTRACT_PERM; cpio->extract_flags |= ARCHIVE_EXTRACT_FFLAGS; cpio->extract_flags |= ARCHIVE_EXTRACT_ACL; #if !defined(_WIN32) && !defined(__CYGWIN__) if (geteuid() == 0) cpio->extract_flags |= ARCHIVE_EXTRACT_OWNER; #endif cpio->bytes_per_block = 512; cpio->filename = NULL; while ((opt = cpio_getopt(cpio)) != -1) { switch (opt) { case '0': /* GNU convention: --null, -0 */ cpio->option_null = 1; break; case 'A': /* NetBSD/OpenBSD */ cpio->option_append = 1; break; case 'a': /* POSIX 1997 */ cpio->option_atime_restore = 1; break; case 'B': /* POSIX 1997 */ cpio->bytes_per_block = 5120; break; case 'C': /* NetBSD/OpenBSD */ cpio->bytes_per_block = atoi(cpio->optarg); if (cpio->bytes_per_block <= 0) lafe_errc(1, 0, "Invalid blocksize %s", cpio->optarg); break; case 'c': /* POSIX 1997 */ cpio->format = "odc"; break; case 'd': /* POSIX 1997 */ cpio->extract_flags &= ~ARCHIVE_EXTRACT_NO_AUTODIR; break; case 'E': /* NetBSD/OpenBSD */ lafe_include_from_file(&cpio->matching, cpio->optarg, cpio->option_null); break; case 'F': /* NetBSD/OpenBSD/GNU cpio */ cpio->filename = cpio->optarg; break; case 'f': /* POSIX 1997 */ lafe_exclude(&cpio->matching, cpio->optarg); break; case 'H': /* GNU cpio (also --format) */ cpio->format = cpio->optarg; break; case 'h': long_help(); break; case 'I': /* NetBSD/OpenBSD */ cpio->filename = cpio->optarg; break; case 'i': /* POSIX 1997 */ if (cpio->mode != '\0') lafe_errc(1, 0, "Cannot use both -i and -%c", cpio->mode); cpio->mode = opt; break; case 'J': /* GNU tar, others */ cpio->compress = opt; break; case 'j': /* GNU tar, others */ cpio->compress = opt; break; case OPTION_INSECURE: cpio->extract_flags &= ~ARCHIVE_EXTRACT_SECURE_SYMLINKS; cpio->extract_flags &= ~ARCHIVE_EXTRACT_SECURE_NODOTDOT; break; case 'L': /* GNU cpio */ cpio->option_follow_links = 1; break; case 'l': /* POSIX 1997 */ cpio->option_link = 1; break; case OPTION_LZMA: /* GNU tar, others */ cpio->compress = opt; break; case 'm': /* POSIX 1997 */ cpio->extract_flags |= ARCHIVE_EXTRACT_TIME; break; case 'n': /* GNU cpio */ cpio->option_numeric_uid_gid = 1; break; case OPTION_NO_PRESERVE_OWNER: /* GNU cpio */ cpio->extract_flags &= ~ARCHIVE_EXTRACT_OWNER; break; case 'O': /* GNU cpio */ cpio->filename = cpio->optarg; break; case 'o': /* POSIX 1997 */ if (cpio->mode != '\0') lafe_errc(1, 0, "Cannot use both -o and -%c", cpio->mode); cpio->mode = opt; break; case 'p': /* POSIX 1997 */ if (cpio->mode != '\0') lafe_errc(1, 0, "Cannot use both -p and -%c", cpio->mode); cpio->mode = opt; cpio->extract_flags &= ~ARCHIVE_EXTRACT_SECURE_NODOTDOT; break; case OPTION_PRESERVE_OWNER: cpio->extract_flags |= ARCHIVE_EXTRACT_OWNER; break; case OPTION_QUIET: /* GNU cpio */ cpio->quiet = 1; break; case 'R': /* GNU cpio, also --owner */ errmsg = owner_parse(cpio->optarg, &uid, &gid); if (errmsg) { lafe_warnc(-1, "%s", errmsg); usage(); } if (uid != -1) cpio->uid_override = uid; if (gid != -1) cpio->gid_override = gid; break; case 'r': /* POSIX 1997 */ cpio->option_rename = 1; break; case 't': /* POSIX 1997 */ cpio->option_list = 1; break; case 'u': /* POSIX 1997 */ cpio->extract_flags &= ~ARCHIVE_EXTRACT_NO_OVERWRITE_NEWER; break; case 'v': /* POSIX 1997 */ cpio->verbose++; break; case OPTION_VERSION: /* GNU convention */ version(); break; #if 0 /* * cpio_getopt() handles -W specially, so it's not * available here. */ case 'W': /* Obscure, but useful GNU convention. */ break; #endif case 'y': /* tar convention */ cpio->compress = opt; break; case 'Z': /* tar convention */ cpio->compress = opt; break; case 'z': /* tar convention */ cpio->compress = opt; break; default: usage(); } } /* * Sanity-check args, error out on nonsensical combinations. */ /* -t implies -i if no mode was specified. */ if (cpio->option_list && cpio->mode == '\0') cpio->mode = 'i'; /* -t requires -i */ if (cpio->option_list && cpio->mode != 'i') lafe_errc(1, 0, "Option -t requires -i"); /* -n requires -it */ if (cpio->option_numeric_uid_gid && !cpio->option_list) lafe_errc(1, 0, "Option -n requires -it"); /* Can only specify format when writing */ if (cpio->format != NULL && cpio->mode != 'o') lafe_errc(1, 0, "Option --format requires -o"); /* -l requires -p */ if (cpio->option_link && cpio->mode != 'p') lafe_errc(1, 0, "Option -l requires -p"); /* TODO: Flag other nonsensical combinations. */ switch (cpio->mode) { case 'o': /* TODO: Implement old binary format in libarchive, use that here. */ if (cpio->format == NULL) cpio->format = "odc"; /* Default format */ mode_out(cpio); break; case 'i': while (*cpio->argv != NULL) { lafe_include(&cpio->matching, *cpio->argv); --cpio->argc; ++cpio->argv; } if (cpio->option_list) mode_list(cpio); else mode_in(cpio); break; case 'p': if (*cpio->argv == NULL || **cpio->argv == '\0') lafe_errc(1, 0, "-p mode requires a target directory"); mode_pass(cpio, *cpio->argv); break; default: lafe_errc(1, 0, "Must specify at least one of -i, -o, or -p"); } free_cache(cpio->gname_cache); free_cache(cpio->uname_cache); return (cpio->return_value); }
int main(int argc, char *argv[]) { static char buff[16384]; struct cpio _cpio; /* Allocated on stack. */ struct cpio *cpio; const char *errmsg; int uid, gid; int opt; cpio = &_cpio; memset(cpio, 0, sizeof(*cpio)); cpio->buff = buff; cpio->buff_size = sizeof(buff); #if defined(HAVE_SIGACTION) && defined(SIGPIPE) { /* Ignore SIGPIPE signals. */ struct sigaction sa; sigemptyset(&sa.sa_mask); sa.sa_flags = 0; sa.sa_handler = SIG_IGN; sigaction(SIGPIPE, &sa, NULL); } #endif /* Set lafe_progname before calling lafe_warnc. */ lafe_setprogname(*argv, "bsdcpio"); #if HAVE_SETLOCALE if (setlocale(LC_ALL, "") == NULL) lafe_warnc(0, "Failed to set default locale"); #endif cpio->uid_override = -1; cpio->gid_override = -1; cpio->argv = argv; cpio->argc = argc; cpio->mode = '\0'; cpio->verbose = 0; cpio->compress = '\0'; cpio->extract_flags = ARCHIVE_EXTRACT_NO_AUTODIR; cpio->extract_flags |= ARCHIVE_EXTRACT_NO_OVERWRITE_NEWER; cpio->extract_flags |= ARCHIVE_EXTRACT_SECURE_SYMLINKS; cpio->extract_flags |= ARCHIVE_EXTRACT_SECURE_NODOTDOT; cpio->extract_flags |= ARCHIVE_EXTRACT_PERM; cpio->extract_flags |= ARCHIVE_EXTRACT_FFLAGS; cpio->extract_flags |= ARCHIVE_EXTRACT_ACL; #if !defined(_WIN32) && !defined(__CYGWIN__) if (geteuid() == 0) cpio->extract_flags |= ARCHIVE_EXTRACT_OWNER; #endif cpio->bytes_per_block = 512; cpio->filename = NULL; cpio->matching = archive_match_new(); if (cpio->matching == NULL) lafe_errc(1, 0, "Out of memory"); while ((opt = cpio_getopt(cpio)) != -1) { switch (opt) { case '0': /* GNU convention: --null, -0 */ cpio->option_null = 1; break; case 'A': /* NetBSD/OpenBSD */ cpio->option_append = 1; break; case 'a': /* POSIX 1997 */ cpio->option_atime_restore = 1; break; case 'B': /* POSIX 1997 */ cpio->bytes_per_block = 5120; break; case OPTION_B64ENCODE: cpio->add_filter = opt; break; case 'C': /* NetBSD/OpenBSD */ cpio->bytes_per_block = atoi(cpio->argument); if (cpio->bytes_per_block <= 0) lafe_errc(1, 0, "Invalid blocksize %s", cpio->argument); break; case 'c': /* POSIX 1997 */ cpio->format = "odc"; break; case 'd': /* POSIX 1997 */ cpio->extract_flags &= ~ARCHIVE_EXTRACT_NO_AUTODIR; break; case 'E': /* NetBSD/OpenBSD */ if (archive_match_include_pattern_from_file( cpio->matching, cpio->argument, cpio->option_null) != ARCHIVE_OK) lafe_errc(1, 0, "Error : %s", archive_error_string(cpio->matching)); break; case 'F': /* NetBSD/OpenBSD/GNU cpio */ cpio->filename = cpio->argument; break; case 'f': /* POSIX 1997 */ if (archive_match_exclude_pattern(cpio->matching, cpio->argument) != ARCHIVE_OK) lafe_errc(1, 0, "Error : %s", archive_error_string(cpio->matching)); break; case OPTION_GRZIP: cpio->compress = opt; break; case 'H': /* GNU cpio (also --format) */ cpio->format = cpio->argument; break; case 'h': long_help(); break; case 'I': /* NetBSD/OpenBSD */ cpio->filename = cpio->argument; break; case 'i': /* POSIX 1997 */ if (cpio->mode != '\0') lafe_errc(1, 0, "Cannot use both -i and -%c", cpio->mode); cpio->mode = opt; break; case 'J': /* GNU tar, others */ cpio->compress = opt; break; case 'j': /* GNU tar, others */ cpio->compress = opt; break; case OPTION_INSECURE: cpio->extract_flags &= ~ARCHIVE_EXTRACT_SECURE_SYMLINKS; cpio->extract_flags &= ~ARCHIVE_EXTRACT_SECURE_NODOTDOT; break; case 'L': /* GNU cpio */ cpio->option_follow_links = 1; break; case 'l': /* POSIX 1997 */ cpio->option_link = 1; break; case OPTION_LRZIP: case OPTION_LZMA: /* GNU tar, others */ case OPTION_LZOP: /* GNU tar, others */ cpio->compress = opt; break; case 'm': /* POSIX 1997 */ cpio->extract_flags |= ARCHIVE_EXTRACT_TIME; break; case 'n': /* GNU cpio */ cpio->option_numeric_uid_gid = 1; break; case OPTION_NO_PRESERVE_OWNER: /* GNU cpio */ cpio->extract_flags &= ~ARCHIVE_EXTRACT_OWNER; break; case 'O': /* GNU cpio */ cpio->filename = cpio->argument; break; case 'o': /* POSIX 1997 */ if (cpio->mode != '\0') lafe_errc(1, 0, "Cannot use both -o and -%c", cpio->mode); cpio->mode = opt; break; case 'p': /* POSIX 1997 */ if (cpio->mode != '\0') lafe_errc(1, 0, "Cannot use both -p and -%c", cpio->mode); cpio->mode = opt; cpio->extract_flags &= ~ARCHIVE_EXTRACT_SECURE_NODOTDOT; break; case OPTION_PRESERVE_OWNER: cpio->extract_flags |= ARCHIVE_EXTRACT_OWNER; break; case OPTION_QUIET: /* GNU cpio */ cpio->quiet = 1; break; case 'R': /* GNU cpio, also --owner */ /* TODO: owner_parse should return uname/gname * also; use that to set [ug]name_override. */ errmsg = owner_parse(cpio->argument, &uid, &gid); if (errmsg) { lafe_warnc(-1, "%s", errmsg); usage(); } if (uid != -1) { cpio->uid_override = uid; cpio->uname_override = NULL; } if (gid != -1) { cpio->gid_override = gid; cpio->gname_override = NULL; } break; case 'r': /* POSIX 1997 */ cpio->option_rename = 1; break; case 't': /* POSIX 1997 */ cpio->option_list = 1; break; case 'u': /* POSIX 1997 */ cpio->extract_flags &= ~ARCHIVE_EXTRACT_NO_OVERWRITE_NEWER; break; case OPTION_UUENCODE: cpio->add_filter = opt; break; case 'v': /* POSIX 1997 */ cpio->verbose++; break; case 'V': /* GNU cpio */ cpio->dot++; break; case OPTION_VERSION: /* GNU convention */ version(); break; #if 0 /* * cpio_getopt() handles -W specially, so it's not * available here. */ case 'W': /* Obscure, but useful GNU convention. */ break; #endif case 'y': /* tar convention */ cpio->compress = opt; break; case 'Z': /* tar convention */ cpio->compress = opt; break; case 'z': /* tar convention */ cpio->compress = opt; break; default: usage(); } } /* * Sanity-check args, error out on nonsensical combinations. */ /* -t implies -i if no mode was specified. */ if (cpio->option_list && cpio->mode == '\0') cpio->mode = 'i'; /* -t requires -i */ if (cpio->option_list && cpio->mode != 'i') lafe_errc(1, 0, "Option -t requires -i"); /* -n requires -it */ if (cpio->option_numeric_uid_gid && !cpio->option_list) lafe_errc(1, 0, "Option -n requires -it"); /* Can only specify format when writing */ if (cpio->format != NULL && cpio->mode != 'o') lafe_errc(1, 0, "Option --format requires -o"); /* -l requires -p */ if (cpio->option_link && cpio->mode != 'p') lafe_errc(1, 0, "Option -l requires -p"); /* -v overrides -V */ if (cpio->dot && cpio->verbose) cpio->dot = 0; /* TODO: Flag other nonsensical combinations. */ switch (cpio->mode) { case 'o': /* TODO: Implement old binary format in libarchive, use that here. */ if (cpio->format == NULL) cpio->format = "odc"; /* Default format */ mode_out(cpio); break; case 'i': while (*cpio->argv != NULL) { if (archive_match_include_pattern(cpio->matching, *cpio->argv) != ARCHIVE_OK) lafe_errc(1, 0, "Error : %s", archive_error_string(cpio->matching)); --cpio->argc; ++cpio->argv; } if (cpio->option_list) mode_list(cpio); else mode_in(cpio); break; case 'p': if (*cpio->argv == NULL || **cpio->argv == '\0') lafe_errc(1, 0, "-p mode requires a target directory"); mode_pass(cpio, *cpio->argv); break; default: lafe_errc(1, 0, "Must specify at least one of -i, -o, or -p"); } archive_match_free(cpio->matching); free_cache(cpio->gname_cache); free_cache(cpio->uname_cache); free(cpio->destdir); return (cpio->return_value); }
_nc_last_db(void) { if (my_blob != 0 && cache_expired()) { free_cache(); } }
_nc_first_db(DBDIRS * state, int *offset) { bool cache_has_expired = FALSE; *state = dbdTIC; *offset = 0; T(("_nc_first_db")); /* build a blob containing all of the strings we will use for a lookup * table. */ if (my_blob == 0 || (cache_has_expired = cache_expired())) { size_t blobsize = 0; const char *values[dbdLAST]; struct stat *my_stat; int j, k; if (cache_has_expired) free_cache(); for (j = 0; j < dbdLAST; ++j) values[j] = 0; /* * This is the first item in the list, and is used only when tic is * writing to the database, as a performance improvement. */ values[dbdTIC] = TicDirectory; #if NCURSES_USE_DATABASE #ifdef TERMINFO_DIRS values[dbdCfgList] = TERMINFO_DIRS; #endif #ifdef TERMINFO values[dbdCfgOnce] = TERMINFO; #endif #endif #if NCURSES_USE_TERMCAP values[dbdCfgList2] = TERMPATH; #endif if (use_terminfo_vars()) { #if NCURSES_USE_DATABASE values[dbdEnvOnce] = cache_getenv("TERMINFO", dbdEnvOnce); values[dbdHome] = _nc_home_terminfo(); (void) cache_getenv("HOME", dbdHome); values[dbdEnvList] = cache_getenv("TERMINFO_DIRS", dbdEnvList); #endif #if NCURSES_USE_TERMCAP values[dbdEnvOnce2] = cache_getenv("TERMCAP", dbdEnvOnce2); /* only use $TERMCAP if it is an absolute path */ if (values[dbdEnvOnce2] != 0 && *values[dbdEnvOnce2] != '/') { values[dbdEnvOnce2] = 0; } values[dbdEnvList2] = cache_getenv("TERMPATH", dbdEnvList2); #endif /* NCURSES_USE_TERMCAP */ } for (j = 0; j < dbdLAST; ++j) { if (values[j] == 0) values[j] = ""; blobsize += 2 + strlen(values[j]); } my_blob = malloc(blobsize); if (my_blob != 0) { *my_blob = '\0'; for (j = 0; j < dbdLAST; ++j) { add_to_blob(values[j], blobsize); } /* Now, build an array which will be pointers to the distinct * strings in the blob. */ blobsize = 2; for (j = 0; my_blob[j] != '\0'; ++j) { if (my_blob[j] == NCURSES_PATHSEP) ++blobsize; } my_list = typeCalloc(char *, blobsize); my_stat = typeCalloc(struct stat, blobsize); if (my_list != 0 && my_stat != 0) { k = 0; my_list[k++] = my_blob; for (j = 0; my_blob[j] != '\0'; ++j) { if (my_blob[j] == NCURSES_PATHSEP) { my_blob[j] = '\0'; my_list[k++] = &my_blob[j + 1]; } } /* * Eliminate duplicates from the list. */ for (j = 0; my_list[j] != 0; ++j) { #ifdef TERMINFO if (*my_list[j] == '\0') my_list[j] = strdup(TERMINFO); #endif for (k = 0; k < j; ++k) { if (!strcmp(my_list[j], my_list[k])) { k = j - 1; while ((my_list[j] = my_list[j + 1]) != 0) { ++j; } j = k; break; } } } /* * Eliminate non-existent databases, and those that happen to * be symlinked to another location. */ for (j = 0; my_list[j] != 0; ++j) { bool found = check_existence(my_list[j], &my_stat[j]); #if HAVE_LINK if (found) { for (k = 0; k < j; ++k) { if (my_stat[j].st_dev == my_stat[k].st_dev && my_stat[j].st_ino == my_stat[k].st_ino) { found = FALSE; break; } } } #endif if (!found) { k = j; while ((my_list[k] = my_list[k + 1]) != 0) { ++k; } --j; } } my_size = j; my_time = time((time_t *) 0); } else { FreeAndNull(my_blob); } free(my_stat); }
static void free_cache_rcu(struct rcu_head *rcu) { struct tnl_cache *c = container_of(rcu, struct tnl_cache, rcu); free_cache(c); }
void tsin_parse() { TSIN_PARSE out[MAX_PH_BF_EXT+1]; bzero(out, sizeof(out)); int i, ofsi; if (tss.c_len <= 1) return; load_tsin_db(); set_tsin_parse_len(tss.c_len); init_cache(tss.c_len); char pinyin_set[MAX_PH_BF_EXT]; c_pinyin_set = pin_juyin?pinyin_set:NULL; get_chpho_pinyin_set(pinyin_set); short smatch_phr_N, sno_match_ch_N; tsin_parse_recur(0, out, &smatch_phr_N, &sno_match_ch_N); #if 0 puts("vvvvvvvvvvvvvvvv"); for(i=0; i < tss.c_len; i++) { printf("%d:", out[i].len); utf8_putcharn(out[i].str, out[i].len); } dbg("\n"); #endif for(i=0; i < tss.c_len; i++) tss.chpho[i].flag &= ~(FLAG_CHPHO_PHRASE_HEAD|FLAG_CHPHO_PHRASE_BODY); for(ofsi=i=0; out[i].len; i++) { int j, ofsj; int psta = ofsi; if (out[i].flag & FLAG_TSIN_PARSE_PHRASE) tss.chpho[ofsi].flag |= FLAG_CHPHO_PHRASE_HEAD; for(ofsj=j=0; j < out[i].len; j++) { ofsj += utf8cpy(tss.chpho[ofsi].cha, (char *)&out[i].str[ofsj]); // tss.chpho[ofsi].ch = tss.chpho[ofsi].cha; tss.chpho[ofsi].flag |= FLAG_CHPHO_PHRASE_BODY; if (out[i].flag & FLAG_TSIN_PARSE_PHRASE) tss.chpho[ofsi].psta = psta; ofsi++; } } int ph_sta_idx = tss.ph_sta; if (tss.chpho[tss.c_len-1].psta>=0 && tss.c_len - tss.chpho[tss.c_len-1].psta > 1) { ph_sta_idx = tss.chpho[tss.c_len-1].psta; } #if 1 disp_ph_sta_idx(ph_sta_idx); #endif #if 0 for(i=0;i<tss.c_len;i++) utf8_putchar(tss.chpho[i].ch); puts(""); #endif free_cache(); }
/** * Set the page cache size. * @return 0 if OK, -1 on failure with errno set. */ int setcache(DBM *db, long pages) { struct lru_cache *cache = db->cache; bool wdelay; sdbm_lru_check(cache); if (pages <= 0) { errno = EINVAL; return -1; } if (NULL == cache) return init_cache(db, pages, FALSE); /* * Easiest case: the size identical. */ if (pages == cache->pages) return 0; /* * Cache size is changed. * * This means the arena will be reallocated, so we must invalidate the * current db->pagbuf pointer, which lies within the old arena. It is * sufficient to reset db->pagbno, forcing a reload from the upper layers. * Note than when the cache size is enlarged, the old page is still cached * so reloading will be just a matter of recomputing db->pagbuf. We could * do so here, but cache size changes should only be infrequent. * * We also reset all the cache statistics, since a different cache size * will imply a different set of hit/miss ratio. */ db->pagbno = -1; /* Current page address will become invalid */ db->pagbuf = NULL; if (common_stats) { s_info("sdbm: \"%s\" LRU cache size %s from %ld page%s to %ld", sdbm_name(db), pages > cache->pages ? "increased" : "decreased", cache->pages, plural(cache->pages), pages); log_lrustats(db); } cache->rhits = cache->rmisses = 0; cache->whits = cache->wmisses = 0; /* * Straightforward: the size is increased. */ if (pages > cache->pages) { char *new_arena = vmm_alloc(pages * DBM_PBLKSIZ); if (NULL == new_arena) return -1; memmove(new_arena, cache->arena, cache->pages * DBM_PBLKSIZ); vmm_free(cache->arena, cache->pages * DBM_PBLKSIZ); cache->arena = new_arena; cache->dirty = wrealloc(cache->dirty, cache->pages, pages); cache->numpag = wrealloc(cache->numpag, cache->pages * sizeof(long), pages * sizeof(long)); cache->pages = pages; return 0; } /* * Difficult: the size is decreased. * * The current page buffer could point in a cache area that is going * to disappear, and the internal data structures must forget about * all the old indices that are greater than the new limit. * * We do not try to optimize anything here, as this call should happen * only infrequently: we flush the current cache (in case there are * deferred writes), destroy the LRU cache data structures, recreate a * new one and invalidate the current DB page. */ wdelay = cache->write_deferred; flush_dirtypag(db); free_cache(cache); return setup_cache(cache, pages, wdelay); }
int main(int argc, char **argv) { cache_built_param param; cache_output_param output; output.hits = 0; output.misses = 0; output.evicts = 0; char *trace_file; FILE *input_file; char trace_op; unsigned long long int address; // hold for 64-bytes address int size; char c; while ((c = getopt(argc, argv, "s: E: b: t: hv")) != -1) { switch(c) { case 's': param.s = atoi(optarg); // transfer input string argument to integer break; case 'E': param.E = atoi(optarg); break; case 'b': param.b = atoi(optarg); break; case 't': trace_file = optarg; break; default: break; } } /* * check whether the input parameters are legal and complete */ if (param.s == 0 || param.E == 0 || param.b == 0 || trace_file == NULL) { printf("Miss required command line argument"); exit(1); } // create a cache according to the given parameters cache new_cache = create_cache(param.s, param.E, param.b); // open the input file to get operations input_file = fopen(trace_file, "r"); if (input_file != NULL) { /* * get the trace command from each line */ while(fscanf(input_file, " %c %llx,%d", &trace_op, &address, &size) == 3) { switch(trace_op) { case 'I': break; case 'S': printf("%c %llx %d\n", trace_op, address, size); output = simulated_cache(&new_cache, param, output, address); break; case 'L': printf("%c %llx %d\n", trace_op, address, size); output = simulated_cache(&new_cache, param, output, address); break; case 'M': printf("%c %llx %d\n", trace_op, address, size); output = simulated_cache(&new_cache, param, output, address); output = simulated_cache(&new_cache, param, output, address); break; default: break; } } printSummary(output.hits, output.misses, output.evicts); // print out the result free_cache(&new_cache, param.s, param.E, param.b); fclose(input_file); return 0; } }
/********************** ************************/ int main(int argc,char *argv[]) { int n_pages = 0; //int n_frames = 0; ram_info_t ram_info;// ram_info.n_frames = 0;// ram_info.algorithm = NULL;// int n_cache = 0; int n_tlb = 0; char *access_file = NULL; FILE *access_fd = NULL; addr_t virtual_addr = 0; addr_t physical_addr; pid_t pid = 0; char mode; /* * Parse arguments */ if( 0 != parse_args(argc, argv, &access_file, &n_pages, &ram_info.n_frames, &n_cache, &n_tlb, &ram_info.algorithm) ) {// return -1; } /* * Setup data structures */ srand(time(NULL)); current_ref = (char *)malloc(sizeof(char) * MAX_LINE); clear_stats(); stats.cache_size = n_cache; stats.tlb_size = n_tlb; stats.num_pages = n_pages; stats.num_frames = ram_info.n_frames;// printf("Allocating resources...\n"); allocate_cache(n_cache); allocate_tlb(n_tlb); allocate_page_table(n_pages); allocate_page_directory(n_pages); //allocate_ram(n_frames); allocate_ram(ram_info); /* * Open the file that we are going to read */ if( NULL == (access_fd = fopen(access_file, "r") ) ) { fprintf(stderr, "Error: Unable to open the access file <%s>\n", access_file); return -1; } /* * Read page requests from the file */ gettimeofday(&stats.start, NULL); while(0 == feof(access_fd) ) { /* Read one line */ current_ref[0] = '\0'; if( NULL == fgets(current_ref, MAX_LINE, access_fd) ) { break; } /* Strip off the newline */ if( '\n' == current_ref[strlen(current_ref)-1] ) { current_ref[strlen(current_ref)-1] = '\0'; } extract_args(current_ref, &pid, &mode, &virtual_addr); /* * Memory management operations to access the page */ if(VERBOSE){ printf("-----------------------------------------------------------\n"); printf("%s: Process %*d \t Access [Page %4d, Offset %#05x] (%#010x)\n", current_ref, MAX_PID_LEN, pid, GET_PAGE(virtual_addr), GET_OFFSET(virtual_addr), virtual_addr); } access_page(pid, mode, virtual_addr, &physical_addr); if(VERBOSE){ printf("%s: Process %*d \t Access [Page %4d, Offset %#05x] (%#010x) --> (%#010x) [Frame %4d, Offset %#05x]\n", current_ref, MAX_PID_LEN, pid, GET_PAGE(virtual_addr), GET_OFFSET(virtual_addr), virtual_addr, physical_addr, GET_FRAME(physical_addr), GET_OFFSET(physical_addr)); } } gettimeofday(&stats.end, NULL); display_stats(); /* * Cleanup */ fclose(access_fd); if( NULL != current_ref ) { free(current_ref); current_ref = NULL; } free_ram(); free_page_dir(); free_tlb(); free_cache(); return 0; }
static int do_free_cache(char **arg, char reply[REPLY_MAX]) /* TODO int:free_size */ { return free_cache((int64_t)atoll(arg[0])); /* free_size */ }
int32_t main(int32_t argc, char *argv[]) { fix_stacksize(); run_tests(); int32_t i, j; prog_name = argv[0]; struct timespec start_ts; cs_gettime(&start_ts); // Initialize clock_type if(pthread_key_create(&getclient, NULL)) { fprintf(stderr, "Could not create getclient, exiting..."); exit(1); } void (*mod_def[])(struct s_module *) = { #ifdef MODULE_MONITOR module_monitor, #endif #ifdef MODULE_CAMD33 module_camd33, #endif #ifdef MODULE_CAMD35 module_camd35, #endif #ifdef MODULE_CAMD35_TCP module_camd35_tcp, #endif #ifdef MODULE_NEWCAMD module_newcamd, #endif #ifdef MODULE_CCCAM module_cccam, #endif #ifdef MODULE_PANDORA module_pandora, #endif #ifdef MODULE_GHTTP module_ghttp, #endif #ifdef CS_CACHEEX module_csp, #endif #ifdef MODULE_GBOX module_gbox, #endif #ifdef MODULE_CONSTCW module_constcw, #endif #ifdef MODULE_RADEGAST module_radegast, #endif #ifdef MODULE_SCAM module_scam, #endif #ifdef MODULE_SERIAL module_serial, #endif #ifdef HAVE_DVBAPI module_dvbapi, #endif 0 }; find_conf_dir(); parse_cmdline_params(argc, argv); if(bg && do_daemon(1, 0)) { printf("Error starting in background (errno=%d: %s)", errno, strerror(errno)); cs_exit(1); } get_random_bytes_init(); #ifdef WEBIF if(cs_restart_mode) { restart_daemon(); } #endif memset(&cfg, 0, sizeof(struct s_config)); cfg.max_pending = max_pending; if(cs_confdir[strlen(cs_confdir) - 1] != '/') { strcat(cs_confdir, "/"); } init_signal_pre(); // because log could cause SIGPIPE errors, init a signal handler first init_first_client(); cs_lock_create(__func__, &system_lock, "system_lock", 5000); cs_lock_create(__func__, &config_lock, "config_lock", 10000); cs_lock_create(__func__, &gethostbyname_lock, "gethostbyname_lock", 10000); cs_lock_create(__func__, &clientlist_lock, "clientlist_lock", 5000); cs_lock_create(__func__, &readerlist_lock, "readerlist_lock", 5000); cs_lock_create(__func__, &fakeuser_lock, "fakeuser_lock", 5000); cs_lock_create(__func__, &ecmcache_lock, "ecmcache_lock", 5000); cs_lock_create(__func__, &ecm_pushed_deleted_lock, "ecm_pushed_deleted_lock", 5000); cs_lock_create(__func__, &readdir_lock, "readdir_lock", 5000); cs_lock_create(__func__, &cwcycle_lock, "cwcycle_lock", 5000); init_cache(); cacheex_init_hitcache(); init_config(); cs_init_log(); init_machine_info(); init_check(); if(!oscam_pidfile && cfg.pidfile) { oscam_pidfile = cfg.pidfile; } if(!oscam_pidfile) { oscam_pidfile = get_tmp_dir_filename(default_pidfile, sizeof(default_pidfile), "oscam.pid"); } if(oscam_pidfile) { pidfile_create(oscam_pidfile); } cs_init_statistics(); coolapi_open_all(); init_stat(); ssl_init(); // These initializations *MUST* be called after init_config() // because modules depend on config values. for(i = 0; mod_def[i]; i++) { struct s_module *module = &modules[i]; mod_def[i](module); } init_sidtab(); init_readerdb(); cfg.account = init_userdb(); init_signal(); init_provid(); init_srvid(); init_tierid(); init_fakecws(); start_garbage_collector(gbdb); cacheex_init(); init_len4caid(); init_irdeto_guess_tab(); write_versionfile(false); led_init(); led_status_default(); azbox_init(); mca_init(); global_whitelist_read(); ratelimit_read(); for(i = 0; i < CS_MAX_MOD; i++) { struct s_module *module = &modules[i]; if((module->type & MOD_CONN_NET)) { for(j = 0; j < module->ptab.nports; j++) { start_listener(module, &module->ptab.ports[j]); } } } //set time for server to now to avoid 0 in monitor/webif first_client->last = time((time_t *)0); webif_init(); start_thread("reader check", (void *) &reader_check, NULL, NULL, 1, 1); cw_process_thread_start(); checkcache_process_thread_start(); lcd_thread_start(); do_report_emm_support(); init_cardreader(); cs_waitforcardinit(); emm_load_cache(); load_emmstat_from_file(); led_status_starting(); ac_init(); start_thread("card poll", (void *) &card_poll, NULL, NULL, 1, 1); for(i = 0; i < CS_MAX_MOD; i++) { struct s_module *module = &modules[i]; if((module->type & MOD_CONN_SERIAL) && module->s_handler) { module->s_handler(NULL, NULL, i); } } // main loop function process_clients(); SAFE_COND_SIGNAL(&card_poll_sleep_cond); // Stop card_poll thread cw_process_thread_wakeup(); // Stop cw_process thread SAFE_COND_SIGNAL(&reader_check_sleep_cond); // Stop reader_check thread // Cleanup #ifdef MODULE_GBOX stop_sms_sender(); #endif webif_close(); azbox_close(); coolapi_close_all(); mca_close(); led_status_stopping(); led_stop(); lcd_thread_stop(); remove_versionfile(); stat_finish(); dvbapi_stop_all_descrambling(); dvbapi_save_channel_cache(); emm_save_cache(); save_emmstat_to_file(); cccam_done_share(); gbox_send_good_night(); kill_all_clients(); kill_all_readers(); for(i = 0; i < CS_MAX_MOD; i++) { struct s_module *module = &modules[i]; if((module->type & MOD_CONN_NET)) { for(j = 0; j < module->ptab.nports; j++) { struct s_port *port = &module->ptab.ports[j]; if(port->fd) { shutdown(port->fd, SHUT_RDWR); close(port->fd); port->fd = 0; } } } } if(oscam_pidfile) { unlink(oscam_pidfile); } // sleep a bit, so hopefully all threads are stopped when we continue cs_sleepms(200); free_cache(); cacheex_free_hitcache(); webif_tpls_free(); init_free_userdb(cfg.account); cfg.account = NULL; init_free_sidtab(); free_readerdb(); free_irdeto_guess_tab(); config_free(); ssl_done(); detect_valgrind(); if (!running_under_valgrind) cs_log("cardserver down"); else cs_log("running under valgrind, waiting 5 seconds before stopping cardserver"); log_free(); if (running_under_valgrind) sleep(5); // HACK: Wait a bit for things to settle stop_garbage_collector(); NULLFREE(first_client->account); NULLFREE(first_client); free(stb_boxtype); free(stb_boxname); // This prevents the compiler from removing config_mak from the final binary syslog_ident = config_mak; return exit_oscam; }