allow python modules to set progname.

This commit is contained in:
Joris Vink 2019-09-04 20:37:33 +02:00
parent 88bd3ce045
commit f2472ba485
3 changed files with 20 additions and 0 deletions

View File

@ -43,6 +43,7 @@ static PyObject *python_kore_queue(PyObject *, PyObject *);
static PyObject *python_kore_worker(PyObject *, PyObject *);
static PyObject *python_kore_tracer(PyObject *, PyObject *);
static PyObject *python_kore_fatalx(PyObject *, PyObject *);
static PyObject *python_kore_setname(PyObject *, PyObject *);
static PyObject *python_kore_suspend(PyObject *, PyObject *);
static PyObject *python_kore_shutdown(PyObject *, PyObject *);
static PyObject *python_kore_bind_unix(PyObject *, PyObject *);
@ -82,6 +83,7 @@ static struct PyMethodDef pykore_methods[] = {
METHOD("gather", python_kore_gather, METH_VARARGS | METH_KEYWORDS),
METHOD("fatal", python_kore_fatal, METH_VARARGS),
METHOD("fatalx", python_kore_fatalx, METH_VARARGS),
METHOD("setname", python_kore_setname, METH_VARARGS),
METHOD("suspend", python_kore_suspend, METH_VARARGS),
METHOD("shutdown", python_kore_shutdown, METH_NOARGS),
METHOD("bind_unix", python_kore_bind_unix, METH_VARARGS),

View File

@ -335,9 +335,12 @@ static const char *python_config_data =
"}\n";
static const char *python_init_data =
"import kore\n"
"from .app import koreapp\n"
"\n"
"def kore_parent_configure(args):\n"
" if hasattr(koreapp, \"_appname\"):\n"
" kore.setname(koreapp._appname)\n"
" koreapp.configure(args)\n"
"\n"
"def kore_worker_configure():\n"

View File

@ -1410,6 +1410,21 @@ python_kore_fatalx(PyObject *self, PyObject *args)
Py_RETURN_TRUE;
}
static PyObject *
python_kore_setname(PyObject *self, PyObject *args)
{
const char *name;
extern char *kore_progname;
if (!PyArg_ParseTuple(args, "s", &name))
return (NULL);
kore_free(kore_progname);
kore_progname = kore_strdup(name);
Py_RETURN_NONE;
}
static PyObject *
python_kore_suspend(PyObject *self, PyObject *args)
{