예제 #1
0
void log_trace(int type, char *line, int len)
{
  int i = 0;
  int ch;
  char data[64] = "\0";
  char *dptr = NULL;
  char text[17];


  if (len == 0)
    return;

  if ((type & trace_flags) != 0) {
    text[16] = 0;
    for (i = 0; i < len; i++) {
      if ((i % 16) == 0) {
        // beginning of line
        dptr = data;
        sprintf(dptr, "%4.4x|", i);
      }
      ch = line[i];
      sprintf(dptr + 5 + ((i % 16) * 3), "%2.2x", ch);
      if (ch > 31 && ch < 127) {
        text[i % 16] = ch;
      }
      else {
        text[i % 16] = '.';
      }
      if ((i % 16) == 15) {
        log_start(LOG_TRACE);
        fprintf(log_file, "%s|%s|%s|", trace_type[type], data, text);
        log_end();
      }
      else {
        sprintf(dptr + 7 + ((i % 16) * 3), " ");
      }
    }
    i = i % 16;
    if (i > 0) {
      for (; i < 16; i++) {
        sprintf(dptr + 5 + ((i % 16) * 3), "  ");
        if ((i % 16) != 15) {
          sprintf(dptr + 7 + ((i % 16) * 3), " ");
        }
        text[i % 16] = ' ';
      }
      log_start(LOG_TRACE);
      fprintf(log_file, "%s|%s|%s|", trace_type[type], data, text);
      //fprintf(log_file, "%s", text);
    }
    log_end();
  }
}
예제 #2
0
파일: manager.c 프로젝트: jbli/udpcopy
void udp_copy_exit()
{
    int i;
    fprintf(stderr, "exit udpcopy\n");
    if (-1 != raw_sock){
        close(raw_sock);
        raw_sock = -1;
    }
    send_close();
#if (UDPCOPY_OFFLINE)
    if (pcap != NULL) {
        pcap_close(pcap);
    }
#endif
    log_end();
    if (clt_settings.transfer.mappings != NULL){
        for (i = 0; i < clt_settings.transfer.num; i++){
            free(clt_settings.transfer.mappings[i]);
        }
        free(clt_settings.transfer.mappings);
        clt_settings.transfer.mappings = NULL;
    }
    exit(EXIT_SUCCESS);

}
예제 #3
0
파일: service.c 프로젝트: Veilen/xinetd
/*
 * Steps:
 *      1. Deactivate the service
 *      2. Free all memory used by the service and free the service itself
 *
 * Since this function may free all memory associated with the service as
 * well as the memory pointed by sp, only the value of sp should be used
 * after this call if the return value is 0 (i.e. no dereferencing of sp).
 *
 * Special services are never deactivated.
 */
int svc_release( struct service *sp )
{
   char *sid = SVC_ID( sp ) ;
   const char *func = "svc_release" ;

   if ( SVC_REFCOUNT(sp) == 0 )
   {
      msg( LOG_ERR, func, "%s: svc_release with 0 count", sid ) ;
      return( 0 ) ;
   }
   
   SVC_REFCOUNT(sp)-- ;
   if ( SVC_REFCOUNT(sp) == 0 )
   {
      if ( debug.on )
         msg( LOG_DEBUG, func, "ref count of service %s dropped to 0", sid ) ;
      if ( ! SC_IS_SPECIAL( SVC_CONF( sp ) ) )
      {
         if ( SVC_LOG(sp) )
            log_end( SC_LOG( SVC_CONF( sp ) ), SVC_LOG(sp) ) ;
         svc_deactivate( sp ) ;
         svc_free( sp ) ;
         sp = NULL;
      }
      else      /* this shouldn't happen */
         msg( LOG_WARNING, func,
            "ref count of special service %s dropped to 0", sid ) ;
      return( 0 ) ;
   }
   else
      return( SVC_REFCOUNT(sp) ) ;
}
예제 #4
0
/**
 * Logs a formatted string -- similiar to printf()
 *
 * @param sev     The severity
 * @param fmt     The format string
 * @param ...     Additional arguments
 */
void log_fmt(log_sev_t sev, const char *fmt, ...)
{
   va_list args;
   int     len;
   size_t  cap;

   if ((fmt == NULL) || !log_sev_on(sev))
   {
      return;
   }

   /* Some implementation of vsnprintf() return the number of characters
    * that would have been stored if the buffer was large enough instead of
    * the number of characters actually stored.
    */
   cap = log_start(sev);

   /* Add on the variable log parameters to the log string */
   va_start(args, fmt);
   len = vsnprintf(&g_log.buf[g_log.buf_len], cap, fmt, args);
   va_end(args);

   if (len > 0)
   {
      if (len > (int)cap)
      {
         len = cap;
      }
      g_log.buf_len           += len;
      g_log.buf[g_log.buf_len] = 0;
   }

   log_end();
}
예제 #5
0
파일: manager.c 프로젝트: jbli/tcpcopy
void tcp_copy_exit()
{
    int i;
    fprintf(stderr, "exit tcpcopy\n");
    destroy_for_sessions();
    if(-1 != raw_sock){
        close(raw_sock);
        raw_sock = -1;
    }
    send_close();
    address_close_sock();
    log_end();
#ifdef TCPCOPY_MYSQL_ADVANCED
    release_mysql_user_pwd_info();
#endif
    if(clt_settings.transfer.mappings != NULL){
        for(i = 0; i < clt_settings.transfer.num; i++){
            free(clt_settings.transfer.mappings[i]);
        }
        free(clt_settings.transfer.mappings);
        clt_settings.transfer.mappings = NULL;
    }
    exit(EXIT_SUCCESS);

}
예제 #6
0
파일: sig.c 프로젝트: 340211173/xrdp
void DEFAULT_CC
sig_sesman_reload_cfg(int sig)
{
    int error;
    struct config_sesman *cfg;
    char cfg_file[256];

    log_message(LOG_LEVEL_WARNING, "receiving SIGHUP %d", 1);

    if (g_getpid() != g_pid)
    {
        LOG_DBG("g_getpid() [%d] differs from g_pid [%d]", g_getpid(), g_pid);
        return;
    }

    cfg = g_malloc(sizeof(struct config_sesman), 1);

    if (0 == cfg)
    {
        log_message(LOG_LEVEL_ERROR, "error creating new config:  - keeping old cfg");
        return;
    }

    if (config_read(cfg) != 0)
    {
        log_message(LOG_LEVEL_ERROR, "error reading config - keeping old cfg");
        g_free(cfg);
        return;
    }

    /* stop logging subsystem */
    log_end();

    /* replace old config with new readed one */
    g_cfg = cfg;

    g_snprintf(cfg_file, 255, "%s/sesman.ini", XRDP_CFG_PATH);

    /* start again logging subsystem */
    error = log_start(cfg_file, "XRDP-sesman");

    if (error != LOG_STARTUP_OK)
    {
        char buf[256];

        switch (error)
        {
            case LOG_ERROR_MALLOC:
                g_printf("error on malloc. cannot restart logging. log stops here, sorry.\n");
                break;
            case LOG_ERROR_FILE_OPEN:
                g_printf("error reopening log file [%s]. log stops here, sorry.\n", getLogFile(buf, 255));
                break;
        }
    }

    log_message(LOG_LEVEL_INFO, "configuration reloaded, log subsystem restarted");
}
예제 #7
0
static LPARAM
log_WM_LBUTTONUP(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
{
	LPARAM ret;
	log_begin("WM_LBUTTONUP");
		ret = on_WM_LBUTTONUP(hwnd, msg, wp, lp);
	log_end();
	return ret;
}
예제 #8
0
int dao_copy( unsigned short source, unsigned short dest,
              int simul, int ejsrc, int ejdst )
{
  int ret;
  struct idao_stream * in;
  struct odao_stream * out;

  log_begin();
  log_printf( "*** Begin of a DAO copy\n\n" );

  if( source == TST_FILE )
    in = idao_open_file( copy_info.source_file );
  else if( source == 20000 )
    in = idao_open_file( copy_info.int_file );
  else
    in = idao_open_cd( copy_info.source_dev );
  if( !in )
  {
    alert_msg( "AL_DAOSRCERR", 1 );
    return -1;
  }

  if( dest == TST_FILE )
    out = odao_open_file( copy_info.dest_file );
  else if( dest == 20000 )
    out = odao_open_file( copy_info.int_file );
  else
    out = odao_open_cd( copy_info.dest_dev );
  if( !out )
  {
    idao_close( in );
    alert_msg( "AL_DAODSTERR", 1 );
    return -1;
  }

  if( in->type == TST_CD )
  {
    if( ejsrc ) in->spec.cd.flags |= CDFLG_EJECT;
  }
  if( out->type == TST_CD )
  {
    if( ejdst ) out->spec.cd.flags |= CDFLG_EJECT;
    use_device( out->spec.cd.dev );
    set_dummy_write( simul );
    set_write_speed( copy_info.write_speed );
  }

  ret = dao_pipe( "TXT_COPY", in, out );

  odao_close( out );
  idao_close( in );

  log_printf( "*** End of the DAO copy\n\n" );
  log_end();

  return ret;
}
예제 #9
0
static LPARAM
log_WM_DESTROY(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
{
	LPARAM ret;
	log_begin("WM_DESTROY");
		ret = on_WM_DESTROY(hwnd, msg, wp, lp);
	log_end();
	return ret;
}
예제 #10
0
static LPARAM
log_WM_CREATE(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
{
	LPARAM ret;
	log_begin("WM_CREATE");
		ret = on_WM_CREATE(hwnd, msg, wp, lp);
	log_end();
	return ret;
}
예제 #11
0
static LPARAM
log_DefWindowProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
{
	LPARAM ret;
	log_begin("WM_%d", msg);
		ret = DefWindowProc(hwnd, msg, wp, lp);
	log_end();
	return ret;
}
예제 #12
0
void set_default_colors(Raster *r)
/*****************************************************************************
 *
 ****************************************************************************/
{
	log_start("Calling wait_vsync() then set_colors() to set default test palette...\n");
	r->lib->wait_vsync(r);
	r->lib->set_colors(r, 0, COLORS, pj_default_cmap);
	log_end("...default color palette set.\n\n");
}
예제 #13
0
void
end_trans_man_action()
{
  int i;
  log_start();
  for(i = 0; i < b_index; i++){
    bwrite(bp[i]);
    brelse(bp[i]);
  }

  log_end();
}
예제 #14
0
파일: inverse.hpp 프로젝트: Fadis/miyabi
 bool inverse( Matrix &_matrix ) {
   typedef typename scalar_type< typename scalar_type< Matrix >::type >::type MatrixElement;
   int max_row_index = 0;
   int max_col_index = 0;
   int element_count;
   {
     typename indexed_iterator< Matrix >::type row_iter( _matrix.begin() );
     std::advance( row_iter, _matrix.size() - 1 );
     element_count = row_iter.getIndex() + 1;
   }
   {
     typename indexed_iterator< Matrix >::type row_iter( _matrix.begin() );
     typename indexed_iterator< Matrix >::type row_end( _matrix.end() );
     for( ; row_iter != row_end; ++row_iter ) {
       typename indexed_iterator< typename scalar_type< Matrix >::type >::type col_iter( row_iter->begin() );
       std::advance( col_iter, row_iter->size() - 1 );
       element_count = std::max( element_count, col_iter.getIndex() + 1 );
     }
   }
   Vector< std::vector< int > > log( element_count );
   {
     indexed_iterator< std::vector< int > >::type log_iter( log.begin() );
     indexed_iterator< std::vector< int > >::type log_end( log.end() );
     for( ; log_iter != log_end; ++log_iter )
       *log_iter = log_iter.getIndex();
   }
   Matrix lu_matrix = _matrix;
   if( !lu( lu_matrix, log ) )
     return false;
   
   for( int index = 0; index != element_count; ++index ) {
     {
       for( int row = 0; row != element_count; ++row ) {
         int pivot = log.getConstValue( row );
         MatrixElement sum = ( ( pivot == index ) ? 1 : 0 );
         for( int col = 0; col != row; ++col )
           sum -= lu_matrix.getConstValue( row ).getConstValue( col ) * _matrix.getConstValue( col ).getConstValue( index );
        _matrix.getValue( row ).getValue( index ) = sum;
       }
     }
     {
       for( int row = element_count - 1; row != -1; row-- ) {
         MatrixElement sum = _matrix.getConstValue( row ).getConstValue( index );
         for( int col = row + 1; col != element_count; col++ )
           sum -= lu_matrix.getConstValue( row ).getConstValue( col ) * _matrix.getConstValue( col ).getConstValue( index );
         _matrix.getValue( row ).getValue( index ) = sum / lu_matrix.getConstValue( row ).getConstValue( row );
       }
     }
   }
   return true;
 }
예제 #15
0
int
log_writei(struct inode *ip, char *src, uint off, uint n)
{
  uint tot, m, i, j;
  struct buf *tbp;

  if(ip->type == T_DEV){
    if(ip->major < 0 || ip->major >= NDEV || !devsw[ip->major].write)
      return -1;
    return devsw[ip->major].write(ip, src, n);
  }

  if(off + n < off)
    return -1;
  if(off + n > MAXFILE*BSIZE)
    n = MAXFILE*BSIZE - off;


  b_index = 0; // new xfer, start keeping track of open bufs

  /* allocate all space needed */
  for(i=0, j=off; i<n; i+=m, j+=m){
    log_bmap(ip, j/BSIZE);
    m = min(n - i, BSIZE - j%BSIZE);
  }

  for(tot=0; tot<n; tot+=m, off+=m, src+=m){
    bp[b_index] = bread(ip->dev, log_lookup(ip, off/BSIZE));
    m = min(n - tot, BSIZE - off%BSIZE);
    memmove(bp[b_index]->data + off%BSIZE, src, m);
    b_index++;
  }

  if(n > 0 && off > ip->size){
    ip->size = off;
    log_iupdate(ip);
  }

  log_start();
  for(i = 0; i < b_index; i++){
    bwrite(bp[i]);
    brelse(bp[i]);
  }

  log_end();

  return n;

}
예제 #16
0
파일: log.c 프로젝트: narke/Einherjar.tmp
/** Log a message to the kernel log.
 * 
 * This atomically appends a log entry.
 * The resulting message should not contain a trailing newline, as the log
 * entries are explicitly delimited when stored in the log.
 */
int log(log_facility_t fac, log_level_t level, const char *fmt, ...)
{
	int ret;
	va_list args;
	
	log_begin(fac, level);
	
	va_start(args, fmt);
	ret = log_vprintf(fmt, args);
	va_end(args);
	
	log_end();
	
	return ret;
}
예제 #17
0
파일: Audio_Region.C 프로젝트: imv/non
/** finalize region capture. Assumes that this *is* a captured region
    and that no other regions refer to the same source */
bool
Audio_Region::finalize ( nframes_t frame )
{
    THREAD_ASSERT( Capture );

    DMESSAGE( "finalizing capture region" );

    _range.length = frame - _range.start;

    _clip->close();
    _clip->open();

    log_end();

    return true;
}
예제 #18
0
int main(int argc, char *argv[])
{
  BITMAP *bp;
  int i;

#ifdef MOVIE
  log_start(fopen("lines.log","w"));
#endif
  bp=bit_open(SCREEN_DEV);
  bit_blit(bp,0,0,BIT_WIDE(bp),BIT_HIGH(bp),BIT_CLR,(BITMAP*)0,0,0);
  srand(getpid()*time((time_t*)0));
  for (i=0; i<1000; i++)
  bit_line(bp,rand()%BIT_WIDE(bp),rand()%BIT_HIGH(bp),rand()%BIT_WIDE(bp),rand()%BIT_HIGH(bp),BIT_SET);
  bit_destroy(bp);
#ifdef MOVIE
  log_end();
#endif
  exit(0);
}
예제 #19
0
/**
 * Logs a string of known length
 *
 * @param sev  The severity
 * @param str  The pointer to the string
 * @param len  The length of the string from strlen(str)
 */
void log_str(log_sev_t sev, const char *str, int len)
{
   if ((str == NULL) || (len <= 0) || !log_sev_on(sev))
   {
      return;
   }

   size_t cap = log_start(sev);
   if (cap > 0)
   {
      if (len > (int)cap)
      {
         len = cap;
      }
      memcpy(&g_log.buf[g_log.buf_len], str, len);
      g_log.buf_len           += len;
      g_log.buf[g_log.buf_len] = 0;
   }
   log_end();
}
예제 #20
0
파일: socket.cpp 프로젝트: shuangMoz/b1ee
void ClientSocket::write_data (char *buffer, int len)
{
	log_start (LOG_CLIENTSOCKET, "ClientSocket::write_data (%d : %p) ", len, buffer);
	for (int index = 0; index < len; index ++)
	{
		log_continuation ("%02X", buffer[index]);
	}
	log_end ();

	if (write_buffer_size - write_buffer_len < len)
	{
		write_buffer_size = write_buffer_len + len;
		write_buffer = (char *) realloc (write_buffer, write_buffer_size);
	}

	memcpy (&write_buffer[write_buffer_len], buffer, len);
	write_buffer_len += len;

	write (ListenSocket::get_write_pipefd (), " ", 1);
}
예제 #21
0
void test_colors(Raster *r)
/*****************************************************************************
 *
 ****************************************************************************/
{
Rastlib 	*rlib = r->lib;
short		counter;
Vsyncfunc_t wait_vsync;
Colorfunc_t set_colors;
UBYTE		cmap[COLORS][CHANNELS];
int 		i,j;

	wait_vsync = rlib->wait_vsync;
	set_colors = rlib->set_colors;

	log_progress("Testing wait_vsync()...\n");
	counter = 30;
	while (--counter)
		wait_vsync(r);
	log_progress("...wait_vsync() testing complete.\n\n");

	log_start("Testing set_colors()...\n");

	for (j=0; j<CHANNELS; j++)
		{
		ramp_cmap(cmap, j);
		for (i=0; i<COLORS; i+=2)
			{
			wait_vsync(r);
			set_colors(r, 0, COLORS, cmap);
			cycle_cmap(cmap);
			}
		}

	log_end("...testing of set_colors() complete.\n\n");

	set_default_colors(r);

}
예제 #22
0
int DEFAULT_CC
main(int argc, char** argv)
{
	int fd;
	int error;
	int daemon = 1;
	int pid;
	char pid_s[8];
	char text[256];

	if(g_is_root() != 0){
		g_printf("Error, xrdp-sesman service must be start with root privilege\n");
		return 0;
	}


	g_snprintf(pid_file, 255, "%s/xrdp-sesman.pid", XRDP_PID_PATH);
	if (1 == argc)
	{
		/* no options on command line. normal startup */
		g_printf("starting sesman...");
		daemon = 1;
	}
	else if ((2 == argc) && ((0 == g_strcasecmp(argv[1], "--nodaemon")) ||
			(0 == g_strcasecmp(argv[1], "-n")) ||
			(0 == g_strcasecmp(argv[1], "-ns"))))
	{
		/* starts sesman not daemonized */
		g_printf("starting sesman in foregroud...");
		daemon = 0;
	}
	else if ((2 == argc) && ((0 == g_strcasecmp(argv[1], "--help")) ||
			(0 == g_strcasecmp(argv[1], "-h"))))
	{
		/* help screen */
		g_printf("sesman - xrdp session manager\n\n");
		g_printf("usage: sesman [command]\n\n");
		g_printf("command can be one of the following:\n");
		g_printf("-n, -ns, --nodaemon	starts sesman in foreground\n");
		g_printf("-k, --kill           kills running sesman\n");
		g_printf("-h, --help           shows this help\n");
		g_printf("if no command is specified, sesman is started in background");
		g_exit(0);
	}
	else if ((2 == argc) && ((0 == g_strcasecmp(argv[1], "--kill")) ||
			(0 == g_strcasecmp(argv[1], "-k"))))
	{
		/* killing running sesman */
		/* check if sesman is running */
		if (!g_file_exist(pid_file))
		{
			g_printf("sesman is not running (pid file not found - %s)\n", pid_file);
			g_exit(1);
		}

		fd = g_file_open(pid_file);

		if (-1 == fd)
		{
			g_printf("error opening pid file[%s]: %s\n", pid_file, g_get_strerror());
			return 1;
		}

		error = g_file_read(fd, pid_s, 7);
		if (-1 == error)
		{
			g_printf("error reading pid file: %s\n", g_get_strerror());
			g_file_close(fd);
			g_exit(error);
		}
		g_file_close(fd);
		pid = g_atoi(pid_s);

		error = g_sigterm(pid);
		if (0 != error)
		{
			g_printf("error killing sesman: %s\n", g_get_strerror());
		}
		else
		{
			g_file_delete(pid_file);
		}

		g_exit(error);
	}
	else
	{
		/* there's something strange on the command line */
		g_printf("sesman - xrdp session manager\n\n");
		g_printf("error: invalid command line\n");
		g_printf("usage: sesman [ --nodaemon | --kill | --help ]\n");
		g_exit(1);
	}

	if (g_file_exist(pid_file))
	{
		g_printf("sesman is already running.\n");
		g_printf("if it's not running, try removing ");
		g_printf(pid_file);
		g_printf("\n");
		g_exit(1);
	}

	/* reading config */
	g_cfg = g_malloc(sizeof(struct config_sesman), 1);
	if (0 == g_cfg)
	{
		g_printf("error creating config: quitting.\n");
		g_exit(1);
	}
	g_cfg->log.fd = -1; /* don't use logging before reading its config */
	if (0 != config_read(g_cfg))
	{
		g_printf("error reading config: %s\nquitting.\n", g_get_strerror());
		g_exit(1);
	}

	/* starting logging subsystem */
	error = log_start(&(g_cfg->log));

	if (error != LOG_STARTUP_OK)
	{
		switch (error)
		{
			case LOG_ERROR_MALLOC:
				g_printf("error on malloc. cannot start logging. quitting.\n");
				break;
			case LOG_ERROR_FILE_OPEN:
				g_printf("error opening log file [%s]. quitting.\n", g_cfg->log.log_file);
				break;
		}
		g_exit(1);
	}

	/* libscp initialization */
	scp_init(&(g_cfg->log));

	if (daemon)
	{
		/* start of daemonizing code */
		if (g_daemonize(pid_file) == 0)
		{
			g_writeln("problem daemonize");
			g_exit(1);
		}
	}

	/* initializing locks */
	lock_init();

	/* signal handling */
	g_pid = g_getpid();
	/* old style signal handling is now managed synchronously by a
	 * separate thread. uncomment this block if you need old style
	 * signal handling and comment out thread_sighandler_start()
	 * going back to old style for the time being
	 * problem with the sigaddset functions in sig.c - jts */
#if 1
	g_signal_hang_up(sig_sesman_reload_cfg); /* SIGHUP	*/
	g_signal_user_interrupt(sig_sesman_shutdown); /* SIGINT	*/
	g_signal_kill(sig_sesman_shutdown); /* SIGKILL */
	g_signal_terminate(sig_sesman_shutdown); /* SIGTERM */
//	g_signal_child_stop(sig_sesman_session_end); /* SIGCHLD */
#endif
#if 0
	thread_sighandler_start();
#endif

	/* start program main loop */
	log_message(&(g_cfg->log), LOG_LEVEL_INFO,
			"starting sesman with pid %d", g_pid);

	/* make sure the /tmp/.X11-unix directory exist */
	if (!g_directory_exist("/tmp/.X11-unix"))
	{
		g_create_dir("/tmp/.X11-unix");
		g_chmod_hex("/tmp/.X11-unix", 0x1777);
	}

	if (!g_directory_exist(XRDP_SOCKET_PATH))
	{
		g_create_dir(XRDP_SOCKET_PATH);
		g_chmod_hex(XRDP_SOCKET_PATH, 0x1777);
	}

	g_snprintf(text, 255, "xrdp_sesman_%8.8x_main_term", g_pid);
	g_term_event = g_create_wait_obj(text);
	g_snprintf(text, 255, "xrdp_sesman_%8.8x_main_sync", g_pid);
	g_sync_event = g_create_wait_obj(text);

	scp_init_mutex();
	tc_thread_create(admin_thread, 0);
	tc_thread_create(monit_thread, 0);
	sesman_main_loop();
	scp_remove_mutex();

	g_delete_wait_obj(g_term_event);
	g_delete_wait_obj(g_sync_event);

	if (!daemon)
	{
		log_end(&(g_cfg->log));
	}

	return 0;
}
예제 #23
0
/*
 * nodm - start X with autologin to a given user
 *
 * First, X is started as root, and nodm itself is used as the session.
 *
 * When run as the session, nodm performs a proper login to a given user and
 * starts the X session.
 */
int main (int argc, char **argv)
{
    static int opt_help = 0;
    static int opt_version = 0;
    static int opt_verbose = 0;
    static int opt_quiet = 0;
    static int opt_nested = 0;
    static int opt_log_syslog = -1; // -1 for 'default'
    static int opt_log_stderr = -1; // -1 for 'default'
    static struct option options[] =
    {
        /* These options set a flag. */
        {"help",    no_argument,       &opt_help, 1},
        {"version", no_argument,       &opt_version, 1},
        {"verbose", no_argument,       &opt_verbose, 1},
        {"quiet",   no_argument,       &opt_quiet, 1},
        {"nested",  no_argument,       &opt_nested, 1},
        {"syslog",  no_argument,       &opt_log_syslog, 1},
        {"stderr",  no_argument,       &opt_log_stderr, 1},
        {"no-syslog", no_argument,     &opt_log_syslog, 0},
        {"no-stderr", no_argument,     &opt_log_stderr, 0},
        {0, 0, 0, 0}
    };

    // Parse command line options
    while (1)
    {
        int option_index = 0;
        int c = getopt_long(argc, argv, ":", options, &option_index);
        if (c == -1) break;
        switch (c)
        {
            case 0: break;
            default:
                fprintf(stderr, "Invalid command line option\n");
                do_help(argc, argv, stderr);
                return E_USAGE;
        }
    }
    if (opt_help)
    {
        do_help(argc, argv, stdout);
        return E_SUCCESS;
    }
    if (opt_version)
    {
        printf("%s version %s\n", NAME, VERSION);
        return E_SUCCESS;
    }

    // We only run if we are root
    if (!opt_nested && getuid() != 0)
    {
        fprintf(stderr, "%s: can only be run by root\n", basename(argv[0]));
        return E_NOPERM;
    }

    // Setup logging
    struct log_config cfg = {
        .program_name = basename(argv[0]),
    };
    if (opt_quiet)
        cfg.log_level = NODM_LL_WARN;
    else if (opt_verbose)
        cfg.log_level = NODM_LL_VERB;
    else
        cfg.log_level = NODM_LL_INFO;
    if (opt_nested)
    {
        if (opt_log_syslog == -1) opt_log_syslog = 0;
        if (opt_log_stderr == -1) opt_log_stderr = 1;
    } else {
        if (opt_log_syslog == -1) opt_log_syslog = 1;
        if (opt_log_stderr == -1) opt_log_stderr = 0;
    }
    cfg.log_to_syslog = opt_log_syslog ? true : false;
    cfg.log_to_stderr = opt_log_stderr ? true : false;
    log_start(&cfg);

    log_info("starting nodm");

    // Setup the display manager
    struct nodm_display_manager dm;
    nodm_display_manager_init(&dm);

    // Choose the default X server
    const char* default_x_server = opt_nested ? "/usr/bin/Xnest :1" : "";

    // Parse X server command line
    int res = nodm_display_manager_parse_xcmdline(&dm,
            getenv_with_default("NODM_X_OPTIONS", default_x_server));
    if (res != E_SUCCESS) goto cleanup;

    if (opt_nested)
    {
        // For nested servers, disable PAM, user change, ~/.xsession-error
        // cleanup and VT allocation
        dm.session.conf_use_pam = false;
        dm.session.conf_cleanup_xse = false;
        dm.session.conf_run_as[0] = 0;
        dm.vt.conf_initial_vt = -1;
    }

    // Start the first session
    res = nodm_display_manager_start(&dm);
    if (res != E_SUCCESS) goto cleanup;

    // Enter the wait/restart loop
    res = nodm_display_manager_wait_restart_loop(&dm);
    if (res != E_SUCCESS) goto cleanup;

cleanup:
    nodm_display_manager_cleanup(&dm);
    log_end();
    return res;
}
예제 #24
0
int main (int argc, char* argv[])
{
	struct gps_location gl1 , gl2;
	struct gps_displacement gd;
	struct fatwrite_t fout;
	char logging_state = 0;
	char flag_reset = 0;

	gps_init_serial();
	lcd_init();
	camera_init();
	camera_sleep();
	lcd_printf("sd card:\nconnecting");
	char rt = mmc_init();
	if (rt) {
		lcd_printf("sd card: error\n");
		while (1) ;
	}
	
	init_partition(0);
	init_logtoggle();
	lcd_printf("GPS ...");

	gps_disable_unwanted();

	char in[64];
	int i, img_counter = 0;
	char c = 0;
	char loading_map[] = {'-', '\\', '|', '/'};
	const char * fpic;

	while (1) {

		// wait until valid location
		do {
			receive_str(in);
			gps_log_data(in , &gl1);
			lcd_printf("GPS Fixing %c\n", loading_map[(c++)&0x3]);
		} while (gl1.status != 'A');
	
		// got fix
		lcd_printf("Acquired Fix");

		// compute displacement
		while (1) {
			// read in gps data
			receive_str(in);
			if (flag_reset) {
				// reset waypoint
				gps_log_data(in, &gl1);
				flag_reset = 0;
			}
			i = gps_log_data(in , &gl2);
			
			// end log
			if (logging_state && !CHECK_LOGTOGGLE()) {
					logging_state = 0;
					lcd_printf("log: finishing..\n");
					log_end(&fout);
			}
		
			// check if we have a fix
			if (gl2.status != 'A') {
				lcd_printf("Lost GPS Fix %c\n", loading_map[(c++)&0x3]);
				continue;
			}
		
			// compute and display gps data
			gps_calc_disp(&gl1, &gl2, &gd);
			lcd_printf("I: %d\xb2 F: %d\xb2\nMg: %dm Sp: %d",
				(int)gd.initial_bearing,
				(int)gd.final_bearing,
				(int)gd.magnitude,
				(int)(1.15*gl2.sog + 0.5));
			
			// start / update logging
			if (logging_state) {
				// add to log
				fpic = gps_gen_name(img_counter++);
				camera_init();
				camera_takephoto(fpic, &fout);
				camera_sleep();
				log_add(&fout, &gl2, &gd, fpic);
			} else if (CHECK_LOGTOGGLE()) {
				// start logging
				logging_state = 1;
				flag_reset = 1;
				img_counter = 0;
				log_start(&fout);
			}
		}

	}
	
	return 0;
}
예제 #25
0
void test_rastxors(Raster *r)
/*****************************************************************************
 *
 ****************************************************************************/
{
Raster			*bmr = &tcb.bytemap_raster;
Raster			*vbr = &tcb.verification_raster;
Rastlib			*rlib = r->lib;
Coor			x;
Coor			y;
Pixel			color;
Ucoor			width;
Ucoor			height;
short			iteration_count;
short			iteration_limit;

	width = r->width;
	height = r->height;

	/*-----------------------------------------------------------------------
	 * xor_in_card testing...
	 *   if the driver didn't provide a routine, and we're not testing via
	 *   generics, skip the testing.
	 *---------------------------------------------------------------------*/
	
	if (is_generic(rlib,xor_rast[0]) && !tcb.test_via_generics)
		{
		log_bypass("xor_in_card(), xor_to_ram(), xor_from_ram()");
		goto XRAST_DONE;
		}

	/*------------------------------------------------------------------------
	 * xor_in_card testing..
	 *----------------------------------------------------------------------*/

	if (r == &tcb.display_raster)
		{
		log_progress("Testing bypassed for xor_in_card(), current raster is "
					 "primary display raster.\n\n");
		goto XRAST_IN_CARD_DONE;
		}

	iteration_limit = (tcb.timing_only_run) ? XRAST_TIME_ITCOUNT : 1;

	log_start("Testing xor_in_card()...\n");

	iteration_count = iteration_limit;
	clear_screen();
	while (iteration_count--)
		{
		}

	log_end("...xor_in_card() testing complete.\n\n");

	if (!single_step())
		return;

XRAST_IN_CARD_DONE:

	/*------------------------------------------------------------------------
	 * xor_to_ram testing..
	 *----------------------------------------------------------------------*/

	iteration_limit = (tcb.timing_only_run) ? XRAST_TIME_ITCOUNT : 1;

	log_start("Testing xor_to_ram()...\n");

	iteration_count = iteration_limit;

	pj_set_rast(r,   0);
	pj_set_rast(bmr, 0);
	pj_set_rast(vbr, 0);

	rlib->wait_vsync(r);
	while (iteration_count--)
		{
		color = iteration_count + 1;
		for (x = 0; x < width; x += 2*(WPAT/3))
			pj_set_rect(bmr, color, x, 0, WPAT/3, height);
		for (y = 0; y < height; y += 2*(HPAT/3))
			pj_set_rect(r, ~color, 0, y, width, HPAT/3);
		time_it(
			pj_xor_rast(r, bmr);
			);
		}
예제 #26
0
void test_segs(Raster *r)
/*****************************************************************************
 * test put_hseg, get_hseg, put_vseg, get_vseg.
 ****************************************************************************/
{
short		iteration_count;
short		iteration_limit;
short		do_verify;
Raster		*bmr	= &tcb.bytemap_raster;
Rastlib 	*rlib	= r->lib;
PLANEPTR	pixbuf;
Coor		x;
Coor		y;
Coor		seg1;
Coor		seg2;
Coor		seg3;
Coor		step;
Ucoor		width;
Ucoor		height;
Segfunc_t	put_hseg;
Segfunc_t	get_hseg;
Segfunc_t	put_vseg;
Segfunc_t	get_vseg;

	width  = r->width - 1;
	height = r->height - 1;
	do_verify = !tcb.timing_only_run;

	/*-----------------------------------------------------------------------
	 * hseg testing...
	 *	 if the driver didn't provide a routine, and we're not testing via
	 *	 generics, skip the hseg testing.
	 *---------------------------------------------------------------------*/

	if (is_generic(rlib,put_hseg) && !tcb.test_via_generics)
		{
		log_bypass("put_hseg() and get_hseg()");
		goto HSEG_DONE;
		}

	put_hseg = rlib->put_hseg;
	get_hseg = rlib->get_hseg;

	/*-----------------------------------------------------------------------
	 * test put_hseg using short segments...
	 *---------------------------------------------------------------------*/

	clear_screen();

	step = 1 + height / 8;
	seg1 = 0;
	seg2 = (width / 2) - (SHRTSEG_WIDTH / 2);
	seg3 = width - SHRTSEG_WIDTH;

	pixbuf = bmr->hw.bm.bp[0];

	iteration_limit = (tcb.timing_only_run) ? HSSEG_TIME_ITCOUNT : 1;

	log_start("Testing put_hseg() using short line segments...\n");

	iteration_count = iteration_limit;
	while (iteration_count--)
		{
		make_ripple(bmr, SHRTSEG_WIDTH, 1, 0, 0, iteration_count, 1);
		time_start();
		for (y = 0; y < height; y += step)
			{
			put_hseg(r, pixbuf, seg1, y, SHRTSEG_WIDTH);
			put_hseg(r, pixbuf, seg2, y, SHRTSEG_WIDTH);
			put_hseg(r, pixbuf, seg3, y, SHRTSEG_WIDTH);
			}

		y = height;
		put_hseg(r, pixbuf, seg1, y, SHRTSEG_WIDTH);
		put_hseg(r, pixbuf, seg2, y, SHRTSEG_WIDTH);
		put_hseg(r, pixbuf, seg3, y, SHRTSEG_WIDTH);
		time_end();
		}
	log_end("...put_hseg() short segment testing completed.\n\n");

	/*-----------------------------------------------------------------------
	 * test get_hseg using short segments...
	 *---------------------------------------------------------------------*/

	log_start("Testing get_hseg() using short line segments...\n");

	iteration_count = iteration_limit;
	while (iteration_count--)
		{
		time_start();
		for (y = 0; y < height; y += step)
			{
			memset(pixbuf, 0, SHRTSEG_WIDTH);
			memset(pixbuf, 0, SHRTSEG_WIDTH);
			get_hseg(r, pixbuf, seg1, y, SHRTSEG_WIDTH);
			if (do_verify && !verify_ripple(bmr, SHRTSEG_WIDTH, 1, 0, 0, iteration_count, 1))
				{
				x = seg1;
				goto HSEG_ERROR;
				}
			memset(pixbuf, 0, SHRTSEG_WIDTH);
			get_hseg(r, pixbuf, seg2, y, SHRTSEG_WIDTH);
			if (do_verify && !verify_ripple(bmr, SHRTSEG_WIDTH, 1, 0, 0, iteration_count, 1))
				{
				x = seg2;
				goto HSEG_ERROR;
				}
			memset(pixbuf, 0, SHRTSEG_WIDTH);
			get_hseg(r, pixbuf, seg3, y, SHRTSEG_WIDTH);
			if (do_verify && !verify_ripple(bmr, SHRTSEG_WIDTH, 1, 0, 0, iteration_count, 1))
				{
				x = seg3;
				goto HSEG_ERROR;
				}
			}

		 y = height;
		 memset(pixbuf, 0, SHRTSEG_WIDTH);
		 get_hseg(r, pixbuf, seg1, y, SHRTSEG_WIDTH);
		 if (do_verify && !verify_ripple(bmr, SHRTSEG_WIDTH, 1, 0, 0, iteration_count, 1))
			 {
			 x = seg1;
			 goto HSEG_ERROR;
			 }
		 memset(pixbuf, 0, SHRTSEG_WIDTH);
		 get_hseg(r, pixbuf, seg2, y, SHRTSEG_WIDTH);
		 if (do_verify && !verify_ripple(bmr, SHRTSEG_WIDTH, 1, 0, 0, iteration_count, 1))
			 {
			 x = seg2;
			 goto HSEG_ERROR;
			 }
		 memset(pixbuf, 0, SHRTSEG_WIDTH);
		 get_hseg(r, pixbuf, seg3, y, SHRTSEG_WIDTH);
		 if (do_verify && !verify_ripple(bmr, SHRTSEG_WIDTH, 1, 0, 0, iteration_count, 1))
			 {
			 x = seg3;
			 goto HSEG_ERROR;
			 }
		 time_end();
		}

	log_end("...get_hseg() short segment testing completed.\n\n");

	if (!single_step())
		return;

	/*-----------------------------------------------------------------------
	 * test put_hseg using full-line segments...
	 *---------------------------------------------------------------------*/

	pixbuf = bmr->hw.bm.bp[0];
	x = 0;
	iteration_limit = (tcb.timing_only_run) ? HFSEG_TIME_ITCOUNT : 1;

	log_start("Testing put_hseg() using full-line segments...\n");

	iteration_count = iteration_limit;
	while (iteration_count--)
		{
		make_ripple(bmr, width, 1, 0, 0, iteration_count, 1);
		time_start();
		for (y = 0; y < height; y += step)
			{
			put_hseg(r, pixbuf, x, y, width);
			}
		put_hseg(r, pixbuf, x, height, width);
		time_end();
		}

	log_end("...put_hseg() full-line segment testing completed.\n\n");

	/*-----------------------------------------------------------------------
	 * test get_hseg using full-line segments...
	 *---------------------------------------------------------------------*/

	log_start("Testing get_hseg() using full-line segments...\n");

	iteration_count = iteration_limit;
	while (iteration_count--)
		{
		for (y = 0; y < height; y += step)
			{
			memset(pixbuf, 0, width);
			time_it(
				get_hseg(r, pixbuf, x, y, width);
				);
			if (do_verify && !verify_ripple(bmr, width, 1, 0, 0, iteration_count, 1))
				goto HSEG_ERROR;
			}
		memset(pixbuf, 0, width);
		memset(pixbuf, 0, width);
		time_it(
			get_hseg(r, pixbuf, x, height, width);
			);
예제 #27
0
void test_rastblits(Raster *r)
/*****************************************************************************
 *
 ****************************************************************************/
{
Raster			*bmr = &tcb.bytemap_raster;
Raster			*vbr = &tcb.verification_raster;
Rastlib			*rlib = r->lib;
Coor			x;
Ucoor			width;
Ucoor			height;
short			iteration_count;
short			iteration_limit;

	width = r->width;
	height = r->height;

	/*-----------------------------------------------------------------------
	 * blit_in_card testing...
	 *   if the driver didn't provide a routine, and we're not testing via
	 *   generics, skip the testing.
	 *---------------------------------------------------------------------*/
	
	if (is_generic(rlib,blitrect[0]) && !tcb.test_via_generics)
		{
		log_bypass("blit_in_card(), blit_to_ram(), blit_from_ram()");
		goto RBLIT_DONE;
		}

	/*------------------------------------------------------------------------
	 * blit_in_card testing..
	 *  clear the screen, then lay in a striped background before testing
	 *----------------------------------------------------------------------*/

	iteration_limit = (tcb.timing_only_run) ? RBLIT_TIME_ITCOUNT : 1;

	log_start("Testing blit_in_card()...\n");

	iteration_count = iteration_limit;

	pj_set_rast(r,  0);
	pj_set_rast(vbr,0);
	for (x = 0; x+WPAT/3 <= width; x += 2*(WPAT/3))
		{
		pj_set_rect(r,   1, x, 0, WPAT/3, height);
		pj_set_rect(vbr, 1, x, 0, WPAT/3, height);
		}

	rlib->wait_vsync(r);
	while (iteration_count--)
		{
		draw_blitpattern(r, iteration_count, 0);
		time_start();
		do_blits(r, r);
		time_end();
		}

	draw_blitpattern(vbr, 0, 0);
	do_blits(vbr, vbr);
	verify_raster(r, vbr, TRUE);

	log_end("...blit_in_card() testing complete.\n\n");

	if (!single_step())
		goto RBLIT_DONE;

	/*------------------------------------------------------------------------
	 * blit_to_ram testing..
	 *  clear the screen, lay in a striped background, blit background to ram
	 *----------------------------------------------------------------------*/

	iteration_limit = (tcb.timing_only_run) ? RBLIT_TIME_ITCOUNT : 1;

	log_start("Testing blit_to_ram()...\n");

	iteration_count = iteration_limit;

	pj_set_rast(r,   0);
	pj_set_rast(bmr, 0);
	pj_set_rast(vbr, 0);
	for (x = 0; x+WPAT/3 <= width; x += 2*(WPAT/3))
		{
		pj_set_rect(bmr, 1, x, 0, WPAT/3, height);
		pj_set_rect(vbr, 1, x, 0, WPAT/3, height);
		}

	rlib->wait_vsync(r);
	while (iteration_count--)
		{
		draw_blitpattern(r, iteration_count, 0);
		time_start();
		do_blits(r, bmr);
		time_end();
		}

	draw_blitpattern(vbr, 0, 0);
	do_blits(vbr, vbr);
	verify_raster(bmr, vbr, TRUE);

	log_end("...blit_to_ram() testing complete.\n\n");

	if (!single_step())
		goto RBLIT_DONE;

	/*------------------------------------------------------------------------
	 * blit_from_ram testing..
	 *  clear the screen, lay in a striped background
	 *----------------------------------------------------------------------*/

	iteration_limit = (tcb.timing_only_run) ? RBLIT_TIME_ITCOUNT : 1;

	log_start("Testing blit_from_ram()...\n");

	iteration_count = iteration_limit;

	pj_set_rast(r,   0);
	pj_set_rast(bmr, 0);
	pj_set_rast(vbr, 0);
	for (x = 0; x+WPAT/3 <= width; x += 2*(WPAT/3))
		{
		pj_set_rect(r,   1, x, 0, WPAT/3, height);
		pj_set_rect(vbr, 1, x, 0, WPAT/3, height);
		}

	rlib->wait_vsync(r);
	while (iteration_count--)
		{
		draw_blitpattern(bmr, iteration_count, 0);
		time_start();
		do_blits(bmr, r);
		time_end();
		}

	draw_blitpattern(vbr, 0, 0);
	do_blits(vbr, vbr);
	verify_raster(r, vbr, TRUE);

	log_end("...blit_from_ram() testing complete.\n\n");

	single_step();

RBLIT_DONE:

	return;
}
예제 #28
0
void logmsg(const char* tagstr, const char* msg)
{
  log_start(tagstr);
  log_str(msg);
  log_end();
}
예제 #29
0
void respond_end(void)
{
  log_end();
  if (!obuf_putsflush(&outbuf, CRLF))
    exit(1);
}
예제 #30
0
void toc_extract( WINDOW * win )
{
  static const char * ext[] = { "avr", "raw", "raw", "wav" };
  char pathname[ 256 ];
  char prog_info[ 64 ];
  char buf[ 128 ];
  struct avr_header * avrh;
  struct wave_header * wavh;
  struct audio_entry entry;
  struct audio_stream * as;
  struct _toc_data * data;
  struct device_info * info;
  OBJECT * ck;
  int format, i, max, track_no;
  int fd, swap;
  long offset, length, position, end, progress, total_length;
  long max_buf_blocks, nblocks;
  void * buffer;

  if( !fileselect( preferences.toc_dest, "", "TXT_EXTDEST" ) )
    return;
  strrchr( preferences.toc_dest, '\\' )[1] = '\0';

  data = DataSearch( win, TW_MAGIC );
  max = data->n_tracks;
  format = fmt_popup.selected;
  total_length = 0;
  buffer = alloc_comm_buffer( BUFSIZE );
  if( !buffer )
    return;
  for( i = 0; i < max; i++ )
  {
    ck = data->tree + 1 + TF_CK + i * data->n_obj;
    if( ! (ck->ob_state & SELECTED) )
      continue;
    offset = toc_address( data->f[i].beg_time );
    length = toc_address( data->f[i].end_time ) + 1 - offset;
    if( length > 0 )
      total_length += length;
  }
  max_buf_blocks = BUFSIZE / 2352;

  progress = 0;
  progress_init( get_string( "TXT_EXTMSG" ), total_length );
  progress_activate_cancel( 1 );
  progress_init_timer();

  log_begin();
  log_printf( "*** Begin of a track extraction session\n\n" );
  as = NULL;
  for( i = 0; i < max; i++ )
  {
    ck = data->tree + 1 + TF_CK + i * data->n_obj;
    if( ! (ck->ob_state & SELECTED) )
      continue;
    offset = toc_address( data->f[i].beg_time );
    length = toc_address( data->f[i].end_time ) + 1 - offset;
    if( length <= 0 )
      continue;
    track_no = i + 1;
    position = get_track_offset( &data->toc, track_no, &end );
    if( toc_popup.selected == 0 )
      gen_daoimg_entry( &entry, toc_info.toc_file, track_no,
                        offset - position, end - offset - length );
    else
    {
      info = (struct device_info*)toc_popup.item[toc_popup.selected].info;
      gen_cd_entry( &entry, info, track_no, offset - position, end - offset - length );
    }
    if( as )
      as = audio_reopen( as, &entry );
    else
      as = audio_open( &entry );
    if( as == NULL )
      continue;

    sprintf( prog_info, get_string( "TXT_EXTTRK" ), track_no );
    progress_setinfo( prog_info );

    sprintf( pathname, "%strack%02d.%s", preferences.toc_dest, track_no, ext[ format ] );
    fd = open( pathname, O_WRONLY|O_CREAT|O_TRUNC );
    if( fd == -1 )
    {
      audio_close( as );
      alert_msg( "AL_FILERR", 1, pathname );
      goto error;
    }
    switch( format )
    {
    case 0:        /* AVR */
      avrh = (struct avr_header *) buf;
      avrh->avr_id = '2BIT';
      memset( avrh->name, 0, 8 );
      avrh->num_voices = 0xFFFF;
      avrh->num_bits = 16;
      avrh->signe = 0xffff;
      avrh->loop = 0;
      avrh->midi = 0xffff;
      avrh->freq_type.frequence = 0xff00ac44L;
      avrh->length = length * (2352 / 2);
      avrh->beg_loop = 0;
      avrh->end_loop = avrh->length;
      memset( avrh->reserved, 0, 26 + 64 );
      write( fd, avrh, sizeof( *avrh ) );
      swap = as->little_endian;
      break;
    case 1:        /* RAW big-endian */
      swap = as->little_endian;
      break;
    case 2:        /* RAW little-endian */
      swap = !as->little_endian;
      break;
    case 3:        /* WAVE */
      wavh = (struct wave_header *) buf;
      wavh->riff_id = 'RIFF';
      wavh->riff_len = swap_long( length * 2352 + 36 );
      wavh->wave_id = 'WAVE';
      wavh->fmt_id = 'fmt ';
      wavh->fmt_size = 0x10000000L;
      wavh->fmt_compression_code = 0x0100;
      wavh->fmt_channels = 0x0200;
      wavh->fmt_freq = 0x44ac0000L;
      wavh->fmt_bytes_sec = 0x10b10200L;
      wavh->fmt_block_align = 0x0400;
      wavh->fmt_num_bits = 0x1000;
      wavh->data_id = 'data';
      wavh->data_size = swap_long( length * 2352 );
      write( fd, wavh, sizeof( *wavh ) );
      swap = !as->little_endian;
      break;
    }
    while( length > 0 )
    {
      if( yield() )
      {
        audio_close( as );
        alert_msg( "AL_EXTINT", 1 );
        goto error;
      }
      nblocks = MIN( length, max_buf_blocks );
      if( audio_read( as, buffer, nblocks ) == 0 )
      {
        audio_close( as );
        goto error;
      }
      if( swap )
        swap_endian( buffer, nblocks * 2352 );
      if( write( fd, buffer, nblocks * 2352 ) == -1 )
      {
        close( fd );
        audio_close( as );
        alert_msg( "AL_FWRTERR", 1, pathname );
        goto error;
      }
      length -= nblocks;
      progress += nblocks;
      progress_setcount( progress );
    }
    close( fd );
  }
  audio_close( as );
error:
  log_printf( "*** End of the track extraction session\n\n" );
  log_end();
  progress_exit();
  free_comm_buffer( buffer );

}