Exemplo n.º 1
0
static int initOutFile()
{
	int ret;
	struct uinput_user_dev uinp;	/* our input device information */

	/* Try opening the file */
	printf("Opening %s\n",config.filename);
	outFile = open(config.filename, O_WRONLY | O_NDELAY);
	if (-1 == outFile){
		fprintf(stderr, "Error opening file %s (error %d)\n",
				config.filename, outFile);
		perror("open");
		return -1;
	}

	/* Setup defice information */
	memset(&uinp, 0, sizeof(uinp));
	strncpy(uinp.name, DEVICE_NAME, UINPUT_MAX_NAME_SIZE);
	uinp.id.version = VERSION;
	uinp.id.bustype = BUSTYPE;
	if ( (int)sizeof(uinp) > write(outFile, &uinp, sizeof(uinp))){
		fprintf(stderr, "Error writing defice information\n");
		closeOutFile();
		return -1;
	}

	
	/* Setup all the flags */
	ret  = ioctl(outFile, UI_SET_EVBIT, EV_KEY);
	ret |= ioctl(outFile, UI_SET_EVBIT, EV_REL);
	ret |= ioctl(outFile, UI_SET_RELBIT, REL_X);
	ret |= ioctl(outFile, UI_SET_RELBIT, REL_Y);
	ret |= ioctl(outFile, UI_SET_RELBIT, REL_WHEEL);
	ret |= ioctl(outFile, UI_SET_RELBIT, REL_HWHEEL);
	ret |= ioctl(outFile, UI_SET_KEYBIT, BTN_MOUSE);
	ret |= ioctl(outFile, UI_SET_KEYBIT, BTN_MIDDLE);
	ret |= ioctl(outFile, UI_SET_KEYBIT, BTN_RIGHT);
	
	ret |= ioctl(outFile, UI_DEV_CREATE);
	if (ret){
		perror("ioctl");
		fprintf(stderr, "ERROR: ioctl() failed\n");
		closeOutFile();
		return -1;
	}

	return 0;
}
Exemplo n.º 2
0
static void destrOutFile()
{
	printf("Unregistering event file\n");
	if (-1 == ioctl(outFile, UI_DEV_DESTROY)){
		perror("ioctl");
		fprintf(stderr,"ERROR: Couldn't destroy the uinput device!\n");
	}
	closeOutFile();
}
Exemplo n.º 3
0
  void Process::reset()
  {
    GetExitCodeProcess(m_procinfo.hProcess, &m_exitCode);
    CloseHandle(m_procinfo.hProcess);
    m_created = false;
    m_procinfo.dwThreadId = -1;

    if( m_isOutFileOpen )
    {
      closeOutFile();
    }
  }
Exemplo n.º 4
0
int AnalysisManager::openOutFile(std::string fileName, std::string mode)
{
    closeOutFile();

    if(fileName != "")
    {
        outFileName_ = fileName;
    }
    else if(outFileName_ == "")
    {
        STDLINE("ERROR: Don't have an output file name set!",ACRed);
        return 0;
    }
    outFile_  = TFile::Open(outFileName_.c_str(),mode.c_str());
    return 1;
}
Exemplo n.º 5
0
static int
WorkerBee(struct cmd_syndesc *as, void *arock)
{
    char *tapedev;
    struct tapeLabel *label;
    struct fileMark *fmark;
    afs_int32 fmtype;
    struct blockMark *bmark;
    afs_int32 isheader, isdatablock;
    char *data;
    char *tblock;
    afs_int32 code;
    struct volumeHeader *volheaderPtr = NULL;
    int eod = 1;
    int rc;
    char *nextblock;		/* We cycle through three tape blocks so we  */
    char *lastblock;		/* can trim off the volume trailer from the  */
    char *lastblock2;		/* end of each volume without having to back */
    char *tapeblock1;		/* up the output stream.                     */
    char *tapeblock2;
    char *tapeblock3;

    tapedev = as->parms[0].items->data;	/* -tape     */
    nrestore =
	(as->parms[1].items ? atol(as->parms[1].items->data) : 0x7fffffff);
    nskip = (as->parms[2].items ? atol(as->parms[2].items->data) : 0);
    if (as->parms[4].items)
	nskip = 0x7fffffff;	/* -scan     */
    outfile = (as->parms[3].items ? as->parms[3].items->data : 0);
    ask = (as->parms[5].items ? 0 : 1);	/* -noask    */
    printlabels = (as->parms[6].items ? 1 : 0);	/* -label    */
    printheaders = (as->parms[7].items ? 1 : 0);	/* -vheaders */
    verbose = (as->parms[8].items ? 1 : 0);	/* -verbose  */

    /* Open the tape device */
    rc = usd_Open(tapedev, USD_OPEN_RDONLY, 0, &fd);
    if (rc != 0) {
	printf("Failed to open tape device %s. Code = %d\n", tapedev, rc);
	exit(1);
    }

    /*
     * Initialize the tape block buffers
     */
    tapeblock1 = (char *)malloc(3 * 16384);
    if (tapeblock1 == NULL) {
	printf("Failed to allocate I/O buffers.\n");
	exit(1);
    }
    tapeblock2 = tapeblock1 + 16384;
    tapeblock3 = tapeblock2 + 16384;

    nextblock = tapeblock1;
    lastblock = NULL;
    lastblock2 = NULL;

    /* Read each tape block deciding what to do with it */
    do {			/* while ((nskip!=0) && (nrestore!=0)) */
	code = readblock(nextblock);
	if (code) {
	    if (!eod)
		fprintf(stderr, "Tape device read error: %d\n", code);
	    break;
	}
	isdatablock = 0;

	/* A data block can be either a volume header, volume trailer,
	 * or actual data from a dump.
	 */
	bmark = (struct blockMark *)nextblock;
	label = (struct tapeLabel *)nextblock;
	fmark = (struct fileMark *)nextblock;
	if (ntohl(bmark->magic) == BLOCK_MAGIC) {
	    if (verbose)
		printf("Data block\n");
	    isdatablock = 1;
	    isheader = 0;
	    data = &nextblock[sizeof(struct blockMark)];
	    if (strncmp(data, "H++NAME#", 8) == 0) {
		volheaderPtr = (struct volumeHeader *)data;
		printHeader(volheaderPtr, &isheader);
	    }
	    if (isheader) {
		code = openOutFile(volheaderPtr);
		nextblock = tapeblock1;
		lastblock = NULL;
		lastblock2 = NULL;
	    } else {
		if (lastblock2 != NULL) {
		    data = &lastblock2[sizeof(struct blockMark)];
		    bmark = (struct blockMark *)lastblock2;
		    writeData(data, ntohl(bmark->count));
		    tblock = lastblock2;
		} else if (lastblock != NULL) {
		    tblock = tapeblock2;
		} else {
		    tblock = tapeblock3;
		}
		lastblock2 = lastblock;
		lastblock = nextblock;
		nextblock = tblock;
	    }
	}

	/* Filemarks come in 3 forms: BEGIN, END, and EOD.
	 * There is no information stored in filemarks.
	 */
	else if (ntohl(fmark->magic) == FILE_MAGIC) {
	    fmtype = ntohl(fmark->nBytes);
	    if (fmtype == FILE_BEGIN) {
		if (verbose)
		    fprintf(stderr, "File mark volume begin\n");
	    } else if (fmtype == FILE_END) {
		if (verbose)
		    fprintf(stderr, "File mark volume end\n");
	    } else if (fmtype == FILE_EOD) {
		if (verbose)
		    fprintf(stderr, "File mark end-of-dump\n");
		eod = 1;
	    }
	}

	/* A dump label */
	else if (ntohl(label->magic) == TAPE_MAGIC) {
	    if (verbose)
		fprintf(stderr, "Dump label\n");
	    printLabel(label);
	    eod = 0;
	}

	else {
	    if (verbose) {
		fprintf(stderr, "Unrecognized tape block - end\n");
	    }
	}

	/* Anything other than a data block closes the out file.
	 * At this point nextblock contains the end of tape file mark,
	 * lastblock contains the last data block for the current volume,
	 * and lastblock2 contains the second to last block for the current
	 * volume. If the volume fits in a single block, lastblock2 will
	 * be NULL. Call writeLastBlocks to strip off the dump trailer before
	 * writing the last of the volume data to the dump file. The dump
	 * trailer may span block boundaries.
	 */
	if (!isdatablock && lastblock) {
	    writeLastBlocks(lastblock, lastblock2);
	    closeOutFile();
	    nextblock = tapeblock1;
	    lastblock = NULL;
	    lastblock2 = NULL;
	}
    } while ((nskip != 0) || (nrestore != 0));

    free(tapeblock1);

    return 0;
}
Exemplo n.º 6
0
pid_t forkLisp(any ex) {
   pid_t n;
   int i, hear[2], tell[2];
   static int mic[2];

   flushAll();
   if (!Spkr) {
      if (pipe(mic) < 0)
         pipeError(ex, "open");
      closeOnExec(ex, mic[0]), closeOnExec(ex, mic[1]);
      Spkr = mic[0];
   }
   if (pipe(hear) < 0  ||  pipe(tell) < 0)
      pipeError(ex, "open");
   closeOnExec(ex, hear[0]), closeOnExec(ex, hear[1]);
   closeOnExec(ex, tell[0]), closeOnExec(ex, tell[1]);
   for (i = 0; i < Children; ++i)
      if (!Child[i].pid)
         break;
   if ((n = fork()) < 0)
      err(ex, NULL, "fork");
   if (n == 0) {
      void *p;

      Slot = i;
      Spkr = 0;
      Mic = mic[1];
      close(hear[1]), close(tell[0]), close(mic[0]);
      if (Hear)
         close(Hear),  closeInFile(Hear),  closeOutFile(Hear);
      initInFile(Hear = hear[0], NULL);
      if (Tell)
         close(Tell);
      Tell = tell[1];
      for (i = 0; i < Children; ++i)
         if (Child[i].pid)
            close(Child[i].hear), close(Child[i].tell),  free(Child[i].buf);
      Children = 0,  free(Child),  Child = NULL;
      for (p = Env.inFrames; p; p = ((inFrame*)p)->link)
         ((inFrame*)p)->pid = 0;
      for (p = Env.outFrames; p; p = ((outFrame*)p)->link)
         ((outFrame*)p)->pid = 0;
      for (p = CatchPtr; p; p = ((catchFrame*)p)->link)
         ((catchFrame*)p)->fin = Zero;
      free(Termio),  Termio = NULL;
      if (Repl)
         ++Repl;
      val(PPid) = val(Pid);
      val(Pid) = boxCnt(getpid());
      run(val(Fork));
      val(Fork) = Nil;
      return 0;
   }
   if (i == Children)
      allocChildren();
   close(hear[0]), close(tell[1]);
   Child[i].pid = n;
   Child[i].hear = tell[0];
   nonblocking(Child[i].tell = hear[1]);
   Child[i].ofs = Child[i].cnt = 0;
   Child[i].buf = NULL;
   return n;
}