Exemple #1
1
void
PingusSoundReal::real_play_sound(const std::string& name, float volume, float panning)
{
  if (!globals::sound_enabled)
    return;

  SoundHandle chunk;

  chunk = SoundResMgr::load(name);
  if (!chunk)
  {
    perr(PINGUS_DEBUG_SOUND) << "Can't open sound '" << name << "' -- skipping\n"
                             << "  Mix_Error: " << Mix_GetError() << std::endl;
    return;
  }

  int channel = Mix_PlayChannel(-1, chunk, 0);
  if (channel != -1)
  {
    Mix_Volume(channel, static_cast<int>(volume * MIX_MAX_VOLUME));
    if (panning != 0.0f)
    {
      Uint8 left  = static_cast<Uint8>((panning < 0.0f) ? 255 : static_cast<Uint8>((panning - 1.0f) * -255));
      Uint8 right = static_cast<Uint8>((panning > 0.0f) ? 255 : static_cast<Uint8>((panning + 1.0f) * 255));
      Mix_SetPanning(channel, left, right);
    }
  }
}
Exemple #2
0
void pthreadCreate(pthread_t *thread, const pthread_attr_t *attr,
	void *(*start_routine)(void *), void *arg)
/* Create a thread or squawk and die. */
{
int err = pthread_create(thread, attr, start_routine, arg);
perr("pthread_create", err);
}
Exemple #3
0
int init_ctl_channel(const char *name, int verb)
{
	char buf[PATH_MAX];
	struct statfs st;
	int old_transport = 0;

	if (statfs("/sys/kernel/debug", &st) == 0 && (int)st.f_type == (int)DEBUGFS_MAGIC) {
		if (sprintf_chk(buf, "/sys/kernel/debug/systemtap/%s/.cmd", name))
			return -1;
	} else {
		old_transport = 1;
		if (sprintf_chk(buf, "/proc/systemtap/%s/.cmd", name))
			return -2;
	}

	control_channel = open(buf, O_RDWR);
	dbug(2, "Opened %s (%d)\n", buf, control_channel);
	if (control_channel < 0) {
		if (verb) {
			if (attach_mod && errno == ENOENT)
				err("ERROR: Can not attach. Module %s not running.\n", name);
			else
				perr("Couldn't open control channel '%s'", buf);
		}
		return -3;
	}
	if (set_clexec(control_channel) < 0)
		return -4;

	return old_transport;
}
Exemple #4
0
void pthreadCondSignal(pthread_cond_t *cond)
/* Set conditional signal to wake up a sleeping thread, or
 * die trying. */
{
int err = pthread_cond_signal(cond);
perr("pthread_cond_signal", err);
}
Exemple #5
0
void knox_print_event_log(int sg_fd)
{
#define EVENT_LOG_BUFFER_SIZE 8192
  unsigned char buf[EVENT_LOG_BUFFER_SIZE];
  unsigned char *buf_ptr;
  int64_t timestamp = 0;
  int i, j;
  char id_str[16];

  perr("NOTE: Event log in Knox is not complete at this time...\n");

  sg_ll_read_buffer(sg_fd, 2, 0xe5, 0, (void *) buf,
                    EVENT_LOG_BUFFER_SIZE, 1, 0);

  for (i = 0; i < EVENT_LOG_BUFFER_SIZE; i += 64) {
    buf_ptr = buf + i;
    timestamp = *((int64_t *)(buf_ptr));
    IF_PRINT_NONE_JSON
      printf("[%11ld][Event %d] %d %x %s\n", timestamp,
             buf_ptr[13] * 256 + buf_ptr[12],
             buf_ptr[15] * 256 + buf_ptr[14],
             *((int *)(buf_ptr + 16)),
             (char *)(buf_ptr + 24));

    PRINT_JSON_GROUP_SEPARATE;

    snprintf(id_str, 16, "%d", buf_ptr[13] * 256 + buf_ptr[12]);
    PRINT_JSON_GROUP_HEADER(id_str);
    PRINT_JSON_ITEM("timestamp", "%ld", timestamp);
    PRINT_JSON_ITEM("id", "%d", buf_ptr[13] * 256 + buf_ptr[12]);
    PRINT_JSON_LAST_ITEM("description", "%s", (char *)(buf_ptr + 24));
    PRINT_JSON_GROUP_ENDING;
  }
}
int LshttpdMain::testRunningServer()
{
    int count = 0;
    int ret;
    do
    {
        ret = m_pidFile.lockPidFile(PID_FILE);
        if (ret)
        {
            if ((ret == -2) && (errno == EACCES || errno == EAGAIN))
            {
                ++count;
                if (count >= 10)
                {
                    perr("LiteSpeed Web Server is running!");
                    return 2;
                }
                ls_sleep(100);
            }
            else
            {
                fprintf(stderr, "[ERROR] Failed to write to pid file:%s!\n", PID_FILE);
                return ret;
            }
        }
        else
            break;
    }
    while (true);
    return ret;
}
Exemple #7
0
void
PingusSoundReal::real_play_music (const std::string & arg_filename, float volume, bool loop)
{
  std::string filename;

  filename = arg_filename;

  if (!globals::music_enabled)
    return;

  pout(PINGUS_DEBUG_SOUND) << "PingusSoundReal: Playing music: " << filename << std::endl;

  real_stop_music();

  music_sample = Mix_LoadMUS(filename.c_str());
  if (!music_sample)
  {
    perr(PINGUS_DEBUG_SOUND) << "Can't load music: " << filename << "' -- skipping\n"
                             << "  Mix_Error: " << Mix_GetError() << std::endl;
    return;
  }

  Mix_VolumeMusic(static_cast<int>(volume * 0.5f * MIX_MAX_VOLUME)); // FIXME: music_volume
  Mix_PlayMusic(music_sample, loop ? -1 : 0);
}
void prsnmpstr(char *stroid) {
    struct snmp_pdu *pdu, *resp;
    oid tmp_oid[MAX_OID_LEN];
    size_t tmp_oid_len=MAX_OID_LEN;
    int stat;
    char *tmp;

    pdu=snmp_pdu_create(SNMP_MSG_GET);
    read_objid(stroid, tmp_oid, &tmp_oid_len);
    snmp_add_null_var(pdu, tmp_oid, tmp_oid_len);
    stat=snmp_synch_response(ses, pdu, &resp);

    if (stat != STAT_SUCCESS || resp->errstat != SNMP_ERR_NOERROR) 
        perr(resp);

    if(resp->variables->val_len && strlen((char *)resp->variables->val.string)) {
        tmp=malloc((resp->variables->val_len+1) * sizeof(char));
        memcpy(tmp, resp->variables->val.string, resp->variables->val_len);
        tmp[resp->variables->val_len]=0;
        printf("%s", tmp);
        free(tmp);
    }
    
    if(resp)
            snmp_free_pdu(resp);

}
Exemple #9
0
/*-----------------------------------------------------
        Parameters:

        Returns value:

        Description
------------------------------------------------------*/
int
ErrorPrintf(int ecode, const char *fmt, ...)
{
  va_list  args ;
  FILE     *fp ;

  Gerror = ecode ;
  va_start(args, fmt) ;
  (*error_vfprintf)(stderr, fmt, args) ;
  fprintf(stderr, "\n") ;
  fflush(stderr);
  fflush(stdout);
  va_end(args);
  if (errno)
    perror(NULL) ;
#if 0
  if (hipserrno)
    perr(ecode, "Hips error:") ;
#endif

  va_start(args, fmt) ;
  fp = fopen(ERROR_FNAME, "a") ;
  if (fp)
  {
    (*error_vfprintf)(fp, fmt, args) ;
    fprintf(fp, "\n") ;
    fclose(fp) ;     /* close file to flush changes */
  }
  va_end(args);
  return(ecode) ;
}
Exemple #10
0
/**
 * corrupted_dcache
 * @brief "corrupted D-cache" error injection handler
 *
 * This will inject a corrupted D-cache error onto the system
 *
 * @param ei_func errinjct functionality
 * @return 0 on success, !0 otherwise
 */
int corrupted_dcache(ei_function *ei_func)
{
	int rc;

	if (ext_help || check_cpu_arg() || check_token_arg()) {
		corrupted_dcache_usage(ei_func);
		return 1;
	}

	if ((action < 0) || (action > MAX_DCACHE_ACTION_CODE)) {
		perr(0, "Invalid action code (%d)", action);
		corrupted_dcache_usage(ei_func);
		return 1;
	}

	if (!be_quiet) {
		printf("Injecting a %s error\n", ei_func->name);
		printf("Action: %d - %s\n", action, action_codes[action]);
	}

	if (dryrun)
		return 0;

	err_buf[0] = action;

	rc = do_rtas_errinjct(ei_func);

	return rc;
}
void prifalias(oid inst) {
    struct snmp_pdu *pdu, *resp;
    oid tmp_oid[] = { 1,3,6,1,2,1,31,1,1,1,18,0 };
    int stat;
    char *tmp;

    if(!extended) {
        fprintf(stderr, "ifalias is only available in eXtended mode\n");
        snmp_close(ses);
        SOCK_CLEANUP;
        exit(1);
    }
    
    tmp_oid[11]=inst;
    pdu=snmp_pdu_create(SNMP_MSG_GET);
    snmp_add_null_var(pdu, tmp_oid, sizeof(tmp_oid)/sizeof(oid));
    stat=snmp_synch_response(ses, pdu, &resp);

    if (stat != STAT_SUCCESS || resp->errstat != SNMP_ERR_NOERROR) 
        perr(resp);

    if(resp->variables->val_len && strlen((char *)resp->variables->val.string)) {
        tmp=malloc((resp->variables->val_len+1) * sizeof(char));
        memcpy(tmp, resp->variables->val.string, resp->variables->val_len);
        tmp[resp->variables->val_len]=0;
        printf("  \"%s\"", tmp);
        free(tmp);
    }

    if(resp)
            snmp_free_pdu(resp);

}
uint32_t getcntr32(int dir, oid inst) {
    struct snmp_pdu *pdu, *resp;
    oid iftable_oid[]  = { 1,3,6,1,2,1,2,2,1,0,0 };    // dir=9 ; inst=10
    int stat;
    uint32_t tmp;

    pdu=snmp_pdu_create(SNMP_MSG_GET);
    iftable_oid[9]=dir;
    iftable_oid[10]=inst;
    snmp_add_null_var(pdu, iftable_oid, sizeof(iftable_oid)/sizeof(oid));
    
    stat=snmp_synch_response(ses, pdu, &resp);
    if (stat != STAT_SUCCESS || resp->errstat != SNMP_ERR_NOERROR) 
        perr(resp);

    if(resp->variables->type != ASN_COUNTER) {
        fprintf(stderr, "\nError: unsupported data type (only 32bit counter is supported in normal mode)\n");
        snmp_close(ses);
        SOCK_CLEANUP;
        exit(1);
    }

    tmp=resp->variables->val.counter64->high;

    if(resp)
        snmp_free_pdu(resp);

    return tmp;
}
Exemple #13
0
/**
 * IOチャネル出力時の処理 
 */
static void fi_output(ioent_t *io, event_t *evt, int exec) {
    DWORD error;

//    printf("fi_output: enter(exec=%d,trans=%d)\n", exec, evt->trans);
//    fflush(stdout);

    if (evt->trans == 0) {
        int len = STRLEN(evt->val);
        if (len == 0) {
            io_write_complete(io, 0);
            close_file(io);
            return;
        }
        io->offset = 0;
        write_exec(io, evt);
        return;
    }

    if (!SetEvent(io->ctlblk.hEvent)) {
        error = GetLastError();
        perr(PERR_SYSTEM, "SetEvent", error, __FILE__, __LINE__);
        return;
    }
    TAILQ_INSERT_TAIL(&__prc__mioq, io, mlink);
}
Exemple #14
0
btbool	cmpdirRename(cmpdir_t *dir, char *newPath, int WinVolume)
{
int ii;
	
	if(trace)
		printf("renaming directory %s to %s\n", dir->name, newPath);
	if(rename(dir->name, newPath) < 0) {
		/* 
		 * Remember that Windows will not let you rename a directory, if
		 * there is an open file in the directory. So if we get an EACCES
		 * error, and there are any open files in the directory just ignore
		 * the error.
		 */
		if (WinVolume && (errno == EACCES)) {
			for (ii = 0; ii < CMPDIR_MAX_FILES; ii++)
				if (dir->files[ii].fd)
					return 1;
		}
		perr(errno, "error renaming dir %s to %s", dir->name, newPath);
		return 0;
	}
	free(dir->name);
	dir->name = malloc(strlen(newPath) + 1);
	strcpy(dir->name, newPath);
	return 1;
}
Exemple #15
0
static char *cwdname(void)
{
    /* Read in the current directory; the name will be overwritten on
     * subsequent calls.
     */
    static char *ptr = NULL;
    static size_t size = SIZE;

    if (ptr == NULL)
        if ((ptr = malloc(size)) == NULL)
            errx(EXIT_FAILURE, "virtual memory exhausted");

    while (1)
    {
        if (ptr == NULL)
            panic("out of memory");

        if (getcwd(ptr, size-1) != NULL)
            return ptr;

        if (errno != ERANGE)
            perr("cannot get directory");

        free (ptr);
        size += SIZE;
        if ((ptr = malloc(size)) == NULL)
            errx(EXIT_FAILURE, "virtual memory exhausted");
    }
}
Exemple #16
0
int main(int argc, char **argv)
{
	int pid_fd = -1, r = 0;
	pid_t old_pid;
	struct pfiled pfiled;

	init_perr("pfiled");
	parse_cmdline(argc, argv);

	perr(PI, 0, "p = %ld, nr_ops = %lu\n", cmdline_portno, cmdline_nr_ops);
	
	if (cmdline_pidfile){
		pid_fd = pidfile_open(cmdline_pidfile, &old_pid);
		if (pid_fd < 0) {
			if (old_pid) {
				perr(PFE, 0, "Daemon already running, pid: %d.", old_pid);
			} else {
				perr(PFE, 0, "Cannot open or create pidfile");
			}
			return -1;
		}
	}

	if (cmdline_daemon){
		if (daemon(0, 1) < 0){
			perr(PFE, 0, "Cannot daemonize");
			r = -1;
			goto out;
		}
	}
	setup_signals();
	if (pid_fd > 0)
		pidfile_write(pid_fd);


	if (pfiled_init(&pfiled) < 0){
		r = -1;
		goto out;
	}

	r = pfiled_loop(&pfiled);
out:
	if (pid_fd > 0)
		pidfile_remove(cmdline_pidfile, pid_fd);
	return r;

}
Exemple #17
0
static int get_mass_storage_status(libusb_device_handle *handle, uint8_t endpoint, uint32_t expected_tag)
{
	int i, r, size;
	struct command_status_wrapper csw;

	// The device is allowed to STALL this transfer. If it does, you have to
	// clear the stall and try again.
	i = 0;
	do {
		r = libusb_bulk_transfer(handle, endpoint, (unsigned char*)&csw, 13, &size, 1000);
		if (r == LIBUSB_ERROR_PIPE) {
			libusb_clear_halt(handle, endpoint);
		}
		i++;
	} while ((r == LIBUSB_ERROR_PIPE) && (i<RETRY_MAX));
	if (r != LIBUSB_SUCCESS) {
		perr("   get_mass_storage_status: %s\n", libusb_strerror((enum libusb_error)r));
		return -1;
	}
	if (size != 13) {
		perr("   get_mass_storage_status: received %d bytes (expected 13)\n", size);
		return -1;
	}
	if (csw.dCSWTag != expected_tag) {
		perr("   get_mass_storage_status: mismatched tags (expected %08X, received %08X)\n",
			expected_tag, csw.dCSWTag);
		return -1;
	}
	// For this test, we ignore the dCSWSignature check for validity...
	printf("   Mass Storage Status: %02X (%s)\n", csw.bCSWStatus, csw.bCSWStatus?"FAILED":"Success");
	if (csw.dCSWTag != expected_tag)
		return -1;
	if (csw.bCSWStatus) {
		// REQUEST SENSE is appropriate only if bCSWStatus is 1, meaning that the
		// command failed somehow.  Larger values (2 in particular) mean that
		// the command couldn't be understood.
		if (csw.bCSWStatus == 1)
			return -2;	// request Get Sense
		else
			return -1;
	}

	// In theory we also should check dCSWDataResidue.  But lots of devices
	// set it wrongly.
	return 0;
}
Exemple #18
0
static int intarg (char * op) {
  const char * tok;
  if (!(tok = strtok (0, " ")) || !isnumstr (tok) || strtok (0, " ")) {
    perr ("expected integer argument for '%s'", op);
    exit (1);
  }
  return atoi (tok);
}
int main( int argc, char *argv[] ) {
  word_count *casted_c;
  GHashTableIter iter_c;
  //int *id_t, *id_c; 
  gpointer key_c, value_t_c, value_t, key_t;  
  if( argc != 2 ) { usage(); }
  perr( "Reading input file into hashmap...\n" );
  read_input_file( argv[1] ); 

  // File header
  perr( "Calculating association scores...\n" );
  printf( "target\tid_target\tcontext\tid_context\tf_tc\tf_t\tf_c\t" );
  printf( "cond_prob\tpmi\tnpmi\tlmi\ttscore\tzscore\tdice\tchisquare\t" );
  printf( "loglike\taffinity\tentropy_target\tentropy_context\n" );
  // First calculate all entropies for contexts
  g_hash_table_iter_init( &iter_c, c_dict );
  while( g_hash_table_iter_next( &iter_c, &key_c, &value_t_c ) ){
    casted_c = g_hash_table_lookup( c_dict, key_c );
    casted_c->entropy = calculate_entropy(casted_c->count, casted_c->links);      
  }
  g_hash_table_iter_init( &iter_t, t_dict );
  nb_targets = g_hash_table_size( t_dict );
  if( nb_threads > 1 ) {
    run_multi_threaded( &calculate_ams_all, nb_threads );
  }
  else {
    while( g_hash_table_iter_next( &iter_t, &key_t, &value_t ) ){
      calculate_ams_all_serial( (word_count *)value_t, key_t );
      update_count();
    }
  }
  // Clean and free to avoid memory leaks
  perr( "Finished, cleaning up...\n" );
  g_hash_table_destroy( t_dict );
  g_hash_table_destroy( c_dict );
  // MUST be last to be destroyed, otherwise will destroy keys in previous dicts 
  // and memory will leak from unreachable values
  g_hash_table_destroy( symbols_dict );   
  g_hash_table_destroy( inv_symbols_dict ); // no effect  
  
  perra( "Number of targets: %d\n", idc_t );
  perra( "Number of contexts: %d\n", idc_c );
  perr( "You can now calculate similarities with command below\n");
  perr( "  ./calculate_similarity [OPTIONS] <out-file>\n\n" );
  return 0;
}
Exemple #20
0
// Read the MS WinUSB Feature Descriptors, that are used on Windows 8 for automated driver installation
static void read_ms_winsub_feature_descriptors(libusb_device_handle *handle, uint8_t bRequest, int iface_number)
{
#define MAX_OS_FD_LENGTH 256
	int i, r;
	uint8_t os_desc[MAX_OS_FD_LENGTH];
	uint32_t length;
	void* le_type_punning_IS_fine;
	struct {
		const char* desc;
		uint8_t recipient;
		uint16_t index;
		uint16_t header_size;
	} os_fd[2] = {
		{"Extended Compat ID", LIBUSB_RECIPIENT_DEVICE, 0x0004, 0x10},
		{"Extended Properties", LIBUSB_RECIPIENT_INTERFACE, 0x0005, 0x0A}
	};

	if (iface_number < 0) return;

	for (i=0; i<2; i++) {
		printf("\nReading %s OS Feature Descriptor (wIndex = 0x%04d):\n", os_fd[i].desc, os_fd[i].index);

		// Read the header part
		r = libusb_control_transfer(handle, (uint8_t)(LIBUSB_ENDPOINT_IN|LIBUSB_REQUEST_TYPE_VENDOR|os_fd[i].recipient),
			bRequest, (uint16_t)(((iface_number)<< 8)|0x00), os_fd[i].index, os_desc, os_fd[i].header_size, 1000);
		if (r < os_fd[i].header_size) {
			perr("   Failed: %s", (r<0)?libusb_error_name((enum libusb_error)r):"header size is too small");
			return;
		}
		le_type_punning_IS_fine = (void*)os_desc;
		length = *((uint32_t*)le_type_punning_IS_fine);
		if (length > MAX_OS_FD_LENGTH) {
			length = MAX_OS_FD_LENGTH;
		}

		// Read the full feature descriptor
		r = libusb_control_transfer(handle, (uint8_t)(LIBUSB_ENDPOINT_IN|LIBUSB_REQUEST_TYPE_VENDOR|os_fd[i].recipient),
			bRequest, (uint16_t)(((iface_number)<< 8)|0x00), os_fd[i].index, os_desc, (uint16_t)length, 1000);
		if (r < 0) {
			perr("   Failed: %s", libusb_error_name((enum libusb_error)r));
			return;
		} else {
			display_buffer_hex(os_desc, r);
		}
	}
}
Exemple #21
0
static void
usage(void)
{
    extern char *__progname;

    perr("usage: %s dev0 dev1\n", __progname);
    exit(EXIT_FAILURE);
}
Exemple #22
0
/*
 * cl_init --
 *	Create and partially initialize the CL structure.
 */
static CL_PRIVATE *
cl_init(WIN *wp)
{
	CL_PRIVATE *clp;
	int fd;
	GS *gp;

	gp = wp->gp;

	/* Allocate the CL private structure. */
	CALLOC_NOMSG(NULL, clp, CL_PRIVATE *, 1, sizeof(CL_PRIVATE));
	if (clp == NULL)
		perr(gp->progname, NULL);
	gp->cl_private = clp;

	/*
	 * Set the CL_STDIN_TTY flag.  It's purpose is to avoid setting
	 * and resetting the tty if the input isn't from there.  We also
	 * use the same test to determine if we're running a script or
	 * not.
	 */
	if (isatty(STDIN_FILENO))
		F_SET(clp, CL_STDIN_TTY);
	else
		F_SET(gp, G_SCRIPTED);

	/*
	 * We expect that if we've lost our controlling terminal that the
	 * open() (but not the tcgetattr()) will fail.
	 */
	if (F_ISSET(clp, CL_STDIN_TTY)) {
		if (tcgetattr(STDIN_FILENO, &clp->orig) == -1)
			goto tcfail;
	} else if ((fd = open(_PATH_TTY, O_RDONLY, 0)) != -1) {
		if (tcgetattr(fd, &clp->orig) == -1) {
tcfail:			perr(gp->progname, "tcgetattr");
			exit (1);
		}
		(void)close(fd);
	}

	/* Initialize the list of curses functions. */
	cl_func_std(wp);

	return (clp);
}
Exemple #23
0
void converter_perror(const char * spec)
{
	perr(spec);
	perr("\n");
	switch(errnum)
	{
	case CONVERTER_ERROR_VOID:
		break;
	case CONVERTER_ERROR_NODICT:
		perr(_("No dictionary loaded"));
		break;
	case CONVERTER_ERROR_OUTBUF:
		perr(_("Output buffer not enough for one segment"));
		break;
	default:
		perr(_("Unknown"));
	}
}
Exemple #24
0
void	
svas_base::set_error_info(
	int verr, 
	int res, 
	error_type ekind,
	const w_rc_t &smerrorrc,
	const char *msg,
	int	 line,
	const char *file
)
{
	FUNC(svas_base::set_error_info);
    if(smerrorrc) { 
		status.smresult = -1;
        status.smreason = (int)smerrorrc.err_num(); 
        status.osreason = (int)smerrorrc.sys_err_num(); 
#ifdef DEBUG
		if( ekind != ET_USER ||
			( ShoreVasLayer.pusererrs() && !_suppress_p_user_errors )
		) {
			cerr 
				<< "{ line " << __LINE__
				<< " file " << __FILE__
				<< ": for -DDEBUG only, ekind = "  << ekind  << ":\n"
				<< smerrorrc 
				<< "\n}"
				<< endl;
		}
#endif
		//
		// TRANSLATE CERTAIN ERRORS HERE:
		//
		bool translated=true;
		switch(status.smreason) {
		case eOUTOFSPACE:
		case eDEVICEVOLFULL:
			verr =  OS_NoSpaceLeft;
			break;

		default:
			translated = false;
			break;
		}
		if(translated) {
			status.osreason = status.smresult = status.smreason = 0;
#ifdef DEBUG
			cerr << "TRANSLATED TO " << verr << endl;
#endif
		}
    }/* else -- not an SM error */ else {
		status.osreason = status.smresult = status.smreason = 0;
	}
    status.vasreason = verr;
    status.vasresult = res;
    perr(msg, line, file, ekind);
	perrstop();
}
Exemple #25
0
const char *
devcheck(const char *origname)
{
	struct stat stslash, stchar;

	if (stat("/", &stslash) < 0) {
		perr("Can't stat `/'");
		return (origname);
	}
	if (stat(origname, &stchar) < 0) {
		perr("Can't stat %s\n", origname);
		return (origname);
	}
	if (!S_ISCHR(stchar.st_mode)) {
		perr("%s is not a char device\n", origname);
	}
	return (origname);
}
Exemple #26
0
/**
 * check_cpu_arg
 * @brief Common routine to check if the "-C cpu" flag was used.
 *
 * This routine is provided to check if the "-C cpu" option was
 * specified and generate a common erro message.
 */
int check_cpu_arg(void)
{
	if (logical_cpu == -1) {
		perr(0, "Please specify a logical cpu with the -C option");
		return 1;
	}

	return 0;
}
Exemple #27
0
/**
 * check_token_arg
 * @brief Common routine to check if the "-k token" flag was used.
 *
 * This provides a common point for checking to see if the "-k token"
 * option was specified and generates a common error statement.
 */
int check_token_arg(void)
{
	if (ei_token == -1) {
		perr(0, "Please specify the error inject token with the -k option");
		return 1;
	}

	return 0;
}
Exemple #28
0
int destroy_synchronization_objects(void){
	int r;
	r = pthread_barrier_destroy(&barrier);
	if(r == EBUSY ) perr("EBUSY" );
	if(r == EINVAL) perr("EINVAL");
	if(r) return 1;

	r = sem_destroy(&sem);
	if(r == EINVAL) perr("EINVAL");
	if(r) return 1;

	// r = pthread_mutex_destroy(&mutex);
	// if(r == EBUSY ) perr("EBUSY" );
	// if(r == EINVAL) perr("EINVAL");
	// if(r) return 1;

	return 0;
}
Exemple #29
0
/**
 * read_ei_tokens
 * @brief Gather the RTAS tokens stored in /proc for this machine.
 *
 * This will read the RTAS token values stored in /proc to determine
 * which RTAS error injection capabilities are avaialable on this machine
 *
 * @return 0 on success, !0 otherwise
 */
int read_ei_tokens(void)
{
	char	buf[EI_BUFSZ];
	int	len;
	int	i, found;
	char	*tmp_ptr;
	int	fd;

	fd = open(EI_TOKEN_PROCFILE, O_RDONLY);
	if (fd == -1) {
		perr(errno, "Could not open %s", EI_TOKEN_PROCFILE);
		return 1;
	}

	len = read(fd, buf, EI_BUFSZ);
	if (len == -1) {
		perr(errno, "Could not read from %s", EI_TOKEN_PROCFILE);
		close(fd);
		return 1;
	}

	tmp_ptr = buf;
	while (tmp_ptr < buf + len) {
		found = 0;
		for (i = 0; i < NUM_ERRINJCT_FUNCS; i++) {
			if (strcmp(tmp_ptr, ei_funcs[i].name) == 0) {
				found = 1;
				tmp_ptr += strlen(tmp_ptr) + 1;
				ei_funcs[i].rtas_token = be32toh(*(int *)tmp_ptr);
				tmp_ptr += sizeof(int);
				break;
			}
		}

		if (found == 0) {
			if (verbose)
				perr(0, "Could not find errinjct function for rtas token \"%s\"",
				     tmp_ptr);
			tmp_ptr += strlen(tmp_ptr) + 1 + sizeof(int);
		}
	}

	return 0;
}
Exemple #30
0
/**
 *	process_subbufs - write ready subbufs to disk
 */
static int process_subbufs(struct _stp_buf_info *info,
			   struct switchfile_ctrl_block *scb)
{
	unsigned subbufs_ready, start_subbuf, end_subbuf, subbuf_idx, i;
	int len, cpu = info->cpu;
	char *subbuf_ptr;
	int subbufs_consumed = 0;
	unsigned padding;

	subbufs_ready = info->produced - info->consumed;
	start_subbuf = info->consumed % n_subbufs;
	end_subbuf = start_subbuf + subbufs_ready;

	for (i = start_subbuf; i < end_subbuf; i++) {
		subbuf_idx = i % n_subbufs;
		subbuf_ptr = relay_buffer[cpu] + subbuf_idx * subbuf_size;
		padding = *((unsigned *)subbuf_ptr);
		subbuf_ptr += sizeof(padding);
		len = (subbuf_size - sizeof(padding)) - padding;
		scb->wsize += len;
		if (fsize_max && scb->wsize > fsize_max) {
			if (switch_oldoutfile(cpu, scb) < 0) {
				perr("Couldn't open file for cpu %d, exiting.", cpu);
				return -1;
			}
			scb->wsize = len;
		}
		if (len) {
		#ifdef __ANDROID__
			if (fwrite (subbuf_ptr, len, 1, percpu_tmpfile[cpu]) != 1) {
		#else
			if (fwrite_unlocked (subbuf_ptr, len, 1, percpu_tmpfile[cpu]) != 1) {
		#endif
				if (errno != EPIPE)
					_perr("Couldn't write to output file for cpu %d, exiting:", cpu);
				return -1;
			}
		}
		subbufs_consumed++;
	}

	return subbufs_consumed;
}

/**
 *	reader_thread - per-cpu channel buffer reader
 */
static void *reader_thread(void *data)
{
	int rc;
	int cpu = (long)data;
	struct pollfd pollfd;
	struct _stp_consumed_info consumed_info;
	unsigned subbufs_consumed;
	cpu_set_t cpu_mask;
	struct timespec tim = {.tv_sec=0, .tv_nsec=200000000}, *timeout = &tim;