+
+ // 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 ) {