Пример #1
0
void sigint_handler ( int n ) {

  pnd_log ( pndn_rem, "---[ SIGINT received ]---\n" );

  if ( dbh ) {
    pnd_dbusnotify_shutdown ( dbh );
  }

  if ( nh ) {
    pnd_notify_shutdown ( nh );
  }

  return;
}
Пример #2
0
void gui_clean()
{
    debug_start();

    video_quit();

    gui_clean_skin();
    gui_unload_preview();
    pnd_app_clean_list();

    pnd_notify_shutdown ( nh );
	pnd_dbusnotify_shutdown ( nh2 );
    doneStatusCalls();

    GLES2D_Quit();

    debug_end();
}
Пример #3
0
int main ( int argc, char *argv[] ) {
  // behaviour
  unsigned char scanonlaunch = 1;
  unsigned int interval_secs = 5;
  int logall = -1; // -1 means normal logging rules; >=0 means log all!
  // misc
  int i;

  /* iterate across args
   */
  for ( i = 1; i < argc; i++ ) {

    if ( argv [ i ][ 0 ] == '-' && argv [ i ][ 1 ] == 'd' ) {
      //printf ( "Going daemon mode. Silent running.\n" );
      g_daemon_mode = 1;
    } else if ( isdigit ( argv [ i ][ 0 ] ) ) {
      interval_secs = atoi ( argv [ i ] );
    } else if ( argv [ i ][ 0 ] == '-' && argv [ i ][ 1 ] == 'n' ) {
      scanonlaunch = 0;
    } else if ( argv [ i ][ 0 ] == '-' && argv [ i ][ 1 ] == 'l' ) {

      if ( isdigit ( argv [ i ][ 2 ] ) ) {
	unsigned char x = atoi ( argv [ i ] + 2 );
	if ( x >= 0 &&
	     x < pndn_none )
	{
	  logall = x;
	}
      } else {
	logall = 0;
      }

    } else {
      printf ( "%s [-d] [-l] [##]\n", argv [ 0 ] );
      printf ( "-d\tDaemon mode; detach from terminal, chdir to /tmp, suppress output. Optional.\n" );
      printf ( "-n\tDo not scan on launch; default is to run a scan for apps when %s is invoked.\n", argv [ 0 ] );
      printf ( "-l#\tLog-it; -l is 0-and-up (or all), and -l2 means 2-and-up (not all); l[0-3] for now. Log goes to /tmp/pndnotifyd.log\n" );
      printf ( "##\tA numeric value is interpreted as number of seconds between checking for filesystem changes. Default %u.\n",
	       interval_secs );
      printf ( "Signal: HUP the process to force reload of configuration and reset the notifier watch paths\n" );
      exit ( 0 );
    }

  } // for

  /* enable logging?
   */
  pnd_log_set_pretext ( "pndnotifyd" );
  pnd_log_set_flush ( 1 );

  if ( logall == -1 ) {
    // standard logging; non-daemon versus daemon

    if ( g_daemon_mode ) {
      // nada
    } else {
      pnd_log_set_filter ( pndn_rem );
      pnd_log_to_stdout();
    }

  } else {
    FILE *f;

    f = fopen ( "/tmp/pndnotifyd.log", "w" );

    if ( f ) {
      pnd_log_set_filter ( logall );
      pnd_log_to_stream ( f );
      pnd_log ( pndn_rem, "logall mode - logging to /tmp/pndnotifyd.log\n" );
    }

    if ( logall == pndn_debug ) {
      pnd_log_set_buried_logging ( 1 ); // log the shit out of it
      pnd_log ( pndn_rem, "logall mode 0 - turned on buried logging\n" );
    }

  } // logall

  pnd_log ( pndn_rem, "%s built %s %s", argv [ 0 ], __DATE__, __TIME__ );

  pnd_log ( pndn_rem, "log level starting as %u", pnd_log_get_filter() );

  pnd_log ( pndn_rem, "Interval between checks is %u seconds\n", interval_secs );

  // check if inotify is awake yet; if not, try waiting for awhile to see if it does
  pnd_log ( pndn_rem, "Starting INOTIFY test; should be instant, but may take awhile...\n" );

  if ( ! pnd_notify_wait_until_ready ( 120 /* seconds */ ) ) {
    pnd_log ( pndn_error, "ERROR: INOTIFY refuses to be useful and quite awhile has passed. Bailing out.\n" );
    return ( -1 );
  }

  pnd_log ( pndn_rem, "INOTIFY seems to be useful, whew.\n" );

  // basic daemon set up
  if ( g_daemon_mode ) {

    // set a CWD somewhere else
#if 0
    chdir ( "/tmp" );
#endif

    // detach from terminal
    if ( ( i = fork() ) < 0 ) {
      pnd_log ( pndn_error, "ERROR: Couldn't fork()\n" );
      exit ( i );
    }
    if ( i ) {
      exit ( 0 ); // exit parent
    }
    setsid();

    // umask
    umask ( 022 ); // emitted files can be rwxr-xr-x

  } // set up daemon

  // wait for a user to be logged in - we should probably get hupped when a user logs in, so we can handle
  // log-out and back in again, with SDs popping in and out between..
  pnd_log ( pndn_rem, "Checking to see if a user is logged in\n" );
  while ( 1 ) {
    if ( pnd_check_login ( g_username, 127 ) ) {
      break;
    }
    pnd_log ( pndn_debug, "  No one logged in yet .. spinning.\n" );
    sleep ( 2 );
  } // spin
  pnd_log ( pndn_rem, "Looks like user '%s' is in, continue.\n", g_username );

  /* parse configs
   */

  consume_configuration();

  /* startup
   */

  pnd_log ( pndn_rem, "PXML overrides searchpath is '%s'\n", overridespath );
  pnd_log ( pndn_rem, "Notify searchpath is '%s'\n", notifypath );

  pnd_log ( pndn_rem, "Desktop apps ---------------------------------\n" );
  pnd_log ( pndn_rem, "Apps searchpath is '%s'\n", desktop_appspath );
  pnd_log ( pndn_rem, ".desktop files emit to '%s'\n", desktop_dotdesktoppath );
  pnd_log ( pndn_rem, ".desktop icon files emit to '%s'\n", desktop_iconpath );

  pnd_log ( pndn_rem, "Menu apps ---------------------------------\n" );
  pnd_log ( pndn_rem, "Apps searchpath is '%s'\n", menu_appspath );
  pnd_log ( pndn_rem, ".desktop files emit to '%s'\n", menu_dotdesktoppath );
  pnd_log ( pndn_rem, ".desktop icon files emit to '%s'\n", menu_iconpath );
  pnd_log ( pndn_rem, ".desktop info files emit to '%s'\n", info_dotdesktoppath ? info_dotdesktoppath : "n/a" );

  /* set up signal handler
   */
  sigset_t ss;
  sigemptyset ( &ss );

  struct sigaction siggy;
  siggy.sa_handler = sighup_handler;
  siggy.sa_mask = ss; /* implicitly blocks the origin signal */
  siggy.sa_flags = 0; /* don't need anything */

  sigaction ( SIGHUP, &siggy, NULL );

  siggy.sa_handler = sigint_handler;
  sigaction ( SIGINT, &siggy, NULL );

  /* set up notifies
   */

  // if we're gong to scan on launch, it'll set things right up and then set up notifications.
  // if no scan on launch, we need to set the notif's up now.
  //if ( ! scanonlaunch ) {
  setup_notifications();
  //}

  dbh = pnd_dbusnotify_init();

  /* daemon main loop
   */
  unsigned char watch_inotify, watch_dbus;
  while ( 1 ) {

    watch_dbus = 0;
    watch_inotify = 0;

    if ( dbh ) {
      watch_dbus = pnd_dbusnotify_rediscover_p ( dbh );
    }

    if ( ! watch_dbus && nh ) {
      watch_inotify = pnd_notify_rediscover_p ( nh );
    }

    // need to rediscover?
    if ( scanonlaunch || watch_inotify || watch_dbus ) {

      // by this point, the watched directories have notified us that something of relevent
      // has occurred; we should be clever, but we're not, so just re-brute force the
      // discovery and spit out .desktop files..
      pnd_log ( pndn_rem, "------------------------------------------------------\n" );

      pnd_log ( pndn_rem, "System changes detected in dbus or watched paths .. performing re-discover!\n" );

      // if this was a forced scan, lets not do that next iteration
      if ( scanonlaunch ) {
	pnd_log ( pndn_rem, "scan-on-first-launch detected an event\n" );
	scanonlaunch = 0;
      }

      if ( watch_inotify ) {
	pnd_log ( pndn_rem, "inotify detected an event\n" );
      }

      if ( watch_dbus ) {
	pnd_log ( pndn_rem, "dbusnotify detected an event\n" );
	pnd_notify_shutdown ( nh );
	nh = 0;
      }

      if ( time ( NULL ) - createtime <= 2 ) {
	pnd_log ( pndn_rem, "Rediscovery request comes to soon after previous discovery; skipping.\n" );
	sleep ( interval_secs );
	continue;
      }

      pnd_log ( pndn_rem, "------------------------------------------------------\n" );

      createtime = time ( NULL ); // all 'new' .destops are created at or after this time; prev are old.

      /* run the discovery
       */

      // do some 'locking'
      pnd_log ( pndn_rem, "creating lockfile %s", PNDLOCKNAME );
      if ( ! pnd_lock ( PNDLOCKNAME ) ) {
	// problem .. well, too bad, we need to do this .. proceed!
      }

      // scan..
      pnd_log ( pndn_rem, "  Scanning desktop paths----------------------------\n" );
      if ( ! perform_discoveries ( desktop_appspath, overridespath, desktop_dotdesktoppath, desktop_iconpath ) ) {
	pnd_log ( pndn_rem, "    No applications found in desktop search path\n" );
      }

      if ( menu_appspath && menu_dotdesktoppath && menu_iconpath ) {
	pnd_log ( pndn_rem, "  Scanning menu paths----------------------------\n" );
	if ( ! perform_discoveries ( menu_appspath, overridespath, menu_dotdesktoppath, menu_iconpath ) ) {
	  pnd_log ( pndn_rem, "    No applications found in menu search path\n" );
	}
      }

      // unlock
      pnd_log ( pndn_rem, "clearing lockfile %s", PNDLOCKNAME );
      pnd_unlock ( PNDLOCKNAME );

      // if we've got a hup script located, lets invoke it
      if ( pndhup ) {
	pnd_log ( pndn_rem, "Invoking hup script '%s'.\n", pndhup );
	pnd_exec_no_wait_1 ( pndhup, NULL );
      }

      // since its entirely likely new directories have been found (ie: SD with a directory structure was inserted)
      // we should re-apply watches to catch all these new directories; ie: user might use on-device browser to
      // drop in new applications, or use the shell to juggle them around, or any number of activities.
      if ( watch_dbus ) {
	setup_notifications();
      }

    } // need to rediscover?

    // lets not eat up all the CPU
    // should use an alarm or select() or something -- I mean really, why aren't I putting interval_secs into
    // the select() call above in pnd_notify_whatsitcalled()? -- but lets not break this right before release shall we
    // NOTE: Oh right, I remember now -- inotify will spam when a card is inserted, and it will not be instantaneoous..
    // the events will dribble in over a second. So this sleep is a lame trick that generally works. I really should
    // do select(), and then when it returns just spin for a couple seconds slurping up events until no more and a thresh-hold
    // time is hit, but this will do for now. I suck.
    sleep ( interval_secs );

  } // while

  /* shutdown
   */
  pnd_notify_shutdown ( nh );
  pnd_dbusnotify_shutdown ( dbh );

  return ( 0 );
}