Revision 44290311

View differences:

include/RequestManager.h
43 43
public:
44 44

  
45 45
    RequestManager(
46
            int _port,
46
            const string& _port,
47 47
            int _max_conn,
48 48
            int _max_conn_backlog,
49 49
            int _keepalive_timeout,
50 50
            int _keepalive_max_conn,
51 51
            int _timeout,
52
            const string _xml_log_file,
53
            const string call_log_format,
54
            const string _listen_address,
52
            const string& _xml_log_file,
53
            const string& call_log_format,
54
            const string& _listen_address,
55 55
            int message_size);
56 56

  
57 57
    ~RequestManager(){};
......
105 105
    /**
106 106
     *  Port number where the connection will be open
107 107
     */
108
    int port;
108
    string port;
109 109

  
110 110
    /*
111 111
     *  FD for the XML server socket
include/VirtualMachine.h
964 964
     */
965 965
    void clear_template_monitor_error();
966 966

  
967

  
968 967
    // ------------------------------------------------------------------------
969 968
    // Timers & Requirements
970 969
    // ------------------------------------------------------------------------
......
993 992
     *    @param disk
994 993
     *    @param pci_dev
995 994
     */
996
    void get_requirements (int& cpu, int& memory, int& disk,
995
    void get_requirements(int& cpu, int& memory, int& disk,
997 996
            vector<VectorAttribute *>& pci_dev);
998 997

  
999 998
    /**
......
1013 1012
     *
1014 1013
     *    @return 0 on success
1015 1014
     */
1016
     int check_resize (float cpu, int memory, int vcpu, string& error_str);
1015
     int check_resize(float cpu, int memory, int vcpu, string& error_str);
1017 1016

  
1018 1017
    /**
1019 1018
     *  Resize the VM capacity
......
1024 1023
     *
1025 1024
     *    @return 0 on success
1026 1025
     */
1027
     int resize (float cpu, int memory, int vcpu, string& error_str);
1026
     int resize(float cpu, int memory, int vcpu, string& error_str);
1028 1027

  
1029 1028
    // ------------------------------------------------------------------------
1030 1029
    // Virtual Machine Disks
......
1132 1131
     *    @param  password Password to encrypt the token, if it is set
1133 1132
     *    @return -1 in case of error, 0 if the VM has no context, 1 on success
1134 1133
     */
1135
    int  generate_context(string &files, int &disk_id, const string& password);
1134
    int generate_context(string &files, int &disk_id, const string& password);
1136 1135

  
1137 1136
    /**
1138 1137
     * Returns the CREATED_BY template attribute, or the uid if it does not exist
src/nebula/Nebula.cc
370 370
        //XML Library
371 371
        xmlCleanupParser();
372 372

  
373
        NebulaLog::log("ONE", Log::INFO, "Database bootstrap finalized, exiting.\n");
374

  
373
        NebulaLog::log("ONE", Log::INFO,
374
                "Database bootstrap finalized, exiting.\n");
375 375
        return;
376 376
    }
377 377

  
......
918 918
    // ---- Request Manager ----
919 919
    try
920 920
    {
921
        int  rm_port = 0;
921
        string rm_port;
922 922
        int  max_conn;
923 923
        int  max_conn_backlog;
924 924
        int  keepalive_timeout;
src/rm/RequestManager.cc
54 54

  
55 55
#include <sys/signal.h>
56 56
#include <sys/socket.h>
57
#include <netinet/in.h>
58
#include <netinet/tcp.h>
59
#include <arpa/inet.h>
57
#include <sys/types.h>
58
#include <netdb.h>
60 59
#include <unistd.h>
61 60
#include <fcntl.h>
62 61
#include <string.h>
......
64 63

  
65 64

  
66 65
RequestManager::RequestManager(
67
        int _port,
66
        const string& _port,
68 67
        int _max_conn,
69 68
        int _max_conn_backlog,
70 69
        int _keepalive_timeout,
71 70
        int _keepalive_max_conn,
72 71
        int _timeout,
73
        const string _xml_log_file,
74
        const string call_log_format,
75
        const string _listen_address,
72
        const string& _xml_log_file,
73
        const string& call_log_format,
74
        const string& _listen_address,
76 75
        int message_size):
77 76
            port(_port),
78 77
            socket_fd(-1),
......
167 166

  
168 167
int RequestManager::setup_socket()
169 168
{
170
    int                 rc;
171
    int                 yes = 1;
172
    struct sockaddr_in  rm_addr;
169
    int rc;
170
    int yes = 1;
173 171

  
174
    socket_fd = socket(AF_INET, SOCK_STREAM, 0);
172
    struct addrinfo hints = {0};
173
    struct addrinfo * result;
175 174

  
176
    if ( socket_fd == -1 )
175
    hints.ai_family   = AF_UNSPEC;
176
    hints.ai_socktype = SOCK_STREAM;
177
    hints.ai_flags    = AI_PASSIVE;
178

  
179
    rc = getaddrinfo(listen_address.c_str(), port.c_str(), &hints, &result);
180

  
181
    if ( rc != 0 )
177 182
    {
178 183
        ostringstream oss;
179 184

  
180
        oss << "Cannot open server socket: " << strerror(errno);
185
        oss << "Cannot open server socket: " << gai_strerror(rc);
181 186
        NebulaLog::log("ReM",Log::ERROR,oss);
182 187

  
183 188
        return -1;
184 189
    }
185 190

  
186
    rc = setsockopt(socket_fd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(int));
191
    socket_fd = socket(result->ai_family, result->ai_socktype, 0);
187 192

  
188
    if ( rc == -1 )
193
    if ( socket_fd == -1 )
189 194
    {
190 195
        ostringstream oss;
191 196

  
192
        oss << "Cannot set socket options: " << strerror(errno);
197
        oss << "Cannot open server socket: " << strerror(errno);
193 198
        NebulaLog::log("ReM",Log::ERROR,oss);
194 199

  
195
        close(socket_fd);
200
        freeaddrinfo(result);
196 201

  
197 202
        return -1;
198 203
    }
199 204

  
200
    fcntl(socket_fd,F_SETFD,FD_CLOEXEC); // Close socket in MADs
201

  
202
    rm_addr.sin_family      = AF_INET;
203
    rm_addr.sin_port        = htons(port);
204

  
205
    rc = inet_aton(listen_address.c_str(), &rm_addr.sin_addr);
205
    rc = setsockopt(socket_fd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(int));
206 206

  
207
    if ( rc == 0 )
207
    if ( rc == -1 )
208 208
    {
209 209
        ostringstream oss;
210 210

  
211
        oss << "Invalid listen address: " << listen_address;
211
        oss << "Cannot set socket options: " << strerror(errno);
212 212
        NebulaLog::log("ReM",Log::ERROR,oss);
213 213

  
214 214
        close(socket_fd);
215 215

  
216
        freeaddrinfo(result);
217

  
216 218
        return -1;
217 219
    }
218 220

  
219
    rc = bind(socket_fd,(struct sockaddr *) &(rm_addr),sizeof(struct sockaddr));
221
    fcntl(socket_fd,F_SETFD,FD_CLOEXEC); // Close socket in MADs
222

  
223
    rc = bind(socket_fd, result->ai_addr, result->ai_addrlen);
224

  
225
    freeaddrinfo(result);
220 226

  
221 227
    if ( rc == -1)
222 228
    {
223 229
        ostringstream oss;
224 230

  
225
        oss << "Cannot bind to " << listen_address << ":" << port << " : " << strerror(errno);
231
        oss << "Cannot bind to " << listen_address << ":" << port << " : "
232
            << strerror(errno);
233

  
226 234
        NebulaLog::log("ReM",Log::ERROR,oss);
227 235

  
228 236
        close(socket_fd);

Also available in: Unified diff