Ejemplo n.º 1
0
int main(int argc, char *argv[])
{
	int err;

	if (argc > 2) {
		show_usage(argv[0]);
		exit(-1);
	}

	if (argc == 2)
		test_duration = atoi(argv[1]);

	setup_handlers();

	printf("faulting for %u seconds . . .\n", test_duration);

	err = alarm(test_duration);
	assert(err == 0);

	err = clock_gettime(CLOCK_REALTIME, &time_start);
	assert(err == 0);

	do_faults();

	/* should never reach here */

	return EXIT_FAILURE;
}
Ejemplo n.º 2
0
int main(int argc, char *argv[])
{
    int ret = 0;

    setup_handlers();

    if (ws2811_init(&ledstring))
    {
        return -1;
    }

    while (1)
    {
        matrix_raise();
        matrix_bottom();
        matrix_render();

        if (ws2811_render(&ledstring))
        {
            ret = -1;
            break;
        }

        // 15 frames /sec
        usleep(1000000 / 15);
    }

    ws2811_fini(&ledstring);

    return ret;
}
Ejemplo n.º 3
0
int main(int argc, char* argv[]){
  if(argc < 2){
    printf("Not enough input arguments!\n");
    printf("Usage: %s filename\n", argv[0]);
    return -1;
  }

  loadImage(&image, argv[1]);

  cropToSquare(&image);

  uint16_t numSlices = (REFRESH_RATE * 60) / ROTATION_RATE;

  ws2811_init(&ledstring);
  setup_handlers();

  unsigned int updatesCompleted = 0;
  double th;

  #ifdef PERFCOUNT
  struct timespec start, end;
  printf("Update rate:\n");
  if(clock_gettime(CLOCK_REALTIME, &start)) {
    EPRINT("Error: Couldnt get clock time!");
  }
  #endif

  while(running) {
    th = (updatesCompleted % numSlices) * 2 * M_PI / numSlices;
    generateSlice(ledstring.channel[0].leds, th, image.height);

    if (ws2811_render(&ledstring)) {
      EPRINT("Error: Rendering string didnt return 0!\n");
      break;
    }
    updatesCompleted += 1;

    #ifdef PERFCOUNT
    if(!(updatesCompleted % 300)) {
      if(clock_gettime(CLOCK_REALTIME, &end)) {
        EPRINT("Error: Couldnt get clock time!");
      }
      double freq = 300000.0/((end.tv_sec - start.tv_sec)*1000 + (end.tv_nsec - start.tv_nsec)/1000000);
      printf("\t%.2f Hz\r", freq);
      fflush(stdout);
      start = end;
    }
    #endif
  }

  // Clear the led strip before exiting
  for(int i = 0; i < LED_COUNT; i++) {
    ledstring.channel[0].leds[i] = 0;
  }
  ws2811_render(&ledstring);
  ws2811_fini(&ledstring);
}
Ejemplo n.º 4
0
void dmtcp_event_hook(DmtcpEvent_t event, DmtcpEventData_t *data)
{
  static char *filename = NULL;
  static bool restartingFromCkpt = false;
  static FILE *outfp = NULL;

  switch (event) {
    case DMTCP_EVENT_INIT:
      {
        if (!getenv("DMTCP_START_CTRS_ON_RESTART_STRATEGY")) {
          setup_handlers();
          filename = getStatsFilename(getenv("STATFILE"));
          JWARNING(filename != NULL).Text("Could not get the stats filename in the init event.");
          JTRACE("Filename: ")(filename);
        }
      }
      break;

    case DMTCP_EVENT_WRITE_CKPT:
      {
        JTRACE("CHKP");
        if (getenv("DMTCP_START_CTRS_ON_RESTART_STRATEGY")) {
          filename = getenv("STATFILE");
          if (restartingFromCkpt) {
            JTRACE("WRITE CHKP");
            JASSERT(filename);
            outfp = fopen(filename, "w+");
            if (!outfp) {
              perror("Error opening stats file in w+ mode");
              JASSERT(false);
            }
            read_ctrs(outfp);
            fclose(outfp);
            restartingFromCkpt = false;
          }
        }
      }
      break;

    case DMTCP_EVENT_RESUME:
      {
        if (getenv("DMTCP_KILL_ON_RESUME_STRATEGY")) {
          exit(0);
        }
      }
      break;

    case DMTCP_EVENT_RESTART:
      {
        if (getenv("DMTCP_START_CTRS_ON_RESTART_STRATEGY")) {
          restartingFromCkpt = true;
          filename = getStatsFilename(getenv("STATFILE"));
          JWARNING(filename != NULL).Text("Could not get the stats filename in the restart event.");
          JTRACE("Filename: ")(filename);
          JWARNING(setup_perf_ctr()).Text("Error setting up perf ctrs.");
        }
      }
      break;

    case DMTCP_EVENT_RESUME_USER_THREAD:
      {
        if (getenv("DMTCP_START_CTRS_ON_RESTART_STRATEGY")) {
          filename = getStatsFilename(getenv("STATFILE"));
          JWARNING(filename != NULL).Text("Could not get the stats filename in the resume_user_thread event.");
          JTRACE("Filename: ")(filename);
        }
      }
      break;

    default:
      break;
  }
  DMTCP_NEXT_EVENT_HOOK(event, data);
}
Ejemplo n.º 5
0
/// Constructor that sets up the signal handlers.
signals::interrupts_handler::interrupts_handler(void)
{
    PRE(!interrupts_handler_active);
    setup_handlers();
    interrupts_handler_active = true;
}
Ejemplo n.º 6
0
int main(int argc, char *argv[])
{
    Q_INIT_RESOURCE(commonrc);
    Q_INIT_RESOURCE(translations);

    if(SingleApplication::sendMessage(QObject::tr("An instance of Qcma is already running"))) {
        return 0;
    }

    SingleApplication app(argc, argv);

#ifndef Q_OS_WIN32
    // FIXME: libmtp sends SIGPIPE if a socket write fails crashing the whole app
    // the proper fix is to libmtp to handle the cancel properly or ignoring
    // SIGPIPE on the socket
    signal(SIGPIPE, SIG_IGN);
    setup_handlers();
#endif    

    if(app.arguments().contains("--with-debug")) {
        VitaMTP_Set_Logging(VitaMTP_DEBUG);
    } else if(app.arguments().contains("--verbose")) {
        VitaMTP_Set_Logging(VitaMTP_VERBOSE);
    } else {
        VitaMTP_Set_Logging(VitaMTP_NONE);
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
        qInstallMessageHandler(noMessageOutput);
#else
        qInstallMsgHandler(noMessageOutput);
#endif
    }

#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
    QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8"));
#endif

    QTextStream(stdout) << "Starting Qcma " << QCMA_VER << endl;

    QTranslator translator;
    QString locale = QLocale().system().name();
    qDebug() << "Current locale:" << locale;

    if(app.arguments().contains("--set-locale")) {
        int index = app.arguments().indexOf("--set-locale");
        if(index + 1 < app.arguments().length()) {
            qDebug("Enforcing locale: %s", app.arguments().at(index + 1).toUtf8().data());
            locale = app.arguments().at(index + 1);
        }
    }

    if(translator.load("qcma_" + locale, ":/resources/translations")) {
        app.installTranslator(&translator);
    } else {
        qWarning() << "Cannot load translation for locale:" << locale;
    }

    QTranslator system_translator;
    system_translator.load("qt_" + locale, QLibraryInfo::location(QLibraryInfo::TranslationsPath));
    app.installTranslator(&system_translator);

    qDebug("Starting main thread: 0x%016" PRIxPTR, (uintptr_t)QThread::currentThreadId());

    // set the organization/application for QSettings to work properly
    app.setOrganizationName("codestation");
    app.setApplicationName("qcma");

    //TODO: check if this is actually needed since we don't have a main window by default
    QApplication::setQuitOnLastWindowClosed(false);

    bool showSystray = !app.arguments().contains("--no-systray");

    MainWidget widget;
    widget.prepareApplication(showSystray);

    // receive the message from another process
    QObject::connect(&app, SIGNAL(messageAvailable(QString)), &widget, SLOT(receiveMessage(QString)));

    return app.exec();
}
Ejemplo n.º 7
0
/* main multicore function */
int go_multi_core(char* filename)
{
pid_t child_pids[MAX_PROC];
int i,fd;
struct shmstruct *ptr;
cpu_set_t mask;

	/* Setting up main process shared memory */
	shm_unlink(TMP_FNAME); 		/* delete previous file */
	fd = shm_open(TMP_FNAME, O_RDWR | O_CREAT | O_EXCL, S_IRWXU); /* open */
	if ( (ptr = mmap(NULL, sizeof(struct shmstruct), PROT_READ | PROT_WRITE,
					 MAP_SHARED, fd, 0)) == MAP_FAILED)
	{
		log("cannot map memory :(");
		exit (-1);
	};

	ftruncate(fd, sizeof(struct shmstruct)); /* resize */
	close(fd);								 /* close fd */

	log("Size of memory: %ldM, handle %ld, addr: %lx",
			 sizeof(struct shmstruct)/(1<<20), sizeof(pkt_handle), (long unsigned int) ptr);

	/* initialize sempaphores in shared memory */
	sem_init(&(ptr->pstart_sem), 1, 0);
	sem_init(&(ptr->nvmsetup_sem), 1, 0);
	sem_init(&(ptr->log_sem), 1, 1);

	/* setup some handlers to get children initialization end*/
	setup_handlers();
	log("starting copying capture");
	/* copy capture in memory */
	copy_capture(ptr);
	log("copied capture into memory");

	/* for each child */
	for (i = 0; i < ConfigParams.ncores; i++)
	{
		/* fork */
		log("Forking child %d", i);
		
		if ((child_pids[i] = fork()) >= 0)
		{
			if (child_pids[i] == 0)
			{
				/* kid */
				CPU_ZERO(&mask);
				CPU_SET(i, &mask);
				/* bind each child to a single core */
				if (sched_setaffinity(0, sizeof(mask), &mask) == -1)
				{
					log("setaffinity badly dead");
					exit (-1);
				}
				
				prctl(PR_SET_PDEATHSIG, SIGHUP); /* if parent dies, we die too */
				child_n = i;
				log("Child %d, pid %d", i, getpid());
				/* setup netmv */
				NetVMSetup(filename, ptr, i);
				break;
			}
			else
			{
				/* parent */
				continue;
			}
		};
	}

	/* log ("Freeing rule options"); */
	/* rule_free_options (sdata.rules); */

	/* wait children to finish netvm setup */
	for (i = 0 ; i < ConfigParams.ncores; i++)
	{
		log("%d processes finished setting up nvm", i);
		sem_wait(&(ptr->nvmsetup_sem) );
	}
	
	log("continuing");

	/* now i tell kids to start */
	for (i = 0; i < ConfigParams.ncores; i++)
	{
		sem_post(&(ptr->pstart_sem) );
	}

	/* finally wait packet processing */
	while(!netvm_termination)
		sleep(1);

	log_close();
	return 0;

}
Ejemplo n.º 8
0
/*
 * called to create a new server task
 */
static void prefork_new_task(
	struct tevent_context *ev,
	struct loadparm_context *lp_ctx,
	const char *service_name,
	void (*new_task_fn)(struct tevent_context *,
			    struct loadparm_context *lp_ctx,
			    struct server_id , void *, void *),
	void *private_data,
	const struct service_details *service_details,
	int from_parent_fd)
{
	pid_t pid;
	struct tfork* t = NULL;
	int i, num_children;

	struct tevent_context *ev2;

	t = tfork_create();
	if (t == NULL) {
		smb_panic("failure in tfork\n");
	}

	pid = tfork_child_pid(t);
	if (pid != 0) {
		struct tevent_fd *fde = NULL;
		int fd = tfork_event_fd(t);

		/* Register a pipe handler that gets called when the prefork
		 * master process terminates.
		 */
		fde = tevent_add_fd(ev, ev, fd, TEVENT_FD_READ,
				    prefork_child_pipe_handler, t);
		if (fde == NULL) {
			smb_panic("Failed to add child pipe handler, "
				  "after fork");
		}
		tevent_fd_set_auto_close(fde);
		return;
	}

	pid = getpid();
	setproctitle("task[%s] pre-fork master", service_name);

	/*
	 * this will free all the listening sockets and all state that
	 * is not associated with this new connection
	 */
	if (tevent_re_initialise(ev) != 0) {
		smb_panic("Failed to re-initialise tevent after fork");
	}
	prefork_reload_after_fork();
	setup_handlers(ev, from_parent_fd);

	if (service_details->inhibit_pre_fork) {
		new_task_fn(ev, lp_ctx, cluster_id(pid, 0), private_data, NULL);
		/* The task does not support pre-fork */
		tevent_loop_wait(ev);
		TALLOC_FREE(ev);
		exit(0);
	}

	/*
	 * This is now the child code. We need a completely new event_context
	 * to work with
	 */
	ev2 = s4_event_context_init(NULL);

	/* setup this new connection: process will bind to it's sockets etc
	 *
	 * While we can use ev for the child, which has been re-initialised
	 * above we must run the new task under ev2 otherwise the children would
	 * be listening on the sockets.  Also we don't want the top level
	 * process accepting and handling requests, it's responsible for
	 * monitoring and controlling the child work processes.
	 */
	new_task_fn(ev2, lp_ctx, cluster_id(pid, 0), private_data, NULL);

	{
		int default_children;
		default_children = lpcfg_prefork_children(lp_ctx);
		num_children = lpcfg_parm_int(lp_ctx, NULL, "prefork children",
			                      service_name, default_children);
	}
	if (num_children == 0) {
		DBG_WARNING("Number of pre-fork children for %s is zero, "
			    "NO worker processes will be started for %s\n",
			    service_name, service_name);
	}
	DBG_NOTICE("Forking %d %s worker processes\n",
		   num_children, service_name);
	/* We are now free to spawn some worker processes */
	for (i=0; i < num_children; i++) {
		struct tfork* w = NULL;

		w = tfork_create();
		if (w == NULL) {
			smb_panic("failure in tfork\n");
		}

		pid = tfork_child_pid(w);
		if (pid != 0) {
			struct tevent_fd *fde = NULL;
			int fd = tfork_event_fd(w);

			fde = tevent_add_fd(ev, ev, fd, TEVENT_FD_READ,
					    prefork_child_pipe_handler, w);
			if (fde == NULL) {
				smb_panic("Failed to add child pipe handler, "
					  "after fork");
			}
			tevent_fd_set_auto_close(fde);
		} else {
			/* tfork uses malloc */
			free(w);

			TALLOC_FREE(ev);
			setproctitle("task[%s] pre-forked worker",
				     service_name);
			prefork_reload_after_fork();
			setup_handlers(ev2, from_parent_fd);
			tevent_loop_wait(ev2);
			talloc_free(ev2);
			exit(0);
		}
	}

	/* Don't listen on the sockets we just gave to the children */
	tevent_loop_wait(ev);
	TALLOC_FREE(ev);
	/* We need to keep ev2 until we're finished for the messaging to work */
	TALLOC_FREE(ev2);
	exit(0);

}
Ejemplo n.º 9
0
//main routine
int main(int argc, char *argv[]){
    int ret = 0;
	int i;
	int index=0;

	ledstring.device=NULL;
	command_line = NULL;
    named_pipe_file=NULL;
	malloc_command_line(DEFAULT_COMMAND_LINE_SIZE);

    setup_handlers();

    input_file = stdin; //by default we read from console, stdin
    mode = MODE_STDIN;
    
	if (argc>1){
        if (strcmp(argv[1], "-p")==0){ //use a named pipe, creates a file (by default in /dev/ws281x) which you can write commands to: echo "command..." > /dev/ws281x
            if (argc>2){
                named_pipe_file = malloc(strlen(argv[2]+1));
                strcpy(named_pipe_file,argv[2]);
            }else{
                named_pipe_file = malloc(strlen(DEFAULT_DEVICE_FILE)+1);
                strcpy(named_pipe_file, DEFAULT_DEVICE_FILE);
            }
            printf ("Opening %s as named pipe.", named_pipe_file);
            remove(named_pipe_file);
            mkfifo(named_pipe_file,0777);
            chmod(named_pipe_file,0777);
            input_file = fopen(named_pipe_file, "r");
            mode  = MODE_NAMED_PIPE;
        }else if (strcmp(argv[1], "-f")==0){ //read commands / data from text file
            if (argc>2){
                input_file = fopen(argv[2], "r");
                printf("Opening %s.", argv[2]);
            }else{
                printf("Error you must enter a file name after -f option\n");
                exit(1);
            }
            mode = MODE_FILE;
        }else if (strcmp(argv[1], "-tcp")==0){ //open up tcp ip port and read commands from there
            if (argc>2){
                int port = atoi(argv[2]);
                if (port==0) port=9999;
                printf("Listening on %d.\n", port);
                start_tcpip(port);
            }else{
                printf("You must enter a port after -tcp option\n");
                exit(1);
            }
            mode = MODE_TCP;
        }
	}
	
	if ((mode == MODE_FILE || mode == MODE_NAMED_PIPE) && input_file==NULL){
		perror("Error opening file!");
		exit(1);
	}
	
    int c;
	
	while (exit_program==0) {
        if (mode==MODE_TCP){
            c = 0;
            if (read(active_socket, (void *) & c, 1)<=0) c = EOF; //returns 0 if connection is closed, -1 if no more data available and >0 if data read
        }else{
            c = fgetc (input_file); //doesn't work with tcp
        }
        
	  if (c!=EOF){
        process_character(c);
	  }else{
        //end of file or read error
		switch (mode){
            case MODE_TCP:
                if (!exit_program){
                    tcp_wait_connection(); //go back to wait for connection
                }
                break;
            case MODE_NAMED_PIPE:
            case MODE_STDIN:
                usleep(10000);
                break;
            case MODE_FILE:
                exit_program=1;
                break;
        }
	  }
    }
	
    if (mode==MODE_TCP){
        shutdown(active_socket,SHUT_RDWR);
        shutdown(sockfd,SHUT_RDWR);
        close(active_socket);
        close(sockfd);
    }else{
        fclose(input_file);
    }
        
    if (named_pipe_file!=NULL){
        remove(named_pipe_file);
        free(named_pipe_file);
    }
	free(command_line);
    if (thread_data!=NULL) free(thread_data);
    if (ledstring.device!=NULL) ws2811_fini(&ledstring);

    return ret;
}