void __attribute__ ((constructor)) sim_init(void) { void *handle; #ifdef DEBUG sim_user_info_t *debug_list; #endif determine_libc(); if (attaching_shared_memory() < 0) { error("Error attaching/building shared memory and mmaping it"); }; if (getting_simulation_users() < 0) { error("Error getting users information for simulation"); } #ifdef DEBUG debug_list = sim_users_list; while (debug_list) { info("User %s with uid %u", debug_list->sim_name, debug_list->sim_uid); debug_list = debug_list->next; } #endif if (real_gettimeofday == NULL) { debug("Looking for real gettimeofday function"); handle = dlopen(lib_loc, RTLD_LOCAL | RTLD_LAZY); if (handle == NULL) { error("Error in dlopen %s", dlerror()); return; } real_gettimeofday = dlsym( handle, "gettimeofday"); if (real_gettimeofday == NULL) { error("Error: no sleep function found"); return; } } if (real_time == NULL) { debug("Looking for real time function"); handle = dlopen(lib_loc, RTLD_LOCAL | RTLD_LAZY); if (handle == NULL) { error("Error in dlopen: %s", dlerror()); return; } real_time = dlsym( handle, "time"); if (real_time == NULL) { error("Error: no sleep function found\n"); return; } } debug("sim_init: done"); }
/* User- and uid-related functions */ uid_t sim_getuid(const char *name) { sim_user_info_t *aux; if (!sim_users_list) getting_simulation_users(); aux = sim_users_list; debug2("sim_getuid: starting search for username %s", name); while (aux) { if (strcmp(aux->sim_name, name) == 0) { debug2("sim_getuid: found uid %u for username %s", aux->sim_uid, aux->sim_name); debug2("sim_getuid--name: %s uid: %u", name, aux->sim_uid); return aux->sim_uid; } aux = aux->next; } debug2("sim_getuid--name: %s uid: <Can NOT find uid>", name); return -1; }
void __attribute__ ((constructor)) sim_init(void){ void *handle; #ifdef DEBUG sim_user_info_t *debug_list; #endif if(building_shared_memory() < 0){ printf("Error building shared memory and mmaping it\n"); }; if(getting_simulation_users() < 0){ printf("Error getting users information for simulation\n"); } #ifdef DEBUG debug_list = sim_users_list; while(debug_list){ printf("User %s with uid %u\n", debug_list->sim_name, debug_list->sim_uid); debug_list = debug_list->next; } #endif if(real_gettimeofday == NULL){ printf("Looking for real gettimeofday function\n"); handle = dlopen(LIBC_PATH, RTLD_LOCAL | RTLD_LAZY); if(handle == NULL){ printf("Error in dlopen %s\n", dlerror()); return; } real_gettimeofday = dlsym( handle, "gettimeofday"); if(real_gettimeofday == NULL){ printf("Erro: no sleep function found\n"); return; } } /* slurmctld and slurmd got all the wrappers but some other programs like sinfo or scontrol just time related wrappers */ if(slurmctl_pid[0] == getpid() || slurmd_pid[0] == getpid()) { printf("This slurm program is not the controller nor a slurmd (%d)(controller: %d)(daemon: %d)\n", getpid(), slurmctl_pid[0], slurmd_pid[0]); if(real_sleep == NULL){ printf("Looking for real sleep function\n"); handle = dlopen(LIBC_PATH, RTLD_LOCAL | RTLD_LAZY); if(handle == NULL){ printf("Error in dlopen\n"); return; } real_sleep = dlsym( handle, "sleep"); if(real_sleep == NULL){ printf("Erro: no sleep function found\n"); return; } } } if(real_time == NULL){ printf("Looking for real time function\n"); handle = dlopen(LIBC_PATH, RTLD_LOCAL | RTLD_LAZY); if(handle == NULL){ printf("Error in dlopen: %s\n", dlerror()); return; } real_time = dlsym( handle, "time"); if(real_time == NULL){ printf("Erro: no sleep function found\n"); return; } } if(slurmctl_pid[0] == getpid() || slurmd_pid[0] == getpid()) { if(real_pthread_create == NULL){ printf("Looking for real pthread_create function\n"); handle = dlopen(LIBPTHREAD_PATH, RTLD_LOCAL | RTLD_LAZY); if(handle == NULL){ printf("Error in dlopen: %s\n", dlerror()); return; } real_pthread_create = dlsym( handle, "pthread_create"); if(real_pthread_create == NULL){ printf("Erro: no pthread_create function found\n"); return; } } if(real_pthread_exit == NULL){ printf("Looking for real pthread_exit function\n"); handle = dlopen(LIBPTHREAD_PATH, RTLD_LOCAL | RTLD_LAZY); if(handle == NULL){ printf("Error in dlopen: %s\n", dlerror()); return; } real_pthread_exit = dlsym( handle, "pthread_exit"); if(real_pthread_exit == NULL){ printf("Erro: no pthread_exit function found\n"); return; } } if(real_pthread_join == NULL){ printf("Looking for real pthread_join function\n"); handle = dlopen(LIBPTHREAD_PATH, RTLD_LOCAL | RTLD_LAZY); if(handle == NULL){ printf("Error in dlopen: %s\n", dlerror()); return; } real_pthread_join = dlsym( handle, "pthread_join"); if(real_pthread_join == NULL){ printf("Erro: no pthread_join function found\n"); return; } } /* Telling sim_mgr we are ready for the kick off */ sem_wait(global_sem); thread_exit_array[0]++; sem_post(global_sem); /* And wait for starting */ sem_wait(thread_sem[main_thread_id]); } printf("sim_init: done\n"); }