Hi, I apologise if this is an inappropriate post for this list; my query is concerned with the internals of Python, honest :) I am trying to compile a C module on Solaris, to return extended process information (args greater than 80 characters). However, the _FILE_OFFSET_BITS in pyconfig.h is causing me a bit of bother. It is preventing me, from correctly parsing /proc - according to the man pages, any handling of /proc entries must be done with 32bit structures, variables, etc. I've tried undefining it at compile time, without success. I've had to define _LP64, include <procfs.h>, then undefine _LP64. Doing this, allows me to use structured proc, instead of the deprecatd ioctl method. However, I don't think this is a working solution, as the code compiles, runs, but returns dubious results (I have a pure C version of the code, which works fine). I've included the code below. Is there a way, to tell Python to compile a module in 32bit mode? Or, is there a workaround for this Solaris oddity? Regards John #include "Python.h" #include <stdio.h> #define _LP64 #include <procfs.h> #undef _LP64 #include <fcntl.h> #include <sys/types.h> #include <sys/stat.h> static PyObject * psinfo_fullpidinfo(PyObject *self, PyObject *args) { PyObject *queryPid; char procBuf[50]; char argStr[512]; char **argvp; int fdPSInfoFile, fdASFile, counter; struct psinfo psBuf; if (!PyArg_ParseTuple(args, "i:pidinfo", &queryPid) ) { return NULL; } (void)sprintf(procBuf,"/proc/%i/psinfo", (int)queryPid); (void)sprintf(asBuf,"/proc/%i/as", (int)queryPid); if ((fdPSInfoFile = open(procBuf, O_RDONLY)) != -1 ) { if (read(fdPSInfoFile, &psBuf, sizeof(struct psinfo)) == sizeof(struct psinfo) ) { close(fdPSInfoFile); if ((fdASFile = open(asBuf, O_RDONLY)) == -1 ) { printf(" Open Of AS Failed"); } else { printf( "%d", psBuf.pr_argc); argvp=(char **) malloc(sizeof(char *) * (psBuf.pr_argc + 1)); if (lseek(fdASFile, psBuf.pr_argv, SEEK_SET) == -1) { printf ("Initial LSeek Failed" ); return NULL; } if (read(fdASFile, argvp, sizeof(char *) * (psBuf.pr_argc + 1)) == -1 ) { printf( "Read Failed" ); return NULL; } for ( counter=0; counter < psBuf.pr_argc; counter++ ) { if (lseek(fdASFile, argvp[ counter ], SEEK_SET) == -1) { printf( "2nd LSeek Failed"); return NULL; } if (read(fdASFile, argStr, 512) == -1) { printf( "Read Of AS File Failed"); return NULL; } printf( "Got %s.\n", argStr ); } close(fdASFile); } } } return Py_BuildValue( "s", argStr ); } static struct PyMethodDef PSInfoMethods[]={ { "fullpidinfo", psinfo_fullpidinfo, METH_VARARGS, "Display Full Arg Details For A Given PID" }, { NULL, NULL, 0, NULL } }; void initpsinfo(void) { (void)Py_InitModule("psinfo", PSInfoMethods); }
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4