Merge lp:~jamesodhunt/upstart/handle-no-home-var into lp:upstart

Proposed by James Hunt on 2014-03-12
Status: Rejected
Rejected by: Dimitri John Ledkov on 2014-08-04
Proposed branch: lp:~jamesodhunt/upstart/handle-no-home-var
Merge into: lp:upstart
Diff against target: 110 lines (+46/-7)
3 files modified
ChangeLog (+7/-0)
init/tests/test_xdg.c (+21/-3)
init/xdg.c (+18/-4)
To merge this branch: bzr merge lp:~jamesodhunt/upstart/handle-no-home-var
Reviewer Review Type Date Requested Status
Dimitri John Ledkov 2014-03-12 Disapprove on 2014-03-13
Review via email: mp+210621@code.launchpad.net

Description of the change

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.

To post a comment you must log in.
Dimitri John Ledkov (xnox) wrote :

user-session init shouldn't be started without $HOME set in the environment. getpwent call can block on looking up NIS/ldap, and the expectation is that by the time upstart --user is run $HOME is properly available.

upstart as PID 2 shoudn't be running with --user flag, as we don't want /root/.config/upstart config dir nor logs in /root/.cache/upstart. We want it to read /etc/init and log into /var/log/upstart.

review: Disapprove

Unmerged revisions

1612. By James Hunt on 2014-03-12

* 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().

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'ChangeLog'
2--- ChangeLog 2014-03-11 14:44:56 +0000
3+++ ChangeLog 2014-03-12 14:34:54 +0000
4@@ -1,3 +1,10 @@
5+2014-03-12 James Hunt <james.hunt@ubuntu.com>
6+
7+ * init/xdg.c: get_home_subdir() Try harder to establish users home
8+ directory to handle environments where $HOME may not be set.
9+ * init/tests/test_xdg.c: Updated tests based on new safer behaviour of
10+ get_home_subdir().
11+
12 2014-03-11 James Hunt <james.hunt@ubuntu.com>
13
14 * NEWS: Release 1.12.1
15
16=== modified file 'init/tests/test_xdg.c'
17--- init/tests/test_xdg.c 2013-11-12 12:17:30 +0000
18+++ init/tests/test_xdg.c 2014-03-12 14:34:54 +0000
19@@ -53,11 +53,19 @@
20 TEST_FUNCTION ("get_home_subdir");
21
22 TEST_FEATURE ("with HOME not set");
23+ /* It should be possible to establish the home directory (via
24+ * the password database) even if $HOME is not set.
25+ */
26 TEST_EQ (unsetenv ("HOME"), 0);
27
28 TEST_ALLOC_FAIL {
29 dir = get_home_subdir ("test", FALSE);
30- TEST_EQ_P (dir, NULL);
31+ if (test_alloc_failed) {
32+ TEST_EQ_P (dir, NULL);
33+ } else {
34+ TEST_NE_P (dir, NULL);
35+ nih_free (dir);
36+ }
37 }
38
39 TEST_FEATURE ("with HOME set");
40@@ -212,7 +220,12 @@
41 TEST_ALLOC_FAIL {
42 outname = NULL;
43 outname = function ();
44- TEST_EQ_P (outname, NULL);
45+ if (test_alloc_failed) {
46+ TEST_EQ_P (outname, NULL);
47+ } else {
48+ TEST_NE_P (outname, NULL);
49+ nih_free (outname);
50+ }
51 }
52
53 TEST_FEATURE ("without HOME set and without environment override");
54@@ -220,7 +233,12 @@
55 TEST_ALLOC_FAIL {
56 outname = NULL;
57 outname = function ();
58- TEST_EQ_P (outname, NULL);
59+ if (test_alloc_failed) {
60+ TEST_EQ_P (outname, NULL);
61+ } else {
62+ TEST_NE_P (outname, NULL);
63+ nih_free (outname);
64+ }
65 }
66 }
67
68
69=== modified file 'init/xdg.c'
70--- init/xdg.c 2013-11-16 12:42:57 +0000
71+++ init/xdg.c 2014-03-12 14:34:54 +0000
72@@ -26,6 +26,8 @@
73 #include <stdlib.h>
74 #include <sys/stat.h>
75 #include <sys/types.h>
76+#include <sys/types.h>
77+#include <pwd.h>
78
79 #include <nih/alloc.h>
80 #include <nih/logging.h>
81@@ -85,13 +87,25 @@
82 char *
83 get_home_subdir (const char *suffix, int create)
84 {
85- char *env;
86+ char *env;
87+ struct passwd *pw;
88
89 env = getenv ("HOME");
90- if (! env)
91- return NULL;
92-
93+ if (env)
94+ goto out;
95+
96+ pw = getpwent ();
97+ if (! pw)
98+ return NULL;
99+
100+ if (! pw->pw_dir)
101+ return NULL;
102+
103+ env = pw->pw_dir;
104+
105+out:
106 return get_subdir (env, suffix, create);
107+
108 }
109
110 /**

Subscribers

People subscribed via source and target branches