" class="title" title="home again woohoo">Home ?> pages bg right



Bandwidth Mod : MacOSX Troubles

Well…
Lot of time has passed since i released a stable version of mod_bw.
Stable as it is, it isn’t free of problems.

Frederik Temmermans contacted me a couple of weeks ago, and sent some errors he got compiling current version of mod_bw (0.8 as of now).
He was running MacOSX 10.5.7 with standar Apache 2.2.11.

When compiling normally using apxs, the module will be built and installed. But after starting apache, an error will appear :

httpd: Syntax error on line 54 of /private/etc/apache2/httpd.conf: Cannot load /usr/libexec/apache2/mod_bw.so into server:
dlopen(/usr/libexec/apache2/mod_bw.so, 10): no suitable image found. Did find:
/usr/libexec/apache2/mod_bw.so: mach-o, but wrong architecture

So…. There is a binary.. but for the wrong architecture.
As Mac’s nowadays are Intel based, to me it looks like it is a 32/64bits issue.

As MacOSX is a hybrid system running 32 and 64bits apps (since some time), looks like apache is a 64bit application :

G1X:mod_bw root# httpd -V
 Server version: Apache/2.2.11 (Unix)
 Server built:   Feb  3 2009 01:54:45
 Server's Module Magic Number: 20051115:21
 Server loaded:  APR 1.2.7, APR-Util 1.2.7
 Compiled using: APR 1.2.7, APR-Util 1.2.7
 Architecture:   64-bit
 Server MPM:     Prefork
  threaded:     no
  forked:     yes (variable process count)

G1X:mod_bw root# uname -a
 Darwin G1X.local 9.7.0 Darwin Kernel Version 9.7.0: Tue Mar 31 22:52:17 PDT
 2009; root:xnu-1228.12.14~1/RELEASE_I386 i386

And it also seems that apxs is compiling a 32bit binary.
(G1X is my Asus G1 laptop running OSX. Sorry Apple, I know i should not do this.. but it was a quick test to help. If anyone wants to donate a MacBookPro…. :X)

Well, after realizing whats the problem, it is just a matter of adjusting some compiling flags.. Run apxs like this :

apxs -c -i  -Wc,'-arch x86_64' -Wl,'-arch x86_64'  mod_bw.c

And that’s it. You’ll have a 64bit module.

……………………

Did i said that’s it ?
Well.. Life is not an easy ride. After fixing this, Frederik had another issue. (I find this weird… i had a system setup to be similar to his, and i didn’t have this problem.)

If loading the module you get an error like this one :

httpd: Syntax error on line 117 of /private/etc/apache2/httpd.conf:
Cannot load /usr/libexec/apache2/mod_bw.so into server:
dlopen(/usr/libexec/apache2/mod_bw.so, 10): Symbol not found: _apr_atomic_add\n  Referenced from: /usr/libexec/apache2/mod_bw.so
Expected in: dynamic lookup

It is because that symbol (used in the module) is not in your current APR Lib version. I have seen this occur in some linux distros (but never happened to me… damn). When i first received an email regarding this bug, we came up with an easy fix, and it seemed to solve it. (did last a while…)

Well, to fix it, you need to locate and erase this lines from mod_bw.c

#if (APR_MAJOR_VERSION < 1)
    #define apr_atomic_inc32 apr_atomic_inc
    #define apr_atomic_dec32 apr_atomic_dec
    #define apr_atomic_add32 apr_atomic_add
    #define apr_atomic_cas32 apr_atomic_cas
    #define apr_atomic_set32 apr_atomic_set
#endif

Compile again, and that's it. (this time for real).

In the next release (hope to be soon), i'll try to have this fixed once and for all.



ASP , Reading directories

Well… I almost don’t work with web apps written in ASP.
However, every now and then a client asks for a site in this language.

And every single time, i have to look at my “cheat sheet” to remember some simple stuff.
So… as sometimes my files get messy, and hard to find, i’ll be posting some of those “cheats” here.

(This, was practically copied from here : http://sestud.uv.es/manual.esp/asp/asp16.htm )

Server.CreateObject Method


Server.CreateObject(“Scripting.FileSystemObject”)

Using this object, we will have a way to look (and change) to the structure of files/folders on a given system. First, you need to create a FileSystem object, and then, the File or Folder object (i think you can guess which one is for files , or folders)

<%
  Set FS = Server.CreateObject("Scripting.FileSystemObject")
  Set File = FS.GetFile("C:\ASP\text.txt")
  Set Folder = FS.GetFolder("C:\ASP")
%>

* FS is a FileSystem object, which will allow us to access the file system on the server.
* File is a File object, which will allow us to access the properties of a text fiel, called text.txt (under c:\ASP\)
* Folder is a Folder object (duh), and will allow us to access properties of the c:\ASP folder.

Now… lets take a look at the properties, that can be “read only” (R) or “read/write” (RW). I’ll use Object as a wildcard for both, File and Folder.

  • Objeto.Attributes [=new] Set a new, or show attributes of an object. Values are as follow (you can use either the Name, or the value) :
    • Normal = 0 Normal file. No attributes changed.
    • ReadOnly = 1 Read Only File. RW
    • Hidden = 2 Hidden File. RW
    • System = 4 System File. RW
    • Volume = 8 Volume Label of Disk. R
    • Directory = 16 Folder. R
    • Archive = 32 File has been modified since last backup. RW
    • Alias = 64 Link to another file. R
    • compressed = 128 Compressed file. R
  • Objeto.DateCreated Returns the full date when the object was created. R
  • Objeto.DateLastAccessed Returns the full date when the object was last accessed. R
  • Objeto.DateLastModified Returns the full date when the object was last modified. R
  • Objeto.Drive Returns the drive letter where the object resides. R
  • Objeto.Name [= newname] Returns the name, or sets a new name. RW
  • Objeto.ParentFolder Return the parent folder of the object. R
  • Objeto.Path Returns the full path of the object R
  • Objeto.ShortName Returns the short name (8.3), also called DOS Name. R
  • Objeto.ShortPath Returns the short path (8.3), also called DOS Path. R
  • Objeto.Size With files, returns the size of the File. With folders, return the size in bytes of all files/folders within it. R
  • Objeto.Type Returns a descriptive text of the type of file. I.e. a gif file will return “GIF Image”. R
  • Directorio.Files Returns a file collection, containing all the Files contained in the Folder. This includes hidden and system files. R
  • Directorio.SubFolders Return a folder collection, containing all subfolders, including hidden and system folders.R
  • Directorio.IsRootFolder Returns True if the folder is the root folder. False if it isn’t.

And now, the methods:

  • Objeto.Copy dest[, overwrite] Copies a file or folder to “dest”. The optional “overwrite” flag (True or False), specifies if “dest” will be overwritten if it exists. “dest” cannot contain wildcards.
  • Objeto.Delete option Deletes a file or a folder. If “option” is True, files with readonly attribute will be deleted; False (default) won’t.
  • Objeto.Move dest Moves a file or folder, to “dest”. “dest” cannot have wildcards.

In every case, every object must be closed in the reverse order they were created.

<%
  File.Close
  Set File = Nothing
  Folder.Close
  Set Folder = Nothing
  FS.Close
  Set FS = Nothing
%>

To finish, a full example of a directory listing :

<%
    set fs = CreateObject("Scripting.FileSystemObject")
    path = Server.MapPath("/")
    set folder = fs.GetFolder(path)

    For each file in folder.Files
        Response.write "Filename : " & File.Name & " <br>"
    Next
%>
Page 2 of 4«1234»