Added a bit more debug, check_login() will ignore root as a candidate, and set defaul...
authorskeezix <skeezix@flotsam-vm.(none)>
Tue, 22 Dec 2009 15:31:24 +0000 (10:31 -0500)
committerskeezix <skeezix@flotsam-vm.(none)>
Tue, 22 Dec 2009 15:31:24 +0000 (10:31 -0500)
apps/pndnotifyd.c
lib/pnd_utility.c

index 73fcbab..3301f2c 100644 (file)
@@ -402,6 +402,39 @@ void consume_configuration ( void ) {
     pnd_log ( pndn_rem, "No pndhup found (which is fine.)\n" );
   }
 
+  /* cheap hack, maybe it'll help when pndnotifyd is coming up before the rest of the system and before
+   * the user is formally logged in
+   */
+  pnd_log ( pndn_rem, "Setting a default $HOME to non-root user\n" );
+  {
+    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 );
+
+       // file is a .desktop?
+       if ( dirent -> d_name [ 0 ] == '.' ) {
+         continue;
+       } else if ( strcmp ( dirent -> d_name, "root" ) == 0 ) {
+         continue;
+       }
+
+       // a non-root user is found
+       char buffer [ 200 ];
+       sprintf ( buffer, "/home/%s", dirent -> d_name );
+       pnd_log ( pndn_rem, "  Going with '%s'\n", buffer );
+       setenv ( "HOME", buffer, 1 /* overwrite */ );
+
+      } // while iterating through dir listing
+
+      closedir ( dir );
+    } // opendir?
+
+  } // scope
+
   /* handle globbing or variable substitution
    */
   desktop_dotdesktoppath = pnd_expand_tilde ( strdup ( desktop_dotdesktoppath ) );
index 22f0db5..3733ad0 100644 (file)
@@ -24,9 +24,12 @@ unsigned char pnd_check_login ( char *r_username, unsigned int maxlen ) {
 
   if ( f ) {
 
+    // spin until a non-root user comes along
     while ( fread ( &b, sizeof(struct utmp), 1, f ) == 1 ) {
 
-      if ( b.ut_type == USER_PROCESS ) {
+      if ( ( b.ut_type == USER_PROCESS ) &&
+          ( strcmp ( b.ut_user, "root" ) != 0 ) )
+      {
 
        // ut_user contains the username ..
        // now we need to find the path to that account.
@@ -62,8 +65,8 @@ char *pnd_expand_tilde ( char *freeable_buffer ) {
   char *s = freeable_buffer;
   char *home = getenv ( "HOME" );
 
-  //printf ( "expand tilde IN: '%s'\n", freeable_buffer );
-  //printf ( "  home was %s\n", home );
+  printf ( "DEBUG: expand tilde IN: '%s'\n", freeable_buffer );
+  printf ( "DEBUG:  $HOME was %s\n", home );
 
   // well, as pndnotifyd (etc) may be running as _root_, while the user is logged in
   // as 'pandora' or god knows what, this could be problematic. Other parts of the lib
@@ -101,7 +104,7 @@ char *pnd_expand_tilde ( char *freeable_buffer ) {
              florp = strdup ( pw -> pw_dir );
 
              home = florp;
-             printf ( "  DEBUG: home is %s (from %u)\n", home, b.ut_type );
+             printf ( "  DEBUG: home (for %s) is %s (from %u)\n", b.ut_user, home, b.ut_type );
 
            } // passwd entry matches the utmp entry
 
@@ -121,7 +124,7 @@ char *pnd_expand_tilde ( char *freeable_buffer ) {
     return ( s ); // can't succeed
   }
 
-  printf ( "DEBUG: entering while (%s)\n", s );
+  printf ( "DEBUG: entering while (%s) with home (%s)\n", s, home );
 
   while ( ( p = strchr ( s, '~' ) ) ) {
     printf ( "DEBUG: within while (%s)\n", s );