[CalendarServer-changes] [15381] CalendarServer/trunk/support
source_changes at macosforge.org
source_changes at macosforge.org
Fri Dec 11 12:11:12 PST 2015
Revision: 15381
http://trac.calendarserver.org//changeset/15381
Author: sagen at apple.com
Date: 2015-12-11 12:11:12 -0800 (Fri, 11 Dec 2015)
Log Message:
-----------
Testing out embedding python into the wrapper to avoid an exec
Modified Paths:
--------------
CalendarServer/trunk/support/Apple.make
CalendarServer/trunk/support/python-wrapper.c
Modified: CalendarServer/trunk/support/Apple.make
===================================================================
--- CalendarServer/trunk/support/Apple.make 2015-12-11 20:10:32 UTC (rev 15380)
+++ CalendarServer/trunk/support/Apple.make 2015-12-11 20:11:12 UTC (rev 15381)
@@ -64,7 +64,7 @@
build-wrapper: $(BuildDirectory)/python-wrapper
$(BuildDirectory)/python-wrapper: $(Sources)/support/python-wrapper.c
- $(CC) -sectcreate __TEXT __info_plist $(Sources)/support/appgroup.plist $(Sources)/support/python-wrapper.c -o $(BuildDirectory)/python-wrapper
+ $(CC) -I /usr/include/python2.7 -l python2.7 -sectcreate __TEXT __info_plist $(Sources)/support/appgroup.plist $(Sources)/support/python-wrapper.c -o $(BuildDirectory)/python-wrapper
install:: install-python
install-python:: build
Modified: CalendarServer/trunk/support/python-wrapper.c
===================================================================
--- CalendarServer/trunk/support/python-wrapper.c 2015-12-11 20:10:32 UTC (rev 15380)
+++ CalendarServer/trunk/support/python-wrapper.c 2015-12-11 20:11:12 UTC (rev 15381)
@@ -9,6 +9,7 @@
#include <string.h>
#include <unistd.h>
#include <pwd.h>
+#include <Python.h>
const char * const allowedUsernames[] = {
"_calendar",
@@ -72,6 +73,30 @@
return 0;
}
+char *getCodeToExecute() {
+ char *buffer = NULL;
+ const char* filename = getenv("CS_EXECUTE_EMBEDDED");
+ if (filename != NULL) {
+ FILE *file;
+ if ((file = fopen(filename, "r"))) {
+ struct stat statbuf;
+ if (fstat(fileno(file), &statbuf) == 0) {
+ int size = statbuf.st_size;
+ buffer = malloc((size+1) * sizeof(char));
+ int num = fread(buffer, 1, size, file);
+ if (num != size) {
+ free(buffer);
+ buffer = NULL;
+ } else {
+ buffer[size] = 0;
+ }
+ }
+ fclose(file);
+ }
+ }
+ return buffer;
+}
+
int main(int argc, const char * argv[]) {
if (uidIsAllowed()) {
@@ -79,9 +104,19 @@
prependToPath("PATH", bin);
prependToPath("PYTHONPATH", site);
- // Launch real python
- argv[0] = python;
- return execvp(python, (char* const*)argv);
+ char *code = getCodeToExecute();
+ if (code != NULL) {
+ printf("Executing code:\n%s\n", code);
+ Py_SetProgramName((char *)argv[0]);
+ Py_Initialize();
+ PyRun_SimpleString(code);
+ Py_Finalize();
+ return 0;
+ } else {
+ // Launch real python
+ argv[0] = python;
+ return execvp(python, (char* const*)argv);
+ }
} else {
printf("You are not allowed to run this executable.\n");
return 1;
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20151211/3bec4a63/attachment.html>
More information about the calendarserver-changes
mailing list