[nas] Re: Add support for specifying nasd config file

Steve McIntyre steve at einval.com
Fri Feb 6 17:38:48 MST 2004


On Sat, Feb 07, 2004 at 12:37:17AM +0000, Steve McIntyre wrote:
>I've had a feature request from a Debian user who wants to use nas to
>control multiple sound cards. This is difficult at the moment, as a
>single server only supports a single input/output device pair. An easy
>way to make this work would be to run multiple instances of nasd, one
>for each card. There is currently no way to tell the server to use a
>specific config file to make this happen. The attached patch seems to
>work for me - use the -config <file> option to specify a non-default
>config file on the nasd command line.
>
>What do you think?

<sigh> I'll attach the patch this time... :-)

-- 
Steve McIntyre, Cambridge, UK.                                steve at einval.com
Is there anybody out there?
-------------- next part --------------
--- nas-1.6b.orig/doc/html/man1/nasd.html
+++ nas-1.6b/doc/html/man1/nasd.html
@@ -111,6 +111,10 @@
 well-known    sockets (connection points for
 clients), but establishes at least one.
 </DD>
+
+<DT><B>-config</B> <I>file</I> </DT></DT>
+<DD> Use the config file <I>file</I>, instead of the default (/etc/nasd/nasd.conf).
+</DD>
 </DL>
 
 <H2><A NAME="sect6" HREF="#toc6"><B>Signals</B></A></H2>
--- nas-1.6b.orig/server/dia/main.c
+++ nas-1.6b/server/dia/main.c
@@ -90,12 +90,9 @@
 
 static FILE     *openConfigFile (char *path)
 {
-  static char   buf[1024];
   FILE *config;
 
-  strcat (buf, path);
-  strcat (buf, "nasd.conf");
-  if ((config = fopen (buf, "r")) != NULL)
+  if ((config = fopen (path, "r")) != NULL)
     return config;
   else
     return NULL;
@@ -108,6 +105,7 @@
     char	*argv[];
 {
     int		i;
+    char    *config_file;
 
     /* Notice if we're restart.  Probably this is because we jumped through
      * uninitialized pointer */
@@ -119,8 +117,11 @@
     /* Init the globals... */
     diaInitGlobals();
 
-				/* Now parse the config file */
-    if ((yyin = openConfigFile (NASCONFSEARCHPATH)) != NULL)
+    if ((config_file = FindConfigFile(argc, argv)) == NULL)
+        config_file = NASCONFSEARCHPATH"/nasd.conf";
+
+    /* Now parse the config file */
+    if ((yyin = openConfigFile (config_file)) != NULL)
       yyparse();
 
     /* These are needed by some routines which are called from interrupt
--- nas-1.6b.orig/server/include/os.h
+++ nas-1.6b/server/include/os.h
@@ -153,6 +153,7 @@
 void		Error();
 void		FatalError();
 void		ProcessCommandLine();
+char        *FindConfigFile ();
 void		FlushAllOutput();
 void		FlushIfCriticalOutputPending();
 #ifndef CAHILL_MALLOC
--- nas-1.6b.orig/server/os/utils.c
+++ nas-1.6b/server/os/utils.c
@@ -271,6 +271,7 @@
     ErrorF(" -b                 detach and run in background\n");
     ErrorF(" -v                 enable verbose messages\n");
     ErrorF(" -d <num>           enable debug messages at level <num>\n");
+    ErrorF(" -config <file>     use <file> as the nasd config file\n");
 #ifndef AMOEBA
 #ifdef PART_NET
     ErrorF(" -pn                partial networking enabled [default]\n");
@@ -283,6 +284,31 @@
     ddaUseMsg();		/* print dda specific usage */
 }
 
+/* 
+ * This function parses the command line to check if a non-default
+ * config file has been specified. This needs to be separate from the
+ * normal command-line processing below because we _only_ want to grab
+ * the config file name. Other options need to be read from the config
+ * file and (potentially) overridden by command-line options later.
+ */
+char *
+FindConfigFile (int argc, char *argv[] )
+{
+    int i;
+     for (i = 1; i < argc; i++) {
+         if (strcmp(argv[i], "-config") == 0) {
+             i++;
+             if (i < argc)
+                 return argv[i];
+             else {
+                 UseMsg();
+                 exit(1);
+             }
+         }
+     }
+}
+
+
 /*
  * This function parses the command line. Handles device-independent fields
  * and allows ddx to handle additional fields.  It is not allowed to modify
@@ -325,6 +351,16 @@
 	  {
 	    NasConfig.DoVerbose = TRUE;
 	  }
+    else if (strcmp(argv[i], "-config") == 0)
+    {
+        i++;
+	    if (i < argc)
+	      i++;
+	    else {
+	      UseMsg();
+	      exit(1);
+        }
+    }
 	else if (strcmp(argv[i], "-b") == 0)
 	  {
 	    NasConfig.DoDaemon = TRUE;
--- nas-1.6b.orig/server/nasd.man
+++ nas-1.6b/server/nasd.man
@@ -69,6 +69,9 @@
 allows the server to start, even if the server cannot establish all of
 its well-known sockets (connection points for clients), but
 establishes at least one.
+.TP 8
+.B \-config \fIfile\fP
+Use the config file \fIfile\fP, instead of the default (/etc/nasd/nasd.conf).
 .SH SIGNALS
 The Network Audio System server attaches special meaning to the following signals:
 .TP 8
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://radscan.com/pipermail/nas/attachments/20040207/96d2a846/attachment.pgp>


More information about the Nas mailing list