Пример #1
0
int ra_nv_get(int argc, char *argv[])
{
	char *fz;
	char *key;
	char *value;

	int index;

	if (argc != 3 && argc != 2)
		return get_usage(argv[0]);

	if (argc == 2) {
		fz = DEFAULT_FLASH_ZONE_NAME;
		key = argv[1];
	} else {
		fz = argv[1];
		key = argv[2];
	}

	if ((index = getNvramIndex(fz)) == -1) {
		printf("%s: Error: \"%s\" flash zone not existed\n", argv[0], fz);
		return get_usage(argv[0]);
	}

	nvram_init(index);
	printf("%s\n", nvram_bufget(index, key));
	nvram_close(index);
	return 0;
}
Пример #2
0
gchar *stats_get_cpu_utilization_str()
{
	get_usage(process_pid, &pstat_process_current);
	double user_percent, sys_percent;
	double *thread_user_percentp, *thread_sys_percentp = NULL;
	if (thread_info_enabled) {
		thread_user_percentp = malloc(sizeof(double) * pstat_process_current.num_threads);
		thread_sys_percentp = malloc(sizeof(double) * pstat_process_current.num_threads);
	}
	calc_cpu_usage_pct(&pstat_process_current, &pstat_process_base,
			   &user_percent, &sys_percent, thread_user_percentp, thread_sys_percentp);
	char *s = g_strdup_printf("CPU utilization (application)\n"
		"%-38s user %4.1lf%%, sys %4.1lf%%\n"
		"Number of threads: %d\n",
		pstat_process_current.process_stats.name,
		user_percent, sys_percent, pstat_process_current.num_threads);
	if (thread_info_enabled) {
		for (int i = 0; i < pstat_process_current.num_threads; i++) {
			char *s2;
			if (thread_user_percentp[i] >= 0 && thread_sys_percentp[i] >= 0)
				s2 = g_strdup_printf("Thread %6d %-24s "
					"user %4.1lf%%, sys %4.1lf%%\n",
					pstat_process_current.thread_stats[i].pid,
					pstat_process_current.thread_stats[i].name,
					thread_user_percentp[i], thread_sys_percentp[i]);
			else
				s2 = g_strdup_printf("Thread %6d %-24s\n",
					pstat_process_current.thread_stats[i].pid,
					pstat_process_current.thread_stats[i].name);
			char *s1 = s;
			s = g_strconcat(s, s2, NULL);
			g_free(s2);
			g_free(s1);
		}
		if (thread_info_enabled) {
			free(thread_user_percentp);
			free(thread_sys_percentp);
		}
	}
	if (X_pid >= 0) {
		get_usage(X_pid, &pstat_Xserver_current);
		double X_user_percent, X_sys_percent;
		calc_cpu_usage_pct(&pstat_Xserver_current, &pstat_Xserver_base,
				   &X_user_percent, &X_sys_percent, NULL, NULL);
		char *s2 = g_strdup_printf
			("\nCPU utilization (X server)\n"
			"%-38s user %4.1lf%%, sys %4.1lf%%\n",
		  pstat_Xserver_current.process_stats.name, X_user_percent, X_sys_percent);
		char *s1 = s;
		s = g_strconcat(s, s2, NULL);
		g_free(s2);
		g_free(s1);
	}
	return s;
}
Пример #3
0
/*
 * Display usage message.  If we're inside a command, display only the usage for
 * that command.  Otherwise, iterate over the entire command table and display
 * a complete usage message.
 */
static void
usage(boolean_t requested, ndmp_command_t *current_command)
{
	int i;
	boolean_t show_properties = B_FALSE;
	FILE *fp = requested ? stdout : stderr;

	if (current_command == NULL) {
		(void) fprintf(fp,
		    gettext("Usage: ndmpadm subcommand args ...\n"));
		(void) fprintf(fp,
		    gettext("where 'command' is one of the following:\n\n"));

		for (i = 0; i < NCOMMAND; i++) {
			(void) fprintf(fp, "%s",
			    get_usage(command_table[i].nc_usage));
		}
		(void) fprintf(fp, gettext("\t\twhere %s can be either "
		    "%s or %s\n"), "'auth-type'", "'cram-md5'", "'cleartext'");
	} else {
		(void) fprintf(fp, gettext("Usage:\n"));
		(void) fprintf(fp, "%s", get_usage(current_command->nc_usage));
		if ((current_command->nc_usage == HELP_ENABLE_AUTH) ||
		    (current_command->nc_usage == HELP_DISABLE_AUTH))
			(void) fprintf(fp, gettext("\t\twhere %s can be either "
			    "%s or %s\n"),
			    "'auth-type'", "'cram-md5'", "'cleartext'");
	}

	if (current_command != NULL &&
	    (strcmp(current_command->nc_name, "set") == 0))
		show_properties = B_TRUE;

	if (show_properties) {
		(void) fprintf(fp,
		    gettext("\nThe following properties are supported:\n"));

		(void) fprintf(fp, gettext("\n\tPROPERTY"));
		(void) fprintf(fp, "\n\t%s", "-------------");
		for (i = 0; i < NDMPADM_NPROP; i++)
			(void) fprintf(fp, "\n\t%s", prop_table[i]);
		(void) fprintf(fp, "\n");
	}

	exit(requested ? 0 : 2);
}
Пример #4
0
void* log_thr(){
    pid_t pid = getpid();
    printf("PID: %u\n", pid);
    printf("PAGESIZE: %u\n", getpagesize());

    struct pstat last_cpu;
    struct pstat cur_cpu;
    double ucpu;
    double scpu;
    time_t curtime;

    if(get_usage(pid, &cur_cpu) == -1){
        fprintf(stderr, "GET USAGE ERROR\n");    
        exit(EXIT_FAILURE);
    }

    fprintf(bench_f, "%s", "#clock date VALID_STATES INVALID_STATES NOTFOUND_STATES CPU_USAGE VSIZE RSS\n");
    while(true){
        last_cpu = cur_cpu;
        get_usage(pid, &cur_cpu);
        calc_cpu_usage(&cur_cpu, &last_cpu, &ucpu, &scpu);
        curtime = time(NULL);
        pthread_mutex_lock(&mutex);
        char tmp[100];
        time_t t = time(NULL);
        struct tm* tm = localtime(&t);
        strftime(tmp, sizeof(tmp), "%R:%S %F", tm);
        fprintf(bench_f,"%s %lu %lu %lu %f %lu %lu\n",tmp, valid_state, invalid_state, not_found_state, ucpu+scpu, cur_cpu.vsize, cur_cpu.rss);
        fflush(NULL);
        valid_state = 0;
        invalid_state = 0;
        not_found_state = 0;
        pthread_mutex_unlock(&mutex);
        /*
        if((curtime - starttime) >= 86400){
            exit(EXIT_SUCCESS);
        }
        */
        sleep(60);
    }
}
Пример #5
0
void stats_reset()
{
	g_list_free(element_statistics_list);
	element_statistics_list = NULL;

	if (X_pid < 0) {
		X_pid = find_pid("Xorg");
		init_pstat(&pstat_Xserver_base);
		init_pstat(&pstat_Xserver_current);
		strcpy(pstat_Xserver_base.process_stats.name, "Xorg");
		strcpy(pstat_Xserver_current.process_stats.name, "Xorg");
	}

	if (process_pid < 0) {
		process_pid = getpid();
		init_pstat(&pstat_process_base);
		init_pstat(&pstat_process_current);
		strcpy(pstat_process_base.process_stats.name, "gstplay");
		strcpy(pstat_process_current.process_stats.name, "gstplay");
	}
	get_usage(process_pid, &pstat_process_base);
	if (X_pid >= 0)
		get_usage(X_pid, &pstat_Xserver_base);
}
Пример #6
0
  // Just pass the whole program argument list here.
  static int from_main(int argc, const char *argv[]) {
    const char *real_program_name = argv[0];
  
    NP1_ASSERT(argc >= 2, get_usage(real_program_name));
    NP1_ASSERT(str::is_valid_utf8(argc, argv), "Arguments are not valid UTF-8 strings");
  
    int fake_argc = argc - 1;
    const char **fake_argv = &argv[1];

    std::vector<std::string> args = str::argv_to_string_vector(fake_argc, fake_argv);

    io::file stdin_f;
    stdin_f.from_stdin();

    io::file stdout_f;
    stdout_f.from_stdout();

    run_once(stdin_f, stdout_f, args);
  
    return 0;
  }
Пример #7
0
static int
get_usages (struct hid_device_info *dev, unsigned short *usage_page,
	    unsigned short *usage)
{
#ifdef __linux
  int res, desc_size;
  int ret = U2FH_TRANSPORT_ERROR;
  struct hidraw_report_descriptor rpt_desc;
  int handle = open (dev->path, O_RDWR);
  if (handle > 0)
    {
      memset (&rpt_desc, 0, sizeof (rpt_desc));
      res = ioctl (handle, HIDIOCGRDESCSIZE, &desc_size);
      if (res >= 0)
	{
	  rpt_desc.size = desc_size;
	  res = ioctl (handle, HIDIOCGRDESC, &rpt_desc);
	  if (res >= 0)
	    {
	      res =
		get_usage (rpt_desc.value, rpt_desc.size, usage_page, usage);
	      if (res >= 0)
		{
		  ret = U2FH_OK;
		}
	    }
	}
      close (handle);
    }
  return ret;
#else
  *usage_page = dev->usage_page;
  *usage = dev->usage;
  return U2FH_OK;
#endif
}
Пример #8
0
struct hid_device_info  HID_API_EXPORT *hid_enumerate(unsigned short vendor_id, unsigned short product_id)
{
    libusb_device **devs;
    libusb_device *dev;
    libusb_device_handle *handle;
    ssize_t num_devs;
    int i = 0;

    struct hid_device_info *root = NULL; // return object
    struct hid_device_info *cur_dev = NULL;

    setlocale(LC_ALL,"");

    if (!initialized)
	hid_init();

    num_devs = libusb_get_device_list(NULL, &devs);

    if (num_devs < 0)
	return NULL;
    while ((dev = devs[i++]) != NULL) {
	struct libusb_device_descriptor desc;
	struct libusb_config_descriptor *conf_desc = NULL;
	int j, k;
	int interface_num = 0;

	int res = libusb_get_device_descriptor(dev, &desc);
	unsigned short dev_vid = desc.idVendor;
	unsigned short dev_pid = desc.idProduct;

	/* HID's are defined at the interface level. */
	if (desc.bDeviceClass != LIBUSB_CLASS_PER_INTERFACE)
	    continue;

	res = libusb_get_active_config_descriptor(dev, &conf_desc);

	if (res < 0)
	    libusb_get_config_descriptor(dev, 0, &conf_desc);
	if (conf_desc) {
	    for (j = 0; j < conf_desc->bNumInterfaces; j++) {
		const struct libusb_interface *intf = &conf_desc->interface[j];
		for (k = 0; k < intf->num_altsetting; k++) {
		    const struct libusb_interface_descriptor *intf_desc;
		    intf_desc = &intf->altsetting[k];
		    if (intf_desc->bInterfaceClass == LIBUSB_CLASS_HID) {
			interface_num = intf_desc->bInterfaceNumber;

			/* Check the VID/PID against the arguments */
			if ((vendor_id == 0x0 && product_id == 0x0) ||
				(vendor_id == dev_vid && product_id == dev_pid)) {
			    struct hid_device_info *tmp;

			    /* VID/PID match. Create the record. */
			    tmp = calloc(1, sizeof(struct hid_device_info));
			    if (cur_dev) {
				cur_dev->next = tmp;
			    }
			    else {
				root = tmp;
			    }
			    cur_dev = tmp;

			    /* Fill out the record */
			    cur_dev->next = NULL;
			    cur_dev->path = make_path(dev, interface_num);
			    
			    res = libusb_open(dev, &handle);
			    
			    if (res >= 0) { 
				/* Serial Number */
				if (desc.iSerialNumber > 0)
				    cur_dev->serial_number =
					get_usb_string(handle, desc.iSerialNumber);

				/* Manufacturer and Product strings */
				if (desc.iManufacturer > 0)
				    cur_dev->manufacturer_string =
					get_usb_string(handle, desc.iManufacturer);
				if (desc.iProduct > 0)
				    cur_dev->product_string =
					get_usb_string(handle, desc.iProduct);

#ifdef INVASIVE_GET_USAGE
				/*
				   This section is removed because it is too
				   invasive on the system. Getting a Usage Page
				   and Usage requires parsing the HID Report
				   descriptor. Getting a HID Report descriptor
				   involves claiming the interface. Claiming the
				   interface involves detaching the kernel driver.
				   Detaching the kernel driver is hard on the system
				   because it will unclaim interfaces (if another
				   app has them claimed) and the re-attachment of
				   the driver will sometimes change /dev entry names.
				   It is for these reasons that this section is
#if 0. For composite devices, use the interface
field in the hid_device_info struct to distinguish
between interfaces. */
				int detached = 0;
				unsigned char data[256];

				/* Usage Page and Usage */
				res = libusb_kernel_driver_active(handle, interface_num);
				if (res == 1) {
				    res = libusb_detach_kernel_driver(handle, interface_num);
				    if (res < 0)
					LOG("Couldn't detach kernel driver, even though a kernel driver was attached.");
				    else
					detached = 1;
				}
				res = libusb_claim_interface(handle, interface_num);
				if (res >= 0) {
				    /* Get the HID Report Descriptor. */
				    res = libusb_control_transfer(handle, LIBUSB_ENDPOINT_IN|LIBUSB_RECIPIENT_INTERFACE, LIBUSB_REQUEST_GET_DESCRIPTOR, (LIBUSB_DT_REPORT << 8)|interface_num, 0, data, sizeof(data), 5000);
				    if (res >= 0) {
					unsigned short page=0, usage=0;
					/* Parse the usage and usage page
					   out of the report descriptor. */
					get_usage(data, res,  &page, &usage);
					cur_dev->usage_page = page;
					cur_dev->usage = usage;
				    }
				    else
					LOG("libusb_control_transfer() for getting the HID report failed with %d\n", res);

				    /* Release the interface */
				    res = libusb_release_interface(handle, interface_num);
				    if (res < 0)
					LOG("Can't release the interface.\n");
				}
				else
				    LOG("Can't claim interface %d\n", res);

				/* Re-attach kernel driver if necessary. */
				if (detached) {
				    res = libusb_attach_kernel_driver(handle, interface_num);
				    if (res < 0)
					LOG("Couldn't re-attach kernel driver.\n");
				}
#endif /*******************/

				libusb_close(handle);
			    }
			    /* VID/PID */
			    cur_dev->vendor_id = dev_vid;
			    cur_dev->product_id = dev_pid;

			    /* Release Number */
			    cur_dev->release_number = desc.bcdDevice;

			    /* Interface Number */
			    cur_dev->interface_number = interface_num;
			}
		    }
		} /* altsettings */
	    } /* interfaces */
	    libusb_free_config_descriptor(conf_desc);
	}
    }

    libusb_free_device_list(devs, 1);

    return root;
}
Пример #9
0
int
main(int argc, char* argv[])
{
	char *procd_address = NULL;
	myDistro->Init(argc, argv);

	if (argc < 2) {
		fprintf(stderr, 
			"Usage: %s <options w/arguments> <command> [<arg> ...]\n",
			argv[0]);
		list_commands();
		return 1;
	}

	config();
	Termlog = 1;
	dprintf_config("TOOL", get_param_functions());

	int cmd_argc = argc - 1;
	char** cmd_argv = argv + 1;

	// Process the first set of options.
	while(cmd_argv[0] != NULL && cmd_argv[0][0] == '-')
	{
		if (strcmp(cmd_argv[0], "-A") == MATCH) {
			cmd_argc--;
			cmd_argv++;
			if (cmd_argc == 0) {
				fprintf(stderr, "error: -A needs an argument\n");
				list_commands();
				return 1;
			}
			// store the argument to -A as the file we'll use.
			procd_address = cmd_argv[0];
			cmd_argc--;
			cmd_argv++;
			continue;
		} else if (strcmp(cmd_argv[0], "-h") == MATCH) {
			cmd_argc--;
			cmd_argv++;
			fprintf(stderr, 
				"Usage: %s <options w/arguments> <command> [<arg> ...]\n",
				argv[0]);
			list_commands();
			return 1;
			continue;
		}

		// This is the failure case if we manage to pass all checks above.
		fprintf(stderr, "error: Don't understand option %s\n", cmd_argv[0]);
		list_commands();
		return 1;
	}

	// If there are no command line arguments left, then there is no
	// command specified after the options, which is a failure.
	if (cmd_argc == 0) {
		fprintf(stderr, 
			"Please specify a command.\n"
			"Usage: %s <options w/arguments> <command> [<arg> ...]\n",
			argv[0]);
		list_commands();
		return 1;
	}

	// If a procd address wasn't specified on the command line, see if we
	// have an entry in a config file to use.
	if (procd_address == NULL) {
		procd_address = param("PROCD_ADDRESS");
		if (procd_address == NULL) {
			fprintf(stderr, "error: PROCD_ADDRESS not defined\n");
			return 1;
		}
	}

	
	ProcFamilyClient pfc;
	if (!pfc.initialize(procd_address)) {
		fprintf(stderr, "error: failed to initialize ProcD client\n");
		return 1;
	}

	// Process this single command we should be performing
	if (strcasecmp(cmd_argv[0], "REGISTER_FAMILY") == 0) {
		return register_family(pfc, cmd_argc, cmd_argv);
	}
	else if (strcasecmp(cmd_argv[0], "TRACK_BY_ASSOCIATED_GID") == 0) {
		return track_by_associated_gid(pfc, cmd_argc, cmd_argv);
	}
	else if (strcasecmp(cmd_argv[0], "TRACK_BY_ASSOCIATED_CGROUP") == 0) {
		return track_by_associated_cgroup(pfc, cmd_argc, cmd_argv);
	}
	else if (strcasecmp(cmd_argv[0], "GET_USAGE") == 0) {
		return get_usage(pfc, cmd_argc, cmd_argv);
	}
	else if (strcasecmp(cmd_argv[0], "DUMP") == 0) {
		return dump(pfc, cmd_argc, cmd_argv);
	}
	else if (strcasecmp(cmd_argv[0], "LIST") == 0) {
		return list(pfc, cmd_argc, cmd_argv);
	}
	else if (strcasecmp(cmd_argv[0], "SIGNAL_PROCESS") == 0) {
		return signal_process(pfc, cmd_argc, cmd_argv);
	}
	else if (strcasecmp(cmd_argv[0], "SUSPEND_FAMILY") == 0) {
		return suspend_family(pfc, cmd_argc, cmd_argv);
	}
	else if (strcasecmp(cmd_argv[0], "CONTINUE_FAMILY") == 0) {
		return continue_family(pfc, cmd_argc, cmd_argv);
	}
	else if (strcasecmp(cmd_argv[0], "KILL_FAMILY") == 0) {
		return kill_family(pfc, cmd_argc, cmd_argv);
	}
	else if (strcasecmp(cmd_argv[0], "UNREGISTER_FAMILY") == 0) {
		return unregister_family(pfc, cmd_argc, cmd_argv);
	}
	else if (strcasecmp(cmd_argv[0], "SNAPSHOT") == 0) {
		return snapshot(pfc, cmd_argc, cmd_argv);
	}
	else if (strcasecmp(cmd_argv[0], "QUIT") == 0) {
		return quit(pfc, cmd_argc, cmd_argv);
	}
	else {
		fprintf(stderr, "error: invalid command: %s\n", cmd_argv[0]);
		list_commands();
		return 1;
	}
}
Пример #10
0
int main (int argc, char **argv) {
  
  if (argc != 5) {
    printf("Usage: %s -p <process name / id> -i <interval>\n", argv[0]);
    return 1;
  }

  char* proc = NULL;

  int c, pid, interval;
  int got_proc_name = 0;

  double user, sys;
  struct pstat mark0, mark1;

  while ((c = getopt(argc, argv, "p:i:")) != -1) {
    switch (c) {
      case 'p':

        if (strspn(optarg, "0123456789") == strlen(optarg)) {
          pid = atoi(optarg);
          proc = NULL;
        } else {
          // not an integer, assume a process name
          got_proc_name = 1;
          proc = optarg;
        }
        break;
      case 'i':

        if (strspn(optarg, "0123456789") == strlen(optarg)) {
          interval = atoi(optarg);
        } else {
          fprintf(stderr, "invalid -i option %s - expecting a number\n",
            optarg ? optarg : "");
          exit(EXIT_FAILURE);
        }
        break;
      case '?':
        if (optopt == 'p') {
          fprintf(stderr, "Option -%c requires an argument.\n", optopt);
        } else if (optopt == 'i') {
          fprintf(stderr, "Option -%c requires an argument.\n", optopt);
        } else if (isprint(optopt)) {
          fprintf(stderr, "Unknown option `-%c'.\n", optopt);
        } else {
          fprintf(stderr, "Unknown option character `\\x%x'.\n", optopt);
        }
        return 1;
      default:
        exit(EXIT_FAILURE);
    }
  }

  if (got_proc_name == 1) {
    char pidfile[75];
    strcpy(pidfile, "/var/run/");
    strcat(pidfile, proc);
    strcat(pidfile, ".pid");

    pid = read_pid(pidfile);

    if (pid == 0) 
      return 1;
  }

  get_usage(pid, &mark0);
  sleep(interval);
  get_usage(pid, &mark1);

  calc_cpu_usage_pct(&mark1, &mark0, &user, &sys);

  printf("%f\n", user + sys);

  return 0;
} 
Пример #11
0
struct hid_device_info  HID_API_EXPORT *hid_enumerate(unsigned short vendor_id, unsigned short product_id)
{
	struct udev *udev;
	struct udev_enumerate *enumerate;
	struct udev_list_entry *devices, *dev_list_entry;
	
	struct hid_device_info *root = NULL; // return object
	struct hid_device_info *cur_dev = NULL;

	hid_init();

	/* Create the udev object */
	udev = udev_new();
	if (!udev) {
		printf("Can't create udev\n");
		return NULL;
	}

	/* Create a list of the devices in the 'hidraw' subsystem. */
	enumerate = udev_enumerate_new(udev);
	udev_enumerate_add_match_subsystem(enumerate, "hidraw");
	udev_enumerate_scan_devices(enumerate);
	devices = udev_enumerate_get_list_entry(enumerate);
	/* For each item, see if it matches the vid/pid, and if so
	   create a udev_device record for it */
	udev_list_entry_foreach(dev_list_entry, devices) {
		const char *sysfs_path;
		const char *dev_path;
		const char *str;
		struct udev_device *hid_dev; // The device's HID udev node.
		struct udev_device *dev; // The actual hardware device.
		struct udev_device *intf_dev; // The device's interface (in the USB sense).
		unsigned short dev_vid;
		unsigned short dev_pid;
		
		/* Get the filename of the /sys entry for the device
		   and create a udev_device object (dev) representing it */
		sysfs_path = udev_list_entry_get_name(dev_list_entry);
		hid_dev = udev_device_new_from_syspath(udev, sysfs_path);
		dev_path = udev_device_get_devnode(hid_dev);
		
		/* The device pointed to by hid_dev contains information about
		   the hidraw device. In order to get information about the
		   USB device, get the parent device with the
		   subsystem/devtype pair of "usb"/"usb_device". This will
		   be several levels up the tree, but the function will find
		   it.*/
		dev = udev_device_get_parent_with_subsystem_devtype(
		       hid_dev,
		       "usb",
		       "usb_device");
		if (!dev) {
			/* Unable to find parent usb device. */
			goto next;
		}

		/* Get the VID/PID of the device */
		str = udev_device_get_sysattr_value(dev,"idVendor");
		dev_vid = (str)? strtol(str, NULL, 16): 0x0;
		str = udev_device_get_sysattr_value(dev, "idProduct");
		dev_pid = (str)? strtol(str, NULL, 16): 0x0;

		/* Check the VID/PID against the arguments */
		if ((vendor_id == 0x0 && product_id == 0x0) ||
		    (vendor_id == dev_vid && product_id == dev_pid)) {
			struct hid_device_info *tmp;
			size_t len;

		    	/* VID/PID match. Create the record. */
			tmp = malloc(sizeof(struct hid_device_info));
			if (cur_dev) {
				cur_dev->next = tmp;
			}
			else {
				root = tmp;
			}
			cur_dev = tmp;
			
			/* Fill out the record */
			cur_dev->next = NULL;
			str = dev_path;
			if (str) {
				len = strlen(str);
				cur_dev->path = calloc(len+1, sizeof(char));
				strncpy(cur_dev->path, str, len+1);
				cur_dev->path[len] = '\0';
			}
			else
				cur_dev->path = NULL;
			
			/* Serial Number */
			cur_dev->serial_number
				= copy_udev_string(dev, "serial");

			/* Manufacturer and Product strings */
			cur_dev->manufacturer_string
				= copy_udev_string(dev, "manufacturer");
			cur_dev->product_string
				= copy_udev_string(dev, "product");

			/* Usage Page and Usage */
			int res;
			struct hidraw_report_descriptor rpt_desc;
			int device_handle = open(dev_path, O_RDWR);
			if (device_handle > 0) {
				res = get_report_descriptor(device_handle, &rpt_desc);
				if (res >= 0) {
					unsigned short page=0, usage=0;
					/* Parse the usage and usage page
					   out of the report descriptor. */
					get_usage(rpt_desc.value, rpt_desc.size,  &page, &usage);
					cur_dev->usage_page = page;
					cur_dev->usage = usage;
				}
				close(device_handle);
			}
			
			/* VID/PID */
			cur_dev->vendor_id = dev_vid;
			cur_dev->product_id = dev_pid;

			/* Release Number */
			str = udev_device_get_sysattr_value(dev, "bcdDevice");
			cur_dev->release_number = (str)? strtol(str, NULL, 16): 0x0;
			
			/* Interface Number */
			cur_dev->interface_number = -1;
			/* Get a handle to the interface's udev node. */
			intf_dev = udev_device_get_parent_with_subsystem_devtype(
				   hid_dev,
				   "usb",
				   "usb_interface");
			if (intf_dev) {
				str = udev_device_get_sysattr_value(intf_dev, "bInterfaceNumber");
				cur_dev->interface_number = (str)? strtol(str, NULL, 16): -1;
			}
		}
		else
			goto next;

	next:
		udev_device_unref(hid_dev);
		/* dev and intf_dev don't need to be (and can't be)
		   unref()d.  It will cause a double-free() error.  I'm not
		   sure why.  */
	}
	/* Free the enumerator and udev objects. */
	udev_enumerate_unref(enumerate);
	udev_unref(udev);
	
	return root;
}
Пример #12
0
void CPUStat::Update() {
	ProcessStat *usage = process_stat;
	get_usage(pid, usage);
}