Revision: 432
          http://vde.svn.sourceforge.net/vde/?rev=432&view=rev
Author:   shammash
Date:     2010-07-20 11:15:12 +0000 (Tue, 20 Jul 2010)

Log Message:
-----------
vde_switch: datasock ctl_socket cleanup

Put path resolution and ctl_socket assignment/tests in a single place.
This also fixes bug #3031623 , a regression introduced by revision 427 .

Signed-off-by: Luca Bigliardi <shamm...@artha.org>

Revision Links:
--------------
    http://vde.svn.sourceforge.net/vde/?rev=427&view=rev

Modified Paths:
--------------
    trunk/vde-2/src/vde_switch/datasock.c

Modified: trunk/vde-2/src/vde_switch/datasock.c
===================================================================
--- trunk/vde-2/src/vde_switch/datasock.c       2010-07-04 14:34:42 UTC (rev 
431)
+++ trunk/vde-2/src/vde_switch/datasock.c       2010-07-20 11:15:12 UTC (rev 
432)
@@ -43,8 +43,8 @@
 static unsigned int wd_type;
 static unsigned int data_type;
 
-static char real_ctl_socket[PATH_MAX];
-static char *ctl_socket = real_ctl_socket;
+static char *rel_ctl_socket = NULL;
+static char ctl_socket[PATH_MAX];
 
 static int mode = -1;
 static int dirmode = -1;
@@ -308,6 +308,10 @@
        int test_fd;
 
        if (fd < 0) {
+               if (!strlen(ctl_socket)) {
+                       /* ctl_socket has not been created yet */
+                       return;
+               }
                if((test_fd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0){
                        printlog(LOG_ERR,"socket %s",strerror(errno));
                }
@@ -363,17 +367,10 @@
        struct group *grp;
        switch (c) {
                case 's':
-                       if (((mkdir(optarg, 0777) < 0) && (errno != EEXIST))) {
-                               fprintf(stderr,"Cannot create ctl directory 
'%s': %s\n",
-                                       optarg, strerror(errno));
+                       if (!(rel_ctl_socket = strdup(optarg))) {
+                               fprintf(stderr, "Memory error while parsing 
'%s'\n", optarg);
                                exit(1);
                        }
-                       ctl_socket = vde_realpath(optarg, real_ctl_socket);
-                       if (!ctl_socket) {
-                               fprintf(stderr,"Cannot resolve ctl dir path 
'%s': %s\n",
-                                       optarg, strerror(errno));
-                               exit(1);
-                       }
                        break;
                case 'm':
                        sscanf(optarg,"%o",&mode);
@@ -439,8 +436,21 @@
                printlog(LOG_ERR,"Could not set O_NONBLOCK on connection fd %d: 
%s", connect_fd, strerror(errno));
                return;
        }
-       /* ctl_socket dir is created while parsing to provide an existing path
-        * to vde_realpath() */
+       /* resolve ctl_socket, eventually defaulting to standard paths */
+       if (rel_ctl_socket == NULL) {
+               rel_ctl_socket = (geteuid()==0)?VDESTDSOCK:VDETMPSOCK;
+       }
+       if (((mkdir(rel_ctl_socket, 0777) < 0) && (errno != EEXIST))) {
+               fprintf(stderr,"Cannot create ctl directory '%s': %s\n",
+                       rel_ctl_socket, strerror(errno));
+               exit(-1);
+       }
+       if (!vde_realpath(rel_ctl_socket, ctl_socket)) {
+               fprintf(stderr,"Cannot resolve ctl dir path '%s': %s\n",
+                       rel_ctl_socket, strerror(errno));
+               exit(1);
+       }
+
        if(chown(ctl_socket,-1,grp_owner) < 0) {
                rmdir(ctl_socket);
                printlog(LOG_ERR, "Could not chown socket '%s': %s", 
sun.sun_path, strerror(errno));
@@ -498,7 +508,6 @@
 
 void start_datasock(void)
 {
-       ctl_socket = (geteuid()==0)?VDESTDSOCK:VDETMPSOCK;
        modfun.modname=swmi.swmname=MODULENAME;
        swmi.swmnopts=Nlong_options;
        swmi.swmopts=long_options;


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

------------------------------------------------------------------------------
This SF.net email is sponsored by Sprint
What will you do first with EVO, the first 4G phone?
Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first
_______________________________________________
vde-users mailing list
vde-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/vde-users

Reply via email to