mirror of
https://github.com/clearlinux/uwsgi.git
synced 2026-10-04 07:58:33 +00:00
added command mode
This commit is contained in:
@@ -34,6 +34,12 @@ void uwsgi_opt_pyshell(char *opt, char *value, void *foobar) {
|
||||
}
|
||||
}
|
||||
|
||||
void uwsgi_opt_pyrun(char *opt, char *value, void *foobar) {
|
||||
uwsgi.honour_stdin = 1;
|
||||
uwsgi.command_mode = 1;
|
||||
up.pyrun = value;
|
||||
}
|
||||
|
||||
#ifdef UWSGI_INI
|
||||
void uwsgi_opt_ini_paste(char *opt, char *value, void *foobar) {
|
||||
|
||||
@@ -110,11 +116,10 @@ struct uwsgi_option uwsgi_python_options[] = {
|
||||
#endif
|
||||
{"pyshell", no_argument, 0, "run an interactive python shell in the uWSGI environment", uwsgi_opt_pyshell, NULL, 0},
|
||||
{"pyshell-oneshot", no_argument, 0, "run an interactive python shell in the uWSGI environment (one-shot variant)", uwsgi_opt_pyshell, NULL, 0},
|
||||
/*
|
||||
FUTURE additions...
|
||||
{"python", required_argument, 0, ...},
|
||||
{"py", required_argument, 0, ...},
|
||||
*/
|
||||
|
||||
{"python", required_argument, 0, "run a python script in the uWSGI environment", uwsgi_opt_pyrun, NULL, 0},
|
||||
{"py", required_argument, 0, "run a python script in the uWSGI environment", uwsgi_opt_pyrun, NULL, 0},
|
||||
{"pyrun", required_argument, 0, "run a python script in the uWSGI environment", uwsgi_opt_pyrun, NULL, 0},
|
||||
|
||||
{0, 0, 0, 0, 0, 0, 0},
|
||||
};
|
||||
@@ -1423,8 +1428,22 @@ void uwsgi_python_fixup() {
|
||||
}
|
||||
|
||||
void uwsgi_python_hijack(void) {
|
||||
|
||||
// the pyshell will be execute only in the first worker
|
||||
|
||||
FILE *pyfile;
|
||||
if (up.pyrun) {
|
||||
uwsgi.workers[uwsgi.mywid].hijacked = 1;
|
||||
pyfile = fopen(up.pyrun, "r");
|
||||
if (!pyfile) {
|
||||
uwsgi_error_open(up.pyrun);
|
||||
exit(1);
|
||||
}
|
||||
PyRun_SimpleFile(pyfile, up.pyrun);
|
||||
// could be never executed
|
||||
exit(0);
|
||||
}
|
||||
|
||||
#ifndef UWSGI_PYPY
|
||||
if (up.pyshell_oneshot && uwsgi.workers[uwsgi.mywid].hijacked_count > 0) {
|
||||
uwsgi.workers[uwsgi.mywid].hijacked = 0;
|
||||
|
||||
@@ -97,7 +97,8 @@ void init_pyargv() {
|
||||
|
||||
up.py_argv[0] = pname;
|
||||
|
||||
if (up.argv != NULL) {
|
||||
|
||||
if (up.argv) {
|
||||
|
||||
up.argc = 1;
|
||||
#ifdef PYTHREE
|
||||
@@ -120,12 +121,11 @@ void init_pyargv() {
|
||||
#endif
|
||||
up.argc++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#ifndef UWSGI_PYPY
|
||||
PySys_SetArgv(up.argc, up.py_argv);
|
||||
#endif
|
||||
}
|
||||
|
||||
PySys_SetArgv(up.argc, up.py_argv);
|
||||
|
||||
PyObject *sys_dict = get_uwsgi_pydict("sys");
|
||||
if (!sys_dict) {
|
||||
|
||||
@@ -112,6 +112,7 @@ struct uwsgi_python {
|
||||
|
||||
int pyshell;
|
||||
int pyshell_oneshot;
|
||||
|
||||
|
||||
struct uwsgi_string_list *python_path;
|
||||
struct uwsgi_string_list *import_list;
|
||||
@@ -169,6 +170,8 @@ struct uwsgi_python {
|
||||
PyObject *after_req_hook;
|
||||
PyObject *after_req_hook_args;
|
||||
|
||||
char *pyrun;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user