fiss-minit

A standalone service supervisor based on minit
Log | Files | Refs | README | LICENSE

commit 06e88f445336e2732ccd423178d808df64661483
parent b2105d862b1f0e6c351c11c12438d611e7a35daf
Author: leitner <leitner>
Date:   Mon, 13 Apr 2015 18:29:06 +0000

  add powersave (demo tool to set up power saving, needs customization, not actually installed)

Diffstat:
M.cvsignore | 2++
MCHANGES | 2++
MMakefile | 3++-
Apowersave.c | 84+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 90 insertions(+), 1 deletion(-)

diff --git a/.cvsignore b/.cvsignore @@ -9,3 +9,5 @@ shutdown minit-update serdo ftrigger +waitinterface +waitport diff --git a/CHANGES b/CHANGES @@ -10,6 +10,8 @@ only install SIGWINCH and SIGINT if running with PID 1 you can now do "make MINITROOT=/var/minit" add ftrigger (run a command if a file changes) + add waitinterface and waitport (to resolve races) + add powersave (demo tool to set up power saving, needs customization, not actually installed) 0.10: add sample script for /etc/minit/ctrlaltdel/run as diff --git a/Makefile b/Makefile @@ -1,5 +1,5 @@ all: minit msvc pidfilehack hard-reboot write_proc killall5 shutdown \ -minit-update serdo ftrigger waitinterface waitport # governor +minit-update serdo ftrigger waitinterface waitport powersave # governor #CFLAGS=-pipe -march=i386 -fomit-frame-pointer -Os -I../dietlibc/include CC=gcc @@ -53,6 +53,7 @@ minit-update: minit-update.o split.o openreadclose.o serdo: serdo.o waitinterface: waitinterface.o waitport: waitport.o +powersave: powersave.o governor: governor.o shutdown: shutdown.o split.o openreadclose.o opendevconsole.o diff --git a/powersave.c b/powersave.c @@ -0,0 +1,84 @@ +#define _GNU_SOURCE +#include <sys/types.h> +#include <open.h> +#include <string.h> +#include <stdlib.h> +#include <dirent.h> +#include <netinet/in.h> +#include <sys/socket.h> +#include <net/if.h> +#include <sys/ioctl.h> + +int write_to(const char* filename,const char* string) { + int fd=open_write(filename); + if (fd!=-1) { + write(fd,string,strlen(string)); + fd=close(fd); + } + return fd; +} + +void handle(const char* s) { + size_t l=strlen(s); + char* x=alloca(l+20); + strcpy(x,s); + strcpy(x+l,"/power/control"); + write_to(x,"auto"); +} + +void dwim(const char* name) { + DIR* D; + struct dirent* d; + if (chdir(name)) return; + if (!(D=opendir("."))) return; + while ((d=readdir(D))) { +// puts(d->d_name); + handle(d->d_name); + } + closedir(D); +} + +void pci() { + dwim("/sys/bus/pci/devices"); +} + +void usb() { + dwim("/sys/bus/usb/devices"); +} + +void wakeonlan(const char* interface) { + struct ethtool_wolinfo { + uint32_t cmd,supported,wolopts; + char sopass[6]; + } wol; + int fd=socket(PF_INET,SOCK_DGRAM,0); + struct ifreq ifr; + if (strlen(interface) > IFNAMSIZ) + return; + memset(&ifr,0,sizeof(ifr)); + strncpy(ifr.ifr_name,interface,sizeof(ifr.ifr_name)); + ifr.ifr_data=(void*)&wol; + memset(&wol,0,sizeof(wol)); + wol.cmd=6; // ETHTOOL_SWOL + wol.wolopts=0; + ioctl(fd,SIOCETHTOOL,&ifr); + close(fd); +} + +int main() { + write_to("/sys/class/scsi_host/host0/link_power_management_policy","min_power"); + write_to("/sys/class/scsi_host/host1/link_power_management_policy","min_power"); + write_to("/sys/class/scsi_host/host2/link_power_management_policy","min_power"); + write_to("/sys/class/scsi_host/host3/link_power_management_policy","min_power"); + write_to("/sys/class/scsi_host/host4/link_power_management_policy","min_power"); + write_to("/sys/class/scsi_host/host5/link_power_management_policy","min_power"); + write_to("/sys/class/scsi_host/host6/link_power_management_policy","min_power"); + write_to("/sys/module/snd_hda_intel/parameters/power_save","1"); + write_to("/sys/bus/usb/devices/1-3/power/control","auto"); + write_to("/sys/bus/usb/devices/1-4/power/control","auto"); + write_to("/proc/sys/vm/dirty_writeback_centisecs","1500"); + pci(); + wakeonlan("eth0"); +// usb(); + return 0; +}