James Hunt has proposed merging lp:~jamesodhunt/upstart/handle-no-home-var into lp:upstart.
Requested reviews: Upstart Reviewers (upstart-reviewers) For more details, see: https://code.launchpad.net/~jamesodhunt/upstart/handle-no-home-var/+merge/210621 Currently, if $HOME is unset and upstart is run as a Session Init, it will spin at 100% CPU,due to the following in main(): 592 dirs = NIH_MUST (get_user_upstart_dirs ()); We could just change that logic, but a better approach is to query the password database to determine the users home directory as that is a more reliable method anyway. -- https://code.launchpad.net/~jamesodhunt/upstart/handle-no-home-var/+merge/210621 Your team Upstart Reviewers is requested to review the proposed merge of lp:~jamesodhunt/upstart/handle-no-home-var into lp:upstart.
=== modified file 'ChangeLog' --- ChangeLog 2014-03-11 14:44:56 +0000 +++ ChangeLog 2014-03-12 14:34:54 +0000 @@ -1,3 +1,10 @@ +2014-03-12 James Hunt <[email protected]> + + * init/xdg.c: get_home_subdir() Try harder to establish users home + directory to handle environments where $HOME may not be set. + * init/tests/test_xdg.c: Updated tests based on new safer behaviour of + get_home_subdir(). + 2014-03-11 James Hunt <[email protected]> * NEWS: Release 1.12.1 === modified file 'init/tests/test_xdg.c' --- init/tests/test_xdg.c 2013-11-12 12:17:30 +0000 +++ init/tests/test_xdg.c 2014-03-12 14:34:54 +0000 @@ -53,11 +53,19 @@ TEST_FUNCTION ("get_home_subdir"); TEST_FEATURE ("with HOME not set"); + /* It should be possible to establish the home directory (via + * the password database) even if $HOME is not set. + */ TEST_EQ (unsetenv ("HOME"), 0); TEST_ALLOC_FAIL { dir = get_home_subdir ("test", FALSE); - TEST_EQ_P (dir, NULL); + if (test_alloc_failed) { + TEST_EQ_P (dir, NULL); + } else { + TEST_NE_P (dir, NULL); + nih_free (dir); + } } TEST_FEATURE ("with HOME set"); @@ -212,7 +220,12 @@ TEST_ALLOC_FAIL { outname = NULL; outname = function (); - TEST_EQ_P (outname, NULL); + if (test_alloc_failed) { + TEST_EQ_P (outname, NULL); + } else { + TEST_NE_P (outname, NULL); + nih_free (outname); + } } TEST_FEATURE ("without HOME set and without environment override"); @@ -220,7 +233,12 @@ TEST_ALLOC_FAIL { outname = NULL; outname = function (); - TEST_EQ_P (outname, NULL); + if (test_alloc_failed) { + TEST_EQ_P (outname, NULL); + } else { + TEST_NE_P (outname, NULL); + nih_free (outname); + } } } === modified file 'init/xdg.c' --- init/xdg.c 2013-11-16 12:42:57 +0000 +++ init/xdg.c 2014-03-12 14:34:54 +0000 @@ -26,6 +26,8 @@ #include <stdlib.h> #include <sys/stat.h> #include <sys/types.h> +#include <sys/types.h> +#include <pwd.h> #include <nih/alloc.h> #include <nih/logging.h> @@ -85,13 +87,25 @@ char * get_home_subdir (const char *suffix, int create) { - char *env; + char *env; + struct passwd *pw; env = getenv ("HOME"); - if (! env) - return NULL; - + if (env) + goto out; + + pw = getpwent (); + if (! pw) + return NULL; + + if (! pw->pw_dir) + return NULL; + + env = pw->pw_dir; + +out: return get_subdir (env, suffix, create); + } /**
-- upstart-devel mailing list [email protected] Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/upstart-devel
