void free_select_statement(select_statement_t* i){ if(!i) return; free_id_list(i->fields); free(i->table); free_condition(i->conditions); free(i); }
static int mod_child(int rank) { int pid; struct ctrl_socket* cs; static int rpc_handler=0; /* do nothing from PROC_INIT, is the same as PROC_MAIN */ if (rank==PROC_INIT) return 0; /* we want to fork(), but only from one process */ if ((rank == PROC_MAIN ) && (ctrl_sock_lst)){ /* FIXME: no fork ?? */ DBG("ctl: mod_child(%d), ctrl_sock_lst=%p\n", rank, ctrl_sock_lst); /* fork, but make sure we know not to close our own sockets when * ctl child_init will be called for the new child */ rpc_handler=1; /* child should start with a correct estimated used fds number*/ register_fds(MAX_IO_READ_CONNECTIONS); pid=fork_process(PROC_RPC, "ctl handler", 1); DBG("ctl: mod_child(%d), fork_process=%d, csl=%p\n", rank, pid, ctrl_sock_lst); if (pid<0){ goto error; } if (pid == 0){ /* child */ is_main=0; DBG("ctl: %d io_listen_loop(%d, %p)\n", rank, fd_no, ctrl_sock_lst); io_listen_loop(fd_no, ctrl_sock_lst); }else{ /* parent */ /* not used in parent */ register_fds(-MAX_IO_READ_CONNECTIONS); rpc_handler=0; } } if (rank!=PROC_RPC || !rpc_handler){ /* close all the opened fds, we don't need them here */ for (cs=ctrl_sock_lst; cs; cs=cs->next){ close(cs->fd); cs->fd=-1; if (cs->write_fd!=-1){ close(cs->write_fd); cs->write_fd=-1; } } if (rank!=PROC_MAIN){ /* we need the lists in main for on_exit cleanup, see mod_destroy */ /* free memory, we don't need the lists anymore */ free_ctrl_socket_list(ctrl_sock_lst); ctrl_sock_lst=0; free_id_list(listen_lst); listen_lst=0; } } return 0; error: return -1; }
int generic_num_cores_per_package() { struct dirent **namelist; int ndir, m, n, pkg_id_tocount = -1; char tmppath[_HW_DETECT_MAX_OUTPUT]; char buf[20]; id_le *core_id_list = NULL; if (num_cores_per_package_sav != 0) return num_cores_per_package_sav; num_cores_per_package_sav=-1; strcpy(path, "/sys/devices/system/cpu/"); ndir = scandir(path, &namelist, 0, 0); if(ndir >= 0) { while(ndir--) { if(match_str(namelist[ndir]->d_name, "cpu", &m)) { strncpy(tmppath, path,sizeof(tmppath)); snprintf(buf, sizeof(buf), "cpu%i", m); strcat(tmppath, buf); strcat(tmppath, "/online"); read_file(tmppath, output, sizeof(output)); if (strncmp(output, "0", 1)!=0) { strcpy(tmppath, path); sprintf(buf, "cpu%i", m); strcat(tmppath, buf); strcat(tmppath, "/topology/physical_package_id"); read_file(tmppath, output, _HW_DETECT_MAX_OUTPUT); m = atoi(output); if(pkg_id_tocount == -1) pkg_id_tocount = m; strcpy(tmppath, path); strcat(tmppath, buf); strcat(tmppath, "/topology/core_id"); read_file(tmppath, output, _HW_DETECT_MAX_OUTPUT); n = atoi(output); if(m == pkg_id_tocount) /*FIXME: only counts cores from first package_id that is found, assumes that every package has the same amount of cores*/ { //if (num<n+1) num=n+1; //doesn't work if there is a gap in between the ids inc_id_count(n, &core_id_list); } } } free(namelist[ndir]); } free(namelist); num_cores_per_package_sav = id_total_count(core_id_list); free_id_list(&core_id_list); } else num_cores_per_package_sav = -1; if (num_cores_per_package_sav == 0) num_cores_per_package_sav = -1; return num_cores_per_package_sav; }
static void mod_destroy(void) { struct ctrl_socket* cs; /* close all the opened fds & unlink the files */ for (cs=ctrl_sock_lst; cs; cs=cs->next){ switch(cs->transport){ case UNIXS_SOCK: case UNIXD_SOCK: close(cs->fd); cs->fd=-1; if (cs->write_fd!=-1){ close(cs->write_fd); cs->write_fd=-1; } if (cs->name){ if (unlink(cs->name)<0){ LOG(L_ERR, "ERROR: ctl: could not delete unix" " socket %s: %s (%d)\n", cs->name, strerror(errno), errno); } } break; #ifdef USE_FIFO case FIFO_SOCK: destroy_fifo(cs->fd, cs->write_fd, cs->name); break; #endif default: close(cs->fd); cs->fd=-1; if (cs->write_fd!=-1){ close(cs->write_fd); cs->write_fd=-1; } } } if (listen_lst){ free_id_list(listen_lst); listen_lst=0; } if (ctrl_sock_lst){ free_ctrl_socket_list(ctrl_sock_lst); ctrl_sock_lst=0; } }
/** * the following four functions describe how the CPUs are distributed among packages * num_cpus() = num_packages() * num_threads_per_package() * num_threads_per_package() = num_cores_per_package() * num_threads_per_core() */ int generic_num_packages() { struct dirent **namelist; int ndir, m; char tmppath[_HW_DETECT_MAX_OUTPUT]; char buf[20]; id_le * pkg_id_list = NULL; if (num_packages_sav != 0) return num_packages_sav; num_packages_sav = -1; strcpy(path, "/sys/devices/system/cpu/"); ndir = scandir(path, &namelist, 0, 0); if(ndir >= 0) { while(ndir--) { if(match_str(namelist[ndir]->d_name, "cpu", &m)) { strncpy(tmppath, path, sizeof(tmppath)); snprintf(buf, sizeof(buf), "cpu%i", m); strcat(tmppath, buf); strcat(tmppath, "/online"); read_file(tmppath, output, sizeof(output)); if (strncmp(output,"0",1) != 0) { strncpy(tmppath, path, sizeof(tmppath)); snprintf(buf, sizeof(buf), "cpu%i", m); strcat(tmppath, buf); strcat(tmppath, "/topology/physical_package_id"); if(read_file(tmppath, output, sizeof(output))) inc_id_count(atoi(output), &pkg_id_list); } } free(namelist[ndir]); } free(namelist); num_packages_sav = id_total_count(pkg_id_list); free_id_list(&pkg_id_list); } return num_packages_sav; }
void free_create_table_statement(create_table_statement_t* i){ if(!i) return; free(i->table); free_id_list(i->columns); free(i); }