[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    kdenonbeta/icecream/icecream/daemon
From:       Stephan Kulow <coolo () kde ! org>
Date:       2004-08-21 16:15:20
Message-ID: 20040821161520.677F990C5 () office ! kde ! org
[Download RAW message or body]

CVS commit by coolo: 

don't bind to random port if there is already a iceccd running. There are just
too many conflicts


  M +17 -24    main.cpp   1.93


--- kdenonbeta/icecream/icecream/daemon/main.cpp  #1.92:1.93
@@ -79,4 +79,5 @@
 #include "findmyself.h"
 
+const int PORT = 10245;
 
 using namespace std;
@@ -199,7 +200,6 @@ void reannounce_environments(const strin
 }
 
-int setup_listen_fd(int &port)
+int setup_listen_fd()
 {
-    const int START_PORT = 10245;
     int listen_fd;
     if ((listen_fd = socket (PF_INET, SOCK_STREAM, 0)) < 0) {
@@ -215,18 +215,12 @@ int setup_listen_fd(int &port)
 
     struct sockaddr_in myaddr;
-    port = START_PORT;
-    for ( ; port < START_PORT + 10; port++) {
         myaddr.sin_family = AF_INET;
-        myaddr.sin_port = htons (port);
+    myaddr.sin_port = htons (PORT);
         myaddr.sin_addr.s_addr = INADDR_ANY;
         if (bind (listen_fd, (struct sockaddr *) &myaddr,
                   sizeof (myaddr)) < 0) {
-            if (errno == EADDRINUSE && port < START_PORT + 9)
-                continue;
             perror ("bind()");
             return -1;
         }
-        break;
-    }
 
     if (listen (listen_fd, 20) < 0)
@@ -349,4 +343,9 @@ int main( int argc, char ** argv )
     }
 
+    if ( !logfile.length() && detach)
+        logfile = "/var/log/iceccd";
+
+    setup_debug( debug_level, logfile );
+
     if ((geteuid()!=0) && !runasuser)
     {
@@ -355,9 +354,4 @@ int main( int argc, char ** argv )
     }
  
-    if ( !logfile.length() && detach)
-        logfile = "/var/log/iceccd";
-
-    setup_debug( debug_level, logfile );
-
     log_info() << "will use nice level " << nice_level << endl;
 
@@ -478,11 +472,10 @@ int main( int argc, char ** argv )
         }
 
-        int port;
-        listen_fd = setup_listen_fd(port);
+        listen_fd = setup_listen_fd();
         if ( listen_fd == -1 ) // error
             return 1;
 
         trace() << "login as " << uname_buf.machine << endl;
-        LoginMsg lmsg( port, nodename, uname_buf.machine );
+        LoginMsg lmsg( PORT, nodename, uname_buf.machine );
         lmsg.envs = available_environmnents(envbasedir);
         lmsg.max_kids = max_kids;


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic