main() { FILE *in; int rtn,i; in = fopen ("/Users/laurenceschenk/mini-src/mySrc/Coldipozzo/type_1_sort","r"); if (in == NULL) { perror ("Unable to open type_1_sort\n"); exit (1); } rtn = shared_memory_attach(); clear_shm(); while (1) { rtn = fscanf(in,"%d\t%s\t%s\t%d",&etime,name,days,&action); if (rtn == EOF) break; printf ("Data read: name %s time %d days %s action %d\n",name,etime,days,action); //write_to_shm(); rtn = get_name_index(name); if (( rtn > -1) && (rtn < NUM_DEVICES)) { write_to_shm(rtn); } else { printf ("**********FAILURE to find %s\n",name); printf ("\n\n*****************program abort....\n"); shared_memory_detach(); exit(5); } } fclose(in); shared_memory_detach(); printf("shm_type_1:main written %d records\n",ptr); exit(0); }
static int free_index(int index) { proc_entry *entry; entry = (proc_entry *) get_proc_at_index(index); print(LOG_INFO, "Remove proc %s from index %d\n", entry->proc_name, index); clear_shm(entry->key_shm, entry->size_shm); entry->key_shm = 0; entry->size_shm = 0; mem_entry[index].shm = 0; destroy_lock(entry->key_rlock); entry->key_rlock = 0; mem_entry[index].rlock = 0; destroy_lock(entry->key_wlock); entry->key_wlock = 0; mem_entry[index].wlock = 0; destroy_lock(entry->key_active); entry->key_active = 0; mem_entry[index].active = 0; entry->active = 0; return 0; }
static int hostprotect_handler(request_rec *r) { char *client_ip; int is_ip = 0; int rbl_status = 0; if(hp.enabled == 1) { client_ip = ap_get_remote_host(r->connection, r->per_dir_config, REMOTE_NAME, &is_ip); if(is_ip) { /* purging */ if(!strcmp(client_ip, hp.purger) && !strcmp(r->method, "DELETE")) { char *ip_to_purge = apr_table_get(r->headers_in, "X-Purge-From-BL"); if(ip_to_purge == NULL) return DECLINED; int purge_status = purge_shm(ip_to_purge); if(purge_status == PURGE_OK) { int cache_to_clear = clear_shm(hp.expire); if(cache_to_clear != CLEAR_ERR) { if(hp.debug) ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "%s: PURGED %d ITEMS FROM CACHE, EXPIRE TIME %d", MODULE_NAME, cache_to_clear, hp.expire); } if(hp.debug) ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "%s: PURGED FROM CACHE %s", MODULE_NAME, ip_to_purge); } return DECLINED; } /* cache search */ int cache_hit = search_shm(client_ip); /* cache hit */ if(cache_hit > 1) { /* clear expired cache on random HIT request */ if(!(r->request_time % 256)) { int cache_to_clear = clear_shm(hp.expire); if(cache_to_clear != CLEAR_ERR) { if(hp.debug) ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "%s: PURGED %d ITEMS FROM CACHE, EXPIRE TIME %d", MODULE_NAME, cache_to_clear, hp.expire); } } if(hp.debug) ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "%s: CACHE HIT FOR %s (counter %d)", MODULE_NAME, client_ip, cache_hit); update_shm(client_ip); rbl_status = 1; goto err_redirect; } else { /* cache miss */ check_rbl(client_ip, hp.resolver, &rbl_status, r); if(hp.debug) ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "%s: Checking for blacklist %s | status %d", MODULE_NAME, client_ip, rbl_status); err_redirect: /* blacklisted */ if(rbl_status) { update_shm(client_ip); ap_set_content_type(r, "text/html"); ap_rprintf(r, "<html><head><title>Your IP is blacklisted in bl.hostprotect.net - redirecting..</title><META http-equiv='refresh' content='1;URL=http://www.hostprotect.net/'></head><body bgcolor='#ffffff'><center>Your IP is blacklisted in bl.hostprotect.net. You will be redirected automatically in 3 seconds.</center></body></html>"); return OK; } } } } return DECLINED; }