コード例 #1
0
ファイル: args.c プロジェクト: AlisonSchofield/lm-sensors
int parseChips(int argc, char **argv)
{
	int i, n = argc - optind, err;

	if (n == 0) {
		sensord_args.chipNames[0].prefix =
			SENSORS_CHIP_NAME_PREFIX_ANY;
		sensord_args.chipNames[0].bus.type = SENSORS_BUS_TYPE_ANY;
		sensord_args.chipNames[0].bus.nr = SENSORS_BUS_NR_ANY;
		sensord_args.chipNames[0].addr = SENSORS_CHIP_NAME_ADDR_ANY;
		sensord_args.numChipNames = 1;

		return 0;
	}

	if (n > MAX_CHIP_NAMES) {
		fprintf(stderr, "Too many chip names.\n");
		return -1;
	}
	for (i = 0; i < n; ++i) {
		char *arg = argv[optind + i];

		err = sensors_parse_chip_name(arg, sensord_args.chipNames + i);
		if (err) {
			fprintf(stderr,	"Invalid chip name `%s': %s\n", arg,
				sensors_strerror(err));
			for (i--; i >= 0; i--)
				sensors_free_chip_name(sensord_args.chipNames + i);
			return -1;
		}
	}
	sensord_args.numChipNames = n;

	return 0;
}
コード例 #2
0
ファイル: sensors.c プロジェクト: SteveJones/j4status
static J4statusPluginContext *
_j4status_sensors_init(J4statusCoreInterface *core)
{
    gchar **sensors = NULL;
    gboolean show_details = FALSE;
    guint64 interval = 0;

    if ( sensors_init(NULL) != 0 )
        return NULL;

    GKeyFile *key_file;
    key_file = j4status_config_get_key_file("Sensors");
    if ( key_file != NULL )
    {
        sensors = g_key_file_get_string_list(key_file, "Sensors", "Sensors", NULL, NULL);
        show_details = g_key_file_get_boolean(key_file, "Sensors", "ShowDetails", NULL);
        interval = g_key_file_get_uint64(key_file, "Sensors", "Interval", NULL);
        g_key_file_free(key_file);
    }

    J4statusPluginContext *context;
    context = g_new0(J4statusPluginContext, 1);
    context->core = core;

    context->config.show_details = show_details;


    if ( sensors == NULL )
        _j4status_sensors_add_sensors(context, NULL);
    else
    {
        sensors_chip_name chip;
        gchar **sensor;
        for ( sensor = sensors ; *sensor != NULL ; ++sensor )
        {
            if ( sensors_parse_chip_name(*sensor, &chip) != 0 )
                continue;
            _j4status_sensors_add_sensors(context, &chip);
            sensors_free_chip_name(&chip);
        }
    }
    g_strfreev(sensors);

    if ( context->sections == NULL )
    {
        g_message("Missing configuration: No sensor to monitor, aborting");
        _j4status_sensors_uninit(context);
        return NULL;
    }

    g_timeout_add_seconds(MAX(2, interval), _j4status_sensors_update, context);

    return context;
}
コード例 #3
0
ファイル: chipname.c プロジェクト: sophiekovalevsky/pysensors
/*
 * This is a static method; self is NULL.
 */
static PyObject*
parse_chip_name(ChipName *self, PyObject *args, PyObject *kwargs)
{
    char *kwlist[] = {"orig_name", NULL};
    const char *orig_name = NULL;

    (void)self;

    if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s", kwlist,
                                     &orig_name))
    {
        return NULL;
    }

    sensors_chip_name name = {NULL, {0, 0}, 0, NULL};
    int status = sensors_parse_chip_name(orig_name, &name);

    if (status < 0)
    {
        PyErr_SetString(SensorsException, sensors_strerror(status));
        return NULL;
    }

    ChipName *py_chip_name = PyObject_New(ChipName, &ChipNameType);

    if (py_chip_name == NULL)
    {
        return NULL;
    }

    /*
     * Copy the content of the obtained name into py_chip_name.  We
     * duplicate the strings, because name is supposed to freed by
     * sensors_free_chip_name(), instead of our own destructor.
     * Looking at the code of libsensors, it seems that it would
     * actually work just fine if our destructor cleaned it up, but I
     * prefer to be on the safe side.
     */
    py_chip_name->chip_name = name;

    if (name.prefix == NULL)
    {
        py_chip_name->chip_name.prefix = NULL;
        py_chip_name->py_prefix = Py_None;
        Py_INCREF(py_chip_name->py_prefix);
    }
    else
    {
        py_chip_name->chip_name.prefix = strdup(name.prefix);
        py_chip_name->py_prefix = PyString_FromString(name.prefix);
    }

    if (name.path == NULL)
    {
        py_chip_name->chip_name.path = NULL;
        py_chip_name->py_path = Py_None;
        Py_INCREF(py_chip_name->py_path);
    }
    else
    {
        py_chip_name->chip_name.path = strdup(name.path);
        py_chip_name->py_path = PyString_FromString(name.path);
    }

    sensors_free_chip_name(&name);

    return (PyObject*)py_chip_name;
}
コード例 #4
0
ファイル: main.c プロジェクト: rickwangtw/lm-sensors
int main(int argc, char *argv[])
{
    int c, i, err, do_bus_list;
    const char *config_file_name = NULL;

    struct option long_opts[] =  {
        { "help", no_argument, NULL, 'h' },
        { "set", no_argument, NULL, 's' },
        { "version", no_argument, NULL, 'v'},
        { "fahrenheit", no_argument, NULL, 'f' },
        { "no-adapter", no_argument, NULL, 'A' },
        { "config-file", required_argument, NULL, 'c' },
        { "bus-list", no_argument, NULL, 'B' },
        { 0, 0, 0, 0 }
    };

    setlocale(LC_CTYPE, "");

    do_raw = 0;
    do_sets = 0;
    do_bus_list = 0;
    hide_adapter = 0;
    while (1) {
        c = getopt_long(argc, argv, "hsvfAc:u", long_opts, NULL);
        if (c == EOF)
            break;
        switch(c) {
        case ':':
        case '?':
            print_short_help();
            exit(1);
        case 'h':
            print_long_help();
            exit(0);
        case 'v':
            print_version();
            exit(0);
        case 'c':
            config_file_name = optarg;
            break;
        case 's':
            do_sets = 1;
            break;
        case 'f':
            fahrenheit = 1;
            break;
        case 'A':
            hide_adapter = 1;
            break;
        case 'u':
            do_raw = 1;
            break;
        case 'B':
            do_bus_list = 1;
            break;
        default:
            fprintf(stderr,
                    "Internal error while parsing options!\n");
            exit(1);
        }
    }

    err = read_config_file(config_file_name);
    if (err)
        exit(err);

    /* build the degrees string */
    set_degstr();

    if (do_bus_list) {
        print_bus_list();
    } else if (optind == argc) { /* No chip name on command line */
        if (!do_the_real_work(NULL, &err)) {
            fprintf(stderr,
                    "No sensors found!\n"
                    "Make sure you loaded all the kernel drivers you need.\n"
                    "Try sensors-detect to find out which these are.\n");
            err = 1;
        }
    } else {
        int cnt = 0;
        sensors_chip_name chip;

        for (i = optind; i < argc; i++) {
            if (sensors_parse_chip_name(argv[i], &chip)) {
                fprintf(stderr,
                        "Parse error in chip name `%s'\n",
                        argv[i]);
                print_short_help();
                err = 1;
                goto exit;
            }
            cnt += do_the_real_work(&chip, &err);
            sensors_free_chip_name(&chip);
        }

        if (!cnt) {
            fprintf(stderr, "Specified sensor(s) not found!\n");
            err = 1;
        }
    }

exit:
    sensors_cleanup();
    exit(err);
}