PYConfig.h/_FILE_OFFSET_BITS On Solaris

John Abel johnfabel at btinternet.com
Mon Jul 21 18:59:24 CEST 2003


Hi,

I have written a Python module in C, for the parsing of /proc.  I have 
written it using the Structured Proc API, as per Sun's 
documentation/recommendations.  However, in order to get it to compile, 
I have had to define _LP64, include <ProcFS.h>, and then undefine it, to 
get round the fact, pyconfig.h defines _FILE_OFFSET_BITS.  This seems to 
be forcing everything to support large file support, something that is 
not allowed for correct parsing of /proc.

Does anyone know of a way round this?  I've included the code below.  I 
have a pure C version of the script, which works fine.

Thanks

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);
}







More information about the Python-list mailing list