[mod_python] process privileges

Khormaee, Cy cy.khormaee at hp.com
Mon Sep 12 11:10:06 EDT 2005

I apologize for the lenghty turnaround time on this issue.  I did a some more testing including running the script under different users and modifying the unix privileges of the containg folders.  When I redirected the output of pdf latex to a file this was the error i recieved:

This is pdfTeX, Version 3.14159-14h-released-20010417 (Web2C
! I can't write on file `plotoutput112.log'.
Please type another transcript file name
! Emergency stop
No pages of output.

when running this code exerpt:

def makecsvpdf(results):
         """results dictionary should contain:
                 html - the html formatting to present the file to user
                 file - name of the output file
                 time - timestamp(beautified)
                 query - the query used to generate the output"""
         csvfile = open("/var/www/html/pcode/tmp/"+results['file'],'r')
         temp = "temp"
         while len(temp)!=0:
                 temp= csvfile.readline()
                 csvdata = csvdata+temp+"\\newline"
         tex = """\documentclass[12pt,letterpaper]{article}
\section{"Comma Separated Value Output:"}"""+results['time']+""" \\newline """+csvdata+""" \end{document}"""
         texfile = open("/var/www/html/pcode/tmp/"+results['file'][0:len(results['file'])-4]+'.tex','w')
         os.system('pdflatex --interaction nonstopmode '+"/var/www/html/pcode/tmp/"+results['file'][0:len(results['file'])-4]+'.tex > /tmp/testoutput.txt')
         return """<HTML>
<TITLE>Servo Home</TITLE>

The basic idea is that this file will take a text file of csv values, make a TeX file out of them, and then convert that TeX file into a pdf by directly entering the command "'pdflatex --interaction nonstopmode '+"/var/www/html/pcode/tmp/"+results['file'][0:len(results['file'])-4]+'.tex > /tmp/testoutput.txt'" into the commandline using the os module.  

Unfortunatly, I do not have sufficient access privalages on the system I am working on to complete the modifications so kindly suggested by Eric.  Subsequently, I am attempting to find a simpler approach or find a well defined access issue to be corrected.  Again, I am at a loss for a solution/explanation, any assistance/debugging advice would be much appreciated.


-----Original Message-----
From: mod_python-bounces at modpython.org
[mailto:mod_python-bounces at modpython.org]On Behalf Of Eric Walstad
Sent: Friday, August 26, 2005 11:38 AM
To: mod_python at modpython.org
Subject: Re: [mod_python] process privileges

On Friday 26 August 2005 11:08, Jon-Pierre Gentil wrote:
> On Friday 26 August 2005 11:31 am, Khormaee, Cy wrote:
> > I'm currently trying to run pdflatex on a machine with RedHat
> > Linux Corporate 3.0 by calling the os.system() command from mod
> > python.  I am able to complete this operation from the command
> > line python interpreter, but ill I get back when trying to run
> > the command from apache/mod python all I receive is '256' and no
> > changes are made to the file system.  All of the folders involved
> > are set for full access(unix privilege 777).  My current guess is
> > that this issue has something to do with apache's priority, but
> > haven't been able to confirm this suspicion yet.  If you can
> > provide any hints on how to debug this it would be much
> > appreciated.
> If you could show us some code it would help.  Having a different
> priority should not affect filesystem access, but running in apache
> is a lot different than running manually in the interpreter, since
> you would run as a completely different user and most likely not
> have a home directory.

I've had luck running a system process triggered with mod_python by:

 1.  setup the sudo file to allow the Apache process (user www-data on 
my debian box) to run a particular shell command.  Here a sample of 
my sudo file:

# User alias specification
User_Alias      APACHE = www-data
# Cmnd alias specification
Cmnd_Alias      MOD_PYTHON_BRANCH = /path/to/shell/script.sh
# User privilege specification

 2.  Call the register_cleanup method of the mod_python request object 
to basically detach the system process (the shell script) from the 
mod_python request.  You may not need to do it this way, but I did 
because my shell script took a long time to complete and I didn't 
want the web user waiting for it to complete.

    req.register_cleanup(buildIt, working_dir)

def buildIt(working_dir):
    """The 'callable object' needed by req.register_cleanup.
    All this does is call the shell script.
    r, shell_script_output = \
      commands.getstatusoutput(SHELL_SCRIPT_COMMAND % working_dir)

If you search the mod_python list archives for my email address and 
"register_cleanup" you will find more details.

I hope that helps.

Mod_python mailing list
Mod_python at modpython.org

More information about the Mod_python mailing list