From 3b8680635554d605276eb489f298b6427d371027 Mon Sep 17 00:00:00 2001 From: skeezix Date: Mon, 15 Feb 2010 13:49:18 -0500 Subject: [PATCH] Added 'seconds since first log line' to pnd_logger pndnotifyd should now ignore a rediscover request within 2s of past one, maybe avoid a few 'redraws' --- apps/pndevmapperd.c | 2 ++ apps/pndnotifyd.c | 49 +++++++++++++++++++++++++++++++++++++++------ lib/pnd_logger.c | 16 ++++++++++----- 3 files changed, 56 insertions(+), 11 deletions(-) diff --git a/apps/pndevmapperd.c b/apps/pndevmapperd.c index 170deb6..8a49d6d 100644 --- a/apps/pndevmapperd.c +++ b/apps/pndevmapperd.c @@ -169,6 +169,8 @@ int main ( int argc, char *argv[] ) { } // 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() ); // basic daemon set up diff --git a/apps/pndnotifyd.c b/apps/pndnotifyd.c index a2ca73f..d31395b 100644 --- a/apps/pndnotifyd.c +++ b/apps/pndnotifyd.c @@ -61,6 +61,8 @@ char *run_searchpath; // searchpath to find pnd_run.sh char *run_script; // name of pnd_run.sh script from config char *pndrun; // full path to located pnd_run.sh char *pndhup = NULL; // full path to located pnd_hup.sh +// default username +char g_username [ 128 ]; // since we have to wait for login (!!), store username here // notifier handle pnd_notify_handle nh = 0; @@ -153,6 +155,8 @@ int main ( int argc, char *argv[] ) { } // 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 ); @@ -193,15 +197,14 @@ int main ( int argc, char *argv[] ) { // 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" ); - char tmp_username [ 128 ]; while ( 1 ) { - if ( pnd_check_login ( tmp_username, 127 ) ) { + 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", tmp_username ); + pnd_log ( pndn_rem, "Looks like user '%s' is in, continue.\n", g_username ); /* parse configs */ @@ -253,6 +256,13 @@ int main ( int argc, char *argv[] ) { if ( scanonlaunch || pnd_notify_rediscover_p ( nh ) ) { + + if ( time ( NULL ) - createtime <= 2 ) { + pnd_log ( pndn_rem, "Rediscovery request comes to soon after previous discovery; skipping.\n" ); + sleep ( interval_secs ); + continue; + } + createtime = time ( NULL ); // all 'new' .destops are created at or after this time; prev are old. // if this was a forced scan, lets not do that next iteration @@ -448,14 +458,41 @@ void consume_configuration ( void ) { * the user is formally logged in */ pnd_log ( pndn_rem, "Setting a default $HOME to non-root user\n" ); - { + + // first, try to see if known-username maps to a homedir; if so, just use that! + // otherwise, pick first non-root homedir and assume .. or we start blaring .desktops + // out to all users like idiots + unsigned char got_user_homedir = 0; + + if ( g_username [ 0 ] ) { + struct stat homedir; + char path [ PATH_MAX ]; + + sprintf ( path, "/home/%s", g_username ); + + // does this made up path exist? + if ( stat ( path, &homedir ) == 0 ) { + + // and its a dir? + if ( S_ISDIR(homedir.st_mode) ) { + pnd_log ( pndn_rem, " User [%s] matches path [%s], going with '%s'\n", g_username, path, path ); + setenv ( "HOME", path, 1 /* overwrite */ ); + got_user_homedir = 1; + } // and its a dir? + + } // guessing a homedirname.. + + } // got a username? + + // if guessing a path was no good, just try finding one + if ( got_user_homedir == 0 ) { DIR *dir; if ( ( dir = opendir ( "/home" ) ) ) { struct dirent *dirent; while ( ( dirent = readdir ( dir ) ) ) { - pnd_log ( pndn_rem, " Found user homedir '%s'\n", dirent -> d_name ); + pnd_log ( pndn_rem, " Scanning user homedir '%s'\n", dirent -> d_name ); // file is a .desktop? if ( dirent -> d_name [ 0 ] == '.' ) { @@ -731,7 +768,7 @@ unsigned char perform_discoveries ( char *appspath, char *overridespath, "File '%s' appears to have been created by libpnd so candidate for delete: %u\n", buffer, source_libpnd ); #endif } else { -#if 1 +#if 0 pnd_log ( pndn_debug, "File '%s' appears NOT to have been created by libpnd, so leave it alone\n", buffer ); #endif continue; // skip deleting it diff --git a/lib/pnd_logger.c b/lib/pnd_logger.c index 38a6586..79b8558 100644 --- a/lib/pnd_logger.c +++ b/lib/pnd_logger.c @@ -2,11 +2,13 @@ #include // va-args #include // malloc/free #include // strdup +#include #include "pnd_logger.h" -char *log_pretext = NULL; -unsigned char log_filterlevel = 0; -unsigned char log_flushafter = 0; +static char *log_pretext = NULL; +static unsigned char log_filterlevel = 0; +static unsigned char log_flushafter = 0; +static time_t log_first = 0; typedef enum { pndl_nil = 0, @@ -120,10 +122,10 @@ static void pnd_log_emit ( unsigned char level, char *message ) { case pndl_stream: // pretext if ( log_pretext ) { - fprintf ( log_targets [ i ].stream, "%s\t", log_pretext ); + fprintf ( log_targets [ i ].stream, "%s ", log_pretext ); } // log level - fprintf ( log_targets [ i ].stream, "%u\t", level ); + fprintf ( log_targets [ i ].stream, "%u %u\t", level, (unsigned int) (time ( NULL ) - log_first) ); // message if ( message ) { fprintf ( log_targets [ i ].stream, "%s", message ); @@ -153,6 +155,10 @@ static void pnd_log_emit ( unsigned char level, char *message ) { unsigned char pnd_log ( unsigned char level, char *fmt, ... ) { + if ( log_first == 0 ) { + log_first = time ( NULL ); + } + if ( level == PND_LOG_FORCE ) { // always proceed } else if ( level < log_filterlevel ) { -- 2.39.2