X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=lib%2Funixctl.c;h=c982214adc6a2d22be4b18b823f6858d9e4719ef;hb=e3f512b07c11de6b297050bb969fd0d8a07f9357;hp=20acc3c9cbb2ef7f0e3215b4a262eb4366f48ebb;hpb=c7c1bdf355d8885a61363f39a759baa96621f0f2;p=sliver-openvswitch.git diff --git a/lib/unixctl.c b/lib/unixctl.c index 20acc3c9c..c982214ad 100644 --- a/lib/unixctl.c +++ b/lib/unixctl.c @@ -211,28 +211,31 @@ unixctl_server_create(const char *path, struct unixctl_server **serverp) { struct unixctl_server *server; struct pstream *listener; - char *punix_path, *abs_path = NULL; + char *punix_path; int error; -#ifdef _WIN32 - FILE *file; -#endif *serverp = NULL; if (path && !strcmp(path, "none")) { return 0; } -#ifndef _WIN32 if (path) { + char *abs_path; +#ifndef _WIN32 abs_path = abs_file_name(ovs_rundir(), path); +#else + abs_path = strdup(path); +#endif punix_path = xasprintf("punix:%s", abs_path); + free(abs_path); } else { +#ifndef _WIN32 punix_path = xasprintf("punix:%s/%s.%ld.ctl", ovs_rundir(), program_name, (long int) getpid()); - } #else - punix_path = xstrdup("ptcp:0:127.0.0.1"); + punix_path = xasprintf("punix:%s/%s.ctl", ovs_rundir(), program_name); #endif + } error = pstream_open(punix_path, &listener, 0); if (error) { @@ -240,30 +243,6 @@ unixctl_server_create(const char *path, struct unixctl_server **serverp) goto exit; } -#ifdef _WIN32 - if (path) { - abs_path = xstrdup(path); - } else { - abs_path = xasprintf("%s/%s.ctl", ovs_rundir(), program_name); - } - - file = fopen(abs_path, "w"); - if (!file) { - error = errno; - ovs_error(error, "could not open %s", abs_path); - goto exit; - } - - fprintf(file, "%d\n", ntohs(listener->bound_port)); - if (fflush(file) == EOF) { - error = EIO; - ovs_error(error, "write failed for %s", abs_path); - fclose(file); - goto exit; - } - fclose(file); -#endif - unixctl_command_register("help", "", 0, 0, unixctl_help, NULL); unixctl_command_register("version", "", 0, 0, unixctl_version, NULL); @@ -273,9 +252,6 @@ unixctl_server_create(const char *path, struct unixctl_server **serverp) *serverp = server; exit: - if (abs_path) { - free(abs_path); - } free(punix_path); return error; } @@ -460,32 +436,13 @@ unixctl_client_create(const char *path, struct jsonrpc **client) char *abs_path, *unix_path; struct stream *stream; int error; -#ifdef _WIN32 - FILE *file; - int port; +#ifdef _WIN32 abs_path = strdup(path); - file = fopen(abs_path, "r"); - if (!file) { - int error = errno; - ovs_error(error, "could not open %s", abs_path); - free(abs_path); - return error; - } - - error = fscanf(file, "%d", &port); - if (error != 1) { - ovs_error(errno, "failed to read port from %s", abs_path); - free(abs_path); - return EINVAL; - } - fclose(file); - - unix_path = xasprintf("tcp:127.0.0.1:%d", port); #else abs_path = abs_file_name(ovs_rundir(), path); - unix_path = xasprintf("unix:%s", abs_path); #endif + unix_path = xasprintf("unix:%s", abs_path); *client = NULL;