2 * virsh-completer-snapshot.c: virsh completer callbacks related to snapshots
4 * Copyright (C) 2019 Red Hat, Inc.
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library. If not, see
18 * <http://www.gnu.org/licenses/>.
23 #include "virsh-completer-snapshot.h"
24 #include "virsh-util.h"
28 virshSnapshotNameCompleter(vshControl
*ctl
,
32 virshControl
*priv
= ctl
->privData
;
33 g_autoptr(virshDomain
) dom
= NULL
;
34 virDomainSnapshotPtr
*snapshots
= NULL
;
39 g_auto(GStrv
) tmp
= NULL
;
41 virCheckFlags(0, NULL
);
43 if (!priv
->conn
|| virConnectIsAlive(priv
->conn
) <= 0)
46 if (!(dom
= virshCommandOptDomain(ctl
, cmd
, NULL
)))
49 if ((rc
= virDomainListAllSnapshots(dom
, &snapshots
, flags
)) < 0)
53 tmp
= g_new0(char *, nsnapshots
+ 1);
55 for (i
= 0; i
< nsnapshots
; i
++) {
56 const char *name
= virDomainSnapshotGetName(snapshots
[i
]);
58 tmp
[i
] = g_strdup(name
);
61 ret
= g_steal_pointer(&tmp
);
64 for (i
= 0; i
< nsnapshots
; i
++)
65 virshDomainSnapshotFree(snapshots
[i
]);