You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

78 lines
2.2 KiB

  1. /*
  2. * virsh-completer-checkpoint.c: virsh completer callbacks related to checkpoints
  3. *
  4. * Copyright (C) 2019 Red Hat, Inc.
  5. *
  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.
  10. *
  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.
  15. *
  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/>.
  19. */
  20. #include <config.h>
  21. #include "virsh-completer-checkpoint.h"
  22. #include "viralloc.h"
  23. #include "virsh-util.h"
  24. #include "virsh.h"
  25. #include "virstring.h"
  26. char **
  27. virshCheckpointNameCompleter(vshControl *ctl,
  28. const vshCmd *cmd,
  29. unsigned int flags)
  30. {
  31. virshControlPtr priv = ctl->privData;
  32. virDomainPtr dom = NULL;
  33. virDomainCheckpointPtr *checkpoints = NULL;
  34. int ncheckpoints = 0;
  35. size_t i = 0;
  36. char **ret = NULL;
  37. virCheckFlags(0, NULL);
  38. if (!priv->conn || virConnectIsAlive(priv->conn) <= 0)
  39. return NULL;
  40. if (!(dom = virshCommandOptDomain(ctl, cmd, NULL)))
  41. return NULL;
  42. if ((ncheckpoints = virDomainListAllCheckpoints(dom, &checkpoints,
  43. flags)) < 0)
  44. goto error;
  45. if (VIR_ALLOC_N(ret, ncheckpoints + 1) < 0)
  46. goto error;
  47. for (i = 0; i < ncheckpoints; i++) {
  48. const char *name = virDomainCheckpointGetName(checkpoints[i]);
  49. ret[i] = g_strdup(name);
  50. virshDomainCheckpointFree(checkpoints[i]);
  51. }
  52. VIR_FREE(checkpoints);
  53. virshDomainFree(dom);
  54. return ret;
  55. error:
  56. for (; i < ncheckpoints; i++)
  57. virshDomainCheckpointFree(checkpoints[i]);
  58. VIR_FREE(checkpoints);
  59. for (i = 0; i < ncheckpoints; i++)
  60. VIR_FREE(ret[i]);
  61. VIR_FREE(ret);
  62. virshDomainFree(dom);
  63. return NULL;
  64. }