#include "globals.h" #include #include #include #include #include #include #include static char *_fqdn = NULL; static int _log_level = DEBUG; char *getFQDN(void) { struct utsname uts; if ((uname(&uts) > 0) && (uts.nodename != NULL)) { return strdup(uts.nodename); } char hostname[256]; hostname[255] = '\0'; if (gethostname(hostname, 255) == -1) { // FIXME: what to do, if we can't use gethostname? return NULL; } struct addrinfo hints; struct addrinfo *info = NULL, *p; memset(&hints, 0, sizeof hints); hints.ai_family = AF_UNSPEC; // either IPV4 or IPV6 hints.ai_socktype = SOCK_STREAM; hints.ai_flags = AI_CANONNAME; if (getaddrinfo(hostname, "http", &hints, &info) == 0) { for (p = info; p != NULL; p = p->ai_next) { if (p->ai_canonname && strstr(p->ai_canonname, "localhost") == NULL) { char *dn = strdup(p->ai_canonname); freeaddrinfo(info); return dn; } } } if (info != NULL) { freeaddrinfo(info); } return strdup(hostname); } const char *get_system_name() { if (_fqdn == NULL) { _fqdn = getFQDN(); } return _fqdn; } const char *get_system_creation_class_name() { return "Linux_ComputerSystem"; } void _debug(int level, const char *file, int line, const char *format, ...) { if (level > _log_level) { return; } FILE *trace_file = stderr; const char *lvl[] = { "NONE", "ERROR", "WARNING", "DEBUG" }; // TODO: use logger from sfcbd and pegasus fprintf(trace_file, "[%s] %s:%d\t", lvl[level], file, line); va_list args; va_start(args, format); vfprintf(stderr, format, args); va_end(args); fprintf(stderr, "\n"); }