home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / c / condor40.zip / CONDOR / src / util_lib / dprintf_config < prev    next >
Text File  |  1989-05-15  |  4KB  |  175 lines

  1. /* 
  2. ** Copyright 1986, 1987, 1988, 1989 University of Wisconsin
  3. ** 
  4. ** Permission to use, copy, modify, and distribute this software and its
  5. ** documentation for any purpose and without fee is hereby granted,
  6. ** provided that the above copyright notice appear in all copies and that
  7. ** both that copyright notice and this permission notice appear in
  8. ** supporting documentation, and that the name of the University of
  9. ** Wisconsin not be used in advertising or publicity pertaining to
  10. ** distribution of the software without specific, written prior
  11. ** permission.  The University of Wisconsin makes no representations about
  12. ** the suitability of this software for any purpose.  It is provided "as
  13. ** is" without express or implied warranty.
  14. ** 
  15. ** THE UNIVERSITY OF WISCONSIN DISCLAIMS ALL WARRANTIES WITH REGARD TO
  16. ** THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
  17. ** FITNESS. IN NO EVENT SHALL THE UNIVERSITY OF WISCONSIN  BE LIABLE FOR
  18. ** ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  19. ** WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  20. ** ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  21. ** OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  22. ** 
  23. ** Authors:  Allan Bricker and Michael J. Litzkow,
  24. **              University of Wisconsin, Computer Sciences Dept.
  25. ** 
  26. */ 
  27.  
  28.  
  29. /************************************************************************
  30. **
  31. **    Set up the various dprintf variables based on the configuration file.
  32. **
  33. ************************************************************************/
  34.  
  35. #include <stdio.h>
  36. #include <varargs.h>
  37. #include <time.h>
  38. #include <sys/file.h>
  39. #include <sys/param.h>
  40.  
  41. #include "condor_sys.h"
  42. #include "debug.h"
  43. #include "except.h"
  44. #include "clib.h"
  45.  
  46. static char *_FileName_ = __FILE__;        /* Used by EXCEPT (see except.h)     */
  47.  
  48. int        Termlog;
  49.  
  50. dprintf_config( subsys, logfd )
  51. char *subsys;
  52. int logfd;        /* The descriptor to use if the log output goes to a tty */
  53. {
  54.     char pname[ BUFSIZ ];
  55.     char *pval, *param();
  56.  
  57.     /*
  58.     **    Pick up the subsys_DEBUG parameters
  59.     */
  60.     (void)sprintf(pname, "%s_DEBUG", subsys);
  61.     pval = param(pname);
  62.     if( pval == NULL ) {
  63.         DebugFlags = D_ALWAYS;
  64.     } else {
  65.         set_debug_flags( pval );
  66.     }
  67.  
  68.     /*
  69.     **    If this is not going to the terminal, pick up the name
  70.     **    of the log file, maximum log size, and the name of the
  71.     **    lock file (if it is specified).
  72.     */
  73.     if( !( DebugFlags & D_TERMLOG) ) {
  74.         (void)sprintf(pname, "%s_LOG", subsys);
  75.         DebugFile = param(pname);
  76.  
  77.         if( DebugFile == NULL ) {
  78.             EXCEPT("No '%s' parameter specified.", pname);
  79.         }
  80.  
  81.         (void)sprintf(pname, "TRUNC_%s_LOG_ON_OPEN", subsys);
  82.         pval = param(pname);
  83.         if( pval && (*pval == 't' || *pval == 'T') ) {
  84.             DebugFP = fopen( DebugFile, "w" );
  85.         } else {
  86.             DebugFP = fopen( DebugFile, "a" );
  87.         }
  88.  
  89.         if( DebugFP == NULL ) {
  90.             EXCEPT("Cannot open log file '%s'", DebugFile);
  91.         }
  92.  
  93.         (void)fclose( DebugFP );
  94.         DebugFP = (FILE *)0;
  95.  
  96. #ifdef notdef
  97.         /*
  98.         **    We don't need these anymore...
  99.         */
  100.         (void) close(0);
  101.         (void) close(1);
  102.         (void) close(2);
  103. #endif notdef
  104.  
  105.         (void)sprintf(pname, "MAX_%s_LOG", subsys);
  106.         pval = param(pname);
  107.         if( pval != NULL ) {
  108.             MaxLog = atoi( pval );
  109.         }
  110.  
  111.         if( MaxLog == 0 ) {
  112.             MaxLog = 65536;
  113.         }
  114.  
  115.         (void)sprintf(pname, "%s_LOCK", subsys);
  116.         DebugLock = param(pname);
  117.     } else {
  118.         if( fileno(stderr) != logfd ) {
  119.             if( dup2(fileno(stderr), logfd) < 0 ) {
  120.                 perror("Can't get error channel:");
  121.                 exit( 1 );
  122.             }
  123.         }
  124. #ifndef LINT
  125.         fileno(stderr) = logfd;
  126. #endif LINT
  127.  
  128.         setlinebuf( stderr );
  129.  
  130.         (void)fflush( stderr );    /* Don't know why we need this, but if not here
  131.                                the first couple dprintf don't come out right */
  132.     }
  133. }
  134.  
  135. static
  136. set_debug_flags( strflags )
  137. char *strflags;
  138. {
  139.     char tmp[ BUFSIZ ];
  140.     char *argv[ BUFSIZ ], *flag;
  141.     int argc, notflag, bit, i;
  142.  
  143.     (void)strncpy(tmp, strflags, sizeof(tmp));
  144.     mkargv(&argc, argv, tmp);
  145.  
  146.     while( --argc >= 0 ) {
  147.         flag = argv[argc];
  148.         if( *flag == '-' ) {
  149.             flag += 1;
  150.             notflag = 1;
  151.         } else {
  152.             notflag = 0;
  153.         }
  154.  
  155.         bit = 0;
  156.         if( stricmp(flag, "D_ALL") == 0 ) {
  157.             bit = D_ALL;
  158.         } else for( i = 0; i < D_MAXFLAGS; i++ ) {
  159.             if( stricmp(flag, DebugFlagNames[i]) == 0 ) {
  160.                 bit = (1 << i);
  161.                 break;
  162.             }
  163.         }
  164.  
  165.         if( notflag ) {
  166.             DebugFlags &= ~bit;
  167.         } else {
  168.             DebugFlags |= bit;
  169.         }
  170.     }
  171.     if( Termlog ) {
  172.         DebugFlags |= D_TERMLOG;
  173.     }
  174. }
  175.