■ 回路
232C Din9 -------------------- 1 DCD ---+ 2 | 3 | 4 | 5 | 6 | 7 RTD ---+ 8
/etc/rc.local ---------------------------------------- # put your local stuff here /bin/shutdown-check & echo shutdown-check echo '.'
/bin/shutdown-check ---------------------------------------- #! /bin/sh cmd=/home/k-wada/program/232C/t while [ true ] do $cmd flag=`echo $?` if [ $flag -eq 0 ] then sleep 5 else echo "Shutdown -h now" fi done
/bin/get-232c-shutdownstatus.c ---------------------------------------- /* * shutdown program using 232C */ #include <sys/types.h> #include <sys/ioctl.h> #include <fcntl.h> #include <errno.h> #include <stdlib.h> #include <unistd.h> #include <stdio.h> #include <signal.h> int main(int argc, char **argv) { int fd; int dtr_bit = TIOCM_DTR; int rts_bit = TIOCM_RTS; int set_bits; int flags; if ((fd = open("/dev/cuaa0", O_RDWR | O_NDELAY)) < 0) { fprintf(stderr, "OPEN ERROR!.\n"); exit(1); } set_bits = TIOCM_DTR | TIOCM_RTS; ioctl(fd, TIOCMSET, &set_bits); sleep(1); ioctl(fd, TIOCMGET, &flags); if (flags & TIOCM_CD) { fprintf(stderr, "Received Shutdown.\n"); return 1; } else { fprintf(stderr, "Norman Run\n"); return 0; } close(fd); }