"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "core/src/plugins/filed/python/python-fd.cc" between
bareos-Release-20.0.0.tar.gz and bareos-Release-20.0.1.tar.gz

About: Bareos is a network based backup solution offering many different backup strategies (a fork of "Bacula").

python-fd.cc  (bareos-Release-20.0.0):python-fd.cc  (bareos-Release-20.0.1)
/* /*
BAREOSĀ® - Backup Archiving REcovery Open Sourced BAREOSĀ® - Backup Archiving REcovery Open Sourced
Copyright (C) 2011-2015 Planets Communications B.V. Copyright (C) 2011-2015 Planets Communications B.V.
Copyright (C) 2013-2020 Bareos GmbH & Co. KG Copyright (C) 2013-2021 Bareos GmbH & Co. KG
This program is Free Software; you can redistribute it and/or This program is Free Software; you can redistribute it and/or
modify it under the terms of version three of the GNU Affero General Public modify it under the terms of version three of the GNU Affero General Public
License as published by the Free Software Foundation, which is License as published by the Free Software Foundation, which is
listed in the file LICENSE. listed in the file LICENSE.
This program is distributed in the hope that it will be useful, but This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Affero General Public License for more details. Affero General Public License for more details.
skipping to change at line 129 skipping to change at line 129
getPluginValue, setPluginValue, handlePluginEvent, startBackupFile, getPluginValue, setPluginValue, handlePluginEvent, startBackupFile,
endBackupFile, startRestoreFile, endRestoreFile, pluginIO, createFile, endBackupFile, startRestoreFile, endRestoreFile, pluginIO, createFile,
setFileAttributes, checkFile, getAcl, setAcl, getXattr, setXattr}; setFileAttributes, checkFile, getAcl, setAcl, getXattr, setXattr};
#include "plugin_private_context.h" #include "plugin_private_context.h"
/** /**
* We don't actually use this but we need it to tear down the * We don't actually use this but we need it to tear down the
* final python interpreter on unload of the plugin. Each instance of * final python interpreter on unload of the plugin. Each instance of
* the plugin get its own interpreter. * the plugin get its own interpreter.
*/ */
static PyThreadState* mainThreadState; static PyThreadState* mainThreadState{nullptr};
/* functions common to all plugins */ /* functions common to all plugins */
#include "plugins/include/python_plugins_common.inc" #include "plugins/include/python_plugins_common.inc"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
static void PyErrorHandler() static void PyErrorHandler()
{ {
skipping to change at line 172 skipping to change at line 172
Py_DECREF(tbList); Py_DECREF(tbList);
Py_DECREF(emptyString); Py_DECREF(emptyString);
Py_DECREF(strRetval); Py_DECREF(strRetval);
Py_DECREF(tracebackModule); Py_DECREF(tracebackModule);
} else { } else {
error_string = strdup("Unable to import traceback module."); error_string = strdup("Unable to import traceback module.");
} }
Py_DECREF(type); Py_DECREF(type);
Py_XDECREF(value); Py_XDECREF(value);
Py_XDECREF(traceback); Py_XDECREF(traceback);
// printf("%s", error_string);
free(error_string); free(error_string);
exit(1); exit(1);
} }
/** /**
* Plugin called here when it is first loaded * Plugin called here when it is first loaded
*/ */
bRC loadPlugin(PluginApiDefinition* lbareos_plugin_interface_version, bRC loadPlugin(PluginApiDefinition* lbareos_plugin_interface_version,
CoreFunctions* lbareos_core_functions, CoreFunctions* lbareos_core_functions,
PluginInformation** plugin_information, PluginInformation** plugin_information,
PluginFunctions** plugin_functions) PluginFunctions** plugin_functions)
{ {
if (!Py_IsInitialized()) { if (Py_IsInitialized()) { return bRC_Error; }
Py_InitializeEx(0);
// add bareos plugin path to python module search path Py_InitializeEx(0);
PyObject* sysPath = PySys_GetObject((char*)"path"); // add bareos plugin path to python module search path
PyObject* pluginPath = PyUnicode_FromString(PLUGIN_DIR); PyObject* sysPath = PySys_GetObject((char*)"path");
PyList_Append(sysPath, pluginPath); PyObject* pluginPath = PyUnicode_FromString(PLUGIN_DIR);
Py_DECREF(pluginPath); PyList_Append(sysPath, pluginPath);
Py_DECREF(pluginPath);
/* import the bareosfd module */
PyObject* bareosfdModule = PyImport_ImportModule("bareosfd"); /* import the bareosfd module */
if (!bareosfdModule) { PyObject* bareosfdModule = PyImport_ImportModule("bareosfd");
printf("loading of bareosfd failed\n"); if (!bareosfdModule) {
if (PyErr_Occurred()) { PyErrorHandler(); } printf("loading of bareosfd failed\n");
} if (PyErr_Occurred()) { PyErrorHandler(); }
}
/* import the CAPI from the bareosfd python module
* afterwards, Bareosfd_* macros are initialized to /* import the CAPI from the bareosfd python module
* point to the corresponding functions in the bareosfd python * afterwards, Bareosfd_* macros are initialized to
* module */ * point to the corresponding functions in the bareosfd python
import_bareosfd(); * module */
import_bareosfd();
/* set bareos_core_functions inside of barosfd module */
Bareosfd_set_bareos_core_functions(lbareos_core_functions); /* set bareos_core_functions inside of barosfd module */
Bareosfd_set_bareos_core_functions(lbareos_core_functions);
bareos_core_functions
= lbareos_core_functions; /* Set Bareos funct pointers */ bareos_core_functions
bareos_plugin_interface_version = lbareos_plugin_interface_version; = lbareos_core_functions; /* Set Bareos funct pointers */
bareos_plugin_interface_version = lbareos_plugin_interface_version;
*plugin_information = &pluginInfo; /* Return pointer to our info */ *plugin_information = &pluginInfo; /* Return pointer to our info */
*plugin_functions = &pluginFuncs; /* Return pointer to our functions */ *plugin_functions = &pluginFuncs; /* Return pointer to our functions */
#if PY_VERSION_HEX < VERSION_HEX(3, 7, 0) #if PY_VERSION_HEX < VERSION_HEX(3, 7, 0)
PyEval_InitThreads(); PyEval_InitThreads();
#endif #endif
mainThreadState = PyEval_SaveThread(); mainThreadState = PyEval_SaveThread();
}
return bRC_OK; return bRC_OK;
} }
/** /**
* Plugin called here when it is unloaded, normally when Bareos is going to * Plugin called here when it is unloaded, normally when Bareos is going to
* exit. * exit.
*/ */
bRC unloadPlugin() bRC unloadPlugin()
{ {
/* /* Terminate Python if it was initialized correctly */
* Terminate Python if (mainThreadState) {
*/ PyEval_RestoreThread(mainThreadState);
PyEval_RestoreThread(mainThreadState); Py_Finalize();
Py_Finalize(); mainThreadState = nullptr;
}
return bRC_OK; return bRC_OK;
} }
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
/** /**
* Called here to make a new instance of the plugin -- i.e. when * Called here to make a new instance of the plugin -- i.e. when
* a new Job is started. There can be multiple instances of * a new Job is started. There can be multiple instances of
skipping to change at line 263 skipping to change at line 261
static bRC newPlugin(PluginContext* plugin_ctx) static bRC newPlugin(PluginContext* plugin_ctx)
{ {
struct plugin_private_context* plugin_priv_ctx struct plugin_private_context* plugin_priv_ctx
= (struct plugin_private_context*)malloc( = (struct plugin_private_context*)malloc(
sizeof(struct plugin_private_context)); sizeof(struct plugin_private_context));
if (!plugin_priv_ctx) { return bRC_Error; } if (!plugin_priv_ctx) { return bRC_Error; }
memset(plugin_priv_ctx, 0, sizeof(struct plugin_private_context)); memset(plugin_priv_ctx, 0, sizeof(struct plugin_private_context));
plugin_ctx->plugin_private_context plugin_ctx->plugin_private_context
= (void*)plugin_priv_ctx; /* set our context pointer */ = (void*)plugin_priv_ctx; /* set our context pointer */
/* set bareos_plugin_context inside of barosfd module */ /* set bareos_plugin_context inside of bareosfd module */
Bareosfd_set_plugin_context(plugin_ctx); Bareosfd_set_plugin_context(plugin_ctx);
/* For each plugin instance we instantiate a new Python interpreter. */ /* For each plugin instance we instantiate a new Python interpreter. */
PyEval_AcquireThread(mainThreadState); PyEval_AcquireThread(mainThreadState);
plugin_priv_ctx->interpreter = Py_NewInterpreter(); plugin_priv_ctx->interpreter = Py_NewInterpreter();
PyEval_ReleaseThread(plugin_priv_ctx->interpreter); PyEval_ReleaseThread(plugin_priv_ctx->interpreter);
/* Always register some events the python plugin itself can register /* Always register some events the python plugin itself can register
any other events it is interested in. */ any other events it is interested in. */
bareos_core_functions->registerBareosEvents( bareos_core_functions->registerBareosEvents(
 End of changes. 10 change blocks. 
42 lines changed or deleted 40 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)