void packCleanRes() { if(fd>0) { io_fclose(fd); fd = -1; } if(name!=NULL) { free(name); name = NULL; } packageInit(); }
//============================================================== // Main program //============================================================== int main(int argc, char** argv) { int arg; int idx = 0; bool verbose = false; bool daemonize = false; bool gssapi = false; char *host = NULL; char *username = NULL; char *service = NULL; int port = 5672; struct option opt[] = { {"help", 0, 0, 'h'}, {"daemon", 0, 0, 'd'}, {"broker", 1, 0, 'b'}, {"gssapi", 0, 0, 'g'}, {"username", 1, 0, 'u'}, {"service", 1, 0, 's'}, {"port", 1, 0, 'p'}, {0, 0, 0, 0} }; while ((arg = getopt_long(argc, argv, "hdb:gu:s:p:", opt, &idx)) != -1) { switch (arg) { case 'h': case '?': print_usage(); exit(0); break; case 'd': daemonize = true; break; case 'v': verbose = true; break; case 's': if (optarg) { service = strdup(optarg); } else { print_usage(); exit(1); } break; case 'u': if (optarg) { username = strdup(optarg); } else { print_usage(); exit(1); } break; case 'g': gssapi = true; break; case 'p': if (optarg) { port = atoi(optarg); } else { print_usage(); exit(1); } break; case 'b': if (optarg) { host = strdup(optarg); } else { print_usage(); exit(1); } break; default: fprintf(stderr, "unsupported option '-%c'. See --help.\n", arg); print_usage(); exit(0); break; } } if (daemonize == true) { if (daemon(0, 0) < 0) { fprintf(stderr, "Error daemonizing: %s\n", strerror(errno)); exit(1); } } openlog("libvirt-qpid", 0, LOG_DAEMON); // This prevents us from dying if libvirt disconnects. signal(SIGPIPE, SIG_IGN); // Create the management agent ManagementAgent::Singleton singleton; ManagementAgent* agent = singleton.getInstance(); // Register the schema with the agent _qmf::Package packageInit(agent); // Start the agent. It will attempt to make a connection to the // management broker. The third argument is the interval for sending // updates to stats/properties to the broker. The last is set to 'true' // to keep this all single threaded. Otherwise a second thread would be // used to implement methods. qpid::management::ConnectionSettings settings; settings.host = host ? host : "127.0.0.1"; settings.port = port; if (username != NULL) { settings.username = username; } if (service != NULL) { settings.service = service; } if (gssapi == true) { settings.mechanism = "GSSAPI"; } agent->setName("Red Hat", "libvirt-qpid"); agent->init(settings, 3, true); while(true) { try { NodeWrap node(agent, "Libvirt Node"); node.doLoop(); } catch (int err) { } sleep(10); } }