aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMattias Andrée <maandree@operamail.com>2014-06-20 19:59:35 +0200
committerMattias Andrée <maandree@operamail.com>2014-06-20 19:59:35 +0200
commitee80b4ee994836d3458fc763818147f20913bfc8 (patch)
treef48543d15c6cda67b750f52cad62ae17e1b8308d
parentupdate todo (diff)
downloadxpybar-ee80b4ee994836d3458fc763818147f20913bfc8.tar.gz
xpybar-ee80b4ee994836d3458fc763818147f20913bfc8.tar.bz2
xpybar-ee80b4ee994836d3458fc763818147f20913bfc8.tar.xz
add hdparm
Signed-off-by: Mattias Andrée <maandree@operamail.com>
-rw-r--r--.gitignore4
-rw-r--r--DEPENDENCIES1
-rw-r--r--INSTALLING5
-rw-r--r--Makefile29
-rw-r--r--TODO3
-rw-r--r--src/plugins/hdparm.py97
-rw-r--r--src/restricted-hdparm.c66
7 files changed, 198 insertions, 7 deletions
diff --git a/.gitignore b/.gitignore
index 80197b2..72aa774 100644
--- a/.gitignore
+++ b/.gitignore
@@ -14,4 +14,8 @@ __pycache__/
*.swp
*.swo
*.bak
+*.out
+*.o
+*.su
+*.gch
diff --git a/DEPENDENCIES b/DEPENDENCIES
index b791e6a..fb51285 100644
--- a/DEPENDENCIES
+++ b/DEPENDENCIES
@@ -11,6 +11,7 @@ OPTIONAL RUNTIME DEPENDENCIES:
linux: most of the monitors require Linux's procfs or sysfs
wget: for Internet services
python-pyalsaaudio: for ALSA volume control
+ hdparm: for hdparm support
BUILD DEPENDENCIES:
diff --git a/INSTALLING b/INSTALLING
new file mode 100644
index 0000000..7c4e11d
--- /dev/null
+++ b/INSTALLING
@@ -0,0 +1,5 @@
+After running `make install`, you
+should run `chmod 4755 /usr/bin/restricted-hdparm`
+assuming DESTDIR=, PREFIX=/usr and BIN=/bin
+or DESTDIR= and BINDIR=/usr/bin.
+
diff --git a/Makefile b/Makefile
index f62cafd..9a7f5d1 100644
--- a/Makefile
+++ b/Makefile
@@ -13,6 +13,18 @@ COMMAND = xpybar
PKGNAME = xpybar
PLUGIN_PATH = $(DATADIR)/$(PKGNAME)
+WARN = -Wall -Wextra -pedantic -Wdouble-promotion -Wformat=2 -Winit-self \
+ -Wmissing-include-dirs -Wtrampolines -Wfloat-equal -Wshadow \
+ -Wmissing-prototypes -Wmissing-declarations -Wredundant-decls \
+ -Wnested-externs -Winline -Wno-variadic-macros -Wsign-conversion \
+ -Wswitch-default -Wconversion -Wsync-nand -Wunsafe-loop-optimizations \
+ -Wcast-align -Wstrict-overflow -Wdeclaration-after-statement -Wundef \
+ -Wbad-function-cast -Wcast-qual -Wwrite-strings -Wlogical-op \
+ -Waggregate-return -Wstrict-prototypes -Wold-style-definition -Wpacked \
+ -Wvector-operation-performance -Wunsuffixed-float-constants \
+ -Wsuggest-attribute=const -Wsuggest-attribute=noreturn \
+ -Wsuggest-attribute=pure -Wsuggest-attribute=format -Wnormalized=nfkc
+
SRC = __main__ util x
@@ -20,19 +32,19 @@ PLUGINS = chase clock cpuifo cpuonline cpu df discstats ipaddress \
kmsg leapsec linereader loadavg lunar mem moc network \
pacman snmp snmp6 softirqs solar uname uptime users \
vmstat weather xdisplay xkb alsa dentrystate inodestate \
- files
+ files hdparm
PLUGIN_EXAMPLES = chase clock cpu cpuinfo cpuonline df discstats \
ipaddress kmsg loadavg lunar mem moc network \
pacman uname uptime users xdisplay xkb slsa \
- dentrystate inodestate files
+ dentrystate inodestate files hdparm
EXAMPLES = clock mixed moderate plugin-test test xmonad
.PHONY: all
-all: bin/xpybar
+all: bin/xpybar bin/restricted-hdparm
bin/xpybar: obj/xpybar.zip
mkdir -p bin
@@ -48,6 +60,11 @@ obj/%.py: src/%.py
cp $< $@
sed -i "s:PLUGIN_PATH = None:PLUGIN_PATH = '$(PLUGIN_PATH)':g" $@
+bin/restricted-hdparm: obj/restricted-hdparm.o
+ $(CC) -std=c89 -Ofast $(WARN) -o $@ $^
+
+obj/%.o: src/%.c
+ $(CC) -std=c89 -Ofast $(WARN) -c -o $@ $<
.PHONY: install
@@ -57,9 +74,10 @@ install: install-base
install-base: install-command install-license install-all-examples install-plugins
.PHONY: install-command
-install-command: bin/xpybar
+install-command: bin/xpybar bin/restricted-hdparm
install -dm755 -- "$(DESTDIR)$(BINDIR)"
- install -m755 $< -- "$(DESTDIR)$(BINDIR)/$(COMMAND)"
+ install -m755 bin/xpybar -- "$(DESTDIR)$(BINDIR)/$(COMMAND)"
+ install -m755 bin/restricted-hdparm -- "$(DESTDIR)$(BINDIR)/restricted-hdparm"
.PHONY: install-license
install-license: COPYING LICENSE.gpl3 LICENSE.agpl3
@@ -89,6 +107,7 @@ install-plugins: $(foreach F,$(PLUGINS),src/plugins/$(F).py)
.PHONY: uninstall
uninstall:
-rm -- "$(DESTDIR)$(BINDIR)/$(COMMAND)"
+ -rm -- "$(DESTDIR)$(BINDIR)/restricted-hdparm"
-rm -- "$(DESTDIR)$(LICENSEDIR)/$(PKGNAME)/COPYING"
-rm -- "$(DESTDIR)$(LICENSEDIR)/$(PKGNAME)/LICENSE.gpl3"
-rm -- "$(DESTDIR)$(LICENSEDIR)/$(PKGNAME)/LICENSE.agpl3"
diff --git a/TODO b/TODO
index fe862d5..0116c68 100644
--- a/TODO
+++ b/TODO
@@ -14,7 +14,6 @@ List of plugins to implement:
UPS
Blueshift integration
Backlight control
- hdparm
Thermal monitoring
ESSID and link quality for wireless interfaces
News feed syndication
@@ -36,7 +35,6 @@ List of plugins to implement:
/proc/net/sockstat
/proc/net/sockstat6
/proc/net/wireless
- /sys/class/net/<nic>/duplex (half, full)
Demo plugins:
@@ -47,4 +45,5 @@ Demo plugins:
solar
vmstat
weather
+ hdparm
diff --git a/src/plugins/hdparm.py b/src/plugins/hdparm.py
new file mode 100644
index 0000000..bbbec18
--- /dev/null
+++ b/src/plugins/hdparm.py
@@ -0,0 +1,97 @@
+# -*- python -*-
+'''
+xpybar – xmobar replacement written in python
+Copyright © 2014 Mattias Andrée (maandree@member.fsf.org)
+
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program. If not, see <http://www.gnu.org/licenses/>.
+'''
+
+import os
+
+from util import *
+
+
+class HDParm: # TODO add output parsers
+ '''
+ Set/get SATA/IDE device parameters
+ '''
+
+
+ READAHEAD_SECTOR_COUNT = 'a'
+ HAVE_READAHEAD = 'A'
+ ADVANCED_POWER_MANAGEMENT = 'B'
+ IDE_32BIT_IO_SUPPORT = 'c'
+ POWER_MODE_STATUS = 'C'
+ GEOMETRY = 'g'
+ HITACHI_TEMPERATURE = 'H'
+ KERNEL_INFORMATION = 'i'
+ DIRECT_INFORMATION = 'I'
+ WESTERN_DIGITAL_IDLE3_TIMEOUT = 'J'
+ MULTIPLE_SECTOR_IO_SECTOR_COUNT = 'm'
+ AUTOMATIC_ACOUSTIC_MANAGEMENT = 'M'
+ MAX_VISIBLE_SECTOR_COUNT = 'N'
+ COMMAND_QUEUE_DEPTH = 'Q'
+ IS_READONLY = 'r'
+ HAVE_WRITE_READ_VERIFY = 'R'
+ IDLE_MODE = 'S'
+ HAVE_WRITE_CACHING = 'W'
+ STANDBY_MODE = 'y'
+ SLEEP_MODE = 'Y'
+ DISABLE_SEAGATE_AUTOMATIC_POWER_SAVING = 'Z'
+
+
+ def __init__(self, devices = None):
+ '''
+ Constructor
+
+ @param devices:list<str>? The devices to use, `None` for all
+ '''
+ self.devices = HDParm.get_devices() if devices is None else self.devices
+ spawn_read()
+
+
+ def get(self, action):
+ '''
+ Read information about selected devices
+
+ @param action:str The information to read
+ @return :str The read information
+ '''
+ return spawn_read('restricted-hdparm', '-%s' % action)
+
+
+ def set(self, action, value = None):
+ '''
+ Configure selected devices
+
+ @param action:str The settings to reconfigure
+ @param value:int? The value to apply, `None` if there is no value to apply
+ @return :str The read information
+ '''
+ if value is None:
+ spawn('restricted-hdparm', action)
+ else:
+ spawn('restricted-hdparm', '-%s%s' % (action, str(value)))
+
+
+ @staticmethod
+ def get_devices(self):
+ '''
+ List available devices
+
+ @param :list<str> Available devices
+ '''
+ test = lambda dev : (len(dev) == 3) and (dev[:2] in ('sd', 'hd'))
+ return filter(test, os.listdir('/dev'))
+
diff --git a/src/restricted-hdparm.c b/src/restricted-hdparm.c
new file mode 100644
index 0000000..bb4d923
--- /dev/null
+++ b/src/restricted-hdparm.c
@@ -0,0 +1,66 @@
+/**
+ * xpybar – xmobar replacement written in python
+ * Copyright © 2014 Mattias Andrée (maandree@member.fsf.org)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+#include <unistd.h>
+#include <stdio.h>
+#include <string.h>
+
+
+int main(int argc, char** argv)
+{
+ char* act = argv[1];
+ int i;
+
+ setuid(0);
+
+ for (i = 2; i < argc; i++)
+ if (argv[i][0] == '/')
+ return 1;
+
+ if (*act++ != '-')
+ return 1;
+
+ if (!strcmp(act, "a")) ;
+ else if (!strcmp(act, "A")) ;
+ else if ( strstr(act, "B") == act) ;
+ else if (!strcmp(act, "c")) ;
+ else if (!strcmp(act, "C")) ;
+ else if (!strcmp(act, "g")) ;
+ else if (!strcmp(act, "H")) ;
+ else if (!strcmp(act, "i")) ;
+ else if (!strcmp(act, "I")) ;
+ else if ( strstr(act, "J") == act) ;
+ else if (!strcmp(act, "m")) ;
+ else if ( strstr(act, "M") == act) ;
+ else if (!strcmp(act, "N")) ;
+ else if (!strcmp(act, "Q")) ;
+ else if (!strcmp(act, "r")) ;
+ else if (!strcmp(act, "R")) ;
+ else if ( strstr(act, "S") == act) ;
+ else if (!strcmp(act, "W")) ;
+ else if (!strcmp(act, "y")) ;
+ else if (!strcmp(act, "Y")) ;
+ else if (!strcmp(act, "Z")) ;
+ else
+ return 1;
+
+ execv("hdparm", argv);
+ perror(*argv);
+
+ return 1;
+}
+