Debian Codegraph @

libvirt-lxc-override.c

raw symbols SCIP
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
6 *
7 * Copyright (C) 2012-2019 Red Hat, Inc.
8 *
9 * Daniel Veillard <[email protected]>
10 */
11
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
16
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"
23
24 #if 0
25 # define DEBUG_ERROR 1
26 #endif
27
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
35
36 /************************************************************************
37 * *
38 * Statistics *
39 * *
40 ************************************************************************/
41
42 static PyObject *
43 libvirt_lxc_virDomainLxcOpenNamespace(PyObject *self ATTRIBUTE_UNUSED,
44 PyObject *args)
45 {
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;
53
54 if (!PyArg_ParseTuple(args, (char *)"OI:virDomainLxcOpenNamespace",
55 &pyobj_domain, &flags))
56 return NULL;
57 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
58
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;
64
65 if (c_retval < 0)
66 return VIR_PY_NONE;
67
68 if ((py_retval = PyList_New(0)) == NULL)
69 goto error;
70
71 for (i = 0; i < c_retval; i++)
72 VIR_PY_LIST_APPEND_GOTO(py_retval, libvirt_intWrap(fdlist[i]), error);
73
74 cleanup:
75 VIR_FREE(fdlist);
76 return py_retval;
77
78 error:
79 for (i = 0; i < c_retval; i++) {
80 VIR_FORCE_CLOSE(fdlist[i]);
81 }
82 Py_CLEAR(py_retval);
83 goto cleanup;
84 }
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}
94 };
95
96 static struct PyModuleDef moduledef = {
97 PyModuleDef_HEAD_INIT,
98 #ifndef __CYGWIN__
99 "libvirtmod_lxc",
100 #else
101 "cygvirtmod_lxc",
102 #endif
103 NULL,
104 -1,
105 libvirtLxcMethods,
106 NULL,
107 NULL,
108 NULL,
109 NULL
110 };
111
112 PyMODINIT_FUNC
113 #ifndef __CYGWIN__
114 PyInit_libvirtmod_lxc
115 #else
116 PyInit_cygvirtmod_lxc
117 #endif
118 (void)
119 {
120 PyObject *module;
121
122 if (virInitialize() < 0)
123 return NULL;
124
125 // PyModule_Create can return NULL if module creation fails
126 // https://docs.python.org/3/c-api/module.html#c.PyModule_Create
127 module = PyModule_Create(&moduledef);
128 if (module == NULL)
129 return NULL;
130
131 #ifdef Py_GIL_DISABLED
132 PyUnstable_Module_SetGIL(module, Py_MOD_GIL_NOT_USED);
133 #endif
134
135 return module;
136 }