Ejemplo n.º 1
0
/*
 * Function     : signal_handler
 * Description  : signal handler
 * Input params : pointer to ath_ssd_info_t
 * Return       : void
 *
 */
void signal_handler(int signal)
{
    switch (signal) {
        case SIGHUP:
        case SIGTERM:
        case SIGCHLD:
        case SIGINT:
            cleanup(pinfo);
            break;
        case SIGALRM:
            alarm_handler(pinfo);
            break;
    }
}
Ejemplo n.º 2
0
static int bench_cpu(int argc, char **argv) {
	ull noop_index = 0;

	parse_opts(argc, argv);

	if(end_time == ~0 && end_number == ~0) {
		bzero(error_msg, strlen(error_msg));
		sprintf(error_msg, "No options specified\nTerminating program due to infinite loop!\n");
		panic();
	}

	ull malloc_size;
	if(end_number != ~0)
		malloc_size = sizeof(ull) * (end_number / 2);
	else
		malloc_size = sizeof(ull) * 10 * 1024;	//Allocate 10K

	primes = malloc(malloc_size);
	bzero(primes, malloc_size);

	append(primes, 2);
	signal(SIGALRM, alarm_handler);


	setitimer(ITIMER_REAL, &timeout_timer, 0);
	start_time = rdclock();

	while(1) {
		is_prime(current_number);
		if(current_number == end_number)
			break;

		current_number++;
	}

	alarm_handler(SIGALRM);
}
Ejemplo n.º 3
0
/*
 ***************************************************************************
 * Main entry to the cifsiostat program.
 ***************************************************************************
 */
int main(int argc, char **argv)
{
	int it = 0;
	int opt = 1;
	int i;
	long count = 1;
	struct utsname header;
	struct tm rectime;

#ifdef USE_NLS
	/* Init National Language Support */
	init_nls();
#endif

	/* Get HZ */
	get_HZ();

	/* Process args... */
	while (opt < argc) {

#ifdef DEBUG
		if (!strcmp(argv[opt], "--debuginfo")) {
			flags |= I_D_DEBUG;
			opt++;
		} else
#endif
		if (!strncmp(argv[opt], "-", 1)) {
			for (i = 1; *(argv[opt] + i); i++) {

				switch (*(argv[opt] + i)) {

				case 'h':
					/* Display an easy-to-read CIFS report */
					flags |= I_D_HUMAN_READ;
					break;
	
				case 'k':
					if (DISPLAY_MEGABYTES(flags)) {
						usage(argv[0]);
					}
					/* Display stats in kB/s */
					flags |= I_D_KILOBYTES;
					break;

				case 'm':
					if (DISPLAY_KILOBYTES(flags)) {
						usage(argv[0]);
					}
					/* Display stats in MB/s */
					flags |= I_D_MEGABYTES;
					break;

				case 't':
					/* Display timestamp */
					flags |= I_D_TIMESTAMP;
					break;

				case 'V':
					/* Print version number and exit */
					print_version();
					break;
	
				default:
					usage(argv[0]);
				}
			}
			opt++;
		}

		else if (!it) {
			interval = atol(argv[opt++]);
			if (interval < 0) {
				usage(argv[0]);
			}
			count = -1;
			it = 1;
		}

		else if (it > 0) {
			count = atol(argv[opt++]);
			if ((count < 1) || !interval) {
				usage(argv[0]);
			}
			it = -1;
		}
		else {
			usage(argv[0]);
		}
	}

	if (!interval) {
		count = 1;
	}

	/* Init structures according to machine architecture */
	io_sys_init();

	get_localtime(&rectime);

	/* Get system name, release number and hostname */
	uname(&header);
	if (print_gal_header(&rectime, header.sysname, header.release,
			     header.nodename, header.machine, cpu_nr)) {
		flags |= I_D_ISO;
	}
	printf("\n");

	/* Set a handler for SIGALRM */
	alarm_handler(0);

	/* Main loop */
	rw_io_stat_loop(count, &rectime);

	/* Free structures */
	io_sys_free();

	return 0;
}
Ejemplo n.º 4
0
void alarm_handler0(int severity, char *text)
{
  alarm_handler(severity, "%s", text);
}
Ejemplo n.º 5
0
/*
 * The main function.
 */
int main(int argc, char *argv[]) {
	int ret = 0, it = 0, opt = 1;
	int i, j = 0;
	long count = 1;
	unsigned int flags;
	char* t;
	cg_group* group = NULL;
	/* Get HZ */
	get_HZ();
	/* parse arguments */
	while (opt < argc) {
		if (!strcmp(argv[opt], "-g")) {
			flags |= I_D_GROUP;
			if (argv[++opt] && (strspn(argv[opt], DIGITS) != strlen(argv[opt]))
					&& (strncmp(argv[opt], "-", 1))) {

				for (t = strtok(argv[opt], ","); t; t = strtok(NULL, ",")) {
					/* Store device name */
					strncpy(group_name[j++], t, strlen(t));
				}
				opt++;
			} else {
				flags |= I_D_ALL;
			}
		} else if (!strncmp(argv[opt], "-", 1)) {
			for (i = 1; *(argv[opt] + i); i++) {
				switch (*(argv[opt] + i)) {
				case 'h':
					usage(0, argv[0]);
					ret = 0;
					goto err;
				case 'a':
					flags |= I_D_ACTIVE;
					break;
				case 'b':
					flags |= I_D_BYTES;
					break;
				case 'k':
					flags |= I_D_KILOBYTES;
					break;
				case 'm':
					flags |= I_D_MEGABYTES;
					break;
				case 'n':
					flags |= I_D_UNHEADER;
				case 'G':
					flags |= I_D_GIGABYTES;
					break;
				case 'V':
					show_version();
					return 0;
				default:
					usage(1, argv[0]);
					ret = 1;
					goto err;
				}
			}
			opt++;
		} else if (!isdigit(argv[opt][0])) {
			if (strcmp(argv[opt], K_ALL)) {
				/* Store device name */
				strncpy(group_name[j++], argv[opt], strlen(argv[opt]));
				opt++;
			} else {
				opt++;
			}
		} else if (!it) {
			interval = atol(argv[opt++]);
			if (interval < 0) {
				usage(1, argv[0]);
			}
			count = -1;
			it = 1;
		} else if (it > 0) {
			count = atol(argv[opt++]);
			if ((count < 1) || !interval) {
				usage(1, argv[0]);
			}
			it = -1;
		} else {
			usage(1, argv[0]);
		}
	}

	if (!interval) {
		count = 1;
	}
	/* Set a handler for SIGALRM */
	alarm_handler(0);

	if (init_stats()) {
		fprintf(stderr, "cgvmstat: initialize the stats failed.\n");
		printf("error: Initialize the stats failed.\n");
		goto err;
	}
	/** Read all of the groups from CPUSET.*/
	if (read_all_groups(mem_groups, CG_MEMORY)) {
		fprintf(stderr, "cgvmstat: read all of the groups in %s failed.\n",
				CG_CPUSET);
		printf("error: Read all of the groups in %s failed.\n", CG_CPUSET);
		goto err;
	}
	/** If no group to display, then display all of the group statistics information.*/
	if (!j && mem_groups && !TAILQ_EMPTY(mem_groups))
		TAILQ_FOREACH(group, mem_groups,next)
			strncpy(group_name[j++], group->name, strlen(group->name));
	/* Main loop */
	if (j)
		rw_stats_loop(count, flags, j);

	err: uninit_stats();
	return ret;
}
Ejemplo n.º 6
0
static void quit_handler(int signum){
	alarm_handler(signum);
	please_quit = 1;	
}
Ejemplo n.º 7
0
int
main (int argc, char *argv[])
{
  int numbytes;
  static char buf[MAXBUFLEN];
  //int c;
  //int ret = 0;

	prog = strdup( base_name(argv[0]) );
  
	/* program header */
	std::cout << prog << " - a communication radio based on VoIP with IAX/Asterisk" << std::endl;
	std::cout << "Original (c) 2007-2011 by H. Wirtz <*****@*****.**>" << std::endl;
    std::cout << "OSX and Windows ports 2012 by Yves Sablonier and Geoff R. McLane, respectively." << std::endl;
	std::cout << "Version " << FGCOM_VERSION << " build " << SVN_REV << " date " << __DATE__ << ", at " << __TIME__ << std::endl;
	std::cout << "Using iaxclient library Version " << iaxc_version (tmp) << std::endl;
	std::cout << std::endl;

  /* init values */
  voipserver = DEFAULT_VOIP_SERVER;
  fgserver = DEFAULT_FG_SERVER;
  port = DEFAULT_FG_PORT;
  username = DEFAULT_USER;
  password = DEFAULT_PASSWORD;
  codec_option = DEFAULT_CODEC;
  mode = 0;			/* 0 = ATC mode, 1 = FG mode */
  positions_file = (char *) DEFAULT_POSITIONS_FILE;
  frequency_file = (char *) SPECIAL_FREQUENCIES_FILE;

#ifndef _WIN32
  /* catch signals */
  signal (SIGINT, quit);
  signal (SIGQUIT, quit);
  signal (SIGTERM, quit);
#endif

  /* setup iax */
#ifdef HAVE_IAX12
  if (iaxc_initialize (DEFAULT_MAX_CALLS))
#else
  if (iaxc_initialize (DEFAULT_IAX_AUDIO, DEFAULT_MAX_CALLS))
#endif
    fatal_error ("cannot initialize iaxclient!\nHINT: Have you checked the mic and speakers?");

  initialized = 1;

  // option parser
  fgcomInitOptions (fgcomOptionArray, argc, argv);

  // codec
  if (codec_option)
    {
      switch (codec_option)
	{
	case 'u':
	  codec = IAXC_FORMAT_ULAW;
	  break;
	case 'a':
	  codec = IAXC_FORMAT_ALAW;
	  break;
	case 'g':
	  codec = IAXC_FORMAT_GSM;
	  break;
	case '7':
	  codec = IAXC_FORMAT_G726;
	  break;
	case 's':
	  codec = IAXC_FORMAT_SPEEX;
	  break;
	}
    }

  // airport
  if (airport_option)
    {
      strtoupper (airport_option, airport, sizeof (airport));
    }

  // input level
  if (level_in > 1.0)
    {
      level_in = 1.0;
    }
  if (level_in < 0.0)
    {
      level_in = 0.0;
    }

  // output level
  if (level_out > 1.0)
    {
      level_out = 1.0;
    }
  if (level_out < 0.0)
    {
      level_out = 0.0;
    }

  // microphone boost
  if (mic_boost)
    {
      iaxc_mic_boost_set (1);
    }

  if (list_audio)
    {
      std::cout << "Input audio devices:" << std::endl;
      std::cout << report_devices (IAXC_AD_INPUT) << std::endl;

      std::cout << "Output audio devices:" << std::endl;
      std::cout << report_devices (IAXC_AD_OUTPUT) << std::endl;

      iaxc_shutdown ();
      exit (1);
    }


  if (audio_in)
    {
      set_device (audio_in, 0);
    }

  if (audio_out)
    {
      set_device (audio_out, 1);
    }

//#ifdef DEBUG
  /* Print any remaining command line arguments (not options). */
  //if (optind < argc) {
  //      printf ("non-option ARGV-elements: ");
  //      while (optind < argc)
  //              printf ("%s ", argv[optind++]);
  //      putchar ('\n');
  //}
//#endif

  /* checking consistency of arguments */
  if (frequency > 0.0 && frequency < 1000.0)
    {
      if (strlen (airport) == 0 || strlen (airport) > 4)
	{
	  strcpy (airport, "ZZZZ");
	}
      /* airport and frequency are given => ATC mode */
      mode = 0;
    }
  else
    {
      /* no airport => FG mode */
      mode = 1;
    }

	/* Read special frequencies file (if exists).
	 * If no file $(INSTALL_DIR)/special_frequencies.txt exists, then default frequencies
	 * are used and are hard coded.
	 */

    if (fix_input_files()) { /* adjust default input per OS */
        fatal_error ("cannot adjust default input files per OS!\nHINT: Maybe recompile with larger buffer.");
    }

	if((special_frequencies = read_special_frequencies(frequency_file)) == 0) {
        std::cout << "Failed to load file [" << frequency_file << "]!\nUsing internal defaults." << std::endl;
        special_frequencies = special_frq;
    } else {
        std::cout << "Loaded file [" << frequency_file << "]." << std::endl;
    }

	/* read airport frequencies and positions */
	airportlist = read_airports (positions_file);   /* never returns if fail! */

  /* preconfigure iax */
  std::cout << "Initializing IAX client as " << username << ":" <<
    "xxxxxxxxxxx@" << voipserver << std::endl;

  iaxc_set_callerid (const_cast < char *>(username),
		     const_cast < char *>("0125252525122750"));
  iaxc_set_formats (codec,
		    IAXC_FORMAT_ULAW | IAXC_FORMAT_GSM | IAXC_FORMAT_SPEEX);
  iaxc_set_event_callback (iaxc_callback);

  iaxc_start_processing_thread ();

  if (username && password && voipserver)
    {
      reg_id =
	iaxc_register (const_cast < char *>(username),
		       const_cast < char *>(password),
		       const_cast < char *>(voipserver));
#ifdef DEBUG
      std::cout << "DEBUG: Registered as '" << username << "' at '" << voipserver <<
	"'." << std::endl;
#endif
    }
  else
    {
      std::cout << "Failed iaxc_register!\nHINT: Check user name, pwd and ip of server." << std::endl;
      exitcode = 130;
      quit (0);
    }

  iaxc_millisleep (DEFAULT_MILLISLEEP);

  /* main loop */
#ifdef DEBUG
  std::cout << "Entering main loop in mode " << mode_map[mode] << "." <<
    std::endl;
#endif

  if (mode == 1)
    {
      /* only in FG mode */
      netInit ();
      netSocket fgsocket;
      fgsocket.open (false);
      fgsocket.bind (fgserver, port);

      /* mute mic, speaker on */
      iaxc_input_level_set (0);
      iaxc_output_level_set (level_out);

      ulClock clock;
      clock.update ();
      double next_update = clock.getAbsTime () + DEFAULT_ALARM_TIMER;
      /* get data from flightgear */
      while (1)
	{
	  clock.update ();
	  double wait = next_update - clock.getAbsTime ();
	  if (wait > 0.001)
	    {
	      netSocket *readsockets[2] = { &fgsocket, 0 };
	      if (fgsocket.select (readsockets, readsockets + 1,
				   (int) (wait * 1000)) == 1)
		{
		  netAddress their_addr;
		  if ((numbytes =
		       fgsocket.recvfrom (buf, MAXBUFLEN - 1, 0,
					  &their_addr)) == -1)
		    {
		      perror ("recvfrom");
		      exit (1);
		    }
		  buf[numbytes] = '\0';
#ifdef DEBUG
		  std::
		    cout << "DEBUG: got packet from " << their_addr.getHost () << ":"
		    << their_addr.getPort () << std::endl;
		  std::cout << "packet is " << numbytes << " bytes long" <<
		    std::endl;
		  std::
		    cout << "packet contains \"" << buf << "\"" << std::endl;
#endif
		  process_packet (buf);
		}
	    }
	  else
	    {
	      alarm_handler (0);
	      clock.update ();
	      next_update = clock.getAbsTime () + DEFAULT_ALARM_TIMER;
	    }
	}
    }
  else
    {
      /* only in ATC mode */
      struct pos p;

      /* mic on, speaker on */
      iaxc_input_level_set (level_in);
      iaxc_output_level_set (level_out);

      /* get geo positions of the airport */
      p = posbyicao (airportlist, airport);

      icao2number (airport, frequency, tmp);
#ifdef DEBUG
      printf ("DEBUG: dialing %s %3.3f MHz: %s\n", airport, frequency, tmp);
#endif
      do_iaxc_call (username, password, voipserver, tmp);
      /* iaxc_select_call (0); */

      while (1)
	{
	  /* sleep endless */
	  ulSleep (3600);
	}
    }

  /* should never be reached */
  exitcode = 999;
  quit (0);
}