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 ) );
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.
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
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
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 );