1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
/*
* Copyright (C) 2015 Red Hat, Inc.
*
* This file is part of LVM2.
*
* This copyrighted material is made available to anyone wishing to use,
* modify, copy, or redistribute it subject to the terms and conditions
* of the GNU Lesser General Public License v.2.1.
*/
#include "lib.h"
#include "toolcontext.h"
#include "metadata.h"
#include "lvmnotify.h"
#ifdef LVMNOTIFY_SUPPORT
#include <dbus/dbus.h>
#define NOTIFY_DBUS_PATH "com.lvm"
#define NOTIFY_DBUS_IFACE "com/lvm"
static DBusConnection *_dbus_con = NULL;
void lvmnotify_init(struct cmd_context *cmd)
{
if (!(_dbus_con = dbus_bus_get_private(DBUS_BUS_SYSTEM, NULL)))
log_debug("Failed to connect to dbus");
}
void lvmnotify_exit(void)
{
if (_dbus_con) {
dbus_connection_close(_dbus_con);
dbus_connection_unref(_dbus_con);
}
_dbus_con = NULL;
}
void notify_vg_update(struct volume_group *vg)
{
DBusMessage *msg = NULL;
if (_dbus_con && !dbus_connection_read_write(_dbus_con, 1)) {
log_debug("Disconnected from dbus");
notify_exit();
}
if (!_dbus_con)
return;
if (!(msg = dbus_message_new_signal(NOTIFY_DBUS_PATH,
NOTIFY_DBUS_IFACE,
"vg_update"))) {
log_error("Failed to create dbus signal");
goto out;
}
if (!dbus_message_append_args(msg,
DBUS_TYPE_STRING, &vg->name,
DBUS_TYPE_INT32, &vg->seqno,
DBUS_TYPE_INVALID)) {
log_error("Failed to append args to dbus signal");
goto out;
}
dbus_connection_send(_dbus_con, msg, NULL);
dbus_connection_flush(_dbus_con);
out:
if (msg)
dbus_message_unref(msg);
}
#else
void lvmnotify_init(struct cmd_context *cmd)
{
}
void lvmnotify_exit(void)
{
}
void notify_vg_update(struct volume_group *vg)
{
}
#endif
|