Beispiel #1
0
int main() {
  void *handle = dlopen("libnss_ldap.so.2", RTLD_LAZY);
  if (!handle) {
    fprintf(stderr, "Cannon open library: %s\n", dlerror());
    return 1;
  }
  /* pw = passwd */
  fetch_data(handle, "pw");
  /* gr = group */
  fetch_data(handle, "gr");
  dlclose(handle);
  return 0;
}
Beispiel #2
0
void MickeyThread::run()
{
  sn4_btn_event_t ev;
  ssize_t read;
  finish = false;
  while(1){
    while(fifo <= 1){
      if(finish){
        return;
      }
      fifo = prepareBtnChanel();
      if(fifo <= 0){
        QThread::sleep(1);
      }
    }
    while(fetch_data(fifo, (void*)&ev, sizeof(ev), &read)){
      //std::cout<<"Thread alive!"<<std::endl;
      if(finish){
        return;
      }
      if(read == sizeof(ev)){
        ev.btns ^= 3;
        processClick(ev);
      }
    }
  }
}
Beispiel #3
0
void jmp(CPU* cpu, unsigned char* memory)
{
	uint16_t pc = cpu->PC;
	uint16_t addr = fetch_data(cpu, memory);
	cpu->PC = addr;
	cpu->cycles += 1;
}
Beispiel #4
0
/***********************************************************************//**
 * @brief Column data access operator (const variant)
 *
 * @param[in] row Row of column to access.
 * @param[in] inx Vector index in column row to access.
 *
 * Provides access to data in a column.
 ***************************************************************************/
const unsigned char& GFitsTableByteCol::operator()(const int& row, const int& inx) const
{
    // If data are not available then load them now
    if (m_data == NULL) fetch_data();

    // Return data bin
    return m_data[offset(row, inx)];
}
Beispiel #5
0
/***********************************************************************//**
 * @brief Column data access operator (const variant)
 *
 * @param[in] row Row of column to access.
 * @param[in] inx Vector index in column row to access.
 *
 * Provides access to data in a column.
 ***************************************************************************/
const long long& GFitsTableLongLongCol::operator()(const int& row, const int& inx) const
{
    // If data are not available then load them now
    if (m_data == NULL) fetch_data();

    // Return data bin
    return m_data[offset(row, inx)];
}
Beispiel #6
0
/***********************************************************************//**
 * @brief Get string value
 *
 * @param[in] row Table row.
 * @param[in] inx Table column vector index.
 *
 * Returns value of specified row and vector index as string.
 ***************************************************************************/
std::string GFitsTableLongLongCol::string(const int& row, const int& inx) const
{
    // If data are not available then load them now
    if (m_data == NULL) fetch_data();

    // Return value
    return (gammalib::str(m_data[offset(row,inx)]));
}
Beispiel #7
0
void eor(CPU* cpu, unsigned char* memory)
{
	cpu->A ^= fetch_data(cpu,memory);
	cpu->P[1] = (cpu->A == 0) ? 1 : 0;
	cpu->P[7] = (cpu->A & 0x80) ? 1 : 0;
	cpu->PC += address_bytes[memory[cpu->PC]] + 1;
	cpu->cycles += 2;
}
Beispiel #8
0
void sty(CPU* cpu, unsigned char* memory)
{
	uint16_t address = fetch_data(cpu, memory);
	cpu->memory[address] = cpu->Y;
	cpu->PC += address_bytes[memory[cpu->PC]] + 1;
	cpu->cycles += 2;
	store_extra(address, cpu->Y, cpu);
}
/***********************************************************************//**
 * @brief Column data access operator
 *
 * @param[in] row Row of column to access.
 * @param[in] inx Vector index in column row to access.
 *
 * Provides access to data in a column.
 ***************************************************************************/
GFits::cfloat& GFitsTableCFloatCol::operator()(const int& row, const int& inx)
{
    // If data are not available then load them now
    if (m_data == NULL) fetch_data();

    // Return data bin
    return m_data[offset(row, inx)];
}
Beispiel #10
0
			data_type inline fetch(filter_obj *parent, fun_ptr_type f, client_type &client) {
				if (!client) {
					client.reset(traits::get_default());
					data_type tmp;
					if (fetch_data(parent, f, tmp))
						client.reset(tmp);
				}
				return *client;
			}
Beispiel #11
0
void cpx(CPU* cpu, unsigned char* memory)
{
	uint8_t value = (uint8_t)(fetch_data(cpu, memory)&0xFF);
	uint8_t comp = cpu->X - value;
	cpu->P[0] = (cpu->X >= value) ? 1 : 0;
	cpu->P[1] = (cpu->X == value) ? 1 : 0;
	cpu->P[7] = (comp & 0x80) ? 1 : 0;
	cpu->cycles += 2;
	cpu->PC += address_bytes[memory[cpu->PC]] + 1;
}
Beispiel #12
0
void ldy(CPU *cpu, unsigned char* memory)
{

	uint8_t data = (uint8_t)(fetch_data(cpu, memory)&0xFF);
	cpu->P[1] = (data == 0) ? 1 : 0;
	cpu->P[7] = (data & 0x80) ? 1 : 0;
	cpu->Y = data;
	cpu->PC += address_bytes[memory[cpu->PC]] + 1;
	cpu->cycles += 2;
}
Beispiel #13
0
void lda(CPU* cpu, unsigned char* memory)
{
	uint16_t pc = cpu->PC;
	uint16_t data = fetch_data(cpu, memory);
	cpu->P[1] = (data == 0) ? 1 : 0;
	cpu->P[7] = (data & 0x80) ? 1 : 0;
	cpu->A = (uint8_t)(data & 0xFF);
	cpu->PC += address_bytes[memory[cpu->PC]] + 1;
	cpu->cycles += 2;
}
Beispiel #14
0
			data_type operator() (object_type *object, const std::string &title) {
				if (!data_) {
					data_type tmp;
					if (fetch_data(object, tmp, title))
						data_.reset(tmp);
					else
						data_.reset(traits::get_default());
				}
				return *data_;
			}
Beispiel #15
0
/***********************************************************************//**
 * @brief Get string value
 *
 * @param[in] row Table row.
 * @param[in] inx Table column vector index.
 *
 * Returns value of specified row and vector index as string.
 ***************************************************************************/
std::string GFitsTableBoolCol::string(const int& row, const int& inx) const
{
    // If data are not available then load them now
    if (m_data == NULL) fetch_data();

    // Convert bool into string
    std::string result = (m_data[offset(row,inx)]) ? "T" : "F";

    // Return value
    return result;
}
Beispiel #16
0
/***********************************************************************//**
 * @brief Get integer value
 *
 * @param[in] row Table row.
 * @param[in] inx Table column vector index.
 *
 * Returns value of specified row and vector index as integer.
 ***************************************************************************/
int GFitsTableLongLongCol::integer(const int& row, const int& inx) const
{
    // If data are not available then load them now
    if (m_data == NULL) fetch_data();

    // Convert long long into int
    int value = (int)m_data[offset(row,inx)];

    // Return value
    return value;
}
/***********************************************************************//**
 * @brief Resize column data
 *
 * @param[in] index Start index.
 * @param[in] number Number of elements to add/remove.
 *
 * Adds or removes elements from specified index on. Adding is done if
 * @p number is a positive number, removing if @p number is negative.
 * Note that the method does not change the validity of the arguments.
 * This needs to be done by the client.
 ***************************************************************************/
void GFitsTableCFloatCol::resize_data(const int& index, const int& number)
{
    // Continue only if number of elements is not zero
    if (number != 0) {

        // If data are not available then load them now
        if (m_data == NULL) fetch_data();

        // If elements should be removed then do not allocate new memory
        // but just move elements forward and change the logical size of
        // memory. Only if all elements should be removed the memory is
        // released.
        if (number < 0) {
            int            left = index - number;
            GFits::cfloat* dst  = m_data + index;
            GFits::cfloat* src  = m_data + left;
            int    num  = m_size - left;
            for (int i = 0; i < num; ++i) {
                *dst++ = *src++;
            }
            m_size += number;
            if (m_size < 1) {
                release_data();
            }
        }

        // If elements should be added then allocate new memory, copy over
        // the old data and initialise the new elements
        else {
            int left                = m_size - index;
            m_size                 += number;
            GFits::cfloat* new_data = new GFits::cfloat[m_size];
            GFits::cfloat* dst      = new_data;
            GFits::cfloat* src      = m_data;
            for (int i = 0; i < index; ++i) {
                *dst++ = *src++;
            }
            for (int i = 0; i < number; ++i) {
                dst->re = 0.0;
                dst->im = 0.0;
                dst++;
            }
            for (int i = 0; i < left; ++i) {
                *dst++ = *src++;
            }
            if (m_data != NULL) delete [] m_data;
            m_data = new_data;
        }

    } // endif: number was non-zero

    // Return
    return;
}
Beispiel #18
0
/***********************************************************************//**
 * @brief Get double precision value
 *
 * @param[in] row Table row.
 * @param[in] inx Table column vector index.
 *
 * Returns value of specified row and vector index as double precision.
 ***************************************************************************/
double GFitsTableLongLongCol::real(const int& row, const int& inx) const
{
    // If data are not available then load them now
    if (m_data == NULL) fetch_data();

    // Convert long long into double
    double value = (double)m_data[offset(row,inx)];

    // Return value
    return value;
}
Beispiel #19
0
void adc(CPU *cpu, unsigned char* memory)
{
	uint16_t imm = fetch_data(cpu,memory);
	uint16_t temp = imm + cpu->A + cpu->P[0];
	cpu->P[1] = ((temp & 0xFF) == 0) ? 1 : 0;
	cpu->P[7] = (temp & 0x80) ? 1 : 0;
	cpu->P[6] = overflow(cpu->A, (uint8_t)(imm), (uint8_t)(temp));
	cpu->P[0] = (temp & 0x100) ? 1 : 0;
	cpu->A = (uint8_t)(temp & 0x0FF);
	cpu->PC += address_bytes[memory[cpu->PC]] + 1;
	cpu->cycles += 2;
}
Beispiel #20
0
void sbc(CPU *cpu, unsigned char* memory)
{
	uint8_t imm = (uint8_t)(fetch_data(cpu, memory) & 0xFF);
	uint16_t temp = cpu->A - imm - (1 - cpu->P[0]);
	cpu->P[1] = ((temp & 0xFF) == 0) ? 1 : 0;
	cpu->P[7] = (temp & 0x80) ? 1 : 0;
	cpu->P[6] = overflowsbc(cpu->A, (uint8_t)(imm), (uint8_t)(temp));
	cpu->P[0] = (temp & 0x100) ? 0 : 1;
	cpu->A = (uint8_t)(temp & 0x0FF);
	cpu->PC += address_bytes[memory[cpu->PC]] + 1;
	cpu->cycles += 2;
}
/***********************************************************************//**
 * @brief Get string value
 *
 * @param[in] row Table row.
 * @param[in] inx Table column vector index.
 *
 * Returns value of specified row and vector index as string.
 ***************************************************************************/
std::string GFitsTableFloatCol::string(const int& row, const int& inx) const
{
    // If data are not available then load them now
    if (m_data == NULL) fetch_data();

    // Convert float into string
    std::ostringstream s_value;
    s_value << m_data[offset(row,inx)];

    // Return value
    return s_value.str();
}
/***********************************************************************//**
 * @brief Get string value
 *
 * @param[in] row Table row.
 * @param[in] inx Table column vector index.
 *
 * Returns value of specified row and vector index as string.
 ***************************************************************************/
std::string GFitsTableCFloatCol::string(const int& row, const int& inx) const
{
    // If data are not available then load them now
    if (m_data == NULL) fetch_data();

    // Convert complex into string
    std::string result = gammalib::str(m_data[offset(row,inx)].re) + ", " +
                         gammalib::str(m_data[offset(row,inx)].im);

    // Return result
    return result;
}
Beispiel #23
0
static void
rc_you_transaction_download (RCYouTransaction *transaction)
{
    GError *err = NULL;

    if (transaction->files_to_download) {
        if (!check_download_space (transaction, &err))
            goto ERROR;

        if (!abortable_transactions) {
            abortable_transactions = g_hash_table_new_full (NULL, NULL,
                                                            g_object_unref,
                                                            g_object_unref);
        }

        g_hash_table_insert (abortable_transactions,
                             g_object_ref (transaction->download_pending),
                             g_object_ref (transaction));

        /* Kick off the download */
        fetch_data (transaction->pool,
                    transaction->files_to_download);

        rcd_transfer_pool_set_expected_size (transaction->pool,
                                             transaction->total_download_size);
        g_signal_connect (transaction->pool, "transfer_done",
                          G_CALLBACK (transfer_done_cb), transaction);
        rcd_transfer_pool_begin (transaction->pool);
    }
    else {
        if (transaction->flags == RCD_TRANSACTION_FLAGS_DOWNLOAD_ONLY)
            rc_you_transaction_finished (transaction, NULL);
        else
            rc_you_transaction_verification (transaction);
    }

    return;

ERROR:

    rc_you_transaction_failed (transaction,
                               err->code == RC_YOU_TRANSACTION_ERROR_DOWNLOAD ?
                               transaction->download_pending :
                               transaction->transaction_pending,
                               err->message);
    g_error_free (err);
}
Beispiel #24
0
static int fetch_body(struct imap_fetch_context *ctx, struct mail *mail,
		      const struct imap_fetch_body_data *body)
{
	const struct message_size *fetch_size;
	struct istream *input;
	struct message_size hdr_size, body_size;

	if (body->section[0] == '\0') {
		if (mail_get_stream(mail, NULL, NULL, &input) < 0 ||
		    mail_get_virtual_size(mail, &body_size.virtual_size) < 0 ||
		    mail_get_physical_size(mail, &body_size.physical_size) < 0)
			return -1;
	} else {
		if (mail_get_stream(mail, &hdr_size,
				    body->section[0] == 'H' ? NULL : &body_size,
				    &input) < 0)
			return -1;
	}

	ctx->cur_input = input;
	i_stream_ref(ctx->cur_input);
	ctx->update_partial = TRUE;

	switch (body->section[0]) {
	case '\0':
		/* BODY[] - fetch everything */
                fetch_size = &body_size;
		ctx->cur_size_field = MAIL_FETCH_VIRTUAL_SIZE;
		break;
	case 'H':
		/* BODY[HEADER] - fetch only header */
                fetch_size = &hdr_size;
		ctx->cur_size_field = MAIL_FETCH_MESSAGE_PARTS;
		break;
	case 'T':
		/* BODY[TEXT] - skip header */
		i_stream_skip(ctx->cur_input, hdr_size.physical_size);
                fetch_size = &body_size;
		ctx->cur_size_field = MAIL_FETCH_VIRTUAL_SIZE;
		break;
	default:
		i_unreached();
	}

	return fetch_data(ctx, body, fetch_size);
}
Beispiel #25
0
void fetch_nonce(FILE *fp)
{
    size_t offset = 54 * SECTOR + 0x21;
    printf("\nnonce:\n");
    fetch_data(fp, offset, 8);
}
Beispiel #26
0
void fetch_veribuf(FILE *fp)
{
    size_t offset = 55 * SECTOR;
    printf("\nverification data:\n");
    fetch_data(fp, offset, SECTOR);
}
Beispiel #27
0
int main(int argc, char **argv)
{
	struct bt_opts opts;
	struct btproc *bt_proc;

	bt_proc = parse_args(argc, argv, &opts);

	bt_proc->pi->pi_debug = opts.debug_opt;
	if (opts.target_opt && opts.pid_opt) {
		bt_proc_destroy(bt_proc);
		printfd(2,
			FATAL " You can't choose target and pid together !\n");
		btrace_banner(*argv, 1);
	} else if (!opts.target_opt && !opts.pid_opt) {
		printfd(2, FATAL "No such target or porcess\n");
		btrace_banner(*argv, 1);
	} else {
		/* using target executable */
		if (opts.target_opt) {
			bt_proc->exec =
			    check_target_path(bt_proc->pi->pi_target,
					      bt_proc->pi->pi_perm);

			if (!bt_proc->exec) {
				bt_proc_destroy(bt_proc);
				btrace_banner(*argv, 1);
			}
			if (opts.target_has_args)
				bt_proc->args_parser((char *)bt_proc->pi->
						     pi_args, bt_proc);

			else
				bt_proc->proc_arguments[0] =
				    strdup((const char *)bt_proc->exec);

			if ((!opts.force_addr_opt && opts.off_opt) ||
			    (opts.force_addr_opt && !opts.off_opt)) {
				printfd(STDERR_FILENO,
					WARN
					"You may choose both of address and offset !\n");
				bt_proc_destroy(bt_proc);
				btrace_banner(*argv, 1);
			}
			/* if address & offset are set */
			else {
				bt_proc->pi->pi_stack->ma_map[0] =
					bt_proc->pi->pi_address;
				bt_proc->pi->pi_stack->ma_map[1] =
					bt_proc->pi->pi_address +
					bt_proc->pi->pi_offset;
				
				bt_proc->pi->pi_addr->ma_map[0] =
				    bt_proc->pi->pi_address;
				bt_proc->pi->pi_addr->ma_map[1] =
				    bt_proc->pi->pi_address +
				    bt_proc->pi->pi_offset;
			}

			exec_target(bt_proc);

			/* If force address and offset are not set we read 
			 * from profs and fetch memory base address 
			 * and write new elf binary
			 */
			if (!opts.force_addr_opt && !opts.off_opt) {
				printfd(2,
					DO "Target :" GREEN " %s " NORM
					" PID : " GREEN "%d" NORM "\n",
					bt_proc->exec, bt_proc->pi->pi_pid);
				if (read_procfs_maps(bt_proc->pi) == -1)
					die("no such process");
			}

			fetch_data(bt_proc->pi);
		}

		/* pid attach */
		if (opts.pid_opt) {
			if (attach_process(bt_proc->pi) == -1)
				die(FATAL "Can't attach process");

			get_cmdline_by_pid(bt_proc->pi);
			printfd(2,
				DO "Attach PID:" GREEN " %d" NORM "  Target :"
				GREEN " %s" NORM "\n", bt_proc->pi->pi_pid,
				bt_proc->pi->pi_perm->p_full_path);

			if ((!opts.force_addr_opt && opts.off_opt) ||
			    (opts.force_addr_opt && !opts.off_opt)) {
				printfd(STDERR_FILENO,
					WARN
					"You may choose both of address and offset !\n");
				bt_proc_destroy(bt_proc);
				btrace_banner(*argv, 1);
			}
			/* if address & offset are set */
			else {
				bt_proc->pi->pi_stack->ma_map[0] =
					bt_proc->pi->pi_address;
				bt_proc->pi->pi_stack->ma_map[1] =
					bt_proc->pi->pi_address +
					bt_proc->pi->pi_offset;
				
				bt_proc->pi->pi_addr->ma_map[0] =
				    bt_proc->pi->pi_address;
				bt_proc->pi->pi_addr->ma_map[1] =
				    bt_proc->pi->pi_address +
				    bt_proc->pi->pi_offset;

			}

			if (!opts.force_addr_opt && !opts.off_opt)
				if (read_procfs_maps(bt_proc->pi) == -1)
					die(FATAL "No such process");

			/* it shouldn't return anything 
			 * BACK TO ME 
			 */
			fetch_data(bt_proc->pi);
		}

		if (opts.raw_opt)
			raw_dump(bt_proc->pi);
		else
			dump_using_memory(bt_proc->pi);

		if(opts.elf_dump_opts) {
			
		}
		
		pinfo_destroy(bt_proc->pi);
		bt_proc_destroy(bt_proc);

	}
	return 0;

}
Beispiel #28
0
int
print_insn_xtensa (bfd_vma memaddr, struct disassemble_info *info)
{
  unsigned operand_val;
  int bytes_fetched, size, maxsize, i, n, noperands, nslots;
  xtensa_isa isa;
  xtensa_opcode opc;
  xtensa_format fmt;
  struct dis_private priv;
  static bfd_byte *byte_buf = NULL;
  static xtensa_insnbuf insn_buffer = NULL;
  static xtensa_insnbuf slot_buffer = NULL;
  int first, first_slot, valid_insn;

  if (!xtensa_default_isa)
    xtensa_default_isa = xtensa_isa_init (0, 0);

  info->target = 0;
  maxsize = xtensa_isa_maxlength (xtensa_default_isa);

  /* Set bytes_per_line to control the amount of whitespace between the hex
     values and the opcode.  For Xtensa, we always print one "chunk" and we
     vary bytes_per_chunk to determine how many bytes to print.  (objdump
     would apparently prefer that we set bytes_per_chunk to 1 and vary
     bytes_per_line but that makes it hard to fit 64-bit instructions on
     an 80-column screen.)  The value of bytes_per_line here is not exactly
     right, because objdump adds an extra space for each chunk so that the
     amount of whitespace depends on the chunk size.  Oh well, it's good
     enough....  Note that we set the minimum size to 4 to accomodate
     literal pools.  */
  info->bytes_per_line = MAX (maxsize, 4);

  /* Allocate buffers the first time through.  */
  if (!insn_buffer)
    {
      insn_buffer = xtensa_insnbuf_alloc (xtensa_default_isa);
      slot_buffer = xtensa_insnbuf_alloc (xtensa_default_isa);
      byte_buf = (bfd_byte *) xmalloc (MAX (maxsize, 4));
    }

  priv.byte_buf = byte_buf;

  info->private_data = (void *) &priv;
  if (OPCODES_SIGSETJMP (priv.bailout) != 0)
      /* Error return.  */
      return -1;

  /* Don't set "isa" before the setjmp to keep the compiler from griping.  */
  isa = xtensa_default_isa;
  size = 0;
  nslots = 0;

  /* Fetch the maximum size instruction.  */
  bytes_fetched = fetch_data (info, memaddr);

  /* Copy the bytes into the decode buffer.  */
  memset (insn_buffer, 0, (xtensa_insnbuf_size (isa) *
			   sizeof (xtensa_insnbuf_word)));
  xtensa_insnbuf_from_chars (isa, insn_buffer, priv.byte_buf, bytes_fetched);

  fmt = xtensa_format_decode (isa, insn_buffer);
  if (fmt == XTENSA_UNDEFINED
      || ((size = xtensa_format_length (isa, fmt)) > bytes_fetched))
    valid_insn = 0;
  else
    {
      /* Make sure all the opcodes are valid.  */
      valid_insn = 1;
      nslots = xtensa_format_num_slots (isa, fmt);
      for (n = 0; n < nslots; n++)
	{
	  xtensa_format_get_slot (isa, fmt, n, insn_buffer, slot_buffer);
	  if (xtensa_opcode_decode (isa, fmt, n, slot_buffer)
	      == XTENSA_UNDEFINED)
	    {
	      valid_insn = 0;
	      break;
	    }
	}
    }

  if (!valid_insn)
    {
      (*info->fprintf_func) (info->stream, ".byte %#02x", priv.byte_buf[0]);
      return 1;
    }

  if (nslots > 1)
    (*info->fprintf_func) (info->stream, "{ ");

  first_slot = 1;
  for (n = 0; n < nslots; n++)
    {
      if (first_slot)
	first_slot = 0;
      else
	(*info->fprintf_func) (info->stream, "; ");

      xtensa_format_get_slot (isa, fmt, n, insn_buffer, slot_buffer);
      opc = xtensa_opcode_decode (isa, fmt, n, slot_buffer);
      (*info->fprintf_func) (info->stream, "%s",
			     xtensa_opcode_name (isa, opc));

      /* Print the operands (if any).  */
      noperands = xtensa_opcode_num_operands (isa, opc);
      first = 1;
      for (i = 0; i < noperands; i++)
	{
	  if (xtensa_operand_is_visible (isa, opc, i) == 0)
	    continue;
	  if (first)
	    {
	      (*info->fprintf_func) (info->stream, " ");
	      first = 0;
	    }
	  else
	    (*info->fprintf_func) (info->stream, ", ");
	  (void) xtensa_operand_get_field (isa, opc, i, fmt, n,
					   slot_buffer, &operand_val);

	  print_xtensa_operand (memaddr, info, opc, i, operand_val);
	}
    }

  if (nslots > 1)
    (*info->fprintf_func) (info->stream, " }");

  info->bytes_per_chunk = size;
  info->display_endian = info->endian;

  return size;
}
Beispiel #29
0
int main(int argc, char **argv){

/* should be 	int result = STATE_UNKNOWN; */

	int return_code = STATE_UNKNOWN;
	char *send_buffer=NULL;
	char *output_message=NULL;
	char *perfdata=NULL;
	char *temp_string=NULL;
	char *temp_string_perf=NULL;
	char *description=NULL,*counter_unit = NULL;
	char *minval = NULL, *maxval = NULL, *errcvt = NULL;
	char *fds=NULL, *tds=NULL;
	char *numstr;

	double total_disk_space=0;
	double free_disk_space=0;
	double percent_used_space=0;
	double warning_used_space=0;
	double critical_used_space=0;
	double mem_commitLimit=0;
	double mem_commitByte=0;
	double fminval = 0, fmaxval = 0;
	unsigned long utilization;
	unsigned long uptime;
	unsigned long age_in_minutes;
	double counter_value = 0.0;
	int offset=0;
	int updays=0;
	int uphours=0;
	int upminutes=0;

	int isPercent = FALSE;
	int allRight = FALSE;

	setlocale (LC_ALL, "");
	bindtextdomain (PACKAGE, LOCALEDIR);
	textdomain (PACKAGE);

	/* Parse extra opts if any */
	argv=np_extra_opts (&argc, argv, progname);

	if(process_arguments(argc,argv) == ERROR)
		usage4 (_("Could not parse arguments"));

	/* initialize alarm signal handling */
	signal(SIGALRM,socket_timeout_alarm_handler);

	/* set socket timeout */
	alarm(socket_timeout);

	switch (vars_to_check) {

	case CHECK_CLIENTVERSION:

		xasprintf(&send_buffer, "%s&1", req_password);
		fetch_data (server_address, server_port, send_buffer);
		if (value_list != NULL && strcmp(recv_buffer, value_list) != 0) {
			xasprintf (&output_message, _("Wrong client version - running: %s, required: %s"), recv_buffer, value_list);
			return_code = STATE_WARNING;
		} else {
			xasprintf (&output_message, "%s", recv_buffer);
			return_code = STATE_OK;
		}
		break;

	case CHECK_CPULOAD:

		if (value_list==NULL)
			output_message = strdup (_("missing -l parameters"));
		else if (strtoularray(lvalue_list,value_list,",")==FALSE)
			output_message = strdup (_("wrong -l parameter."));
		else {
			/* -l parameters is present with only integers */
			return_code=STATE_OK;
			temp_string = strdup (_("CPU Load"));
			temp_string_perf = strdup (" ");

			/* loop until one of the parameters is wrong or not present */
			while (lvalue_list[0+offset]> (unsigned long)0 &&
						 lvalue_list[0+offset]<=(unsigned long)17280 &&
						 lvalue_list[1+offset]> (unsigned long)0 &&
						 lvalue_list[1+offset]<=(unsigned long)100 &&
						 lvalue_list[2+offset]> (unsigned long)0 &&
						 lvalue_list[2+offset]<=(unsigned long)100) {

				/* Send request and retrieve data */
				xasprintf(&send_buffer,"%s&2&%lu",req_password,lvalue_list[0+offset]);
				fetch_data (server_address, server_port, send_buffer);

				utilization=strtoul(recv_buffer,NULL,10);

				/* Check if any of the request is in a warning or critical state */
				if(utilization >= lvalue_list[2+offset])
					return_code=STATE_CRITICAL;
				else if(utilization >= lvalue_list[1+offset] && return_code<STATE_WARNING)
					return_code=STATE_WARNING;

				xasprintf(&output_message,_(" %lu%% (%lu min average)"), utilization, lvalue_list[0+offset]);
				xasprintf(&temp_string,"%s%s",temp_string,output_message);
				xasprintf(&perfdata,_(" '%lu min avg Load'=%lu%%;%lu;%lu;0;100"), lvalue_list[0+offset], utilization,
				  lvalue_list[1+offset], lvalue_list[2+offset]);
				xasprintf(&temp_string_perf,"%s%s",temp_string_perf,perfdata);
				offset+=3;	/* move across the array */
			}

			if (strlen(temp_string)>10) {  /* we had at least one loop */
				output_message = strdup (temp_string);
				perfdata = temp_string_perf;
			} else
				output_message = strdup (_("not enough values for -l parameters"));
		}
		break;

	case CHECK_UPTIME:

		if (value_list == NULL) {
			value_list = "minutes";
		}
		if (strncmp(value_list, "seconds", strlen("seconds") + 1 ) && 
			strncmp(value_list, "minutes", strlen("minutes") + 1) && 
			strncmp(value_list, "hours", strlen("hours") + 1) && 
			strncmp(value_list, "days", strlen("days") + 1)) {

			output_message = strdup (_("wrong -l argument"));
		} else {
			xasprintf(&send_buffer, "%s&3", req_password);
			fetch_data (server_address, server_port, send_buffer);
			uptime=strtoul(recv_buffer,NULL,10);
			updays = uptime / 86400;
			uphours = (uptime % 86400) / 3600;
			upminutes = ((uptime % 86400) % 3600) / 60;

			if (!strncmp(value_list, "minutes", strlen("minutes")))
				uptime = uptime / 60;
			else if (!strncmp(value_list, "hours", strlen("hours")))
				uptime = uptime / 3600;
			else if (!strncmp(value_list, "days", strlen("days")))
				uptime = uptime / 86400;
			/* else uptime in seconds, nothing to do */

			xasprintf(&output_message,_("System Uptime - %u day(s) %u hour(s) %u minute(s) |uptime=%lu"),updays, uphours, upminutes, uptime);

			if (check_critical_value==TRUE && uptime <= critical_value)
				return_code=STATE_CRITICAL;
			else if (check_warning_value==TRUE && uptime <= warning_value)
				return_code=STATE_WARNING;
			else
				return_code=STATE_OK;
		}
		break;

	case CHECK_USEDDISKSPACE:

		if (value_list==NULL)
			output_message = strdup (_("missing -l parameters"));
		else if (strlen(value_list)!=1)
			output_message = strdup (_("wrong -l argument"));
		else {
			xasprintf(&send_buffer,"%s&4&%s", req_password, value_list);
			fetch_data (server_address, server_port, send_buffer);
			fds=strtok(recv_buffer,"&");
			tds=strtok(NULL,"&");
			if(fds!=NULL)
				free_disk_space=atof(fds);
			if(tds!=NULL)
				total_disk_space=atof(tds);

			if (total_disk_space>0 && free_disk_space>=0) {
				percent_used_space = ((total_disk_space - free_disk_space) / total_disk_space) * 100;
				warning_used_space = ((float)warning_value / 100) * total_disk_space;
				critical_used_space = ((float)critical_value / 100) * total_disk_space;

				xasprintf(&temp_string,_("%s:\\ - total: %.2f Gb - used: %.2f Gb (%.0f%%) - free %.2f Gb (%.0f%%)"),
				  value_list, total_disk_space / 1073741824, (total_disk_space - free_disk_space) / 1073741824,
				  percent_used_space, free_disk_space / 1073741824, (free_disk_space / total_disk_space)*100);
				xasprintf(&temp_string_perf,_("'%s:\\ Used Space'=%.2fGb;%.2f;%.2f;0.00;%.2f"), value_list,
				  (total_disk_space - free_disk_space) / 1073741824, warning_used_space / 1073741824,
				  critical_used_space / 1073741824, total_disk_space / 1073741824);

				if(check_critical_value==TRUE && percent_used_space >= critical_value)
					return_code=STATE_CRITICAL;
				else if (check_warning_value==TRUE && percent_used_space >= warning_value)
					return_code=STATE_WARNING;
				else
					return_code=STATE_OK;

				output_message = strdup (temp_string);
				perfdata = temp_string_perf;
			} else {
				output_message = strdup (_("Free disk space : Invalid drive"));
				return_code=STATE_UNKNOWN;
			}
		}
		break;

	case CHECK_SERVICESTATE:
	case CHECK_PROCSTATE:

		if (value_list==NULL)
			output_message = strdup (_("No service/process specified"));
		else {
			preparelist(value_list);		/* replace , between services with & to send the request */
			xasprintf(&send_buffer,"%s&%u&%s&%s", req_password,(vars_to_check==CHECK_SERVICESTATE)?5:6,
							 (show_all==TRUE) ? "ShowAll" : "ShowFail",value_list);
			fetch_data (server_address, server_port, send_buffer);
			numstr = strtok(recv_buffer,"&");
			if (numstr == NULL)
				die(STATE_UNKNOWN, _("could not fetch information from server\n"));
			return_code=atoi(numstr);
			temp_string=strtok(NULL,"&");
			output_message = strdup (temp_string);
		}
		break;

	case CHECK_MEMUSE:

		xasprintf(&send_buffer,"%s&7", req_password);
		fetch_data (server_address, server_port, send_buffer);
		numstr = strtok(recv_buffer,"&");
		if (numstr == NULL)
			die(STATE_UNKNOWN, _("could not fetch information from server\n"));
		mem_commitLimit=atof(numstr);
		numstr = strtok(NULL,"&");
		if (numstr == NULL)
			die(STATE_UNKNOWN, _("could not fetch information from server\n"));
		mem_commitByte=atof(numstr);
		percent_used_space = (mem_commitByte / mem_commitLimit) * 100;
		warning_used_space = ((float)warning_value / 100) * mem_commitLimit;
		critical_used_space = ((float)critical_value / 100) * mem_commitLimit;

		/* Divisor should be 1048567, not 3044515, as we are measuring "Commit Charge" here,
		which equals RAM + Pagefiles. */
		xasprintf(&output_message,_("Memory usage: total:%.2f Mb - used: %.2f Mb (%.0f%%) - free: %.2f Mb (%.0f%%)"),
		  mem_commitLimit / 1048567, mem_commitByte / 1048567, percent_used_space,
		  (mem_commitLimit - mem_commitByte) / 1048567, (mem_commitLimit - mem_commitByte) / mem_commitLimit * 100);
		xasprintf(&perfdata,_("'Memory usage'=%.2fMb;%.2f;%.2f;0.00;%.2f"), mem_commitByte / 1048567,
		  warning_used_space / 1048567, critical_used_space / 1048567, mem_commitLimit / 1048567);

		return_code=STATE_OK;
		if(check_critical_value==TRUE && percent_used_space >= critical_value)
			return_code=STATE_CRITICAL;
		else if (check_warning_value==TRUE && percent_used_space >= warning_value)
			return_code=STATE_WARNING;

		break;

	case CHECK_COUNTER:


		/*
		CHECK_COUNTER has been modified to provide extensive perfdata information.
		In order to do this, some modifications have been done to the code
		and some constraints have been introduced.

		1) For the sake of simplicity of the code, perfdata information will only be
		 provided when the "description" field is added.

		2) If the counter you're going to measure is percent-based, the code will detect
		 the percent sign in its name and will attribute minimum (0%) and maximum (100%)
		 values automagically, as well the ¨%" sign to graph units.

		3) OTOH, if the counter is "absolute", you'll have to provide the following
		 the counter unit - that is, the dimensions of the counter you're getting. Examples:
		 pages/s, packets transferred, etc.

		4) If you want, you may provide the minimum and maximum values to expect. They aren't mandatory,
		 but once specified they MUST have the same order of magnitude and units of -w and -c; otherwise.
		 strange things will happen when you make graphs of your data.
		*/

		if (value_list == NULL)
			output_message = strdup (_("No counter specified"));
		else
		{
			preparelist (value_list);	/* replace , between services with & to send the request */
			isPercent = (strchr (value_list, '%') != NULL);

			strtok (value_list, "&");	/* burn the first parameters */
			description = strtok (NULL, "&");
			counter_unit = strtok (NULL, "&");
			xasprintf (&send_buffer, "%s&8&%s", req_password, value_list);
			fetch_data (server_address, server_port, send_buffer);
			counter_value = atof (recv_buffer);

			if (description == NULL)
			xasprintf (&output_message, "%.f", counter_value);
			else if (isPercent)
			{
				counter_unit = strdup ("%");
				allRight = TRUE;
			}

			if ((counter_unit != NULL) && (!allRight))
			{
				minval = strtok (NULL, "&");
				maxval = strtok (NULL, "&");

				/* All parameters specified. Let's check the numbers */

				fminval = (minval != NULL) ? strtod (minval, &errcvt) : -1;
				fmaxval = (minval != NULL) ? strtod (maxval, &errcvt) : -1;

				if ((fminval == 0) && (minval == errcvt))
					output_message = strdup (_("Minimum value contains non-numbers"));
				else
				{
					if ((fmaxval == 0) && (maxval == errcvt))
						output_message = strdup (_("Maximum value contains non-numbers"));
					else
						allRight = TRUE;	/* Everything is OK. */

				}
			}
			else if ((counter_unit == NULL) && (description != NULL))
				output_message = strdup (_("No unit counter specified"));

			if (allRight)
			{
				/* Let's format the output string, finally... */
					if (strstr(description, "%") == NULL) {
						xasprintf (&output_message, "%s = %.2f %s", description, counter_value, counter_unit);
					} else {
						/* has formatting, will segv if wrong */
						xasprintf (&output_message, description, counter_value);
					}
					xasprintf (&output_message, "%s |", output_message);
					xasprintf (&output_message,"%s %s", output_message,
						fperfdata (description, counter_value,
							counter_unit, 1, warning_value, 1, critical_value,
							(!(isPercent) && (minval != NULL)), fminval,
							(!(isPercent) && (minval != NULL)), fmaxval));
			}
		}

		if (critical_value > warning_value)
		{			/* Normal thresholds */
			if (check_critical_value == TRUE && counter_value >= critical_value)
				return_code = STATE_CRITICAL;
			else if (check_warning_value == TRUE && counter_value >= warning_value)
				return_code = STATE_WARNING;
			else
				return_code = STATE_OK;
		}
		else
		{			/* inverse thresholds */
			return_code = STATE_OK;
			if (check_critical_value == TRUE && counter_value <= critical_value)
				return_code = STATE_CRITICAL;
			else if (check_warning_value == TRUE && counter_value <= warning_value)
				return_code = STATE_WARNING;
		}
	break;

	case CHECK_FILEAGE:

		if (value_list==NULL)
			output_message = strdup (_("No counter specified"));
		else {
			preparelist(value_list);		/* replace , between services with & to send the request */
			xasprintf(&send_buffer,"%s&9&%s", req_password,value_list);
			fetch_data (server_address, server_port, send_buffer);
			age_in_minutes = atoi(strtok(recv_buffer,"&"));
			description = strtok(NULL,"&");
			output_message = strdup (description);

			if (critical_value > warning_value) {        /* Normal thresholds */
				if(check_critical_value==TRUE && age_in_minutes >= critical_value)
					return_code=STATE_CRITICAL;
				else if (check_warning_value==TRUE && age_in_minutes >= warning_value)
					return_code=STATE_WARNING;
				else
					return_code=STATE_OK;
			}
			else {                                       /* inverse thresholds */
				if(check_critical_value==TRUE && age_in_minutes <= critical_value)
					return_code=STATE_CRITICAL;
				else if (check_warning_value==TRUE && age_in_minutes <= warning_value)
					return_code=STATE_WARNING;
				else
					return_code=STATE_OK;
			}
		}
		break;

	case CHECK_INSTANCES:
		if (value_list==NULL)
			output_message = strdup (_("No counter specified"));
		else {
			xasprintf(&send_buffer,"%s&10&%s", req_password,value_list);
			fetch_data (server_address, server_port, send_buffer);
			if (!strncmp(recv_buffer,"ERROR",5)) {
				printf("NSClient - %s\n",recv_buffer);
				exit(STATE_UNKNOWN);
			}
			xasprintf(&output_message,"%s",recv_buffer);
			return_code=STATE_OK;
		}
		break;

	case CHECK_NONE:
	default:
		usage4 (_("Please specify a variable to check"));
		break;

	}

	/* reset timeout */
	alarm(0);

	if (perfdata==NULL)
		printf("%s\n",output_message);
	else
		printf("%s | %s\n",output_message,perfdata);
	return return_code;
}
Beispiel #30
0
/***********************************************************************//**
 * @brief Remove rows from column
 *
 * @param[in] row Row after which rows should be removed (0=first row).
 * @param[in] nrows Number of rows to be removed.
 *
 * @exception GException::fits_invalid_row
 *            Specified row is invalid.
 * @exception GException::fits_invalid_nrows
 *            Invalid number of rows specified.
 *
 * This method removes rows from a FITS table. This implies that the column
 * will be loaded into memory.
 ***************************************************************************/
void GFitsTableLongLongCol::remove(const int& row, const int& nrows)
{
    // Make sure that row is valid
    if (row < 0 || row >= m_length) {
        throw GException::fits_invalid_row(G_REMOVE, row, m_length-1);
    }
    
    // Make sure that we don't remove beyond the limit
    if (nrows < 0 || nrows > m_length-row) {
        throw GException::fits_invalid_nrows(G_REMOVE, nrows, m_length-row);
    }
    
    // Continue only if there are rows to be removed
    if (nrows > 0) {
    
        // If data are not available then load them now
        if (m_data == NULL) fetch_data();

        // Compute new column length
        int length = m_length - nrows;
        
        // Calculate size of new memory
        m_size = m_number * length;

        // If we have rows remaining then allocate new data to hold
        // the column
        if (m_size > 0) {
        
            // Allocate new data to hold the column
            long long* new_data = new long long[m_size];

            // Compute the number of elements before the removal point,
            // the number of elements that get removed, and the total
            // number of elements after the removal point
            int n_before = m_number * row;
            int n_remove = m_number * nrows;
            int n_after  = m_number * (length - row);

            // Copy data
            long long* src = m_data;
            long long* dst = new_data;
            for (int i = 0; i < n_before; ++i) {
                *dst++ = *src++;
            }
            src += n_remove;
            for (int i = 0; i < n_after; ++i) {
                *dst++ = *src++;
            }
        
            // Free old data
            if (m_data != NULL) delete [] m_data;
            
            // Set pointer to new data and store length
            m_data   = new_data;
            m_length = length;
        
        } // endif: there are still elements after removal
        
        // ... otherwise just remove all data
        else {

            // Free old data
            if (m_data != NULL) delete [] m_data;

            // Set pointer to new data and store length
            m_data   = NULL;
            m_length = length;
        }
    
    } // endfor: there were rows to be removed

    // Return
    return;
}