tcl : [exec bash-function] returning 0 leads to 'port install' crashing
Ryan Schmidt
ryandesign at macports.org
Tue Jun 21 13:28:35 PDT 2011
I don't know the answer to your direct questions, but I want to point out that we don't use exec unless there is no Tcl alternative. And Tcl does have existing methods for reading files and looking into strings. Take a look for example at the post-install section of the php5extension portgroup, which looks in the php.ini settings file and prints a message if a particular bad setting exists there.
MacPorts also typically does not modify user config files. Instead, we explain to the user how they can modify them.
I also wasn't sure what you meant by the portfile "crashing". If you could be more specific...?
On Jun 21, 2011, at 13:58, Bjarne D Mathiesen wrote:
> I'm modifying a Portfile, and am trying to see if a setting exists in a
> *.conf-file. These :
>
> set found [exec -ignorestderr -- grep -c "${string}" ${file} 2>@1 ]
> set found [exec -ignorestderr -- grep "${string}" ${file} 2>@1 ]
> set found [string length ### manual break for readability in email
> [exec -ignorestderr -- grep "${string}" ${file} 2>@1 ]]
>
> all ought to give me some kind of measure as to whether the string is in
> the *.conf-file
>
> It works _perfectly_ if [exec ...] returns > 1 ,
> but if [exec grep ...] == 0 the Portfile crashes.
>
> I've tried this :
>
> try {
> set fundet [exec ...]
> }
>
> which ought to ignore any errors, but it still crashes :-(
>
> Incidentialy, this is exactly one of the examples given for
> try ... catch on http://tmml.sourceforge.net/doc/tcl/exec.html
>
> I had to resort to scanning the file line-by-line thus :
>
> === scrip start
> set dylibFile ${prefix}/${apachever}/conf/standard/00000-dylib.conf
>
> set xmllib [ exec find ${prefix}/lib -type f -iname "libxml2*.dylib" ]
> set lualib [ exec find ${prefix}/lib -type f -iname "liblua*.dylib" ]
>
> set chan [open ${dylibFile}]
> foreach libFile [list ${xmllib} ${lualib}] {
> seek ${chan} 0 start
> set fundet 0
> while {[gets ${chan} line] >= 0} {
> if { [ string first ${libFile} ${line} ] > 0 } {
> set fundet [ incr ${fundet} ]
> }
> }
> if { ${fundet} == 0 } {
> exec echo "LoadFile ${libFile}" >> ${dylibFile}
> }
> }
> close ${chan}
> === script end
>
> Now, can anyone point me in a direction that can get my original idea to
> work ???
>
> ====== EXERCISE for the asture reader ======
> consider the following piece of a Portfile,
> === script start
> set confFile ${prefix}/${apachever}/conf/extra/httpd-modsecurity2.conf
>
> if { ![ file exists ${confFile} ] } {
> exec echo "\\<IfModule security2_module\\>" > ${confFile}
> exec cat ${worksrcpath}/modsecurity.conf-recommended >> ${confFile}
> exec echo "\\</IfModule\\>" >> ${confFile}
> reinplace -E -- "s|^\\\\||" ${confFile}
> reinplace -E -- "s|(.)\\\\(.)|\\1\\2|" ${confFile}
> }
> === script end
> and tell me what's happening, and why ;-)
>
More information about the macports-users
mailing list