1
0
mirror of git://sourceware.org/git/lvm2.git synced 2025-01-02 01:18:26 +03:00

cleanup: dmeventd improve _get_status

Use directly dm_asprintf() to allocate buffer with message,
and properly detect failing on replacement of snprintf()
which also returns -1 on error.
This commit is contained in:
Zdenek Kabelac 2014-04-18 14:26:36 +02:00
parent 0503af8466
commit dc21bbfabd

View File

@ -503,26 +503,20 @@ static int _get_status(struct message_data *message_data)
static int _get_parameters(struct message_data *message_data) { static int _get_parameters(struct message_data *message_data) {
struct dm_event_daemon_message *msg = message_data->msg; struct dm_event_daemon_message *msg = message_data->msg;
char buf[128]; int size;
int r = -1;
dm_free(msg->data); dm_free(msg->data);
if ((size = dm_asprintf(&msg->data, "%s pid=%d daemon=%s exec_method=%s",
message_data->id, getpid(),
_foreground ? "no" : "yes",
_systemd_activation ? "systemd" : "direct")) < 0) {
stack;
return -ENOMEM;
}
if (!(dm_snprintf(buf, sizeof(buf), "%s pid=%d daemon=%s exec_method=%s", msg->size = (uint32_t) size;
message_data->id,
getpid(),
_foreground ? "no" : "yes",
_systemd_activation ? "systemd" : "direct")))
goto_out;
msg->size = strlen(buf) + 1; return 0;
if (!(msg->data = dm_malloc(msg->size)))
goto_out;
if (!dm_strncpy(msg->data, buf, msg->size))
goto_out;
r = 0;
out:
return r;
} }
/* Cleanup at exit. */ /* Cleanup at exit. */