2014年08月09日 pobox-1.2.6 enhance patch
_ pobox-1.2.6 enhance patch
Orginal pbserver can answer max 40 words in one query. This patch makes pbserver to be able to answer max 256 words.
And This patch also makes pbserver to be able to save learndic when accept signal(INT, TERM).
*** server/pbserver.html.ORG 2015-12-28 14:47:50.942454872 +0900 --- server/pbserver.html 2015-12-28 14:48:35.676895615 +0900 *************** *** 45,53 **** --- 45,57 ---- #else #include <strings.h> #endif + #include <signal.h> + #include <sys/signal.h> #include "server.h" #include "poboxlib.h" + void sigtrap(int); + #ifdef USE_PROFILER #include <sys/time.h> struct timeval ts,te; *************** *** 67,73 **** #define POBOXSERVERPORT 1178 ! #define MAXCANDS 100 #define MAXWORDLEN 100 unsigned char *cands[MAXCANDS],*candspat[MAXCANDS]; --- 71,77 ---- #define POBOXSERVERPORT 1178 ! #define MAXCANDS 256 #define MAXWORDLEN 100 unsigned char *cands[MAXCANDS],*candspat[MAXCANDS]; *************** *** 121,126 **** --- 125,133 ---- #else main(int argc, char **argv) { + signal(SIGINT, sigtrap); + signal(SIGTERM, sigtrap); + if(argc > 1) poboxdebug = 1; #endif if(pobox_init() < 0) exit(0); *************** *** 137,143 **** process(int sock) { ! unsigned char buf[1000],combuf[BUFSIZE]; unsigned char w[100],p[100]; int i,n; --- 144,150 ---- process(int sock) { ! unsigned char buf[65536],combuf[BUFSIZE]; unsigned char w[100],p[100]; int i,n; *************** *** 178,187 **** else { strcpy(buf,"1\t"); for(i=0;i< n;i++){ ! strcat(buf,cands[i]); ! strcat(buf,"\t"); } - strcat(buf,"\n"); } if(send(sock, buf, strlen(buf), 0) < 0) return -1; return 0; --- 185,199 ---- else { strcpy(buf,"1\t"); for(i=0;i< n;i++){ ! strncat(buf,cands[i],sizeof(buf) - strlen(buf) - 1); ! strncat(buf,"\t",sizeof(buf) - strlen(buf) - 1); ! } ! if ((sizeof(buf) - strlen(buf)) < 2){ ! buf[sizeof(buf) - 2] = '\n'; ! buf[sizeof(buf) - 1] = '\0'; ! }else{ ! strncat(buf,"\n",sizeof(buf) - strlen(buf) - 1); } } if(send(sock, buf, strlen(buf), 0) < 0) return -1; return 0; *************** *** 234,239 **** --- 246,257 ---- return -1; } } + + void sigtrap(int signum) + { + pobox_save(&learndic); + exit(1); + } </pre> *** server/poboxlib.html.ORG 2015-12-28 14:48:00.738332407 +0900 --- server/poboxlib.html 2015-12-28 14:48:28.735982388 +0900 *************** *** 574,580 **** // ///////////////////////////////////////////////////////////////// ! #define MAXCANDS 40 static UCHAR *cands[MAXCANDS]; static UCHAR *candspat[MAXCANDS]; static int ncands = 0; --- 574,580 ---- // ///////////////////////////////////////////////////////////////// ! #define MAXCANDS 256 static UCHAR *cands[MAXCANDS]; static UCHAR *candspat[MAXCANDS]; static int ncands = 0;
2020年08月09日 Setting ACPI for suspending machine automatically when battery charge loss
_ ノートPCのバッテリー残量が少なくなったら自動的にサスペンドするためのACPI設定方法
/etc/acpi/acpi_handler.sh
バッテリーに関するイベントを検知したらスクリプト(/etc/acpi/lowbattery.sh)を起動する。
*** acpi_handler.sh.ORG 2020-08-08 23:40:56.530432033 +0900 --- acpi_handler.sh 2020-08-09 01:16:38.793951977 +0900 *************** *** 13,18 **** --- 13,21 ---- ;; esac ;; + battery) + /etc/acpi/lowbattery.sh & + ;; *) logger "ACPI group $1 / action $2 is not defined" ;;
/etc/acpi/lowbattery.sh
バッテリー駆動の間は60秒間隔でバッテリー残量をチェックし、残量が10%を切った場合サスペンドする。ACアダプタ駆動になったら終了する。
#! /bin/sh trap 'rm -fr /tmp/lowbattery.lock' INT TERM mkdir /tmp/lowbattery.lock || exit 1 wait=60 threshold_percent=10 while [ X = X ] do if [ X`cat /proc/acpi/ac_adapter/ACAD/state | egrep off-line` = "X" ] then off_line=no else off_line=yes fi if [ ${off_line} = yes ] then last_full_capacity=`cat /proc/acpi/battery/BAT1/info |\ egrep 'last full capacity' |\ sed -e 's/: */:/;s/ mAh//' |\ cut -d: -f2` remaining_capacity=`cat /proc/acpi/battery/BAT1/state |\ egrep 'remaining capacity' |\ sed -e 's/: */:/;s/ mAh//' |\ cut -d: -f2` battery_percent=`expr ${remaining_capacity} \* 100 / ${last_full_capacity}` if [ ${battery_percent} -le ${threshold_percent} ] then logger "ACPI /etc/acpi/lowbattery.sh suspend(${battery_percent}%/${threshold_percent}%)" sync;sync;sync echo -n mem > /sys/power/state fi else break fi sleep ${wait} done rm -fr /tmp/lowbattery.lock