From 4ea69dabebed68879be577dfa404c6263c01a7ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tino=20V=C3=A1zquez?= Date: Thu, 28 Feb 2019 15:24:24 +0100 Subject: [PATCH] Ease mac/bsd compilation --- src/common/ActionManager.cc | 1 + src/mad/utils/SConstruct | 22 ----- src/mad/utils/tty_expect.c | 192 ------------------------------------ src/rm/RequestManager.cc | 11 +-- 4 files changed, 6 insertions(+), 220 deletions(-) delete mode 100644 src/mad/utils/SConstruct delete mode 100644 src/mad/utils/tty_expect.c diff --git a/src/common/ActionManager.cc b/src/common/ActionManager.cc index a1629cff22..888f23e7fe 100644 --- a/src/common/ActionManager.cc +++ b/src/common/ActionManager.cc @@ -16,6 +16,7 @@ #include "ActionManager.h" #include +#include /* ************************************************************************** */ /* ActionManager constructor & destructor */ diff --git a/src/mad/utils/SConstruct b/src/mad/utils/SConstruct deleted file mode 100644 index 367354fbc3..0000000000 --- a/src/mad/utils/SConstruct +++ /dev/null @@ -1,22 +0,0 @@ -# ---------------------------------------------------------------------------- # -# Copyright 2002-2019, OpenNebula Project, OpenNebula Systems # -# # -# Licensed under the Apache License, Version 2.0 (the "License"); you may # -# not use this file except in compliance with the License. You may obtain # -# a copy of the License at # -# # -# http://www.apache.org/licenses/LICENSE-2.0 # -# # -# Unless required by applicable law or agreed to in writing, software # -# distributed under the License is distributed on an "AS IS" BASIS, # -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # -# See the License for the specific language governing permissions and # -# limitations under the License. # -# ---------------------------------------------------------------------------- # - -Import('env') -import os - -env['LIBS'] = "util" - -env.Program('tty_expect.c') diff --git a/src/mad/utils/tty_expect.c b/src/mad/utils/tty_expect.c deleted file mode 100644 index b18d007408..0000000000 --- a/src/mad/utils/tty_expect.c +++ /dev/null @@ -1,192 +0,0 @@ -/* -------------------------------------------------------------------------- */ -/* Copyright 2002-2019, OpenNebula Project, OpenNebula Systems */ -/* */ -/* Licensed under the Apache License, Version 2.0 (the "License"); you may */ -/* not use this file except in compliance with the License. You may obtain */ -/* a copy of the License at */ -/* */ -/* http://www.apache.org/licenses/LICENSE-2.0 */ -/* */ -/* Unless required by applicable law or agreed to in writing, software */ -/* distributed under the License is distributed on an "AS IS" BASIS, */ -/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */ -/* See the License for the specific language governing permissions and */ -/* limitations under the License. */ -/* -------------------------------------------------------------------------- */ - -#ifdef __APPLE__ -#include -#else -#include -#endif - -#include -#include -#include - -#include - -#include -#include - -int expect_char(int pty, char * expected, int seconds) -{ - fd_set rfds; - struct timeval tv; - - int rc; - char c; - - do - { - if (seconds != 0) - { - FD_ZERO(&rfds); - FD_SET(pty, &rfds); - - tv.tv_sec = seconds; - tv.tv_usec = 0; - - rc = select(pty+1,&rfds,0,0, &tv); - - if ( rc <= 0 ) // timeout - { - return -1; - } - } - - rc = read(pty, (void *) &c, sizeof(char)); - - if ( rc > 0 ) - { - if(expected == 0) - { - write(1,&c,sizeof(char)); - } - - if (expected != 0 && c == *expected) - { - return 0; - } - } - } - while ( rc > 0 ); - - return -1; -} - -void write_answer(int pty, const char * answer) -{ - int len, i; - - len = strlen(answer); - - for (i=0; i <-u username> \n\n" -"SYNOPSIS\n" -" Wraps the execution of a command and sends username & password\n\n" -"OPTIONS\n" -"\t-h\tprints this help.\n" -"\t-p\tthe password\n" -"\t-u\tthe username\n" -"\t\tcomplete virsh command\n"; - -int main (int argc, char **argv) -{ - char * password = 0; - char * username = 0; - - char expect = ':'; - - int opt, pty, pid, rc; - int times = 1; - - while((opt = getopt(argc,argv,"+hrp:u:")) != -1) - switch(opt) - { - case 'h': - printf("%s",myexpect_usage); - exit(0); - break; - case 'p': - password = strdup(optarg); - break; - case 'u': - username = strdup(optarg); - break; - case 'r': - times = 2; - break; - default: - fprintf(stderr,"Wrong option. Check usage\n"); - fprintf(stderr,"%s",myexpect_usage); - exit(-1); - break; - } - - if (password == 0 || username == 0 || optind >= argc ) - { - fprintf(stderr,"Wrong number of arguments. Check usage\n"); - fprintf(stderr,"%s",myexpect_usage); - exit(-1); - } - - pid = forkpty(&pty,0,0,0); - - if(pid == 0) - { - struct termios tios; - - tcgetattr(pty, &tios); - - tios.c_lflag &= ~(ECHO | ECHOE | ECHOK | ECHONL); - tios.c_oflag &= ~(ONLCR); - - tcsetattr(pty, TCSANOW, &tios); - - execvp(argv[optind],&(argv[optind])); - - exit(-1); - } - else if (pid == -1) - { - perror("fork\n"); - } - - while ( times > 0 ) - { - if (expect_char(pty,&expect,1) == -1) - { - return -1; - } - - sleep(1); - - write_answer(pty,username); - - if (expect_char(pty,&expect,1) == -1) - { - return -1; - } - - sleep(1); - - write_answer(pty,password); - - times = times - 1; - } - - expect_char(pty,0,0); - - wait(&rc); - - return WEXITSTATUS(rc); -} diff --git a/src/rm/RequestManager.cc b/src/rm/RequestManager.cc index 49f8d3ab90..e079cfdb25 100644 --- a/src/rm/RequestManager.cc +++ b/src/rm/RequestManager.cc @@ -124,7 +124,7 @@ extern "C" void * rm_action_loop(void *arg) /** * Connection class is used to pass arguments to connection threads. */ -struct Connection +struct Connection { Connection(int c, ConnectionManager * cm):conn_fd(c), conn_manager(cm){}; @@ -154,7 +154,7 @@ extern "C" void * rm_do_connection(void *arg) }; /** - * Connection Manager Thread waits for client connections and starts a new + * Connection Manager Thread waits for client connections and starts a new * thread to handle the request. */ extern "C" void * rm_xml_server_loop(void *arg) @@ -196,12 +196,12 @@ extern "C" void * rm_xml_server_loop(void *arg) socklen_t addr_len = sizeof(struct sockaddr_storage); - int client_fd = accept(rm->socket_fd, (struct sockaddr*) &addr, + int client_fd = accept(rm->socket_fd, (struct sockaddr*) &addr, &addr_len); int nc = cm->add(); - oss << "Number of active connections: " << nc; + oss << "Number of active connections: " << nc; NebulaLog::log("ReM", Log::DDEBUG, oss); @@ -294,7 +294,7 @@ int RequestManager::setup_socket() fcntl(socket_fd,F_SETFD,FD_CLOEXEC); // Close socket in MADs - rc = bind(socket_fd, result->ai_addr, result->ai_addrlen); + rc = ::bind(socket_fd, result->ai_addr, result->ai_addrlen); freeaddrinfo(result); @@ -1209,4 +1209,3 @@ void RequestManager::register_xml_methods() /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ -