read_bytes = read (fd, ev, sizeof (struct input_event) * 64);
if ( (read_bytes = read (fd, ev, sizeof (struct input_event) * 64))==-1) {  if (errno==ENODEV) { syslog(LOG_NOTICE,"Start sleeping..."); sleep(10); syslog(LOG_NOTICE,"End sleeping...");  close(fd);  syslog(LOG_NOTICE,"Input device changed, back from suspend ?: %m");   snprintf(devinput,MAX_DEVINPUT_SIZE,"/dev/input/event%d",getItemEvent(DEFAULT_KEYBOARD_NAME)); syslog(LOG_NOTICE,"autodevice determines %s as new event",devinput);   if ((fd = open (devinput, O_RDONLY)) < 0) { syslog(LOG_CRIT,"New event interface (%s) open failed: %m",devinput); cleanExit(EXIT_FAILURE); }  if ((read_bytes = read (fd, ev, sizeof (struct input_event) * 64))==-1) { syslog(LOG_CRIT,"Reading new device (%s) failed: %m",devinput); cleanExit(EXIT_FAILURE); } } else { syslog(LOG_CRIT,"Input device reading failed: %m"); cleanExit(EXIT_FAILURE); } }
loop (){  // event interface  int fd = -1;			/* the file descriptor for the device */  int i;			/* loop counter */  size_t read_bytes;		/* how many bytes were read */  struct input_event ev[64];	/* the events (up to 64 at once) */  int key;			/*key code */  /* used if event hit fn */  int hasSomething;#ifdef HAVE_LIBXOSD  // prepare queue handling  int flag = 0, brightness = 0, sound = 0;  createqueue ();#endif    if (strcasecmp(devinput,"AUTO")==0) { // try to figure out rigth event value for keyboard	  snprintf(devinput,MAX_DEVINPUT_SIZE,"/dev/input/event%d",getItemEvent(DEFAULT_KEYBOARD_NAME));	  syslog(LOG_INFO,"autodevice determines %s as keyboard event",devinput);  }    if ((fd = open (devinput, O_RDONLY)) < 0)    {      syslog (LOG_CRIT,"event interface (%s) open failed: %m",devinput);      // shoot auto as LAST chance      snprintf(devinput,MAX_DEVINPUT_SIZE,"/dev/input/event%d",getItemEvent(DEFAULT_KEYBOARD_NAME));      syslog(LOG_CRIT,"autodevice determines %s as a last chance keyboard event",devinput);      if ((fd = open (devinput, O_RDONLY)) < 0)        {	      syslog(LOG_CRIT,"Event interface (%s) open failed: %m",devinput);#ifdef HAVE_LIBXOSD      	      killqueue ();#endif      	      releaseConfig();      	      closelog ();      	      exit (1);        }    }  /* handle important signal */  if (signal(SIGTERM,signal_handler) < 0)    {      perror("signal");      exit(1);    }  if (signal(SIGHUP,signal_handler) < 0)    {      perror("signal");      exit(1);    }  syslog(LOG_INFO,"fsfn loaded");  while (1)    {				/* loop */      hasSomething = 0;		/* nothing yet */      /*       * read the event interface        */      read_bytes = read (fd, ev, sizeof (struct input_event) * 64);      if (read_bytes < (int) sizeof (struct input_event))	{	  syslog (LOG_CRIT,"short read: %m");#ifdef HAVE_LIBXOSD	  killqueue ();#endif      	  releaseConfig();	  closelog ();	  exit (1);	}      /*       * Loop for all readed events until we have something       * interesting..        */      for (i = 0;	   !hasSomething	   && (i < (int) (read_bytes / sizeof (struct input_event))); i++)	{	  hasSomething = (ev[i].type == FN_INPUT_TYPE)	    && (ev[i].code == FN_INPUT_CODE)	    && (ev[i].value == FN_INPUT_VALUE);	}      /*       * If we got a FN event, plz do something...        */      if (hasSomething && (key = getCodes ()))	{	  syslog(LOG_INFO,"fsfn catch %d",key);	  if ((key & FN_F5) == FN_F5)	    { 	      	// check config	      	if (!checkConfig(FN_F5))		  {	      		// lower brightness#ifdef HAVE_LIBXOSD	      		flag = MOD_BRIGHTNESS;	      		brightness = setBrightness (getBrightness () - 1);	      		sendmsg (flag, brightness, sound);#else	      		setBrightness (getBrightness () - 1);#endif		  }	    }	  if ((key & FN_F6) == FN_F6)	    {	    	// check config		if (!checkConfig(FN_F6)) 		  {		  		    		// higher brightness#ifdef HAVE_LIBXOSD	      		flag = MOD_BRIGHTNESS;	      		brightness = setBrightness (getBrightness () + 1);	      		sendmsg (flag, brightness, sound);#else	      		setBrightness (getBrightness () + 1);#endif		  }	    }	  if ((key & FN_F2) == FN_F2)	    {		// check config		if (!checkConfig(FN_F2))		  {#ifdef HAVE_LIBXOSD	      		flag = MOD_SOUND;	      		sound = mute ();	      		sendmsg (flag, brightness, sound);#else	      		mute ();			#endif		  }	    }	  if ((key & FN_F3) == FN_F3)	    {		if (!checkConfig(FN_F3))	          {#ifdef HAVE_LIBXOSD	      		flag = MOD_SOUND;	      		sound = volume_down ();	      		sendmsg (flag, brightness, sound);#else	      		volume_down ();#endif		  }	    }	  if ((key & FN_F4) == FN_F4)	    {	       if (!checkConfig(FN_F4))	         {#ifdef HAVE_LIBXOSD	      		flag = MOD_SOUND;	      		sound = volume_up ();	      		sendmsg (flag, brightness, sound);#else	      		volume_up ();#endif		 }		    }	 /* NO built in commands */	  if ((key & FN_F7) == FN_F7)	    {		  checkConfig(FN_F7);	    }	  if ((key & FN_F10) == FN_F10)	    {		  checkConfig(FN_F10);	    }	  if ((key & FN_F12) == FN_F12)	    {		 checkConfig(FN_F12);	    }	  if (( key & S1_BTN) == S1_BTN) 	    {		 checkConfig(S1_BTN);	    }	  if (( key & S2_BTN) == S2_BTN)	    {		 checkConfig(S2_BTN);	    }		  	}    }// while}