diff options
| -rw-r--r-- | bitlbee.h | 4 | ||||
| -rwxr-xr-x | configure | 29 | ||||
| -rw-r--r-- | lib/misc.c | 65 | ||||
| -rw-r--r-- | storage_xml.c | 7 | ||||
| -rw-r--r-- | unix.c | 67 | 
5 files changed, 93 insertions, 79 deletions
| @@ -94,10 +94,6 @@  #undef g_main_quit  #define g_main_quit		__PLEASE_USE_B_MAIN_QUIT__ -#ifndef F_OK -#define F_OK 0 -#endif -  #ifndef G_GNUC_MALLOC  /* Doesn't exist in GLib <=2.4 while everything else in BitlBee should     work with it, so let's fake this one. */ @@ -73,6 +73,8 @@ Option		Description				Default  --events=...	Event handler (glib, libevent)		$events  --ssl=...	SSL library to use (gnutls, nss, openssl, bogus, auto)  							$ssl + +--target=...	Cross compilation target 		same as host  EOF  		exit;  	fi @@ -131,6 +133,13 @@ cat<<EOF>config.h  #define CPU "$cpu"  EOF +if [ -n "$target" ]; then +	PKG_CONFIG_PATH=/usr/$target/lib/pkgconfig +	PATH=/usr/$target/bin:$PATH +	CC=$target-cc +	LD=$target-ld +fi +  if [ "$debug" = "1" ]; then  	[ -z "$CFLAGS" ] && CFLAGS=-g  	echo 'DEBUG=1' >> Makefile.settings @@ -157,15 +166,17 @@ fi  echo "CC=$CC" >> Makefile.settings; -if [ -n "$LD" ]; then -	echo "LD=$LD" >> Makefile.settings; -elif type ld > /dev/null 2> /dev/null; then -	echo "LD=ld" >> Makefile.settings; -else -	echo 'Cannot find ld, aborting.' -	exit 1; +if [ -z "$LD" ]; then +	if type ld > /dev/null 2> /dev/null; then +		LD=ld +	else +		echo 'Cannot find ld, aborting.' +		exit 1; +	fi  fi +echo "LD=$LD" >> Makefile.settings +  if [ -z "$PKG_CONFIG" ]; then  	PKG_CONFIG=pkg-config  fi @@ -495,6 +506,10 @@ CYGWIN* )  ;;  esac +if [ -n "$target" ]; then +	echo "Cross-compiling for: $target" +fi +  echo  echo 'Configuration done:' @@ -391,71 +391,6 @@ signed int do_iconv( char *from_cs, char *to_cs, char *src, char *dst, size_t si  		return( outbuf - dst );  } -/* A pretty reliable random number generator. Tries to use the /dev/random -   devices first, and falls back to the random number generator from libc -   when it fails. Opens randomizer devices with O_NONBLOCK to make sure a -   lack of entropy won't halt BitlBee. */ -void random_bytes( unsigned char *buf, int count ) -{ -	static int use_dev = -1; -	 -	/* Actually this probing code isn't really necessary, is it? */ -	if( use_dev == -1 ) -	{ -		if( access( "/dev/random", R_OK ) == 0 || access( "/dev/urandom", R_OK ) == 0 ) -			use_dev = 1; -		else -		{ -			use_dev = 0; -			srand( ( getpid() << 16 ) ^ time( NULL ) ); -		} -	} -	 -	if( use_dev ) -	{ -		int fd; -		 -		/* At least on Linux, /dev/random can block if there's not -		   enough entropy. We really don't want that, so if it can't -		   give anything, use /dev/urandom instead. */ -		if( ( fd = open( "/dev/random", O_RDONLY | O_NONBLOCK ) ) >= 0 ) -			if( read( fd, buf, count ) == count ) -			{ -				close( fd ); -				return; -			} -		close( fd ); -		 -		/* urandom isn't supposed to block at all, but just to be -		   sure. If it blocks, we'll disable use_dev and use the libc -		   randomizer instead. */ -		if( ( fd = open( "/dev/urandom", O_RDONLY | O_NONBLOCK ) ) >= 0 ) -			if( read( fd, buf, count ) == count ) -			{ -				close( fd ); -				return; -			} -		close( fd ); -		 -		/* If /dev/random blocks once, we'll still try to use it -		   again next time. If /dev/urandom also fails for some -		   reason, stick with libc during this session. */ -		 -		use_dev = 0; -		srand( ( getpid() << 16 ) ^ time( NULL ) ); -	} -	 -	if( !use_dev ) -	{ -		int i; -		 -		/* Possibly the LSB of rand() isn't very random on some -		   platforms. Seems okay on at least Linux and OSX though. */ -		for( i = 0; i < count; i ++ ) -			buf[i] = rand() & 0xff; -	} -} -  int is_bool( char *value )  {  	if( *value == 0 ) diff --git a/storage_xml.c b/storage_xml.c index f37fce44..ab7da6e3 100644 --- a/storage_xml.c +++ b/storage_xml.c @@ -28,6 +28,7 @@  #include "base64.h"  #include "arc.h"  #include "md5.h" +#include <glib/gstdio.h>  typedef enum  { @@ -242,9 +243,9 @@ GMarkupParser xml_parser =  static void xml_init( void )  { -	if( access( global.conf->configdir, F_OK ) != 0 ) +	if( ! g_file_test( global.conf->configdir, G_FILE_TEST_EXISTS ) )  		log_message( LOGLVL_WARNING, "The configuration directory `%s' does not exist. Configuration won't be saved.", global.conf->configdir ); -	else if( access( global.conf->configdir, R_OK ) != 0 || access( global.conf->configdir, W_OK ) != 0 ) +	else if( ! g_file_test( global.conf->configdir, G_FILE_TEST_EXISTS ) || g_access( global.conf->configdir, W_OK ) != 0 )  		log_message( LOGLVL_WARNING, "Permission problem: Can't read/write from/to `%s'.", global.conf->configdir );  } @@ -371,7 +372,7 @@ static storage_status_t xml_save( irc_t *irc, int overwrite )  	g_snprintf( path, sizeof( path ) - 2, "%s%s%s", global.conf->configdir, path2, ".xml" );  	g_free( path2 ); -	if( !overwrite && access( path, F_OK ) != -1 ) +	if( !overwrite && g_file_test( path, G_FILE_TEST_EXISTS ) )  		return STORAGE_ALREADY_EXISTS;  	strcat( path, "~" ); @@ -218,3 +218,70 @@ double gettime()  	gettimeofday( time, 0 );  	return( (double) time->tv_sec + (double) time->tv_usec / 1000000 );  } + +/* A pretty reliable random number generator. Tries to use the /dev/random +   devices first, and falls back to the random number generator from libc +   when it fails. Opens randomizer devices with O_NONBLOCK to make sure a +   lack of entropy won't halt BitlBee. */ +void random_bytes( unsigned char *buf, int count ) +{ +	static int use_dev = -1; +	 +	/* Actually this probing code isn't really necessary, is it? */ +	if( use_dev == -1 ) +	{ +		if( access( "/dev/random", R_OK ) == 0 || access( "/dev/urandom", R_OK ) == 0 ) +			use_dev = 1; +		else +		{ +			use_dev = 0; +			srand( ( getpid() << 16 ) ^ time( NULL ) ); +		} +	} +	 +	if( use_dev ) +	{ +		int fd; +		 +		/* At least on Linux, /dev/random can block if there's not +		   enough entropy. We really don't want that, so if it can't +		   give anything, use /dev/urandom instead. */ +		if( ( fd = open( "/dev/random", O_RDONLY | O_NONBLOCK ) ) >= 0 ) +			if( read( fd, buf, count ) == count ) +			{ +				close( fd ); +				return; +			} +		close( fd ); +		 +		/* urandom isn't supposed to block at all, but just to be +		   sure. If it blocks, we'll disable use_dev and use the libc +		   randomizer instead. */ +		if( ( fd = open( "/dev/urandom", O_RDONLY | O_NONBLOCK ) ) >= 0 ) +			if( read( fd, buf, count ) == count ) +			{ +				close( fd ); +				return; +			} +		close( fd ); +		 +		/* If /dev/random blocks once, we'll still try to use it +		   again next time. If /dev/urandom also fails for some +		   reason, stick with libc during this session. */ +		 +		use_dev = 0; +		srand( ( getpid() << 16 ) ^ time( NULL ) ); +	} +	 +	if( !use_dev ) +	{ +		int i; +		 +		/* Possibly the LSB of rand() isn't very random on some +		   platforms. Seems okay on at least Linux and OSX though. */ +		for( i = 0; i < count; i ++ ) +			buf[i] = rand() & 0xff; +	} +} + + | 
