CVSROOT: /cvs/lvm2 Module name: LVM2 Changes by: mornfall@sourceware.org 2011-06-27 13:14:53 Modified files: daemons/common : daemon-client.c Log message: Do not open the socket with SOCK_NONBLOCK in daemon-client, since we have no use for that behaviour (at least for now). Patches: http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/daemons/common/daemon-client.c.diff?cvsroot=lvm2&r1=1.1&r2=1.2 --- LVM2/daemons/common/daemon-client.c 2011/06/14 02:34:18 1.1 +++ LVM2/daemons/common/daemon-client.c 2011/06/27 13:14:53 1.2 @@ -5,11 +5,12 @@ #include <string.h> #include <stdio.h> #include <assert.h> +#include <errno.h> // ENOMEM daemon_handle daemon_open(daemon_info i) { daemon_handle h; struct sockaddr_un sockaddr; - if ((h.socket_fd = socket(PF_UNIX, SOCK_STREAM | SOCK_NONBLOCK, 0)) < 0) { + if ((h.socket_fd = socket(PF_UNIX, SOCK_STREAM /* | SOCK_NONBLOCK */, 0)) < 0) { perror("socket"); goto error; } @@ -50,5 +51,22 @@ return reply; } -void daemon_close(daemon_handle h) { +daemon_reply daemon_send_simple(daemon_handle h, char *id, ...) +{ + va_list ap; + va_start(ap, id); + daemon_request rq = { .buffer = format_buffer(id, ap) }; + + if (!rq.buffer) { + daemon_reply err = { .error = ENOMEM, .buffer = NULL, .cft = NULL }; + return err; + } + + daemon_reply repl = daemon_send(h, rq); + dm_free(rq.buffer); + return repl; +} + +void daemon_close(daemon_handle h) +{ }
CVSROOT: /cvs/lvm2 Module name: LVM2 Changes by: zkabelac@sourceware.org 2012-01-25 21:31:59 Modified files: daemons/common : daemon-client.c Log message: Ensure reply struct has all fields defined Reply is returned by value. Patches: http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/daemons/common/daemon-client.c.diff?cvsroot=lvm2&r1=1.10&r2=1.11 --- LVM2/daemons/common/daemon-client.c 2012/01/15 15:16:50 1.10 +++ LVM2/daemons/common/daemon-client.c 2012/01/25 21:31:59 1.11 @@ -34,7 +34,7 @@ daemon_reply daemon_send(daemon_handle h, daemon_request rq) { - daemon_reply reply; + daemon_reply reply = { .cft = NULL }; assert(h.socket_fd >= 0); if (!rq.buffer) {
CVSROOT: /cvs/lvm2 Module name: LVM2 Changes by: mornfall@sourceware.org 2012-02-15 09:14:54 Modified files: daemons/common : daemon-client.c Log message: Do not forget to initialise the error value in daemon_reply. Patches: http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/daemons/common/daemon-client.c.diff?cvsroot=lvm2&r1=1.11&r2=1.12 --- LVM2/daemons/common/daemon-client.c 2012/01/25 21:31:59 1.11 +++ LVM2/daemons/common/daemon-client.c 2012/02/15 09:14:54 1.12 @@ -34,7 +34,7 @@ daemon_reply daemon_send(daemon_handle h, daemon_request rq) { - daemon_reply reply = { .cft = NULL }; + daemon_reply reply = { .cft = NULL, .error = 0 }; assert(h.socket_fd >= 0); if (!rq.buffer) {
CVSROOT: /cvs/lvm2 Module name: LVM2 Changes by: mornfall@sourceware.org 2012-02-24 00:02:54 Modified files: daemons/common : daemon-client.c Log message: Fix an error path in daemon_open. Patches: http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/daemons/common/daemon-client.c.diff?cvsroot=lvm2&r1=1.13&r2=1.14 --- LVM2/daemons/common/daemon-client.c 2012/02/23 23:52:11 1.13 +++ LVM2/daemons/common/daemon-client.c 2012/02/24 00:02:54 1.14 @@ -10,6 +10,7 @@ daemon_handle daemon_open(daemon_info i) { daemon_handle h = { .protocol_version = 0 }; + daemon_reply r = { .cft = NULL }; struct sockaddr_un sockaddr; if ((h.socket_fd = socket(PF_UNIX, SOCK_STREAM /* | SOCK_NONBLOCK */, 0)) < 0) { @@ -25,7 +26,7 @@ goto error; } - daemon_reply r = daemon_send_simple(h, "hello", NULL); + r = daemon_send_simple(h, "hello", NULL); if (r.error || strcmp(daemon_reply_str(r, "response", "unknown"), "OK")) goto error;
CVSROOT: /cvs/lvm2 Module name: LVM2 Changes by: zkabelac@sourceware.org 2012-02-27 11:49:16 Modified files: daemons/common : daemon-client.c Log message: Do not hide deallocation of buffer As API is passing structures by value, do not leave the function which created buffer and keeps valid pointer look like it would be some memory leak and move free of buffer from inner function - makes more obvious, how is the memory management handled. Patches: http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/daemons/common/daemon-client.c.diff?cvsroot=lvm2&r1=1.15&r2=1.16 --- LVM2/daemons/common/daemon-client.c 2012/02/26 08:46:28 1.15 +++ LVM2/daemons/common/daemon-client.c 2012/02/27 11:49:16 1.16 @@ -62,8 +62,6 @@ if (!write_buffer(h.socket_fd, rq.buffer, strlen(rq.buffer))) reply.error = errno; - dm_free(rq.buffer); - if (read_buffer(h.socket_fd, &reply.buffer)) { reply.cft = dm_config_from_string(reply.buffer); } else @@ -93,6 +91,8 @@ return err; repl = daemon_send(h, rq); + dm_free(rq.buffer); + return repl; }