Wednesday, May 21, 2008

Configuring MySQL for Network access

The typical default install of MySQL server only permits connections from localhost (127.0.0.1); this is presumably for reasons of security. While this is certainly secure, in some cases it is undesirable. This post explains how to permit network access to a MySQL server from remote clients.

Locate the my.cnf file, which is the master configuration file for MySQL server. (On a Ubuntu system this file may be located in /etc/mysql.)

Open this file in your favorite editor and look for the following entry:

bind-address = 127.0.0.1


This limits the MySQL server to listening to connections on the localhost address, as explained earlier.

To instead make the MySQL server listen on all interfaces, edit this entry to the following:

bind-address = 0.0.0.0


Save the file, then restart the MySQL server:

sudo /etc/init.d/mysql restart


Your MySQL server should now be network accessible. To verify that it's listening on all interfaces, issue the following command:

netstat -anp | grep 3306


If you see the following, then your configuration is complete:

tcp        0      0 0.0.0.0:3306            0.0.0.0:*               LISTEN     -


You'll want to be certain your database users are permitted to connect via the network. This I'll leave to you to work out, though I will recommend the MySQL Admin tool.

(Conversely this tool can also be used to enable networking of MySQL, though this setting is somewhat buried within the myriad of options, and is more easily accomplished via the method described above.)

Tuesday, May 20, 2008

Macros and Variable Arguments in VisualStudio 2003

The preprocessor in Microsoft VisualStudio 2003 (VC++ 7.1) does not support variable argument lists in macros; instead it spews syntax errors when compiling. However, there is a way to get around this limitation and indeed gain this ability.

In a project I'm working on, we use macros to construct portions of our logging system. A typical declaration looks as such:

#define LOG_TRACE(...) log_routine(__FILE__, __LINE__, __VA_ARGS__)

However this fails to compile on VisualStudio.Net 2003, because as stated before, its preprocessor does not support variable argument lists.

A workaround is to instead use a class to handle the semantics of the variable argument list; observe:

class tracing_output_va
{
private:
const char* m_file;
int m_line;

public:
tracing_output_va(
const char* p_File,
const int p_Line) :
m_file( p_File ),
m_line( p_Line )
{

}

void operator()( const char* p_Format, ... )
{
va_list marker ;
va_start( marker, p_Format ) ;
LoggingOutVa(
m_file,
m_line,
p_Format,
marker ) ;

va_end( marker );

}
};


And then redefine the macro as such:

#define LOG_TRACE_APPLIB (tracing_output_va(__FILE__, __LINE__) )

This will indeed compile and perform as expected in VC++ 7.1

The elegance to this solution is that one need only modify the declaration of this macro, and that existing calls to this macro need not change.

For what it's worth the routine LoggingOutVa( ) wraps the actual magic of formatting and file output.


Cite: http://www.codeproject.com/KB/debug/location_trace.aspx

Thursday, May 15, 2008

VMWare Fusion -- No Hard Links in Shared Folders

VMWare Fusion allows one to use folders on the OSX filesystem from within the guest OS via Shared Folders.

This is useful if you need to access files from both the host OS (OSX) or the guest OS running in VMWare Fusion.

However I have found limitations with this arrangement when the guest OS is a Linux-based system -- it seems that VMWare's driver for Shared Folders does not support all of the linux filesystem operations (most specifically hard links).

Observe (/mnt/hgfs/wa points to a shared folder residing on the OSX filesystem) :


clermontr@synergy:/mnt/hgfs/wa/test$ touch tree
clermontr@synergy:/mnt/hgfs/wa/test$ ln tree shrub
ln: creating hard link `shrub' to `tree': Operation not permitted


Operation not permitted?! How about symbolic links:

clermontr@synergy:/mnt/hgfs/wa/test$ ln -s tree shrub
clermontr@synergy:/mnt/hgfs/wa/test$ ll
total 1
lrwxr-xr-x 1 clermontr ccm_root 4 2008-05-15 14:17 shrub -> tree
-rw-r--r-- 1 clermontr ccm_root 0 2008-05-15 14:16 tree
clermontr@synergy:/mnt/hgfs/wa/test$


Well it looks like symbolic links are permitted, but no chance for hard links. For what it's worth I also attempted to hard-link as sudo but to no avail.

Switching to the OSX filesystem I was able to create hard-links without issue. So then it would appear that this is indeed a limitation of the VMWare Fusion Shared Folders driver (vmhgfs).

I am interested in hearing if others have experienced this issue, and also if anyone has found a workaround.