int BackupStoreAccountsControl::HousekeepAccountNow(int32_t ID) { std::string rootDir; int discSetNum; std::auto_ptr<UnixUser> user; // used to reset uid when we return if(!OpenAccount(ID, rootDir, discSetNum, user, NULL /* housekeeping locks the account itself */)) { BOX_ERROR("Failed to open account " << BOX_FORMAT_ACCOUNT(ID) << " for housekeeping."); return 1; } HousekeepStoreAccount housekeeping(ID, rootDir, discSetNum, NULL); bool success = housekeeping.DoHousekeeping(); if(!success) { BOX_ERROR("Failed to lock account " << BOX_FORMAT_ACCOUNT(ID) << " for housekeeping: perhaps a client is " "still connected?"); return 1; } else { BOX_TRACE("Finished housekeeping on account " << BOX_FORMAT_ACCOUNT(ID)); return 0; } }
void setOperationalMode(int newmode) { extern void buildMyStatsCSV(); if(newmode == (int)P_WAIT) { // stop(); --- should we see if we can WAIT while paused in an audio file? SysIntoWaitMode(); // when leaving wait mode, next instruction is executed, so we return here return; } else { // assume calling for sleep or halt if (newmode == (int)P_HALT) logString((char *)"Halting",BUFFER,LOG_NORMAL); else // newmode == (int)P_SLEEP logString((char *)"Sleeping",BUFFER,LOG_NORMAL); housekeeping(); shutdown(); if (newmode == (int)P_HALT) { SysIntoHaltMode(); } else { // newmode == (int)P_SLEEP _SystemOnOff(); } while(1); // cpu reset on exiting halt/sleep mode, so nothing below here executes } }
int64_t run_housekeeping(BackupStoreAccountDatabase::Entry& rAccount) { std::string rootDir = BackupStoreAccounts::GetAccountRoot(rAccount); int discSet = rAccount.GetDiscSet(); // Do housekeeping on this account HousekeepStoreAccount housekeeping(rAccount.GetID(), rootDir, discSet, NULL); housekeeping.DoHousekeeping(HousekeepStoreAccount::DefaultAction, true /* keep trying forever */); return housekeeping.GetErrorCount(); }
/* Try to find an item in the cache. Note that we currently don't make use of CACHE_MODE. */ const char * agent_get_cache (const char *key, cache_mode_t cache_mode, void **cache_id) { ITEM r; if (cache_mode == CACHE_MODE_IGNORE) return NULL; if (DBG_CACHE) log_debug ("agent_get_cache `%s'...\n", key); housekeeping (); /* first try to find one with no locks - this is an updated cache entry: We might have entries with a lockcount and without a lockcount. */ for (r=thecache; r; r = r->next) { if (!r->lockcount && r->pw && !strcmp (r->key, key)) { /* put_cache does only put strings into the cache, so we don't need the lengths */ r->accessed = gnupg_get_time (); if (DBG_CACHE) log_debug ("... hit\n"); r->lockcount++; *cache_id = r; return r->pw->data; } } /* again, but this time get even one with a lockcount set */ for (r=thecache; r; r = r->next) { if (r->pw && !strcmp (r->key, key)) { r->accessed = gnupg_get_time (); if (DBG_CACHE) log_debug ("... hit (locked)\n"); r->lockcount++; *cache_id = r; return r->pw->data; } } if (DBG_CACHE) log_debug ("... miss\n"); *cache_id = NULL; return NULL; }
int main(int argc, char* argv[]) { pcap_t* pcap_fd = NULL; char errbuff[PCAP_ERRBUF_SIZE]; char* device = "eth0"; memset(errbuff,0, PCAP_ERRBUF_SIZE); /* Open the device */ pcap_fd = pcap_open_live(device, MAXBYTES2CAPTURE, 0, 512, errbuff); if( pcap_fd == NULL ) { printf("Cannot open the pcap\n"); exit(0); } /* Apply filters to grab only tcp and udp IP packets */ struct bpf_program* filter_s = (struct bpf_program*)malloc(sizeof(struct bpf_program)); if( pcap_compile(pcap_fd, filter_s, "tcp or udp", 0, NULL ) == -1 ) { perror("PCAP compile"); return; } if( pcap_setfilter(pcap_fd, filter_s) == -1 ) { perror("PCAP set filter\n"); return; } /* Set up table and cache */ housekeeping(); /* Now capture the packets on this interface */ if( pcap_loop(pcap_fd, 0, handle_packet, NULL) == -1 ) { printf("Error with the pcap loop\n"); exit(0); } }
/* Try to find an item in the cache. Note that we currently don't make use of CACHE_MODE except for CACHE_MODE_NONCE and CACHE_MODE_USER. */ char * agent_get_cache (const char *key, cache_mode_t cache_mode) { gpg_error_t err; ITEM r; char *value = NULL; int res; int last_stored = 0; if (cache_mode == CACHE_MODE_IGNORE) return NULL; if (!key) { key = last_stored_cache_key; if (!key) return NULL; last_stored = 1; } if (DBG_CACHE) log_debug ("agent_get_cache '%s' (mode %d)%s ...\n", key, cache_mode, last_stored? " (stored cache key)":""); housekeeping (); for (r=thecache; r; r = r->next) { if (r->pw && ((cache_mode != CACHE_MODE_USER && cache_mode != CACHE_MODE_NONCE) || r->cache_mode == cache_mode) && !strcmp (r->key, key)) { /* Note: To avoid races KEY may not be accessed anymore below. */ r->accessed = gnupg_get_time (); if (DBG_CACHE) log_debug ("... hit\n"); if (r->pw->totallen < 32) err = gpg_error (GPG_ERR_INV_LENGTH); else if ((err = init_encryption ())) ; else if (!(value = xtrymalloc_secure (r->pw->totallen - 8))) err = gpg_error_from_syserror (); else { res = npth_mutex_lock (&encryption_lock); if (res) log_fatal ("failed to acquire cache encryption mutex: %s\n", strerror (res)); err = gcry_cipher_decrypt (encryption_handle, value, r->pw->totallen - 8, r->pw->data, r->pw->totallen); res = npth_mutex_unlock (&encryption_lock); if (res) log_fatal ("failed to release cache encryption mutex: %s\n", strerror (res)); } if (err) { xfree (value); value = NULL; log_error ("retrieving cache entry '%s' failed: %s\n", key, gpg_strerror (err)); } return value; } } if (DBG_CACHE) log_debug ("... miss\n"); return NULL; }
/* Store the string DATA in the cache under KEY and mark it with a maximum lifetime of TTL seconds. If there is already data under this key, it will be replaced. Using a DATA of NULL deletes the entry. A TTL of 0 is replaced by the default TTL and a TTL of -1 set infinite timeout. CACHE_MODE is stored with the cache entry and used to select different timeouts. */ int agent_put_cache (const char *key, cache_mode_t cache_mode, const char *data, int ttl) { gpg_error_t err = 0; ITEM r; if (DBG_CACHE) log_debug ("agent_put_cache '%s' (mode %d) requested ttl=%d\n", key, cache_mode, ttl); housekeeping (); if (!ttl) { switch(cache_mode) { case CACHE_MODE_SSH: ttl = opt.def_cache_ttl_ssh; break; default: ttl = opt.def_cache_ttl; break; } } if ((!ttl && data) || cache_mode == CACHE_MODE_IGNORE) return 0; for (r=thecache; r; r = r->next) { if (((cache_mode != CACHE_MODE_USER && cache_mode != CACHE_MODE_NONCE) || r->cache_mode == cache_mode) && !strcmp (r->key, key)) break; } if (r) /* Replace. */ { if (r->pw) { release_data (r->pw); r->pw = NULL; } if (data) { r->created = r->accessed = gnupg_get_time (); r->ttl = ttl; r->cache_mode = cache_mode; err = new_data (data, &r->pw); if (err) log_error ("error replacing cache item: %s\n", gpg_strerror (err)); } } else if (data) /* Insert. */ { r = xtrycalloc (1, sizeof *r + strlen (key)); if (!r) err = gpg_error_from_syserror (); else { strcpy (r->key, key); r->created = r->accessed = gnupg_get_time (); r->ttl = ttl; r->cache_mode = cache_mode; err = new_data (data, &r->pw); if (err) xfree (r); else { r->next = thecache; thecache = r; } } if (err) log_error ("error inserting cache item: %s\n", gpg_strerror (err)); } return err; }
/* Store DATA of length DATALEN in the cache under KEY and mark it with a maximum lifetime of TTL seconds. If there is already data under this key, it will be replaced. Using a DATA of NULL deletes the entry. A TTL of 0 is replaced by the default TTL and a TTL of -1 set infinite timeout. CACHE_MODE is stored with the cache entry and used to select different timeouts. */ int agent_put_cache (const char *key, cache_mode_t cache_mode, const char *data, int ttl) { ITEM r; if (DBG_CACHE) log_debug ("agent_put_cache `%s' requested ttl=%d mode=%d\n", key, ttl, cache_mode); housekeeping (); if (!ttl) { switch(cache_mode) { case CACHE_MODE_SSH: ttl = opt.def_cache_ttl_ssh; break; default: ttl = opt.def_cache_ttl; break; } } if (!ttl || cache_mode == CACHE_MODE_IGNORE) return 0; for (r=thecache; r; r = r->next) { if (!r->lockcount && !strcmp (r->key, key)) break; } if (r) { /* replace */ if (r->pw) { release_data (r->pw); r->pw = NULL; } if (data) { r->created = r->accessed = gnupg_get_time (); r->ttl = ttl; r->cache_mode = cache_mode; r->pw = new_data (data, strlen (data)+1); if (!r->pw) log_error ("out of core while allocating new cache item\n"); } } else if (data) { /* simply insert */ r = xtrycalloc (1, sizeof *r + strlen (key)); if (!r) log_error ("out of core while allocating new cache control\n"); else { strcpy (r->key, key); r->created = r->accessed = gnupg_get_time (); r->ttl = ttl; r->cache_mode = cache_mode; r->pw = new_data (data, strlen (data)+1); if (!r->pw) { log_error ("out of core while allocating new cache item\n"); xfree (r); } else { r->next = thecache; thecache = r; } } } return 0; }