This patch is sent to debian bug: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=172722
This patch also addresses these esd bugs: http://bugzilla.gnome.org/show_bug.cgi?id=97138 http://bugzilla.gnome.org/show_bug.cgi?id=88253 http://bugzilla.gnome.org/show_bug.cgi?id=3558 http://bugs.debian.org/cgi-bin/bugreport.cgi?archive=no&bug=125803 Provides a solution for these bugs: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=122627 http://bugzilla.gnome.org/show_bug.cgi?id=3558 and addresses this gnome-session bug: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=170843 When esd is called from within gnome or on the command line, and not setup to autospawn, esd ignores the contents of esd.conf (eg spawn_options=-nobeeps -r 48000). This patch makes esd read in esd.conf if it is called without arguments (and ESD_SPAWN_OPTIONS is unset). Though other behaviors are possible, this made the most sense to me: if the user supplies command line arguments, then assume the user knows what he or she is doing and don't merge in esd.conf. Likewise for ESD_SPAWN_OPTIONS. The benefits of this patch are twofold. 1. the user can adjust a single configuration file, rather than having to worry about environment variables and command line arguments. It also keeps users from wondering why adjusting esd.conf doesn't do anything when esd is not set to autospawn (its default behavior). 2. this patch decouples gnome-session from having to know what options are used to set esd (eg, '-nobeeps'). The esound packager can simply put in reasonable defaults into esd.conf, and gnome-session will just work. Because this patch only reads esd.conf if esd is called with no options, gnome-session would need to be recompiled to not pass esd any options (trivial). The patch is based on the existing code in esound. First, I created esd-config.h, and just pulled a couple of defines out of esd_config.c and put them into esd-config.h, so I could use them in esd.c. I did a small cleanup to get rid of a compilation warning for the strtok_r define. After that, the only change to esd_config.c is to include esd-config.h. The main part of the patch is a modification to esd.c, in main(). Basically, I reference esd_spawn_options in esd_config.c in the same manner that esdlib.c does (ie via extern). Then, if argc > 1, nothing is changed-- command line arguments are processed. If argc == 1, then I call esd_config_read() (from esd_config.c), tokenize esd_spawn_options and then they are processed with the same code that processes argv. To make the code cleaner, I made: num_opts = argc; opts = argv; and then just use num_opts and opts in place of argc and argv for parsing the arguments. The net effect is that if esd is called without arguments, I create arguments for it based on the 'spawn_options' line in esd.conf. Because I am using esd_config_read(), ESD_SPAWN_OPTIONS are also honored. To apply, save the patch to the directory that esound-0.2.28 is in, and do: cd esound-0.2.28 cat ../esound-0.2.28.esdconf.patch | patch -p1 Thanks, Jamie Strandboge PS-- If you are going to patch gnome-session like I suggested above, I killed esd, logged out of gnome, and then killed off gconf and oaf for good measure before logging back into gnome. Just logging out and back in kept the old esd options rather than the ones in esd.conf. -- Email: [EMAIL PROTECTED] GPG/PGP ID: 26384A3A Fingerprint: D9FF DF4A 2D46 A353 A289 E8F5 AA75 DCBE 2638 4A3A
diff -Naur esound-0.2.28-old/esd-config.h esound-0.2.28/esd-config.h --- esound-0.2.28-old/esd-config.h Wed Dec 31 19:00:00 1969 +++ esound-0.2.28/esd-config.h Wed Dec 11 20:57:41 2002 @@ -0,0 +1,20 @@ +#ifndef ESD_CONFIG_H +#define ESD_CONFIG_H + +#include <string.h> + +/* these are some defines to use in when reading + * esd.conf */ + +#define LINEBUF_SIZE 1024 + +/* use strtok_r if available */ +#ifdef HAVE_STRTOK_R +#define DO_STRTOK(S,DELIM) strtok_r(S,DELIM,strtok_state) +char *strtok_state[LINEBUF_SIZE]; +#else +#define DO_STRTOK(S,DELIM) strtok(S,DELIM) +#endif + +#endif + diff -Naur esound-0.2.28-old/esd.c esound-0.2.28/esd.c --- esound-0.2.28-old/esd.c Wed Dec 11 23:10:12 2002 +++ esound-0.2.28/esd.c Wed Dec 11 21:09:01 2002 @@ -1,4 +1,5 @@ #include "esd-server.h" +#include "esd-config.h" #include <arpa/inet.h> #include <sys/types.h> @@ -8,6 +9,8 @@ #include <signal.h> #include <time.h> +#include <string.h> + #ifndef HAVE_NANOSLEEP #include <sys/time.h> #include <sys/types.h> @@ -504,6 +507,14 @@ char *hostname=NULL; + /* from esd_config.c */ + extern char esd_spawn_options[]; + + char tmp_str[LINEBUF_SIZE]; + int num_opts = 0; + char **opts; + char *tok; + /* begin test scaffolding parameters */ /* int format = AFMT_U8; AFMT_S16_LE; */ /* int stereo = 0; */ /* 0=mono, 1=stereo */ @@ -518,100 +529,125 @@ programname = *argv; + /* use opts instead of modifying argv, because that is just + * too weird */ + opts = argv; + num_opts = argc; + + /* if we were called with no arguments, read in esd.conf, + * otherwise process argv (now opts) */ + if (num_opts == 1) { + esd_config_read(); + + /* copy esd_spawn_options to tmp_str in case no strtok_r */ + strncpy(tmp_str, esd_spawn_options, LINEBUF_SIZE); + + tok = DO_STRTOK(tmp_str, " "); + while (tok) { + opts[num_opts] = tok; + num_opts++; + tok = DO_STRTOK(NULL, " "); + } + + /* debug */ + for (i=0;i<num_opts;i++) + fprintf(stderr, "esd.c: [%d] is %s\n", i, opts[i]); + } + /* parse the command line args */ - for ( arg = 1 ; arg < argc ; arg++ ) { - if ( !strcmp( argv[ arg ], "-d" ) ) { - if ( ++arg != argc ) { - esd_audio_device = argv[ arg ]; + for ( arg = 1 ; arg < num_opts ; arg++ ) { + if ( !strcmp( opts[ arg ], "-d" ) ) { + if ( ++arg != num_opts ) { + esd_audio_device = opts[ arg ]; if ( !esd_audio_device ) { esd_port = ESD_DEFAULT_PORT; fprintf( stderr, "- could not read device: %s\n", - argv[ arg ] ); + opts[ arg ] ); } fprintf( stderr, "- using device %s\n", esd_audio_device ); } - } else if ( !strcmp( argv[ arg ], "-port" ) ) { - if ( ++arg != argc ) { - esd_port = atoi( argv[ arg ] ); + } else if ( !strcmp( opts[ arg ], "-port" ) ) { + if ( ++arg != num_opts ) { + esd_port = atoi( opts[ arg ] ); if ( !esd_port ) { esd_port = ESD_DEFAULT_PORT; fprintf( stderr, "- could not read port: %s\n", - argv[ arg ] ); + opts[ arg ] ); } fprintf( stderr, "- accepting connections on port %d\n", esd_port ); } - } else if ( !strcmp( argv[ arg ], "-bind" ) ) { - if ( ++arg != argc ) + } else if ( !strcmp( opts[ arg ], "-bind" ) ) { + if ( ++arg != num_opts ) { - hostname = argv[ arg ]; + hostname = opts[ arg ]; } fprintf( stderr, "- accepting connections on port %d\n", esd_port ); - } else if ( !strcmp( argv[ arg ], "-b" ) ) { + } else if ( !strcmp( opts[ arg ], "-b" ) ) { fprintf( stderr, "- server format: 8 bit samples\n" ); default_format &= ~ESD_MASK_BITS; default_format |= ESD_BITS8; - } else if ( !strcmp( argv[ arg ], "-r" ) ) { - if ( ++arg != argc ) { - default_rate = atoi( argv[ arg ] ); + } else if ( !strcmp( opts[ arg ], "-r" ) ) { + if ( ++arg != num_opts ) { + default_rate = atoi( opts[ arg ] ); if ( !default_rate ) { default_rate = ESD_DEFAULT_RATE; fprintf( stderr, "- could not read rate: %s\n", - argv[ arg ] ); + opts[ arg ] ); } fprintf( stderr, "- server format: sample rate = %d Hz\n", default_rate ); } - } else if ( !strcmp( argv[ arg ], "-as" ) ) { - if ( ++arg != argc ) { - esd_autostandby_secs = atoi( argv[ arg ] ); + } else if ( !strcmp( opts[ arg ], "-as" ) ) { + if ( ++arg != num_opts ) { + esd_autostandby_secs = atoi( opts[ arg ] ); if ( !esd_autostandby_secs ) { esd_autostandby_secs = ESD_DEFAULT_AUTOSTANDBY_SECS; fprintf( stderr, "- could not read autostandby timeout: %s\n", - argv[ arg ] ); + opts[ arg ] ); } /* fprintf( stderr, "- autostandby timeout: %d seconds\n", esd_autostandby_secs );*/ } #ifdef ESDBG - } else if ( !strcmp( argv[ arg ], "-vt" ) ) { + } else if ( !strcmp( opts[ arg ], "-vt" ) ) { esdbg_trace = 1; fprintf( stderr, "- enabling trace diagnostic info\n" ); - } else if ( !strcmp( argv[ arg ], "-vc" ) ) { + } else if ( !strcmp( opts[ arg ], "-vc" ) ) { esdbg_comms = 1; fprintf( stderr, "- enabling comms diagnostic info\n" ); - } else if ( !strcmp( argv[ arg ], "-vm" ) ) { + } else if ( !strcmp( opts[ arg ], "-vm" ) ) { esdbg_mixer = 1; fprintf( stderr, "- enabling mixer diagnostic info\n" ); #endif - } else if ( !strcmp( argv[ arg ], "-nobeeps" ) ) { + } else if ( !strcmp( opts[ arg ], "-nobeeps" ) ) { esd_beeps = 0; /* fprintf( stderr, "- disabling startup beeps\n" );*/ - } else if ( !strcmp( argv[ arg ], "-unix" ) ) { + } else if ( !strcmp( opts[ arg ], "-unix" ) ) { esd_use_tcpip = 0; - } else if ( !strcmp( argv[ arg ], "-tcp" ) ) { + } else if ( !strcmp( opts[ arg ], "-tcp" ) ) { esd_use_tcpip = 1; - } else if ( !strcmp( argv[ arg ], "-public" ) ) { + } else if ( !strcmp( opts[ arg ], "-public" ) ) { esd_public = 1; - } else if ( !strcmp( argv[ arg ], "-promiscuous" ) ) { + } else if ( !strcmp( opts[ arg ], "-promiscuous" ) ) { esd_is_owned = 1; esd_is_locked = 0; - } else if ( !strcmp( argv[ arg ], "-terminate" ) ) { + } else if ( !strcmp( opts[ arg ], "-terminate" ) ) { esd_terminate = 1; - } else if ( !strcmp( argv[ arg ], "-spawnpid" ) ) { - if ( ++arg < argc ) - esd_spawnpid = atoi( argv[ arg ] ); - } else if ( !strcmp( argv[ arg ], "-spawnfd" ) ) { - if ( ++arg < argc ) - esd_spawnfd = atoi( argv[ arg ] ); - } else if ( !strcmp( argv[ arg ], "-trust" ) ) { + } else if ( !strcmp( opts[ arg ], "-spawnpid" ) ) { + if ( ++arg < num_opts ) + esd_spawnpid = atoi( opts[ arg ] ); + } else if ( !strcmp( opts[ arg ], "-spawnfd" ) ) { + if ( ++arg < num_opts ) + esd_spawnfd = atoi( opts[ arg ] ); + } else if ( !strcmp( opts[ arg ], "-trust" ) ) { esd_trustval = 0; - } else if ( !strcmp( argv[ arg ], "-v" ) || !strcmp( argv[ arg ], "--version" ) ) { + } else if ( !strcmp( opts[ arg ], "-v" ) || !strcmp( opts[ arg ], "--version" ) ) { fprintf(stderr, "Esound version " VERSION "\n"); exit (0); - } else if ( !strcmp( argv[ arg ], "-h" ) || !strcmp( argv[ arg ], "--help" ) ) { + } else if ( !strcmp( opts[ arg ], "-h" ) || !strcmp( opts[ arg ], "--help" ) ) { fprintf( stderr, "Usage: esd [options]\n\n" ); fprintf( stderr, " -d DEVICE force esd to use sound device DEVICE\n" ); fprintf( stderr, " -b run server in 8 bit sound mode\n" ); @@ -635,7 +671,7 @@ fprintf( stderr, "\nPossible devices are: %s\n", esd_audio_devices() ); exit( 0 ); } else { - fprintf( stderr, "unrecognized option: %s\n", argv[ arg ] ); + fprintf( stderr, "unrecognized option: %s\n", opts[ arg ] ); } } diff -Naur esound-0.2.28-old/esd_config.c esound-0.2.28/esd_config.c --- esound-0.2.28-old/esd_config.c Wed Jun 19 08:14:24 2002 +++ esound-0.2.28/esd_config.c Wed Dec 11 20:57:36 2002 @@ -1,17 +1,10 @@ +#include "esd-config.h" + #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <ctype.h> #include <string.h> - -#define LINEBUF_SIZE 1024 - -#ifdef HAVE_STRTOK_R -#define DO_STRTOK(S,DELIM) strtok_r(S,DELIM,&strtok_state) -char strtok_state[LINEBUF_SIZE]; -#else -#define DO_STRTOK(S,DELIM) strtok(S,DELIM) -#endif int esd_no_spawn=1; /* If we can't find even the system config file, things are screwed up - don't try to make things