static inline const char * Last_errormsg_get() { Last_errormsg_key_alloc(); char *errormsg = pthread_getspecific(Last_errormsg_key); if (errormsg == NULL) { errormsg = malloc(MAXPRINT); int ret = pthread_setspecific(Last_errormsg_key, errormsg); if (ret) FATAL("!pthread_setspecific"); } return errormsg; }
static inline struct errormsg * Last_errormsg_get(void) { Last_errormsg_key_alloc(); struct errormsg *errormsg = pthread_getspecific(Last_errormsg_key); if (errormsg == NULL) { errormsg = Malloc(sizeof(struct errormsg)); int ret = pthread_setspecific(Last_errormsg_key, errormsg); if (ret) FATAL("!pthread_setspecific"); } return errormsg; }
/* * out_init -- initialize the log * * This is called from the library initialization code. */ void out_init(const char *log_prefix, const char *log_level_var, const char *log_file_var, int major_version, int minor_version) { static int once; /* only need to initialize the out module once */ if (once) return; once++; Log_prefix = log_prefix; #ifdef DEBUG char *log_level; char *log_file; if ((log_level = getenv(log_level_var)) != NULL) { Log_level = atoi(log_level); if (Log_level < 0) { Log_level = 0; } } if ((log_file = getenv(log_file_var)) != NULL) { size_t cc = strlen(log_file); /* reserve more than enough space for a PID + '\0' */ char *log_file_pid = alloca(cc + 30); if (cc > 0 && log_file[cc - 1] == '-') { snprintf(log_file_pid, cc + 30, "%s%d", log_file, getpid()); log_file = log_file_pid; } if ((Out_fp = fopen(log_file, "w")) == NULL) { fprintf(stderr, "Error (%s): %s=%s: %s\n", log_prefix, log_file_var, log_file, strerror(errno)); abort(); } } #endif /* DEBUG */ char *log_alignment = getenv("NVML_LOG_ALIGN"); if (log_alignment) { int align = atoi(log_alignment); if (align > 0) Log_alignment = (unsigned)align; } if (Out_fp == NULL) Out_fp = stderr; else setlinebuf(Out_fp); #ifdef DEBUG LOG(1, "pid %d: program: %s", getpid(), getexecname()); #endif LOG(1, "%s version %d.%d", log_prefix, major_version, minor_version); LOG(1, "src version %s", nvml_src_version); #ifdef USE_VG_PMEMCHECK /* * Attribute "used" to prevent compiler from optimizing out the variable * when LOG expands to no code (!DEBUG) */ static __attribute__((used)) const char *pmemcheck_msg = "compiled with support for Valgrind pmemcheck"; LOG(1, "%s", pmemcheck_msg); #endif /* USE_VG_PMEMCHECK */ #ifdef USE_VG_HELGRIND static __attribute__((used)) const char *helgrind_msg = "compiled with support for Valgrind helgrind"; LOG(1, "%s", helgrind_msg); #endif /* USE_VG_HELGRIND */ #ifdef USE_VG_MEMCHECK static __attribute__((used)) const char *memcheck_msg = "compiled with support for Valgrind memcheck"; LOG(1, "%s", memcheck_msg); #endif /* USE_VG_MEMCHECK */ Last_errormsg_key_alloc(); }