Commit 63f64a8e authored by Vincent Castellano's avatar Vincent Castellano

Adding tgl.safe_exit()

parent cbe442b7
...@@ -127,6 +127,7 @@ int ipv6_enabled; ...@@ -127,6 +127,7 @@ int ipv6_enabled;
char *start_command; char *start_command;
int disable_link_preview; int disable_link_preview;
int enable_json; int enable_json;
int exit_code;
struct tgl_state *TLS; struct tgl_state *TLS;
...@@ -834,6 +835,7 @@ void sig_term_handler (int signum __attribute__ ((unused))) { ...@@ -834,6 +835,7 @@ void sig_term_handler (int signum __attribute__ ((unused))) {
} }
void do_halt (int error) { void do_halt (int error) {
int retval;
if (daemonize) { if (daemonize) {
return; return;
} }
...@@ -857,8 +859,12 @@ void do_halt (int error) { ...@@ -857,8 +859,12 @@ void do_halt (int error) {
if (sfd > 0) { if (sfd > 0) {
close (sfd); 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) { int main (int argc, char **argv) {
......
...@@ -1133,6 +1133,21 @@ PyObject* py_status_offline(PyObject *self, PyObject *args) { return push_py_fun ...@@ -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_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); } 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 // Store callables for python functions
TGL_PYTHON_CALLBACK("on_binlog_replay_end", _py_binlog_end); TGL_PYTHON_CALLBACK("on_binlog_replay_end", _py_binlog_end);
...@@ -1197,6 +1212,8 @@ static PyMethodDef py_tgl_methods[] = { ...@@ -1197,6 +1212,8 @@ static PyMethodDef py_tgl_methods[] = {
{"set_on_user_update", set_py_user_update, METH_VARARGS, ""}, {"set_on_user_update", set_py_user_update, METH_VARARGS, ""},
{"set_on_chat_update", set_py_chat_update, METH_VARARGS, ""}, {"set_on_chat_update", set_py_chat_update, METH_VARARGS, ""},
{"set_on_loop", set_py_on_loop, 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 } { NULL, NULL, 0, NULL }
}; };
...@@ -1236,14 +1253,6 @@ MOD_INIT(tgl) ...@@ -1236,14 +1253,6 @@ MOD_INIT(tgl)
return MOD_SUCCESS_VAL(m); 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) { void py_init (const char *file) {
if (!file) { return; } if (!file) { return; }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment