ci: Drop CentOS 8 Stream and switch F38 to 40, Ubuntu 20.04 to 22.04
[libvirt-python.git] / libvirt-lxc-override.c
blob3dd0a8950c6ad18cc0e4cee0ec35ff2bec5e8394
1 /*
2 * libvir.c: this modules implements the main part of the glue of the
3 * libvir library and the Python interpreter. It provides the
4 * entry points where an automatically generated stub is
5 * unpractical
7 * Copyright (C) 2012-2019 Red Hat, Inc.
9 * Daniel Veillard <veillard@redhat.com>
12 /* Horrible kludge to work around even more horrible name-space pollution
13 via Python.h. That file includes /usr/include/python3.x/pyconfig*.h,
14 which has over 180 autoconf-style HAVE_* definitions. Shame on them. */
15 #undef HAVE_PTHREAD_H
17 #include <Python.h>
18 #include <libvirt/libvirt-lxc.h>
19 #include <libvirt/virterror.h>
20 #include "typewrappers.h"
21 #include "libvirt-utils.h"
22 #include "libvirt-lxc.h"
24 #if 0
25 # define DEBUG_ERROR 1
26 #endif
28 #if DEBUG_ERROR
29 # define DEBUG(fmt, ...) \
30 printf(fmt, __VA_ARGS__)
31 #else
32 # define DEBUG(fmt, ...) \
33 while (0) {printf(fmt, __VA_ARGS__);}
34 #endif
36 /************************************************************************
37 * *
38 * Statistics *
39 * *
40 ************************************************************************/
42 static PyObject *
43 libvirt_lxc_virDomainLxcOpenNamespace(PyObject *self ATTRIBUTE_UNUSED,
44 PyObject *args)
46 PyObject *py_retval;
47 virDomainPtr domain;
48 PyObject *pyobj_domain;
49 unsigned int flags;
50 int c_retval;
51 int *fdlist = NULL;
52 ssize_t i;
54 if (!PyArg_ParseTuple(args, (char *)"OI:virDomainLxcOpenNamespace",
55 &pyobj_domain, &flags))
56 return NULL;
57 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
59 if (domain == NULL)
60 return VIR_PY_NONE;
61 LIBVIRT_BEGIN_ALLOW_THREADS;
62 c_retval = virDomainLxcOpenNamespace(domain, &fdlist, flags);
63 LIBVIRT_END_ALLOW_THREADS;
65 if (c_retval < 0)
66 return VIR_PY_NONE;
68 if ((py_retval = PyList_New(0)) == NULL)
69 goto error;
71 for (i = 0; i < c_retval; i++)
72 VIR_PY_LIST_APPEND_GOTO(py_retval, libvirt_intWrap(fdlist[i]), error);
74 cleanup:
75 VIR_FREE(fdlist);
76 return py_retval;
78 error:
79 for (i = 0; i < c_retval; i++) {
80 VIR_FORCE_CLOSE(fdlist[i]);
82 Py_CLEAR(py_retval);
83 goto cleanup;
85 /************************************************************************
86 * *
87 * The registration stuff *
88 * *
89 ************************************************************************/
90 static PyMethodDef libvirtLxcMethods[] = {
91 #include "libvirt-lxc-export.c.inc"
92 {(char *) "virDomainLxcOpenNamespace", libvirt_lxc_virDomainLxcOpenNamespace, METH_VARARGS, NULL},
93 {NULL, NULL, 0, NULL}
96 static struct PyModuleDef moduledef = {
97 PyModuleDef_HEAD_INIT,
98 #ifndef __CYGWIN__
99 "libvirtmod_lxc",
100 #else
101 "cygvirtmod_lxc",
102 #endif
103 NULL,
105 libvirtLxcMethods,
106 NULL,
107 NULL,
108 NULL,
109 NULL
112 PyMODINIT_FUNC
113 #ifndef __CYGWIN__
114 PyInit_libvirtmod_lxc
115 #else
116 PyInit_cygvirtmod_lxc
117 #endif
118 (void)
120 PyObject *module;
122 if (virInitialize() < 0)
123 return NULL;
125 module = PyModule_Create(&moduledef);
127 return module;