Adding tgl.safe_exit()
This commit is contained in:
parent
cbe442b7c6
commit
63f64a8e70
10
main.c
10
main.c
@ -127,6 +127,7 @@ int ipv6_enabled;
|
||||
char *start_command;
|
||||
int disable_link_preview;
|
||||
int enable_json;
|
||||
int exit_code;
|
||||
|
||||
struct tgl_state *TLS;
|
||||
|
||||
@ -834,6 +835,7 @@ void sig_term_handler (int signum __attribute__ ((unused))) {
|
||||
}
|
||||
|
||||
void do_halt (int error) {
|
||||
int retval;
|
||||
if (daemonize) {
|
||||
return;
|
||||
}
|
||||
@ -857,8 +859,12 @@ void do_halt (int error) {
|
||||
if (sfd > 0) {
|
||||
close (sfd);
|
||||
}
|
||||
|
||||
exit (error ? EXIT_FAILURE : EXIT_SUCCESS);
|
||||
|
||||
if(exit_code)
|
||||
retval = exit_code;
|
||||
else
|
||||
retval = error ? EXIT_FAILURE : EXIT_SUCCESS;
|
||||
exit (retval);
|
||||
}
|
||||
|
||||
int main (int argc, char **argv) {
|
||||
|
25
python-tg.c
25
python-tg.c
@ -1133,6 +1133,21 @@ PyObject* py_status_offline(PyObject *self, PyObject *args) { return push_py_fun
|
||||
PyObject* py_send_location(PyObject *self, PyObject *args) { return push_py_func(pq_send_location, args); }
|
||||
PyObject* py_extf(PyObject *self, PyObject *args) { return push_py_func(pq_extf, args); }
|
||||
|
||||
extern int safe_quit;
|
||||
extern int exit_code;
|
||||
PyObject* py_safe_quit(PyObject *self, PyObject *args)
|
||||
{
|
||||
int exit_val = 0;
|
||||
if(PyArg_ParseTuple(args, "|i", &exit_val)) {
|
||||
safe_quit = 1;
|
||||
exit_code = exit_val;
|
||||
} else {
|
||||
PyErr_Print();
|
||||
}
|
||||
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
|
||||
// Store callables for python functions
|
||||
TGL_PYTHON_CALLBACK("on_binlog_replay_end", _py_binlog_end);
|
||||
@ -1197,6 +1212,8 @@ static PyMethodDef py_tgl_methods[] = {
|
||||
{"set_on_user_update", set_py_user_update, METH_VARARGS, ""},
|
||||
{"set_on_chat_update", set_py_chat_update, METH_VARARGS, ""},
|
||||
{"set_on_loop", set_py_on_loop, METH_VARARGS, ""},
|
||||
{"safe_quit", py_safe_quit, METH_VARARGS, ""},
|
||||
{"safe_exit", py_safe_quit, METH_VARARGS, ""}, // Alias to safe_quit for naming consistancy in python.
|
||||
{ NULL, NULL, 0, NULL }
|
||||
};
|
||||
|
||||
@ -1236,14 +1253,6 @@ MOD_INIT(tgl)
|
||||
return MOD_SUCCESS_VAL(m);
|
||||
}
|
||||
|
||||
/*
|
||||
extern int safe_quit;
|
||||
static int safe_quit_from_py() {
|
||||
Py_Finalize();
|
||||
safe_quit = 1;
|
||||
return 1;
|
||||
}
|
||||
*/
|
||||
|
||||
void py_init (const char *file) {
|
||||
if (!file) { return; }
|
||||
|
Loading…
x
Reference in New Issue
Block a user