Example #1
0
/* Restore the terminal's normal settings and modes. */
void
rl_deprep_terminal (void)
{
#if !defined (__GO32__)
  int tty = fileno (rl_instream);

  if (!terminal_prepped)
    return;

  /* Try to keep this function from being INTerrupted. */
  block_sigint ();

  control_meta_key (0);
#if 0
  control_keypad (0);
#endif
  fflush (rl_outstream);

  if (set_tty_settings (tty, &otio) < 0)
    {
      release_sigint ();
      return;
    }

  terminal_prepped = 0;

  release_sigint ();
#endif /* !__GO32__ */
}
Example #2
0
int scsi_open_device (void) {
#ifdef SG_BIG_BUFF
  int msize;
  scsi_6byte_cmd INQUIRY = { 0x12, 0x00, 0x00, 0x00, 0xff, 0x00 };
  union {
    unsigned char buf[SG_BIG_BUFF + SCSI_HDRLEN];
    struct sg_header hdr;
  } scsi_packet;
#endif
  if (!scsi_device) {             /* Return if no SCSI device is specified */
    fprintf(stderr, "scsi_open_device: no device specified\n");
    return(RET_FAIL);
  }
  scsi_fd = open(scsi_device, O_RDWR);
  if (scsi_fd < 0) {
    perror("scsi_open_device");
    return(RET_FAIL);
  }
#ifdef SG_BIG_BUFF
/* This is a rather brute-force approach to determine the actual buffer */
/* size, which is (or can be) _lower_ than SG_BIG_BUFF bytes. Don't     */
/* know why...                                                          */
  if (block_sigint() < 0)
    SCSI_ERR("scsi_open_device: Cannot block SIGINT.\n");
  for (msize = 4096; msize < SG_BIG_BUFF; msize += 512) {
    scsi_packet.hdr.pack_len  = 6 + SCSI_HDRLEN;
    scsi_packet.hdr.reply_len = msize;
/* Fix from Itai Nahshon <*****@*****.**> */
/* was: memcpy(scsi_packet.buf, INQUIRY, 6);       */
    memcpy(scsi_packet.buf + SCSI_HDRLEN, INQUIRY, 6);
    if (write(scsi_fd, &scsi_packet, SCSI_HDRLEN + 6) < 0) break;
    read(scsi_fd, &scsi_packet, msize + SCSI_HDRLEN);
    scsi_memsize = msize;
  }
  if (unblock_sigint() < 0)
    SCSI_ERR("scsi_open_device: Cannot unblock SIGINT.\n");
#endif
  SCSI_MSG(3, "scsi_open_device: SCSI memory size is %d bytes.\n", 
           scsi_memsize);
  return(scsi_fd);
}
Example #3
0
static void *reader_thread(void *data)
{
	char buf[MAX_BUFLEN];
	char filename[PATH_MAX];
	const char *output = data; 
	int failed = 0, fd, out_fd, len;

	block_sigint();

	if (output) {
		out_fd = open(output, O_CREAT | O_WRONLY | O_TRUNC,
					S_IRUSR|S_IWUSR);
		if (out_fd < 0) {
			fprintf(stderr, "Cannot open output file %s\n", output);
			return NULL;
		}
	} else
		out_fd = 2;

	sprintf(filename, "/sys/kernel/debug/ktap/trace_pipe_%d", ktap_pid);

 open_again:
	fd = open(filename, O_RDONLY);
	if (fd < 0) {
		usleep(10000);

		if (failed++ == 10) {
			fprintf(stderr, "Cannot open file %s\n", filename);
			return NULL;
		}
		goto open_again;
	}

	while ((len = read(fd, buf, sizeof(buf))) > 0)
		write(out_fd, buf, len);

	close(fd);
	close(out_fd);

	return NULL;
}
Example #4
0
/* Put the terminal in CBREAK mode so that we can detect key presses. */
void
rl_prep_terminal (int meta_flag)
{
#if !defined (__GO32__)
  int tty = fileno (rl_instream);
  TIOTYPE tio;

  if (terminal_prepped)
    return;

  /* Try to keep this function from being INTerrupted. */
  block_sigint ();

  if (get_tty_settings (tty, &tio) < 0)
    {
      release_sigint ();
      return;
    }

  otio = tio;

  prepare_terminal_settings (meta_flag, otio, &tio);

  if (set_tty_settings (tty, &tio) < 0)
    {
      release_sigint ();
      return;
    }

  control_meta_key (1);
#if 0
  control_keypad (1);
#endif
  fflush (rl_outstream);
  terminal_prepped = 1;

  release_sigint ();
#endif /* !__GO32__ */
}
Example #5
0
int scsi_handle_cmd (unsigned char *scsi_cmd,   int scsi_cmd_len,
                     unsigned char *scsi_data,  int data_size,
                     unsigned char *scsi_reply, int reply_size) {
  struct sg_header *scsi_hdr;
  unsigned char scsi_buffer[SCSI_BUFSIZE];
  int status = 0;
  int scsi_pack_len  = SCSI_HDRLEN + scsi_cmd_len + data_size;
  int scsi_reply_len = SCSI_HDRLEN + reply_size;
  
  if (scsi_cmd == NULL) 
    SCSI_ERR("scsi_handle_cmd: No command.\n");
  if ((scsi_cmd_len != 6) && (scsi_cmd_len != 10) && (scsi_cmd_len != 12))
    SCSI_ERR("scsi_handle_cmd: Illegal command length (%d).\n", scsi_cmd_len);
  if (data_size && (scsi_data == NULL)) 
    SCSI_ERR("scsi_handle_cmd: Input data expected.\n");
  if (reply_size && (scsi_reply == NULL)) 
    SCSI_ERR("scsi_handle_cmd: No space allocated for expected reply.\n");
  if (scsi_pack_len > SCSI_BUFSIZE)
    SCSI_ERR("scsi_handle_cmd: Packet length exceeds buffer size\n   "
             "              (buffer size %d bytes, packet length %d bytes).\n",
             SCSI_BUFSIZE, scsi_pack_len);
  if (scsi_reply_len > SCSI_BUFSIZE)
    SCSI_ERR("scsi_handle_cmd: Reply length exceeds buffer size\n   "
             "              (buffer size %d bytes, reply length %d bytes).\n",
             SCSI_BUFSIZE, scsi_reply_len);

  SCSI_MSG(5, "scsi_handle_cmd: Sending command, opcode 0x%02x.\n",
           scsi_cmd[0]);
  SCSI_MSG(5, "scsi_handle_cmd: Pack length = %d, expected reply size = %d\n",
           scsi_pack_len, scsi_reply_len);

  scsi_hdr = (struct sg_header *)scsi_buffer;
  scsi_hdr->pack_len    = scsi_pack_len;

/* The reply length should be set to the actual reply length expected, */
/* but this causes various strange errors (kernel panics or silent     */
/* system crashes) with my AVA-1502E adapter card; it works if the     */
/* value is set to the maximum value.                                  */
  
#if (SCSI_REPLYLEN_FIX)
  scsi_hdr->reply_len   = scsi_memsize + SCSI_HDRLEN;
#else
  scsi_hdr->reply_len   = scsi_reply_len;
#endif
  scsi_hdr->pack_id     = ++scsi_pack_id;
  scsi_hdr->twelve_byte = (scsi_cmd_len == 12);
  scsi_hdr->result      = 0;

/* copy command (and data, if available) to the scsi buffer (after */
/* the header data)                                                */
  memcpy(scsi_buffer+SCSI_HDRLEN, scsi_cmd, scsi_cmd_len);
  if (data_size)
    memcpy(scsi_buffer+SCSI_HDRLEN+scsi_cmd_len, scsi_data, data_size);
/* If SIGINT is caught between write and read, the device is */
/* blocked forever. So we block SIGINT instead.              */
  if (block_sigint() < 0)
    SCSI_ERR("scsi_handle_cmd: Cannot block SIGINT.\n");
  status = write(scsi_fd, scsi_buffer, scsi_pack_len);

  if (status < 0) {
    perror("scsi_handle_cmd");
    return(RET_FAIL);
  }
  if (status != scsi_pack_len)
    SCSI_ERR("scsi_handle_cmd: Write incomplete (%d of %d bytes written).\n",
             status, scsi_pack_len);
/* I never get a result other than 0 after a write(), so this */
/* is probably unneccessary                                   */
#if 1
  if (scsi_hdr->result)
    SCSI_ERR("scsi_handle_cmd: SCSI error (opcode 0x%02x, result 0x%02x).\n",
             scsi_cmd[0], scsi_hdr->result);  
#endif

  status = read(scsi_fd, scsi_buffer, scsi_reply_len);

/* Now we can allow SIGINT again. */
  if (unblock_sigint() < 0)
    SCSI_ERR("scsi_handle_cmd: Cannot unblock SIGINT.\n");

  SCSI_MSG(5, "scsi_handle_cmd: %d bytes read, result = 0x%02x.\n", 
           status, scsi_hdr->result);
  SCSI_MSG(4, "scsi_handle_cmd: Sense buffer [0] = 0x%02x\n",
          scsi_hdr->sense_buffer[0]);

  if (status < 0) {
    perror("scsi_handle_cmd");
    return(RET_FAIL);
  }
  if (status != scsi_reply_len) 
    SCSI_ERR("scsi_handle_cmd: Read error (%d bytes read, "
             "%d bytes expected).\n", status, scsi_reply_len);
  if (scsi_hdr->pack_id != scsi_pack_id)
    SCSI_ERR("scsi_handle_cmd: SCSI packet IDs do not match.\n");

  memcpy(scsi_sensebuffer, scsi_hdr->sense_buffer, 16);

  if (scsi_hdr->result || scsi_hdr->sense_buffer[0]) {

/* Sense data is only written to stderr if scsi_debug_level is > 0.  */
/* Otherwise, the function just returns RET_FAIL, and the calling    */
/* function is left to analyze the sense data in scsi_sensebuffer.   */
    if (scsi_debug_level > 0) {

      if (scsi_hdr->result)
        fprintf(stderr, "scsi_handle_cmd: %s\n", strerror(scsi_hdr->result));

      fprintf(stderr, "scsi_handle_cmd: error reading from SCSI device\n");
      fprintf(stderr, "                 SCSI opcode = 0x%02x   "
                      "result = 0x%02x   status = %d\n", scsi_cmd[0],
                      scsi_hdr->result, status);
      fprintf(stderr, "                 sense buffer: "
                      "%02x %02x %02x %02x %02x %02x %02x %02x "
                      "%02x %02x %02x %02x %02x %02x %02x %02x\n",
                      scsi_hdr->sense_buffer[0],  scsi_hdr->sense_buffer[1],
                      scsi_hdr->sense_buffer[2],  scsi_hdr->sense_buffer[3],
                      scsi_hdr->sense_buffer[4],  scsi_hdr->sense_buffer[5],
                      scsi_hdr->sense_buffer[6],  scsi_hdr->sense_buffer[7],
                      scsi_hdr->sense_buffer[8],  scsi_hdr->sense_buffer[9],
                      scsi_hdr->sense_buffer[10], scsi_hdr->sense_buffer[11],
                      scsi_hdr->sense_buffer[12], scsi_hdr->sense_buffer[13],
                      scsi_hdr->sense_buffer[14], scsi_hdr->sense_buffer[15]);
    }
    return(RET_FAIL);
  }
  if (scsi_reply) memcpy(scsi_reply, scsi_buffer+SCSI_HDRLEN, reply_size);
  return(RET_SUCCESS);
}