Merge lp:~xnox/upstart/user-log-dir into lp:upstart
- user-log-dir
- Merge into trunk
Status: | Merged |
---|---|
Merged at revision: | 1428 |
Proposed branch: | lp:~xnox/upstart/user-log-dir |
Merge into: | lp:upstart |
Diff against target: |
896 lines (+352/-86) 10 files modified
ChangeLog (+12/-0) init/Makefile.am (+14/-14) init/control.c (+2/-7) init/job_process.c (+2/-1) init/main.c (+5/-0) init/man/init.5 (+31/-12) init/man/init.8 (+4/-1) init/tests/test_xdg.c (+184/-40) init/xdg.c (+91/-10) init/xdg.h (+7/-1) |
To merge this branch: | bzr merge lp:~xnox/upstart/user-log-dir |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
James Hunt | Approve | ||
Review via email: mp+143091@code.launchpad.net |
Commit message
Description of the change
This branch implements writting job logs to $XDG_CACHE_
One can override the location with command-line arg.
Note the environment variable is not honoured.
- 1425. By James Hunt
-
* init/log.c:
- log_clear_unflushed( ): Correct remote_closed assertion to handle
early-job-logging scenario where a job satisfies both of the
following conditions:
- ends before the log directory becomes writeable.
- has spawned one or more processes that continue to run after the
job itself has exited and which produce output before the log
directory becomes writeable.
(LP: #1096531).
James Hunt (jamesodhunt) wrote : | # |
The reason we don't honour the LOGDIR_ENV variable for Session Inits is to handle the scenario where the root user starts its own Session Init: if that is to happen, we don't want the root Session Init to log to the same directory as Upstart running as PID 1 should the LOGDIR_ENV variable be set when root starts the Session Init.
Dimitri John Ledkov (xnox) wrote : | # |
Reading XDG specification, it sounds like instead of $XDG_CACHE_
"""
$XDG_RUNTIME_DIR defines the base directory relative to which user-specific non-essential runtime files and other file objects (such as sockets, named pipes, ...) should be stored. The directory MUST be owned by the user, and he MUST be the only one having read and write access to it. Its Unix access mode MUST be 0700.
The lifetime of the directory MUST be bound to the user being logged in. It MUST be created when the user first logs in and if the user fully logs out the directory MUST be removed. If the user logs in more than once he should get pointed to the same directory, and it is mandatory that the directory continues to exist from his first login to his last logout on the system, and not removed in between. Files in the directory MUST not survive reboot or a full logout/login cycle.
"""
http://
Currently I like how all our logs are stored in a flat directory and I'd rather not introduce subdirs.
Shall I update the spec with:
logs go to $XDG_CACHE_
the address of the session goes to $XDG_RUNTIME_
James Hunt (jamesodhunt) wrote : | # |
Sounds good. Yes, please update the spec.
Please can you also update the doc as outlined in original comments. Also...
* init/xdg.c:
xdg_get_
Steve Langasek (vorlon) wrote : | # |
On Wed, Jan 16, 2013 at 12:02:21PM -0000, Dmitrijs Ledkovs wrote:
> Reading XDG specification, it sounds like instead of
> $XDG_CACHE_
> $XDG_RUNTIME_
> """
> $XDG_RUNTIME_DIR defines the base directory relative to which
> user-specific non-essential runtime files and other file objects (such as
> sockets, named pipes, ...) should be stored. The directory MUST be owned
> by the user, and he MUST be the only one having read and write access to
> it. Its Unix access mode MUST be 0700.
> The lifetime of the directory MUST be bound to the user being logged in.
> It MUST be created when the user first logs in and if the user fully logs
> out the directory MUST be removed. If the user logs in more than once he
> should get pointed to the same directory, and it is mandatory that the
> directory continues to exist from his first login to his last logout on
> the system, and not removed in between. Files in the directory MUST not
> survive reboot or a full logout/login cycle.
This last paragraph is the problematic part, since up to this point AIUI
we've been discussing having one upstart session per login session, *not*
one upstart session per logged-in user. XDG_RUNTIME_DIR only has the
correct semantics for the latter.
Dimitri John Ledkov (xnox) wrote : | # |
XDG_RUNTIME_DIR guarantees that we get the same dir no matter how many times we login.
We can manage multiple pids/sockets ourself per user.
The file we store there will be pid e.g. $XDG_RUNTIME_
For another session (for the same user) we will have pid e.g. $XDG_RUNTIME_
This is to support one upstart session per login session.
The will know the current session via environment variable.
Also we can implement `initctl list-sessions` command simply by iterating $XDG_RUNTIME_
XDG_CACHE_HOME is not guaranteed to be cleared, while XDG_RUNTIME_DIR will always be fresh after reboots & complete logouts.
Dimitri John Ledkov (xnox) wrote : | # |
> Sounds good. Yes, please update the spec.
>
> Please can you also update the doc as outlined in original comments. Also...
>
> * init/xdg.c:
> xdg_get_
> init/paths.h for consistency.
Why? I only defined upstart specific constants in path.h, e.g. INIT_XDG_SUBDIR - the name of the subdirectory we use within all XDG_* locations.
XDG_* variables are not upstart specific and are compliant with the XDG spec.
Also their fallbacks "/etc/xdg/", "~/.config", "~/.cache" are defined in the XDG spec.
I am failing to see benefits or introducing #ifndef pointers to those names, since changing those will violate XDG specification.
And XDG specification is unlikely to change in a backwards incompatible way at this point.
Note that XDG_CONFIG_HOME, XDG_CONFIG_DIRS, "~/.config", "/etc/xdg/" are not defined in paths.h.
If libnih starts using XDG_* paths for anything, it might even make sense to move xdg_ helper functions into libnih.
I guess I can make a static array of those constants at the top of xdg.c for ease of understanding that these constants are externally specified.
James Hunt (jamesodhunt) wrote : | # |
OK, you've convinced me on paths.h :-)
I've updated the spec such that we have a script which sets the appropriate XDG vars if not already set *and* creates them if they don't exist. It will then start the Session Init. However, I wonder if the Session Init should also attempt to create the directories returned by xdg_get_
I think that to be conformant to the XDG spec, the alluded-to script can as Dmitrijs says run 'initctl list-sessions' and if that returns nothing, remove XDG_RUNTIME_DIR before exiting.
After scrutinizing the XDG spec again, we do need to make some minor changes:
* init/xdg.c:
- xdg_get_
- xdg_get_
- get_user_
Dimitri John Ledkov (xnox) wrote : | # |
> OK, you've convinced me on paths.h :-)
>
> I've updated the spec such that we have a script which sets the appropriate
> XDG vars if not already set *and* creates them if they don't exist. It will
no, this is wrong again.
It's perfectly valid to not have XDG_HOME_* variables set, as by default the default fallbacks should be used.
It's only meant for a user to change them if they want to launch set of applications with "clean" config, cache.
The XDG_RUNTIME_DIR in ubuntu is already set by libpam-xdg-support
https:/
So these variables should not be set, if they don't already exist.
Creating the directories if they don't yet exist is a good point. Especially brand new accounts, might not have those directories.
Oh and as per XDG spec we should create them with permissions 0700 if we need to access them.
The spec is unclear about XDG_RUNTIME_DIR, I'd like to assert if it doesn't exist. In ubuntu it exists in quantal and up. To be compliant with the spec we should gracefully fallback to some other place, but I don't know what that other place is a good to fallback to.
> then start the Session Init. However, I wonder if the Session Init should also
> attempt to create the directories returned by xdg_get_
> xdg_get_
> times and in the first session say deletes one or both of these directories.
>
I don't like the idea of creating empty directories, just to place inotify watch on it (for the $XDG_CONFIG_
We intend to generate logs everytime, so precreating $XDG_CACHE_
> I think that to be conformant to the XDG spec, the alluded-to script can as
> Dmitrijs says run 'initctl list-sessions' and if that returns nothing, remove
> XDG_RUNTIME_DIR before exiting.
>
I believe XDG_RUNTIME_DIR is cleaned up for us after the last logout. I'll check that. Or do you mean to clean up bits in the $XDG_RUNTIME_
(outside of this merge proposal as far as I can see)
> After scrutinizing the XDG spec again, we do need to make some minor changes:
>
> * init/xdg.c:
> - xdg_get_
> it also is an absolute path before we use it.
> - xdg_get_
> - get_user_
All good points.
James Hunt (jamesodhunt) wrote : | # |
> > OK, you've convinced me on paths.h :-)
> >
> > I've updated the spec such that we have a script which sets the appropriate
> > XDG vars if not already set *and* creates them if they don't exist. It will
>
> no, this is wrong again.
> It's perfectly valid to not have XDG_HOME_* variables set, as by default the default fallbacks should be used.
> It's only meant for a user to change them if they want to launch set of applications with "clean" config, cache.
> The XDG_RUNTIME_DIR in ubuntu is already set by libpam-xdg-support
> https:/
>
> So these variables should not be set, if they don't already exist.
>
> Creating the directories if they don't yet exist is a good point. Especially brand new accounts, might not have those directories.
The reason for my specifying in the spec that we create the directories is that if they do not already exist, we end up with impotent inotify watches: meaning no job logging and no way for a user to create jobs *after* they create ~/.config/upstart/ manually. All very confusing from the users perspective. However, yes, seemingly we should not set them, implying Upstart needs to handle this.
> Oh and as per XDG spec we should create them with permissions 0700 if we need to access them.
Right.
>
> The spec is unclear about XDG_RUNTIME_DIR, I'd like to assert if it doesn't exist. In ubuntu it exists in quantal and up. To be compliant with the spec we should gracefully fallback to some other place, but I don't know what that other place is a good to fallback to.
Asserting is a little harsh. If it's not set, how about we display a warning and then fall back to ${TMPDIR}/${USER} and if that's not set, /tmp/${USER}? Steve?
>
> > then start the Session Init. However, I wonder if the Session Init should also
> > attempt to create the directories returned by xdg_get_
> > xdg_get_
> > times and in the first session say deletes one or both of these directories.
Lets go with this then and I'll revert the spec change.
> >
>
> I don't like the idea of creating empty directories, just to place inotify watch on it (for the $XDG_CONFIG_
> We intend to generate logs everytime, so precreating $XDG_CACHE_
See above: we need to do both as what is the point in creating the log directory if no jobs can be registered if the config directory does not exist? 1 inotify watch is a small price to pay for sane behaviour. Added to which there is precedent: we already create a watch for /etc/init.conf.
>
> > I think that to be conformant to the XDG spec, the alluded-to script can as
> > Dmitrijs says run 'initctl list-sessions' and if that returns nothing, remove
> > XDG_RUNTIME_DIR before exiting.
> >
>
> I believe XDG_RUNTIME_DIR is cleaned up for us after the last logout. I'll check that. Or do you mean to clean up bits in the $XDG_RUNTIME_
What is doing the cleaning up currently? And will that need to change when Upstart is in control?
Steve Langasek (vorlon) wrote : | # |
On Thu, Jan 17, 2013 at 02:20:29PM -0000, James Hunt wrote:
> > The spec is unclear about XDG_RUNTIME_DIR, I'd like to assert if it
> > doesn't exist. In ubuntu it exists in quantal and up. To be compliant
> > with the spec we should gracefully fallback to some other place, but I
> > don't know what that other place is a good to fallback to.
> Asserting is a little harsh. If it's not set, how about we display a
> warning and then fall back to ${TMPDIR}/${USER} and if that's not set,
> /tmp/${USER}? Steve
I suggest consulting the desktop team, or looking at existing fd.o software,
for recommendations on a fallback path. Using ${TMPDIR:
some obvious security problems (best case: DoS) that are undesirable even in
a fallback.
I do agree that an assert() here is a bit harsh. In theory we should never
be without $XDG_RUNTIME_DIR in quantal and beyond; however, this is
implemented by way of the pam stack and relies on the local admin not
altering /etc/pam.
having upstart assert instead of opening a login session will be rather
undebuggable, and I doubt this is a good tradeoff for something that's
rather peripheral to the main functionality of upstart.
> > I believe XDG_RUNTIME_DIR is cleaned up for us after the last logout.
> > I'll check that. Or do you mean to clean up bits in the
> > $XDG_RUNTIME_
> > exit?
> What is doing the cleaning up currently? And will that need to change when
> Upstart is in control?
pam_xdg_support, which is the same thing that creates the directory and sets
the env variable. This must not change under upstart user sessions.
- 1426. By James Hunt
-
* init/log.
c:log_clear_ unflushed( ): Simplify asserts.
Dimitri John Ledkov (xnox) wrote : | # |
* Documentation is updated
* Checks for absolute paths added (i.e. must start with '/')
* XDG_HOME_* directories & subdirectories are created
* XDG_RUNTIME_DIR & fallback is not implemented. Need to consult desktop team on fallbacks (e.g. how other XDG compliant software handles it) and then this will be quick to add as a separate merge proposal.
I think this branch is complete for now.
James Hunt (jamesodhunt) wrote : | # |
Hi Dmitrijs,
Just a few comments:
* init/xdg.c:
- get_home_subdir(): Return NULL immediately if nih_sprintf() fails.
- get_user_log_dir(): Return NULL immediately if nih_sprintf() fails.
- create_dir():
- for consistency, this should probably call
init/
@dir and 0700.
- should assert @dir: I don't understand why it currently handles
a NULL directory explicitly?
- @dir param should be const.
- Remove comment: the directory permissions must be 0700 according
to the spec, which is an absolute value. Since we already reset
umask(), the code will work as expected.
- This (and/or system_mkdir()) should be documented explicitly as
only creating the "leaf" directory (ie no recursive creation).
Dimitri John Ledkov (xnox) wrote : | # |
On 22 January 2013 10:28, James Hunt <email address hidden> wrote:
>
> * init/xdg.c:
> - get_home_subdir(): Return NULL immediately if nih_sprintf() fails.
> - get_user_log_dir(): Return NULL immediately if nih_sprintf() fails.
Done.
> - create_dir():
> - for consistency, this should probably call
> init/system.c:int system_mkdir(const char *path, mode_t mode) passing
> @dir and 0700.
> - should assert @dir: I don't understand why it currently handles
> a NULL directory explicitly?
Well, it did so because I didn't return Null straight away when
nih_sprintfs failed in get_home_subdir() and get_user_log_dir().
> - @dir param should be const.
> - Remove comment: the directory permissions must be 0700 according
> to the spec, which is an absolute value. Since we already reset
> umask(), the code will work as expected.
Awesome. Didn't notice this.
> - This (and/or system_mkdir()) should be documented explicitly as
> only creating the "leaf" directory (ie no recursive creation).
Well... after changing get_home_subdir() & get_user_log_dir(), the
"system_mkdir()" is a wrapper with nih_assert around path argument....
I think I went overboard with this wrapper =) instead I just use mkdir
directly. I guess we could add further nih_system_error / warning
saying that we failed to create XDG paths, but imho that's just noise.
- 1427. By James Hunt
-
* Merge of lp:~stgraber/upstart/upstart-session-socket.
- 1428. By Dimitri John Ledkov
-
Merge user-dirs
- 1429. By Dimitri John Ledkov
-
Normalise user_mode extern definitions
James Hunt (jamesodhunt) wrote : | # |
Hi Dmitrijs,
Thanks - merged.
Preview Diff
1 | === modified file 'ChangeLog' | |||
2 | --- ChangeLog 2013-01-21 16:24:48 +0000 | |||
3 | +++ ChangeLog 2013-01-23 13:00:29 +0000 | |||
4 | @@ -1,3 +1,15 @@ | |||
5 | 1 | 2013-01-21 Dmitrijs Ledkovs <xnox@ubuntu.com> | ||
6 | 2 | |||
7 | 3 | * init/xdg.[ch]: add xdg_get_cache_home and get_user_log_dir | ||
8 | 4 | functions. These retrieve XDG_CACHE_HOME and a subdir inside it | ||
9 | 5 | for upstart. | ||
10 | 6 | * init/tests/test_xdg.c: reuse test_get_config_home to test both | ||
11 | 7 | xdg_get_cache_home and xdg_get_config_home. Add test for | ||
12 | 8 | get_user_log_dir. | ||
13 | 9 | * init/main.c: use get_user_log_dir to setup logging | ||
14 | 10 | directory in user_mode. For now, command line argument is | ||
15 | 11 | honoured, while the environment override is not. | ||
16 | 12 | |||
17 | 1 | 2013-01-21 James Hunt <james.hunt@ubuntu.com> | 13 | 2013-01-21 James Hunt <james.hunt@ubuntu.com> |
18 | 2 | 14 | ||
19 | 3 | * init/log.c:log_clear_unflushed(): Simplify asserts. | 15 | * init/log.c:log_clear_unflushed(): Simplify asserts. |
20 | 4 | 16 | ||
21 | === modified file 'init/Makefile.am' | |||
22 | --- init/Makefile.am 2012-12-19 12:46:46 +0000 | |||
23 | +++ init/Makefile.am 2013-01-23 13:00:29 +0000 | |||
24 | @@ -177,7 +177,7 @@ | |||
25 | 177 | system.o environ.o process.o \ | 177 | system.o environ.o process.o \ |
26 | 178 | job_class.o job_process.o job.o event.o event_operator.o blocked.o \ | 178 | job_class.o job_process.o job.o event.o event_operator.o blocked.o \ |
27 | 179 | parse_job.o parse_conf.o conf.o control.o \ | 179 | parse_job.o parse_conf.o conf.o control.o \ |
29 | 180 | session.o log.o state.o \ | 180 | session.o log.o state.o xdg.o \ |
30 | 181 | com.ubuntu.Upstart.o \ | 181 | com.ubuntu.Upstart.o \ |
31 | 182 | com.ubuntu.Upstart.Job.o com.ubuntu.Upstart.Instance.o \ | 182 | com.ubuntu.Upstart.Job.o com.ubuntu.Upstart.Instance.o \ |
32 | 183 | $(NIH_LIBS) \ | 183 | $(NIH_LIBS) \ |
33 | @@ -191,7 +191,7 @@ | |||
34 | 191 | system.o environ.o process.o \ | 191 | system.o environ.o process.o \ |
35 | 192 | job_class.o job_process.o job.o event.o event_operator.o blocked.o \ | 192 | job_class.o job_process.o job.o event.o event_operator.o blocked.o \ |
36 | 193 | parse_job.o parse_conf.o conf.o control.o \ | 193 | parse_job.o parse_conf.o conf.o control.o \ |
38 | 194 | session.o log.o state.o \ | 194 | session.o log.o state.o xdg.o \ |
39 | 195 | com.ubuntu.Upstart.o \ | 195 | com.ubuntu.Upstart.o \ |
40 | 196 | com.ubuntu.Upstart.Job.o com.ubuntu.Upstart.Instance.o \ | 196 | com.ubuntu.Upstart.Job.o com.ubuntu.Upstart.Instance.o \ |
41 | 197 | $(NIH_LIBS) \ | 197 | $(NIH_LIBS) \ |
42 | @@ -205,7 +205,7 @@ | |||
43 | 205 | system.o environ.o process.o \ | 205 | system.o environ.o process.o \ |
44 | 206 | job_class.o job_process.o job.o event.o event_operator.o blocked.o \ | 206 | job_class.o job_process.o job.o event.o event_operator.o blocked.o \ |
45 | 207 | parse_job.o parse_conf.o conf.o control.o \ | 207 | parse_job.o parse_conf.o conf.o control.o \ |
47 | 208 | session.o log.o state.o \ | 208 | session.o log.o state.o xdg.o \ |
48 | 209 | com.ubuntu.Upstart.o \ | 209 | com.ubuntu.Upstart.o \ |
49 | 210 | com.ubuntu.Upstart.Job.o com.ubuntu.Upstart.Instance.o \ | 210 | com.ubuntu.Upstart.Job.o com.ubuntu.Upstart.Instance.o \ |
50 | 211 | $(NIH_LIBS) \ | 211 | $(NIH_LIBS) \ |
51 | @@ -219,7 +219,7 @@ | |||
52 | 219 | system.o environ.o process.o \ | 219 | system.o environ.o process.o \ |
53 | 220 | job_class.o job_process.o job.o event.o event_operator.o blocked.o \ | 220 | job_class.o job_process.o job.o event.o event_operator.o blocked.o \ |
54 | 221 | parse_job.o parse_conf.o conf.o control.o \ | 221 | parse_job.o parse_conf.o conf.o control.o \ |
56 | 222 | session.o log.o state.o \ | 222 | session.o log.o state.o xdg.o \ |
57 | 223 | com.ubuntu.Upstart.o \ | 223 | com.ubuntu.Upstart.o \ |
58 | 224 | com.ubuntu.Upstart.Job.o com.ubuntu.Upstart.Instance.o \ | 224 | com.ubuntu.Upstart.Job.o com.ubuntu.Upstart.Instance.o \ |
59 | 225 | $(NIH_LIBS) \ | 225 | $(NIH_LIBS) \ |
60 | @@ -233,7 +233,7 @@ | |||
61 | 233 | system.o environ.o process.o \ | 233 | system.o environ.o process.o \ |
62 | 234 | job_class.o job_process.o job.o event.o event_operator.o blocked.o \ | 234 | job_class.o job_process.o job.o event.o event_operator.o blocked.o \ |
63 | 235 | parse_job.o parse_conf.o conf.o control.o \ | 235 | parse_job.o parse_conf.o conf.o control.o \ |
65 | 236 | session.o log.o state.o \ | 236 | session.o log.o state.o xdg.o \ |
66 | 237 | com.ubuntu.Upstart.o \ | 237 | com.ubuntu.Upstart.o \ |
67 | 238 | com.ubuntu.Upstart.Job.o com.ubuntu.Upstart.Instance.o \ | 238 | com.ubuntu.Upstart.Job.o com.ubuntu.Upstart.Instance.o \ |
68 | 239 | $(NIH_LIBS) \ | 239 | $(NIH_LIBS) \ |
69 | @@ -247,7 +247,7 @@ | |||
70 | 247 | system.o environ.o process.o \ | 247 | system.o environ.o process.o \ |
71 | 248 | job_class.o job_process.o job.o event.o event_operator.o blocked.o \ | 248 | job_class.o job_process.o job.o event.o event_operator.o blocked.o \ |
72 | 249 | parse_job.o parse_conf.o conf.o control.o \ | 249 | parse_job.o parse_conf.o conf.o control.o \ |
74 | 250 | session.o log.o state.o \ | 250 | session.o log.o state.o xdg.o \ |
75 | 251 | com.ubuntu.Upstart.o \ | 251 | com.ubuntu.Upstart.o \ |
76 | 252 | com.ubuntu.Upstart.Job.o com.ubuntu.Upstart.Instance.o \ | 252 | com.ubuntu.Upstart.Job.o com.ubuntu.Upstart.Instance.o \ |
77 | 253 | $(NIH_LIBS) \ | 253 | $(NIH_LIBS) \ |
78 | @@ -261,7 +261,7 @@ | |||
79 | 261 | system.o environ.o process.o \ | 261 | system.o environ.o process.o \ |
80 | 262 | job_class.o job_process.o job.o event.o event_operator.o blocked.o \ | 262 | job_class.o job_process.o job.o event.o event_operator.o blocked.o \ |
81 | 263 | parse_job.o parse_conf.o conf.o control.o \ | 263 | parse_job.o parse_conf.o conf.o control.o \ |
83 | 264 | session.o log.o state.o \ | 264 | session.o log.o state.o xdg.o \ |
84 | 265 | com.ubuntu.Upstart.o \ | 265 | com.ubuntu.Upstart.o \ |
85 | 266 | com.ubuntu.Upstart.Job.o com.ubuntu.Upstart.Instance.o \ | 266 | com.ubuntu.Upstart.Job.o com.ubuntu.Upstart.Instance.o \ |
86 | 267 | $(NIH_LIBS) \ | 267 | $(NIH_LIBS) \ |
87 | @@ -275,7 +275,7 @@ | |||
88 | 275 | system.o environ.o process.o \ | 275 | system.o environ.o process.o \ |
89 | 276 | job_class.o job_process.o job.o event.o event_operator.o blocked.o \ | 276 | job_class.o job_process.o job.o event.o event_operator.o blocked.o \ |
90 | 277 | parse_job.o parse_conf.o conf.o control.o \ | 277 | parse_job.o parse_conf.o conf.o control.o \ |
92 | 278 | session.o log.o state.o \ | 278 | session.o log.o state.o xdg.o \ |
93 | 279 | com.ubuntu.Upstart.o \ | 279 | com.ubuntu.Upstart.o \ |
94 | 280 | com.ubuntu.Upstart.Job.o com.ubuntu.Upstart.Instance.o \ | 280 | com.ubuntu.Upstart.Job.o com.ubuntu.Upstart.Instance.o \ |
95 | 281 | $(NIH_LIBS) \ | 281 | $(NIH_LIBS) \ |
96 | @@ -289,7 +289,7 @@ | |||
97 | 289 | system.o environ.o process.o \ | 289 | system.o environ.o process.o \ |
98 | 290 | job_class.o job_process.o job.o event.o event_operator.o blocked.o \ | 290 | job_class.o job_process.o job.o event.o event_operator.o blocked.o \ |
99 | 291 | parse_job.o parse_conf.o conf.o control.o \ | 291 | parse_job.o parse_conf.o conf.o control.o \ |
101 | 292 | session.o log.o state.o \ | 292 | session.o log.o state.o xdg.o \ |
102 | 293 | com.ubuntu.Upstart.o \ | 293 | com.ubuntu.Upstart.o \ |
103 | 294 | com.ubuntu.Upstart.Job.o com.ubuntu.Upstart.Instance.o \ | 294 | com.ubuntu.Upstart.Job.o com.ubuntu.Upstart.Instance.o \ |
104 | 295 | $(NIH_LIBS) \ | 295 | $(NIH_LIBS) \ |
105 | @@ -303,7 +303,7 @@ | |||
106 | 303 | system.o environ.o process.o \ | 303 | system.o environ.o process.o \ |
107 | 304 | job_class.o job_process.o job.o event.o event_operator.o blocked.o \ | 304 | job_class.o job_process.o job.o event.o event_operator.o blocked.o \ |
108 | 305 | parse_job.o parse_conf.o conf.o control.o \ | 305 | parse_job.o parse_conf.o conf.o control.o \ |
110 | 306 | session.o log.o state.o \ | 306 | session.o log.o state.o xdg.o \ |
111 | 307 | com.ubuntu.Upstart.o \ | 307 | com.ubuntu.Upstart.o \ |
112 | 308 | com.ubuntu.Upstart.Job.o com.ubuntu.Upstart.Instance.o \ | 308 | com.ubuntu.Upstart.Job.o com.ubuntu.Upstart.Instance.o \ |
113 | 309 | $(NIH_LIBS) \ | 309 | $(NIH_LIBS) \ |
114 | @@ -317,7 +317,7 @@ | |||
115 | 317 | system.o environ.o process.o \ | 317 | system.o environ.o process.o \ |
116 | 318 | job_class.o job_process.o job.o event.o event_operator.o blocked.o \ | 318 | job_class.o job_process.o job.o event.o event_operator.o blocked.o \ |
117 | 319 | parse_job.o parse_conf.o conf.o control.o \ | 319 | parse_job.o parse_conf.o conf.o control.o \ |
119 | 320 | session.o log.o state.o \ | 320 | session.o log.o state.o xdg.o \ |
120 | 321 | com.ubuntu.Upstart.o \ | 321 | com.ubuntu.Upstart.o \ |
121 | 322 | com.ubuntu.Upstart.Job.o com.ubuntu.Upstart.Instance.o \ | 322 | com.ubuntu.Upstart.Job.o com.ubuntu.Upstart.Instance.o \ |
122 | 323 | $(NIH_LIBS) \ | 323 | $(NIH_LIBS) \ |
123 | @@ -331,7 +331,7 @@ | |||
124 | 331 | system.o environ.o process.o \ | 331 | system.o environ.o process.o \ |
125 | 332 | job_class.o job_process.o job.o event.o event_operator.o blocked.o \ | 332 | job_class.o job_process.o job.o event.o event_operator.o blocked.o \ |
126 | 333 | parse_job.o parse_conf.o conf.o control.o \ | 333 | parse_job.o parse_conf.o conf.o control.o \ |
128 | 334 | session.o log.o state.o \ | 334 | session.o log.o state.o xdg.o \ |
129 | 335 | com.ubuntu.Upstart.o \ | 335 | com.ubuntu.Upstart.o \ |
130 | 336 | com.ubuntu.Upstart.Job.o com.ubuntu.Upstart.Instance.o \ | 336 | com.ubuntu.Upstart.Job.o com.ubuntu.Upstart.Instance.o \ |
131 | 337 | $(NIH_LIBS) \ | 337 | $(NIH_LIBS) \ |
132 | @@ -345,7 +345,7 @@ | |||
133 | 345 | system.o environ.o process.o \ | 345 | system.o environ.o process.o \ |
134 | 346 | job_class.o job_process.o job.o event.o event_operator.o blocked.o \ | 346 | job_class.o job_process.o job.o event.o event_operator.o blocked.o \ |
135 | 347 | parse_job.o parse_conf.o control.o \ | 347 | parse_job.o parse_conf.o control.o \ |
137 | 348 | session.o log.o state.o \ | 348 | session.o log.o state.o xdg.o \ |
138 | 349 | com.ubuntu.Upstart.o \ | 349 | com.ubuntu.Upstart.o \ |
139 | 350 | com.ubuntu.Upstart.Job.o com.ubuntu.Upstart.Instance.o \ | 350 | com.ubuntu.Upstart.Job.o com.ubuntu.Upstart.Instance.o \ |
140 | 351 | $(NIH_LIBS) \ | 351 | $(NIH_LIBS) \ |
141 | @@ -366,7 +366,7 @@ | |||
142 | 366 | system.o environ.o process.o \ | 366 | system.o environ.o process.o \ |
143 | 367 | job_class.o job_process.o job.o event.o event_operator.o blocked.o \ | 367 | job_class.o job_process.o job.o event.o event_operator.o blocked.o \ |
144 | 368 | parse_job.o parse_conf.o conf.o control.o \ | 368 | parse_job.o parse_conf.o conf.o control.o \ |
146 | 369 | session.o log.o state.o \ | 369 | session.o log.o state.o xdg.o \ |
147 | 370 | com.ubuntu.Upstart.o \ | 370 | com.ubuntu.Upstart.o \ |
148 | 371 | com.ubuntu.Upstart.Job.o com.ubuntu.Upstart.Instance.o \ | 371 | com.ubuntu.Upstart.Job.o com.ubuntu.Upstart.Instance.o \ |
149 | 372 | $(NIH_LIBS) \ | 372 | $(NIH_LIBS) \ |
150 | 373 | 373 | ||
151 | === modified file 'init/control.c' | |||
152 | --- init/control.c 2013-01-22 15:51:01 +0000 | |||
153 | +++ init/control.c 2013-01-23 13:00:29 +0000 | |||
154 | @@ -76,13 +76,6 @@ | |||
155 | 76 | int use_session_bus = FALSE; | 76 | int use_session_bus = FALSE; |
156 | 77 | 77 | ||
157 | 78 | /** | 78 | /** |
158 | 79 | * user_mode: | ||
159 | 80 | * | ||
160 | 81 | * If TRUE, upstart runs in user session mode. | ||
161 | 82 | **/ | ||
162 | 83 | int user_mode = FALSE; | ||
163 | 84 | |||
164 | 85 | /** | ||
165 | 86 | * control_server_address: | 79 | * control_server_address: |
166 | 87 | * | 80 | * |
167 | 88 | * Address on which the control server may be reached. | 81 | * Address on which the control server may be reached. |
168 | @@ -112,6 +105,8 @@ | |||
169 | 112 | **/ | 105 | **/ |
170 | 113 | NihList *control_conns = NULL; | 106 | NihList *control_conns = NULL; |
171 | 114 | 107 | ||
172 | 108 | /* External definitions */ | ||
173 | 109 | extern int user_mode; | ||
174 | 115 | 110 | ||
175 | 116 | /** | 111 | /** |
176 | 117 | * control_init: | 112 | * control_init: |
177 | 118 | 113 | ||
178 | === modified file 'init/job_process.c' | |||
179 | --- init/job_process.c 2013-01-21 22:44:27 +0000 | |||
180 | +++ init/job_process.c 2013-01-23 13:00:29 +0000 | |||
181 | @@ -66,6 +66,7 @@ | |||
182 | 66 | #include "job.h" | 66 | #include "job.h" |
183 | 67 | #include "errors.h" | 67 | #include "errors.h" |
184 | 68 | #include "control.h" | 68 | #include "control.h" |
185 | 69 | #include "xdg.h" | ||
186 | 69 | 70 | ||
187 | 70 | 71 | ||
188 | 71 | /** | 72 | /** |
189 | @@ -2197,7 +2198,7 @@ | |||
190 | 2197 | nih_assert (class->name); | 2198 | nih_assert (class->name); |
191 | 2198 | 2199 | ||
192 | 2199 | /* Override, primarily for tests */ | 2200 | /* Override, primarily for tests */ |
194 | 2200 | if (getenv (LOGDIR_ENV)) { | 2201 | if (getenv (LOGDIR_ENV) && ! user_mode) { |
195 | 2201 | dir = nih_strdup (NULL, getenv (LOGDIR_ENV)); | 2202 | dir = nih_strdup (NULL, getenv (LOGDIR_ENV)); |
196 | 2202 | nih_debug ("Using alternative directory '%s' for logs", dir); | 2203 | nih_debug ("Using alternative directory '%s' for logs", dir); |
197 | 2203 | } else { | 2204 | } else { |
198 | 2204 | 2205 | ||
199 | === modified file 'init/main.c' | |||
200 | --- init/main.c 2013-01-22 15:53:05 +0000 | |||
201 | +++ init/main.c 2013-01-23 13:00:29 +0000 | |||
202 | @@ -949,6 +949,11 @@ | |||
203 | 949 | if (log_dir) | 949 | if (log_dir) |
204 | 950 | goto out; | 950 | goto out; |
205 | 951 | 951 | ||
206 | 952 | if (user_mode) { | ||
207 | 953 | log_dir = get_user_log_dir (); | ||
208 | 954 | return; | ||
209 | 955 | } | ||
210 | 956 | |||
211 | 952 | log_dir = JOB_LOGDIR; | 957 | log_dir = JOB_LOGDIR; |
212 | 953 | 958 | ||
213 | 954 | dir = getenv (LOGDIR_ENV); | 959 | dir = getenv (LOGDIR_ENV); |
214 | 955 | 960 | ||
215 | === modified file 'init/man/init.5' | |||
216 | --- init/man/init.5 2013-01-16 19:20:54 +0000 | |||
217 | +++ init/man/init.5 2013-01-23 13:00:29 +0000 | |||
218 | @@ -149,11 +149,8 @@ | |||
219 | 149 | of that job name: any subsequently searched directory that contains a | 149 | of that job name: any subsequently searched directory that contains a |
220 | 150 | job of the same name will be ignored. The same applies for override | 150 | job of the same name will be ignored. The same applies for override |
221 | 151 | files: only the first override file found in the search order will be | 151 | files: only the first override file found in the search order will be |
227 | 152 | applied. Note that an override file does not have to be in the same | 152 | applied. Note that an override file can be in the same directory or |
228 | 153 | directory as the job it overrides, but if not in the directory of the | 153 | earlier to that directory which contains the job file. |
224 | 154 | job it overrides, it must be in an | ||
225 | 155 | .I earlier | ||
226 | 156 | directory to that which contains the job. | ||
229 | 157 | 154 | ||
230 | 158 | Jobs in these locations are expected to launch the user's session. | 155 | Jobs in these locations are expected to launch the user's session. |
231 | 159 | Upstart will try to parent all spawned process with the aid of | 156 | Upstart will try to parent all spawned process with the aid of |
232 | @@ -166,6 +163,12 @@ | |||
233 | 166 | When running in User Session mode, Upstart will kill all job processes | 163 | When running in User Session mode, Upstart will kill all job processes |
234 | 167 | on session logout or shutdown. | 164 | on session logout or shutdown. |
235 | 168 | 165 | ||
236 | 166 | All log output will be in | ||
237 | 167 | .I $XDG_CACHE_HOME/upstart | ||
238 | 168 | which defaults to | ||
239 | 169 | .I $HOME/.cache/upstart | ||
240 | 170 | . | ||
241 | 171 | |||
242 | 169 | .\" | 172 | .\" |
243 | 170 | .SS Configuration File Format | 173 | .SS Configuration File Format |
244 | 171 | Each line begins with a configuration stanza and continues until either | 174 | Each line begins with a configuration stanza and continues until either |
245 | @@ -664,19 +667,23 @@ | |||
246 | 664 | .B log | 667 | .B log |
247 | 665 | .RS | 668 | .RS |
248 | 666 | .B | 669 | .B |
250 | 667 | Only applies to system jobs: | 670 | Only applies to system and user session jobs: |
251 | 668 | if specified by user jobs, the job will be considered to have specified | 671 | if specified by user jobs, the job will be considered to have specified |
252 | 669 | the value | 672 | the value |
253 | 670 | .BR none "." | 673 | .BR none "." |
254 | 671 | 674 | ||
256 | 672 | For system jobs, if \fBlog\fR is specified, standard input is connected | 675 | For system and user session jobs jobs, if \fBlog\fR is specified, standard input is connected |
257 | 673 | to | 676 | to |
258 | 674 | .IR /dev/null "," | 677 | .IR /dev/null "," |
259 | 675 | and standard output and standard error are connected to a pseudo-tty | 678 | and standard output and standard error are connected to a pseudo-tty |
260 | 676 | which logs all job output. | 679 | which logs all job output. |
261 | 677 | 680 | ||
262 | 678 | Output is logged to file | 681 | Output is logged to file |
264 | 679 | .IR /var/log/upstart/<job-log-file> "." | 682 | .IR /var/log/upstart/<job-log-file> |
265 | 683 | or | ||
266 | 684 | .IR $XDG_CACHE_HOME/upstart/<job-log-file> | ||
267 | 685 | for system and user session jobs respectively. | ||
268 | 686 | |||
269 | 680 | If a job has specified \fBinstance\fR, | 687 | If a job has specified \fBinstance\fR, |
270 | 681 | .I <job-log-file> | 688 | .I <job-log-file> |
271 | 682 | will equate to | 689 | will equate to |
272 | @@ -1019,18 +1026,30 @@ | |||
273 | 1019 | .TP | 1026 | .TP |
274 | 1020 | .I $HOME/.init/*.conf | 1027 | .I $HOME/.init/*.conf |
275 | 1021 | User job configuration files. | 1028 | User job configuration files. |
276 | 1022 | Note that you may make the directory | ||
277 | 1023 | .I $HOME/.init/ | ||
278 | 1024 | a symbolic link to | ||
279 | 1025 | .BR $HOME/.config/upstart/ "." | ||
280 | 1026 | . | 1029 | . |
281 | 1027 | .TP | 1030 | .TP |
282 | 1028 | .I $HOME/.init/*.override | 1031 | .I $HOME/.init/*.override |
283 | 1029 | User job override files. | 1032 | User job override files. |
284 | 1030 | . | 1033 | . |
285 | 1031 | .TP | 1034 | .TP |
286 | 1035 | .I $XDG_CONFIG_HOME/upstart/*.conf | ||
287 | 1036 | User session job configuration files. See | ||
288 | 1037 | .B User Session Mode | ||
289 | 1038 | for other locations. | ||
290 | 1039 | . | ||
291 | 1040 | .TP | ||
292 | 1041 | .I $XDG_CONFIG_HOME/upstart/*.override | ||
293 | 1042 | User session job override files. See | ||
294 | 1043 | .B User Session Mode | ||
295 | 1044 | for other locations. | ||
296 | 1045 | . | ||
297 | 1046 | .TP | ||
298 | 1032 | .I /var/log/upstart/*.log | 1047 | .I /var/log/upstart/*.log |
299 | 1033 | Default location of system job output logs. | 1048 | Default location of system job output logs. |
300 | 1049 | . | ||
301 | 1050 | .TP | ||
302 | 1051 | .I $XDG_CACHE_HOME/upstart/*.log | ||
303 | 1052 | Default location of user session job output logs. | ||
304 | 1034 | .RE | 1053 | .RE |
305 | 1035 | .\" | 1054 | .\" |
306 | 1036 | .SH AUTHOR | 1055 | .SH AUTHOR |
307 | 1037 | 1056 | ||
308 | === modified file 'init/man/init.8' | |||
309 | --- init/man/init.8 2012-12-18 17:40:49 +0000 | |||
310 | +++ init/man/init.8 2013-01-23 13:00:29 +0000 | |||
311 | @@ -67,6 +67,8 @@ | |||
312 | 67 | .B \-\-confdir \fIdirectory\fP | 67 | .B \-\-confdir \fIdirectory\fP |
313 | 68 | Read job configuration files from a directory other than | 68 | Read job configuration files from a directory other than |
314 | 69 | \fI/etc/init\fP. | 69 | \fI/etc/init\fP. |
315 | 70 | For user session mode, read job configuration files from this | ||
316 | 71 | directory at highest priority. | ||
317 | 70 | .\" | 72 | .\" |
318 | 71 | .TP | 73 | .TP |
319 | 72 | .B \-\-default-console \fIvalue\fP | 74 | .B \-\-default-console \fIvalue\fP |
320 | @@ -81,7 +83,8 @@ | |||
321 | 81 | .TP | 83 | .TP |
322 | 82 | .B \-\-logdir \fIdirectory\fP | 84 | .B \-\-logdir \fIdirectory\fP |
323 | 83 | Write job output log files to a directory other than | 85 | Write job output log files to a directory other than |
325 | 84 | \fI/var/log/upstart\fP. | 86 | \fI/var/log/upstart\fP (system mode) or \fI$XDG_CACHE_HOME/upstart\fP |
326 | 87 | (user session mode). | ||
327 | 85 | .\" | 88 | .\" |
328 | 86 | .TP | 89 | .TP |
329 | 87 | .B \-\-no\-log | 90 | .B \-\-no\-log |
330 | 88 | 91 | ||
331 | === modified file 'init/tests/test_xdg.c' | |||
332 | --- init/tests/test_xdg.c 2012-12-18 14:16:10 +0000 | |||
333 | +++ init/tests/test_xdg.c 2013-01-23 13:00:29 +0000 | |||
334 | @@ -22,12 +22,26 @@ | |||
335 | 22 | #include <nih/string.h> | 22 | #include <nih/string.h> |
336 | 23 | #include <nih/test.h> | 23 | #include <nih/test.h> |
337 | 24 | 24 | ||
338 | 25 | #include <limits.h> | ||
339 | 25 | #include <stdlib.h> | 26 | #include <stdlib.h> |
341 | 26 | #include <limits.h> | 27 | #include <sys/types.h> |
342 | 28 | #include <sys/stat.h> | ||
343 | 29 | #include <unistd.h> | ||
344 | 27 | 30 | ||
345 | 28 | #include "xdg.h" | 31 | #include "xdg.h" |
346 | 29 | 32 | ||
347 | 30 | void | 33 | void |
348 | 34 | _test_dir_created (char * dirname) { | ||
349 | 35 | struct stat statbuf; | ||
350 | 36 | |||
351 | 37 | TEST_EQ (lstat (dirname, &statbuf), 0); | ||
352 | 38 | TEST_TRUE (S_ISDIR (statbuf.st_mode)); | ||
353 | 39 | |||
354 | 40 | /* Check that the created directory has 0700 permissions, as per XDG spec */ | ||
355 | 41 | TEST_EQ (0700, statbuf.st_mode & (S_IRWXU | S_IRWXG | S_IRWXO)); | ||
356 | 42 | } | ||
357 | 43 | |||
358 | 44 | void | ||
359 | 31 | test_get_home_subdir (void) | 45 | test_get_home_subdir (void) |
360 | 32 | { | 46 | { |
361 | 33 | char dirname[PATH_MAX]; | 47 | char dirname[PATH_MAX]; |
362 | @@ -40,7 +54,7 @@ | |||
363 | 40 | TEST_EQ (unsetenv ("HOME"), 0); | 54 | TEST_EQ (unsetenv ("HOME"), 0); |
364 | 41 | 55 | ||
365 | 42 | TEST_ALLOC_FAIL { | 56 | TEST_ALLOC_FAIL { |
367 | 43 | dir = get_home_subdir ("test"); | 57 | dir = get_home_subdir ("test", FALSE); |
368 | 44 | TEST_EQ_P (dir, NULL); | 58 | TEST_EQ_P (dir, NULL); |
369 | 45 | } | 59 | } |
370 | 46 | 60 | ||
371 | @@ -54,7 +68,7 @@ | |||
372 | 54 | expected = NIH_MUST (nih_sprintf (NULL, "%s/test", dirname)); | 68 | expected = NIH_MUST (nih_sprintf (NULL, "%s/test", dirname)); |
373 | 55 | } | 69 | } |
374 | 56 | 70 | ||
376 | 57 | dir = get_home_subdir ("test"); | 71 | dir = get_home_subdir ("test", FALSE); |
377 | 58 | 72 | ||
378 | 59 | if (test_alloc_failed) { | 73 | if (test_alloc_failed) { |
379 | 60 | TEST_EQ_P (dir, NULL); | 74 | TEST_EQ_P (dir, NULL); |
380 | @@ -69,28 +83,29 @@ | |||
381 | 69 | } | 83 | } |
382 | 70 | 84 | ||
383 | 71 | void | 85 | void |
385 | 72 | test_get_config_home (void) | 86 | _test_get_home (char * env_var_name, char * dir_name, char * (*function)(void)) |
386 | 73 | { | 87 | { |
387 | 74 | char dirname[PATH_MAX]; | 88 | char dirname[PATH_MAX]; |
388 | 89 | char onemore[PATH_MAX]; | ||
389 | 75 | char * outname; | 90 | char * outname; |
390 | 76 | char * expected; | 91 | char * expected; |
391 | 77 | 92 | ||
392 | 78 | TEST_FUNCTION ("xdg_get_config_home"); | ||
393 | 79 | |||
394 | 80 | TEST_FEATURE ("with HOME set and without environment override"); | 93 | TEST_FEATURE ("with HOME set and without environment override"); |
395 | 81 | TEST_FILENAME (dirname); | 94 | TEST_FILENAME (dirname); |
396 | 82 | TEST_EQ (setenv ("HOME", dirname, 1), 0); | 95 | TEST_EQ (setenv ("HOME", dirname, 1), 0); |
398 | 83 | TEST_EQ (unsetenv ("XDG_CONFIG_HOME"), 0); | 96 | TEST_EQ (mkdir (dirname, 0755), 0); |
399 | 97 | TEST_EQ (unsetenv (env_var_name), 0); | ||
400 | 84 | TEST_ALLOC_FAIL { | 98 | TEST_ALLOC_FAIL { |
401 | 85 | TEST_ALLOC_SAFE { | 99 | TEST_ALLOC_SAFE { |
403 | 86 | expected = NIH_MUST (nih_sprintf (NULL, "%s/.config", dirname)); | 100 | expected = NIH_MUST (nih_sprintf (NULL, "%s/%s", dirname, dir_name)); |
404 | 87 | } | 101 | } |
405 | 88 | 102 | ||
406 | 89 | outname = NULL; | 103 | outname = NULL; |
408 | 90 | outname = xdg_get_config_home (); | 104 | outname = function (); |
409 | 91 | 105 | ||
410 | 92 | if (! test_alloc_failed) { | 106 | if (! test_alloc_failed) { |
411 | 93 | TEST_EQ_STR (outname, expected); | 107 | TEST_EQ_STR (outname, expected); |
412 | 108 | _test_dir_created (expected); | ||
413 | 94 | } else { | 109 | } else { |
414 | 95 | TEST_EQ_P (outname, NULL); | 110 | TEST_EQ_P (outname, NULL); |
415 | 96 | } | 111 | } |
416 | @@ -98,83 +113,131 @@ | |||
417 | 98 | if (outname) | 113 | if (outname) |
418 | 99 | nih_free (outname); | 114 | nih_free (outname); |
419 | 100 | 115 | ||
421 | 101 | nih_free(expected); | 116 | rmdir (expected); |
422 | 117 | nih_free (expected); | ||
423 | 102 | } | 118 | } |
424 | 103 | 119 | ||
425 | 104 | TEST_FEATURE ("with HOME set and with empty environment override"); | 120 | TEST_FEATURE ("with HOME set and with empty environment override"); |
444 | 105 | TEST_EQ (setenv ("XDG_CONFIG_HOME", "", 1), 0); | 121 | TEST_EQ (setenv (env_var_name, "", 1), 0); |
445 | 106 | 122 | ||
446 | 107 | 123 | ||
447 | 108 | TEST_ALLOC_FAIL { | 124 | TEST_ALLOC_FAIL { |
448 | 109 | TEST_ALLOC_SAFE { | 125 | TEST_ALLOC_SAFE { |
449 | 110 | expected = NIH_MUST (nih_sprintf (NULL, "%s/.config", dirname)); | 126 | expected = NIH_MUST (nih_sprintf (NULL, "%s/%s", dirname, dir_name)); |
450 | 111 | } | 127 | } |
451 | 112 | outname = NULL; | 128 | outname = NULL; |
452 | 113 | outname = xdg_get_config_home(); | 129 | outname = function (); |
453 | 114 | 130 | ||
454 | 115 | if (test_alloc_failed) { | 131 | if (test_alloc_failed) { |
455 | 116 | TEST_EQ_P (outname, NULL); | 132 | TEST_EQ_P (outname, NULL); |
456 | 117 | } else { | 133 | } else { |
457 | 118 | TEST_EQ_STR (outname, expected); | 134 | TEST_EQ_STR (outname, expected); |
458 | 119 | } | 135 | _test_dir_created (expected); |
459 | 120 | if (outname) | 136 | } |
460 | 121 | nih_free (outname); | 137 | if (outname) |
461 | 122 | nih_free(expected); | 138 | nih_free (outname); |
462 | 139 | rmdir (expected); | ||
463 | 140 | nih_free (expected); | ||
464 | 141 | } | ||
465 | 142 | |||
466 | 143 | TEST_FEATURE ("with HOME set and with relative environment override"); | ||
467 | 144 | TEST_EQ (setenv (env_var_name, "../", 1), 0); | ||
468 | 145 | |||
469 | 146 | |||
470 | 147 | TEST_ALLOC_FAIL { | ||
471 | 148 | TEST_ALLOC_SAFE { | ||
472 | 149 | expected = NIH_MUST (nih_sprintf (NULL, "%s/%s", dirname, dir_name)); | ||
473 | 150 | } | ||
474 | 151 | outname = NULL; | ||
475 | 152 | outname = function (); | ||
476 | 153 | |||
477 | 154 | if (test_alloc_failed) { | ||
478 | 155 | TEST_EQ_P (outname, NULL); | ||
479 | 156 | } else { | ||
480 | 157 | TEST_EQ_STR (outname, expected); | ||
481 | 158 | _test_dir_created (expected); | ||
482 | 159 | } | ||
483 | 160 | if (outname) | ||
484 | 161 | nih_free (outname); | ||
485 | 162 | rmdir (expected); | ||
486 | 163 | nih_free (expected); | ||
487 | 123 | } | 164 | } |
488 | 124 | 165 | ||
489 | 125 | TEST_FEATURE ("with HOME set and with environment override"); | 166 | TEST_FEATURE ("with HOME set and with environment override"); |
492 | 126 | expected = NIH_MUST (nih_strdup (NULL, "/home/me/.config-test")); | 167 | TEST_FILENAME (onemore); |
493 | 127 | TEST_EQ (setenv ("XDG_CONFIG_HOME", expected, 1), 0); | 168 | expected = NIH_MUST (nih_sprintf (NULL, "%s", onemore)); |
494 | 169 | TEST_EQ (setenv (env_var_name, expected, 1), 0); | ||
495 | 128 | 170 | ||
496 | 129 | TEST_ALLOC_FAIL { | 171 | TEST_ALLOC_FAIL { |
497 | 130 | outname = NULL; | 172 | outname = NULL; |
499 | 131 | outname = xdg_get_config_home(); | 173 | outname = function (); |
500 | 132 | 174 | ||
501 | 133 | if (test_alloc_failed) { | 175 | if (test_alloc_failed) { |
502 | 134 | TEST_EQ_P (outname, NULL); | 176 | TEST_EQ_P (outname, NULL); |
503 | 135 | } else { | 177 | } else { |
504 | 136 | TEST_EQ_STR (outname, expected); | 178 | TEST_EQ_STR (outname, expected); |
505 | 179 | _test_dir_created (expected); | ||
506 | 137 | } | 180 | } |
507 | 138 | if (outname) | 181 | if (outname) |
508 | 139 | nih_free (outname); | 182 | nih_free (outname); |
509 | 183 | rmdir (expected); | ||
510 | 140 | } | 184 | } |
511 | 141 | 185 | ||
512 | 186 | TEST_EQ (rmdir (dirname), 0); | ||
513 | 187 | |||
514 | 142 | TEST_FEATURE ("without HOME set and with environment override"); | 188 | TEST_FEATURE ("without HOME set and with environment override"); |
515 | 143 | TEST_EQ (unsetenv ("HOME"), 0); | 189 | TEST_EQ (unsetenv ("HOME"), 0); |
516 | 144 | 190 | ||
517 | 145 | TEST_ALLOC_FAIL { | 191 | TEST_ALLOC_FAIL { |
518 | 146 | outname = NULL; | 192 | outname = NULL; |
520 | 147 | outname = xdg_get_config_home(); | 193 | outname = function (); |
521 | 148 | 194 | ||
522 | 149 | if (test_alloc_failed) { | 195 | if (test_alloc_failed) { |
523 | 150 | TEST_EQ_P (outname, NULL); | 196 | TEST_EQ_P (outname, NULL); |
524 | 151 | } else { | 197 | } else { |
525 | 152 | TEST_EQ_STR (outname, expected); | 198 | TEST_EQ_STR (outname, expected); |
526 | 199 | _test_dir_created (expected); | ||
527 | 153 | } | 200 | } |
528 | 154 | if (outname) | 201 | if (outname) |
529 | 155 | nih_free (outname); | 202 | nih_free (outname); |
530 | 203 | rmdir (expected); | ||
531 | 156 | } | 204 | } |
532 | 157 | nih_free(expected); | 205 | nih_free(expected); |
533 | 158 | 206 | ||
534 | 159 | TEST_FEATURE ("without HOME set and with empty environment override"); | 207 | TEST_FEATURE ("without HOME set and with empty environment override"); |
536 | 160 | TEST_EQ (setenv ("XDG_CONFIG_HOME", "", 1), 0); | 208 | TEST_EQ (setenv (env_var_name, "", 1), 0); |
537 | 161 | 209 | ||
538 | 162 | TEST_ALLOC_FAIL { | 210 | TEST_ALLOC_FAIL { |
539 | 163 | outname = NULL; | 211 | outname = NULL; |
541 | 164 | outname = xdg_get_config_home(); | 212 | outname = function (); |
542 | 165 | TEST_EQ_P (outname, NULL); | 213 | TEST_EQ_P (outname, NULL); |
543 | 166 | } | 214 | } |
544 | 167 | 215 | ||
545 | 168 | TEST_FEATURE ("without HOME set and without environment override"); | 216 | TEST_FEATURE ("without HOME set and without environment override"); |
547 | 169 | TEST_EQ (unsetenv ("XDG_CONFIG_HOME"), 0); | 217 | TEST_EQ (unsetenv (env_var_name), 0); |
548 | 170 | TEST_ALLOC_FAIL { | 218 | TEST_ALLOC_FAIL { |
549 | 171 | outname = NULL; | 219 | outname = NULL; |
551 | 172 | outname = xdg_get_config_home(); | 220 | outname = function (); |
552 | 173 | TEST_EQ_P (outname, NULL); | 221 | TEST_EQ_P (outname, NULL); |
553 | 174 | } | 222 | } |
554 | 175 | } | 223 | } |
555 | 176 | 224 | ||
556 | 177 | void | 225 | void |
557 | 226 | test_get_config_home (void) | ||
558 | 227 | { | ||
559 | 228 | TEST_FUNCTION ("xdg_get_config_home"); | ||
560 | 229 | _test_get_home ("XDG_CONFIG_HOME", ".config", &xdg_get_config_home); | ||
561 | 230 | |||
562 | 231 | } | ||
563 | 232 | |||
564 | 233 | void | ||
565 | 234 | test_get_cache_home (void) | ||
566 | 235 | { | ||
567 | 236 | TEST_FUNCTION ("xdg_get_cache_home"); | ||
568 | 237 | _test_get_home ("XDG_CACHE_HOME", ".cache", &xdg_get_cache_home); | ||
569 | 238 | } | ||
570 | 239 | |||
571 | 240 | void | ||
572 | 178 | test_get_config_dirs (void) | 241 | test_get_config_dirs (void) |
573 | 179 | { | 242 | { |
574 | 180 | char **dirs = NULL; | 243 | char **dirs = NULL; |
575 | @@ -260,12 +323,12 @@ | |||
576 | 260 | TEST_FEATURE ("with HOME set"); | 323 | TEST_FEATURE ("with HOME set"); |
577 | 261 | TEST_FILENAME (dirname); | 324 | TEST_FILENAME (dirname); |
578 | 262 | TEST_EQ (setenv ("HOME", dirname, 1), 0); | 325 | TEST_EQ (setenv ("HOME", dirname, 1), 0); |
579 | 326 | TEST_EQ (mkdir (dirname, 0755), 0); | ||
580 | 263 | TEST_EQ (unsetenv ("XDG_CONFIG_HOME"), 0); | 327 | TEST_EQ (unsetenv ("XDG_CONFIG_HOME"), 0); |
581 | 264 | TEST_EQ (unsetenv ("XDG_CONFIG_DIRS"), 0); | 328 | TEST_EQ (unsetenv ("XDG_CONFIG_DIRS"), 0); |
582 | 265 | 329 | ||
583 | 266 | TEST_ALLOC_FAIL { | 330 | TEST_ALLOC_FAIL { |
584 | 267 | TEST_ALLOC_SAFE { | 331 | TEST_ALLOC_SAFE { |
585 | 268 | dirs = NULL; | ||
586 | 269 | expected = nih_str_array_new (NULL); | 332 | expected = nih_str_array_new (NULL); |
587 | 270 | path = NIH_MUST (nih_sprintf (NULL, "%s/.config/upstart", dirname)); | 333 | path = NIH_MUST (nih_sprintf (NULL, "%s/.config/upstart", dirname)); |
588 | 271 | assert (nih_str_array_add (&expected, NULL, NULL, path)); | 334 | assert (nih_str_array_add (&expected, NULL, NULL, path)); |
589 | @@ -282,15 +345,94 @@ | |||
590 | 282 | TEST_EQ_P (dirs, NULL); | 345 | TEST_EQ_P (dirs, NULL); |
591 | 283 | } else { | 346 | } else { |
592 | 284 | TEST_EQ_STR (dirs[0], expected[0]); | 347 | TEST_EQ_STR (dirs[0], expected[0]); |
593 | 348 | //_test_dir_created (expected[0]); | ||
594 | 285 | TEST_EQ_STR (dirs[1], expected[1]); | 349 | TEST_EQ_STR (dirs[1], expected[1]); |
595 | 286 | TEST_EQ_STR (dirs[2], "/etc/xdg/upstart"); | 350 | TEST_EQ_STR (dirs[2], "/etc/xdg/upstart"); |
596 | 287 | TEST_EQ_STR (dirs[3], SYSTEM_USERCONFDIR); | 351 | TEST_EQ_STR (dirs[3], SYSTEM_USERCONFDIR); |
597 | 288 | TEST_EQ (dirs[4], NULL); | 352 | TEST_EQ (dirs[4], NULL); |
598 | 289 | nih_free (dirs); | 353 | nih_free (dirs); |
599 | 290 | } | 354 | } |
603 | 291 | nih_free(expected); | 355 | TEST_ALLOC_SAFE { |
604 | 292 | } | 356 | rmdir (expected[0]); |
605 | 293 | 357 | path = nih_sprintf (NULL, "%s/.config", dirname); | |
606 | 358 | rmdir (path); | ||
607 | 359 | nih_free (path); | ||
608 | 360 | nih_free (expected); | ||
609 | 361 | } | ||
610 | 362 | } | ||
611 | 363 | |||
612 | 364 | TEST_FEATURE ("with some invalid XDG_CONFIG_DIRS"); | ||
613 | 365 | TEST_EQ (setenv ("XDG_CONFIG_DIRS", "/etc/xdg/xdg-subdir:../haha:/etc/xdg", 1), 0); | ||
614 | 366 | |||
615 | 367 | TEST_ALLOC_FAIL { | ||
616 | 368 | TEST_ALLOC_SAFE { | ||
617 | 369 | expected = nih_str_array_new (NULL); | ||
618 | 370 | path = NIH_MUST (nih_sprintf (NULL, "%s/.config/upstart", dirname)); | ||
619 | 371 | assert (nih_str_array_add (&expected, NULL, NULL, path)); | ||
620 | 372 | nih_free(path); | ||
621 | 373 | path = NIH_MUST (nih_sprintf (NULL, "%s/.init", dirname)); | ||
622 | 374 | assert (nih_str_array_add (&expected, NULL, NULL, path)); | ||
623 | 375 | nih_free(path); | ||
624 | 376 | } | ||
625 | 377 | |||
626 | 378 | dirs = NULL; | ||
627 | 379 | dirs = get_user_upstart_dirs (); | ||
628 | 380 | |||
629 | 381 | if (test_alloc_failed) { | ||
630 | 382 | TEST_EQ_P (dirs, NULL); | ||
631 | 383 | } else { | ||
632 | 384 | TEST_EQ_STR (dirs[0], expected[0]); | ||
633 | 385 | _test_dir_created (expected[0]); | ||
634 | 386 | TEST_EQ_STR (dirs[1], expected[1]); | ||
635 | 387 | TEST_EQ_STR (dirs[2], "/etc/xdg/xdg-subdir/upstart"); | ||
636 | 388 | TEST_EQ_STR (dirs[3], "/etc/xdg/upstart"); | ||
637 | 389 | TEST_EQ_STR (dirs[4], SYSTEM_USERCONFDIR); | ||
638 | 390 | TEST_EQ (dirs[5], NULL); | ||
639 | 391 | nih_free (dirs); | ||
640 | 392 | } | ||
641 | 393 | TEST_ALLOC_SAFE { | ||
642 | 394 | rmdir (expected[0]); | ||
643 | 395 | path = nih_sprintf (NULL, "%s/.config", dirname); | ||
644 | 396 | rmdir (path); | ||
645 | 397 | nih_free (path); | ||
646 | 398 | nih_free (expected); | ||
647 | 399 | } | ||
648 | 400 | } | ||
649 | 401 | TEST_EQ (rmdir (dirname), 0); | ||
650 | 402 | } | ||
651 | 403 | |||
652 | 404 | void | ||
653 | 405 | test_get_user_log_dir (void) | ||
654 | 406 | { | ||
655 | 407 | char dirname[PATH_MAX]; | ||
656 | 408 | char *expected; | ||
657 | 409 | char *path; | ||
658 | 410 | |||
659 | 411 | TEST_FUNCTION ("get_user_log_dir"); | ||
660 | 412 | TEST_FEATURE ("with HOME set"); | ||
661 | 413 | TEST_FILENAME (dirname); | ||
662 | 414 | TEST_EQ (setenv ("HOME", dirname, 1), 0); | ||
663 | 415 | TEST_EQ (mkdir (dirname, 0755), 0); | ||
664 | 416 | TEST_EQ (unsetenv ("XDG_CACHE_HOME"), 0); | ||
665 | 417 | |||
666 | 418 | expected = nih_sprintf (NULL, "%s/.cache/upstart", dirname); | ||
667 | 419 | |||
668 | 420 | TEST_ALLOC_FAIL { | ||
669 | 421 | path = get_user_log_dir (); | ||
670 | 422 | if (test_alloc_failed) { | ||
671 | 423 | TEST_EQ_P (path, NULL); | ||
672 | 424 | } else { | ||
673 | 425 | TEST_EQ_STR (path, expected); | ||
674 | 426 | _test_dir_created (expected); | ||
675 | 427 | nih_free (path); | ||
676 | 428 | } | ||
677 | 429 | } | ||
678 | 430 | rmdir (expected); | ||
679 | 431 | nih_free (expected); | ||
680 | 432 | path = nih_sprintf (NULL, "%s/.cache", dirname); | ||
681 | 433 | rmdir (path); | ||
682 | 434 | nih_free (path); | ||
683 | 435 | rmdir (dirname); | ||
684 | 294 | } | 436 | } |
685 | 295 | 437 | ||
686 | 296 | int | 438 | int |
687 | @@ -301,6 +443,8 @@ | |||
688 | 301 | test_get_config_home (); | 443 | test_get_config_home (); |
689 | 302 | test_get_config_dirs (); | 444 | test_get_config_dirs (); |
690 | 303 | test_get_user_upstart_dirs (); | 445 | test_get_user_upstart_dirs (); |
691 | 446 | test_get_cache_home (); | ||
692 | 447 | test_get_user_log_dir (); | ||
693 | 304 | 448 | ||
694 | 305 | return 0; | 449 | return 0; |
695 | 306 | } | 450 | } |
696 | 307 | 451 | ||
697 | === modified file 'init/xdg.c' | |||
698 | --- init/xdg.c 2012-12-18 16:31:55 +0000 | |||
699 | +++ init/xdg.c 2013-01-23 13:00:29 +0000 | |||
700 | @@ -24,6 +24,8 @@ | |||
701 | 24 | #endif /* HAVE_CONFIG_H */ | 24 | #endif /* HAVE_CONFIG_H */ |
702 | 25 | 25 | ||
703 | 26 | #include <stdlib.h> | 26 | #include <stdlib.h> |
704 | 27 | #include <sys/stat.h> | ||
705 | 28 | #include <sys/types.h> | ||
706 | 27 | 29 | ||
707 | 28 | #include <nih/alloc.h> | 30 | #include <nih/alloc.h> |
708 | 29 | #include <nih/logging.h> | 31 | #include <nih/logging.h> |
709 | @@ -33,22 +35,37 @@ | |||
710 | 33 | #include "xdg.h" | 35 | #include "xdg.h" |
711 | 34 | 36 | ||
712 | 35 | /** | 37 | /** |
713 | 38 | * user_mode: | ||
714 | 39 | * | ||
715 | 40 | * If TRUE, upstart runs in user session mode. | ||
716 | 41 | **/ | ||
717 | 42 | int user_mode = FALSE; | ||
718 | 43 | |||
719 | 44 | /** | ||
720 | 36 | * get_home_subdir: | 45 | * get_home_subdir: |
723 | 37 | * | 46 | * @suffix: sub-directory name |
724 | 38 | * Construct path to directory in user's HOME dir. | 47 | * @create: flag to create sub-directory |
725 | 48 | * | ||
726 | 49 | * Construct path to @suffix directory in user's HOME dir. If @create | ||
727 | 50 | * flag is TRUE, also attempt to create that directory. Errors upon | ||
728 | 51 | * directory creation are ignored. | ||
729 | 39 | * | 52 | * |
730 | 40 | * Returns: newly-allocated path, or NULL on error. | 53 | * Returns: newly-allocated path, or NULL on error. |
733 | 41 | */ | 54 | **/ |
732 | 42 | |||
734 | 43 | char * | 55 | char * |
736 | 44 | get_home_subdir (const char * suffix) | 56 | get_home_subdir (const char * suffix, int create) |
737 | 45 | { | 57 | { |
738 | 46 | char *dir; | 58 | char *dir; |
740 | 47 | nih_assert (suffix && suffix[0]); | 59 | nih_assert (suffix != NULL); |
741 | 60 | nih_assert (suffix[0]); | ||
742 | 48 | 61 | ||
743 | 49 | dir = getenv ("HOME"); | 62 | dir = getenv ("HOME"); |
745 | 50 | if (dir && dir[0]) { | 63 | if (dir && dir[0] == '/') { |
746 | 51 | dir = nih_sprintf (NULL, "%s/%s", dir, suffix); | 64 | dir = nih_sprintf (NULL, "%s/%s", dir, suffix); |
747 | 65 | if (! dir) | ||
748 | 66 | return NULL; | ||
749 | 67 | if (create) | ||
750 | 68 | mkdir (dir, 0700); | ||
751 | 52 | return dir; | 69 | return dir; |
752 | 53 | } | 70 | } |
753 | 54 | 71 | ||
754 | @@ -56,6 +73,39 @@ | |||
755 | 56 | } | 73 | } |
756 | 57 | 74 | ||
757 | 58 | /** | 75 | /** |
758 | 76 | * xdg_get_cache_home: | ||
759 | 77 | * | ||
760 | 78 | * Determine an XDG compliant XDG_CACHE_HOME | ||
761 | 79 | * | ||
762 | 80 | * Returns: newly-allocated path, or NULL on error. | ||
763 | 81 | **/ | ||
764 | 82 | char * | ||
765 | 83 | xdg_get_cache_home (void) | ||
766 | 84 | { | ||
767 | 85 | nih_local char **env = NULL; | ||
768 | 86 | char *dir; | ||
769 | 87 | |||
770 | 88 | dir = getenv ("XDG_CACHE_HOME"); | ||
771 | 89 | |||
772 | 90 | if (dir && dir[0] == '/') { | ||
773 | 91 | mkdir (dir, 0700); | ||
774 | 92 | dir = nih_strdup (NULL, dir); | ||
775 | 93 | return dir; | ||
776 | 94 | } | ||
777 | 95 | |||
778 | 96 | /* Per XDG spec, we should only create dirs, if we are | ||
779 | 97 | * attempting to write and the dir is not there. Here we | ||
780 | 98 | * anticipate logging to happen really soon now, hence we | ||
781 | 99 | * pre-create the cache dir. That does not protect us from | ||
782 | 100 | * this directory disappering while upstart is running. =/ | ||
783 | 101 | * hence this dir should be created each time we try to write | ||
784 | 102 | * log... */ | ||
785 | 103 | dir = get_home_subdir (".cache", TRUE); | ||
786 | 104 | |||
787 | 105 | return dir; | ||
788 | 106 | } | ||
789 | 107 | |||
790 | 108 | /** | ||
791 | 59 | * xdg_get_config_home: | 109 | * xdg_get_config_home: |
792 | 60 | * | 110 | * |
793 | 61 | * Determine an XDG compliant XDG_CONFIG_HOME | 111 | * Determine an XDG compliant XDG_CONFIG_HOME |
794 | @@ -70,12 +120,17 @@ | |||
795 | 70 | 120 | ||
796 | 71 | dir = getenv ("XDG_CONFIG_HOME"); | 121 | dir = getenv ("XDG_CONFIG_HOME"); |
797 | 72 | 122 | ||
799 | 73 | if (dir && dir[0]) { | 123 | if (dir && dir[0] == '/') { |
800 | 124 | mkdir (dir, 0700); | ||
801 | 74 | dir = nih_strdup (NULL, dir); | 125 | dir = nih_strdup (NULL, dir); |
802 | 75 | return dir; | 126 | return dir; |
803 | 76 | } | 127 | } |
804 | 77 | 128 | ||
806 | 78 | dir = get_home_subdir (".config"); | 129 | /* Per XDG spec, we should only create dirs, if we are |
807 | 130 | * attempting to write to the dir. But we only read config | ||
808 | 131 | * dir. But we rather create it, to place inotify watch on | ||
809 | 132 | * it. */ | ||
810 | 133 | dir = get_home_subdir (".config", TRUE); | ||
811 | 79 | 134 | ||
812 | 80 | return dir; | 135 | return dir; |
813 | 81 | } | 136 | } |
814 | @@ -134,6 +189,7 @@ | |||
815 | 134 | if (path && path[0]) { | 189 | if (path && path[0]) { |
816 | 135 | if (! nih_strcat_sprintf (&path, NULL, "/%s", INIT_XDG_SUBDIR)) | 190 | if (! nih_strcat_sprintf (&path, NULL, "/%s", INIT_XDG_SUBDIR)) |
817 | 136 | goto error; | 191 | goto error; |
818 | 192 | mkdir (path, 0700); | ||
819 | 137 | if (! nih_str_array_add (&all_dirs, NULL, NULL, path)) | 193 | if (! nih_str_array_add (&all_dirs, NULL, NULL, path)) |
820 | 138 | goto error; | 194 | goto error; |
821 | 139 | nih_free (path); | 195 | nih_free (path); |
822 | @@ -141,7 +197,7 @@ | |||
823 | 141 | } | 197 | } |
824 | 142 | 198 | ||
825 | 143 | /* Legacy User's: ~/.init */ | 199 | /* Legacy User's: ~/.init */ |
827 | 144 | path = get_home_subdir (USERCONFDIR); | 200 | path = get_home_subdir (USERCONFDIR, FALSE); |
828 | 145 | if (! path) | 201 | if (! path) |
829 | 146 | goto error; | 202 | goto error; |
830 | 147 | 203 | ||
831 | @@ -158,6 +214,8 @@ | |||
832 | 158 | goto error; | 214 | goto error; |
833 | 159 | 215 | ||
834 | 160 | for (char **p = dirs; p && *p; p++) { | 216 | for (char **p = dirs; p && *p; p++) { |
835 | 217 | if (*p[0] != '/') | ||
836 | 218 | continue; | ||
837 | 161 | if (! nih_strcat_sprintf (p, NULL, "/%s", INIT_XDG_SUBDIR)) | 219 | if (! nih_strcat_sprintf (p, NULL, "/%s", INIT_XDG_SUBDIR)) |
838 | 162 | goto error; | 220 | goto error; |
839 | 163 | if (! nih_str_array_add (&all_dirs, NULL, NULL, *p)) | 221 | if (! nih_str_array_add (&all_dirs, NULL, NULL, *p)) |
840 | @@ -185,3 +243,26 @@ | |||
841 | 185 | return NULL; | 243 | return NULL; |
842 | 186 | } | 244 | } |
843 | 187 | 245 | ||
844 | 246 | /** | ||
845 | 247 | * get_user_log_dir: | ||
846 | 248 | * | ||
847 | 249 | * Constructs an XDG compliant path to a cache directory in the user's | ||
848 | 250 | * home directory. It can be used to store logs. | ||
849 | 251 | * | ||
850 | 252 | * Returns: newly-allocated array of paths, or NULL or error. | ||
851 | 253 | **/ | ||
852 | 254 | char * | ||
853 | 255 | get_user_log_dir (void) | ||
854 | 256 | { | ||
855 | 257 | nih_local char *path = NULL; | ||
856 | 258 | char *dir = NULL; | ||
857 | 259 | path = xdg_get_cache_home (); | ||
858 | 260 | if (path && path[0] == '/') { | ||
859 | 261 | dir = nih_sprintf (NULL, "%s/%s", path, INIT_XDG_SUBDIR); | ||
860 | 262 | if (! dir) | ||
861 | 263 | return NULL; | ||
862 | 264 | mkdir (dir, 0700); | ||
863 | 265 | return dir; | ||
864 | 266 | } | ||
865 | 267 | return NULL; | ||
866 | 268 | } | ||
867 | 188 | 269 | ||
868 | === modified file 'init/xdg.h' | |||
869 | --- init/xdg.h 2012-12-18 13:58:23 +0000 | |||
870 | +++ init/xdg.h 2013-01-23 13:00:29 +0000 | |||
871 | @@ -25,18 +25,24 @@ | |||
872 | 25 | 25 | ||
873 | 26 | NIH_BEGIN_EXTERN | 26 | NIH_BEGIN_EXTERN |
874 | 27 | 27 | ||
876 | 28 | char * get_home_subdir (const char * suffix) | 28 | char * get_home_subdir (const char * suffix, int create) |
877 | 29 | __attribute__ ((malloc, warn_unused_result)); | 29 | __attribute__ ((malloc, warn_unused_result)); |
878 | 30 | 30 | ||
879 | 31 | char * xdg_get_config_home (void) | 31 | char * xdg_get_config_home (void) |
880 | 32 | __attribute__ ((malloc, warn_unused_result)); | 32 | __attribute__ ((malloc, warn_unused_result)); |
881 | 33 | 33 | ||
882 | 34 | char * xdg_get_cache_home (void) | ||
883 | 35 | __attribute__ ((malloc, warn_unused_result)); | ||
884 | 36 | |||
885 | 34 | char ** xdg_get_config_dirs (void) | 37 | char ** xdg_get_config_dirs (void) |
886 | 35 | __attribute__ ((malloc, warn_unused_result)); | 38 | __attribute__ ((malloc, warn_unused_result)); |
887 | 36 | 39 | ||
888 | 37 | char ** get_user_upstart_dirs (void) | 40 | char ** get_user_upstart_dirs (void) |
889 | 38 | __attribute__ ((malloc, warn_unused_result)); | 41 | __attribute__ ((malloc, warn_unused_result)); |
890 | 39 | 42 | ||
891 | 43 | char * get_user_log_dir (void) | ||
892 | 44 | __attribute__ ((malloc, warn_unused_result)); | ||
893 | 45 | |||
894 | 40 | NIH_END_EXTERN | 46 | NIH_END_EXTERN |
895 | 41 | 47 | ||
896 | 42 | #endif /* INIT_XDG_H */ | 48 | #endif /* INIT_XDG_H */ |
* init/main.c: cache/upstart/ logs/ as per the spec: this allows us to create a HOME/.cache/ upstart/ sessions/ also in the spec.
- handle_logdir(): Is there a reason we are not honouring the environment variable? If not, why don't we put
the 'dir = getenv (LOGDIR_ENV)' immediately before the 'if (user_mode)' since we can then say in the
user_mode block: 'log_dir = dir ? dir : get_user_log_dir ()' and thus honour the env var for user mode too.
* init/xdg.c:
- get_user_log_dir():
- Spacing around '='.
- 'path' is leaked.
- We should be logging to $HOME/.
$
* init/man/init.5: This needs updating for '--user' and location of
conf files and logfiles when running in this mode. Specifically the following sections need updating:
- 'User Jobs'
- 'Process environment' -> console -> log
- 'FILES': should reflect conf directories listed in the 'User
Session Mode' and specify location of User Session log files.
* init/man/init.8: Description of '--logdir' and '--confdir' also need updating.