diff -N -r --unified=5 usblock.old2/lockd/lockd.c usblock/lockd/lockd.c --- usblock.old2/lockd/lockd.c 2007-03-04 06:52:47.000000000 +0100 +++ usblock/lockd/lockd.c 2007-03-04 06:48:51.000000000 +0100 @@ -24,19 +24,23 @@ -o set transmitter going out of bounds script -t set sleep time between polls (in seconds) -k set key (in the form 0,66,66,3) -p set user-pidfile -d daemonize +-c continue normal operation although /dev/lock0 cannot be opened, use this if + it is intended that the daemon should run even if the device is not plugged + in or is being removed and plugged in again during operation //maybe add different keys for different scripts later */ char *key=NULL; char *script_in=NULL; char *script_out=NULL; int sleep_time=8; int daemonize=0; +int allow_offline=0; char *lock_file=NULL; //this holds the output of /dev/lock0 int lock_file_len; char *pid_filename=NULL;//this is the pid filename FILE *pid_file=NULL;//pid file handle pid_t pid=0;//our process id for lockd @@ -73,12 +77,14 @@ signal(SIGUSR1, SIG_IGN); } int GetOptions(int argc,const char* argv[]) { int opt; - while((opt = getopt(argc,(char* const *)argv,"di:o:k:t:p:")) != -1) { + while((opt = getopt(argc,(char* const *)argv,"cdi:o:k:t:p:")) != -1) { switch(opt) { + case 'c': allow_offline=1; + break; case 'd': daemonize=1; break; case 'i': script_in=strdup(optarg); // printf("Setting In-Range executable to:%s\n",script_in); @@ -150,13 +156,19 @@ }else printf("Starting usblock-daemon Copyright (c) 2006 Tim 'pez2001' Theede.\n"); while(1) { //start of daemon loop f=fopen("/dev/lock0","r"); if(f==NULL) { - if(daemonize)syslog(LOG_NOTICE,"error can't open file: '/dev/lock0'"); - else printf("error can't open file: '/dev/lock0'\n"); - return(0); + if(allow_offline) { + sleep(sleep_time); + continue; + } + else { + if(daemonize)syslog(LOG_NOTICE,"error can't open file: '/dev/lock0'"); + else printf("error can't open file: '/dev/lock0'\n"); + return(0); + } } lock_file=(char*)malloc(256); memset(lock_file,0,256); //fseek(f,0,SEEK_SET); lock_file_len=fread(lock_file,1,255,f);