Show More
@@ -759,10 +759,6 b' bail:' | |||||
759 | #if defined(HAVE_SETPROCTITLE) |
|
759 | #if defined(HAVE_SETPROCTITLE) | |
760 | /* setproctitle is the first choice - available in FreeBSD */ |
|
760 | /* setproctitle is the first choice - available in FreeBSD */ | |
761 | #define SETPROCNAME_USE_SETPROCTITLE |
|
761 | #define SETPROCNAME_USE_SETPROCTITLE | |
762 | #elif (defined(__linux__) || defined(__APPLE__)) && PY_MAJOR_VERSION == 2 |
|
|||
763 | /* rewrite the argv buffer in place - works in Linux and OS X. Py_GetArgcArgv |
|
|||
764 | * in Python 3 returns the copied wchar_t **argv, thus unsupported. */ |
|
|||
765 | #define SETPROCNAME_USE_ARGVREWRITE |
|
|||
766 | #else |
|
762 | #else | |
767 | #define SETPROCNAME_USE_NONE |
|
763 | #define SETPROCNAME_USE_NONE | |
768 | #endif |
|
764 | #endif | |
@@ -777,44 +773,6 b' static PyObject *setprocname(PyObject *s' | |||||
777 |
|
773 | |||
778 | #if defined(SETPROCNAME_USE_SETPROCTITLE) |
|
774 | #if defined(SETPROCNAME_USE_SETPROCTITLE) | |
779 | setproctitle("%s", name); |
|
775 | setproctitle("%s", name); | |
780 | #elif defined(SETPROCNAME_USE_ARGVREWRITE) |
|
|||
781 | { |
|
|||
782 | static char *argvstart = NULL; |
|
|||
783 | static size_t argvsize = 0; |
|
|||
784 | if (argvstart == NULL) { |
|
|||
785 | int argc = 0, i; |
|
|||
786 | char **argv = NULL; |
|
|||
787 | char *argvend; |
|
|||
788 | extern void Py_GetArgcArgv(int *argc, char ***argv); |
|
|||
789 | Py_GetArgcArgv(&argc, &argv); |
|
|||
790 | /* Py_GetArgcArgv may not do much if a custom python |
|
|||
791 | * launcher is used that doesn't record the information |
|
|||
792 | * it needs. Let's handle this gracefully instead of |
|
|||
793 | * segfaulting. */ |
|
|||
794 | if (argv != NULL) |
|
|||
795 | argvend = argvstart = argv[0]; |
|
|||
796 | else |
|
|||
797 | argvend = argvstart = NULL; |
|
|||
798 |
|
||||
799 | /* Check the memory we can use. Typically, argv[i] and |
|
|||
800 | * argv[i + 1] are continuous. */ |
|
|||
801 | for (i = 0; i < argc; ++i) { |
|
|||
802 | size_t len; |
|
|||
803 | if (argv[i] > argvend || argv[i] < argvstart) |
|
|||
804 | break; /* not continuous */ |
|
|||
805 | len = strlen(argv[i]); |
|
|||
806 | argvend = argv[i] + len + 1 /* '\0' */; |
|
|||
807 | } |
|
|||
808 | if (argvend > argvstart) /* sanity check */ |
|
|||
809 | argvsize = argvend - argvstart; |
|
|||
810 | } |
|
|||
811 |
|
||||
812 | if (argvstart && argvsize > 1) { |
|
|||
813 | int n = snprintf(argvstart, argvsize, "%s", name); |
|
|||
814 | if (n >= 0 && (size_t)n < argvsize) |
|
|||
815 | memset(argvstart + n, 0, argvsize - n); |
|
|||
816 | } |
|
|||
817 | } |
|
|||
818 | #endif |
|
776 | #endif | |
819 |
|
777 | |||
820 | Py_RETURN_NONE; |
|
778 | Py_RETURN_NONE; |
General Comments 0
You need to be logged in to leave comments.
Login now