Merge lp://staging/~stgraber/upstart/upstart-session-socket into lp://staging/upstart

Proposed by Stéphane Graber
Status: Merged
Merged at revision: 1427
Proposed branch: lp://staging/~stgraber/upstart/upstart-session-socket
Merge into: lp://staging/upstart
Diff against target: 417 lines (+189/-33)
8 files modified
init/control.c (+16/-1)
init/job_process.c (+6/-0)
init/main.c (+5/-25)
init/man/init.5 (+4/-0)
init/state.c (+0/-1)
util/initctl.c (+34/-5)
util/man/initctl.8 (+7/-0)
util/tests/test_initctl.c (+117/-1)
To merge this branch: bzr merge lp://staging/~stgraber/upstart/upstart-session-socket
Reviewer Review Type Date Requested Status
James Hunt Approve
Review via email: mp+143344@code.staging.launchpad.net

Description of the change

This branch implements the UPSTART_SESSION variable from the user session
specification.

Upstart will now always listen to a private DBus socket.
The system instance remains on its usual /com/ubuntu/upstart address.
The user instances use /com/ubuntu/upstart-session/%uid/%pid

The path is then exported as UPSTART_SESSION in the job environments, so
that jobs can call initctl and talk to upstart without requiring DBus.

A new --user flag is also added to initctl, when passed, it'll make initctl
use the socket defined in UPSTART_SESSION if present or otherwise will
fallback to the DBus session bus.

To post a comment you must log in.
Revision history for this message
James Hunt (jamesodhunt) wrote :

* conf/rc-sysinit.conf: I've got some reservations about changing the
  default jobs we provide. That said, those building systems should
  really be creating their own jobs. I think I'd be happy if we added a
  note to the README stating that the files in 'conf/' are examples only
  and *will* need to be changed by those creating systems using Upstart.
* conf/rc.conf: As above.
* init/control.c: control_init(): Spaces before '(' (4 occurences).
* init/job_process.c:
* init/main.c:
* util/initctl.c:
  - user_mode: Comment should be something like 'if TRUE, talk to
    Upstart over a private D-Bus socket'.
  - upstart_open():
    - Space before '(' of getenv call (2 occurences).
    - I'd be tempted to save the value of the first call to getenv to
      avoid the 2nd call.
    - 'else' should be on same line as closing brace of 'if'.
    - Shouldn't the logic be inverted here to conform to?:
      https://wiki.ubuntu.com/FoundationsTeam/Specs/RaringUpstartUserSessions#Effect_of_UPSTART_SESSION
      So, by default, if UPSTART_SESSION is set, use the private D-Bus
      socket, unless the user specifies '--system'.
  - options: I'd be tempted to change 'start' to 'run' as the former
    implies a long-running operation.
* init/man/init.5: 'Job environment' section needs to be updated for
  'UPSTART_SESSION'.
* util/man/initctl.8: Need to document '--user'.
* util/tests/test_initctl.c: We could do with a test for '--user'. This
  will necessitate something like:
  - Changing _START_UPSTART() into a function and allowing atleast 1 extra
    argument to be specified or specifying the type (meaning '--user' or
    '--session') would work, along with a test
  - Changing WAIT_FOR_UPSTART() into a function to allow the session
    bus or private socket to be connected to.
  - Then, a test to simply start upstart, wait for it, create a conf
    file, check that initctl list shows that job, then stop upstart
    (see test_list()).

1425. By Stéphane Graber

Also listen for private connections when running as a user, but on a different address.

1426. By Stéphane Graber

Export UPSTART_SESSION in the jobs environment

1427. By Stéphane Graber

Add user mode flag to initctl

1428. By Stéphane Graber

Set the right bus address for user mode

Revision history for this message
Stéphane Graber (stgraber) wrote :

> * conf/rc-sysinit.conf: I've got some reservations about changing the
> default jobs we provide. That said, those building systems should
> really be creating their own jobs. I think I'd be happy if we added a
> note to the README stating that the files in 'conf/' are examples only
> and *will* need to be changed by those creating systems using Upstart.
> * conf/rc.conf: As above.

Those two ended up in this branch by mistake, that should be fixed now.

> * init/control.c: control_init(): Spaces before '(' (4 occurences).
> * init/job_process.c:
> * init/main.c:
> * util/initctl.c:
> - user_mode: Comment should be something like 'if TRUE, talk to
> Upstart over a private D-Bus socket'.
> - upstart_open():
> - Space before '(' of getenv call (2 occurences).
> - I'd be tempted to save the value of the first call to getenv to
> avoid the 2nd call.
> - 'else' should be on same line as closing brace of 'if'.
> - Shouldn't the logic be inverted here to conform to?:
> https://wiki.ubuntu.com/FoundationsTeam/Specs/RaringUpstartUserSessions#
> Effect_of_UPSTART_SESSION
> So, by default, if UPSTART_SESSION is set, use the private D-Bus
> socket, unless the user specifies '--system'.
> - options: I'd be tempted to change 'start' to 'run' as the former
> implies a long-running operation.
> * init/man/init.5: 'Job environment' section needs to be updated for
> 'UPSTART_SESSION'.
> * util/man/initctl.8: Need to document '--user'.
> * util/tests/test_initctl.c: We could do with a test for '--user'. This
> will necessitate something like:
> - Changing _START_UPSTART() into a function and allowing atleast 1 extra
> argument to be specified or specifying the type (meaning '--user' or
> '--session') would work, along with a test
> - Changing WAIT_FOR_UPSTART() into a function to allow the session
> bus or private socket to be connected to.
> - Then, a test to simply start upstart, wait for it, create a conf
> file, check that initctl list shows that job, then stop upstart
> (see test_list()).

1429. By Stéphane Graber

Add missing spaces before '('.

1430. By Stéphane Graber

Add UPSTART_SESSION to manpage.

1431. By Stéphane Graber

Add --user to the manpage

1432. By Stéphane Graber

Update comment for user_mode.

1433. By Stéphane Graber

Avoid duplicate call to getenv

1434. By Stéphane Graber

Add missing spaces before '('.

1435. By Stéphane Graber

Syntax fix and change wording of the help message a bit.

Revision history for this message
Stéphane Graber (stgraber) wrote :

> > * conf/rc-sysinit.conf: I've got some reservations about changing the
> > default jobs we provide. That said, those building systems should
> > really be creating their own jobs. I think I'd be happy if we added a
> > note to the README stating that the files in 'conf/' are examples only
> > and *will* need to be changed by those creating systems using Upstart.
> > * conf/rc.conf: As above.
>
> Those two ended up in this branch by mistake, that should be fixed now.
>
> > * init/control.c: control_init(): Spaces before '(' (4 occurences).

Fixed.

> > * init/job_process.c:
> > * init/main.c:
> > * util/initctl.c:
> > - user_mode: Comment should be something like 'if TRUE, talk to
> > Upstart over a private D-Bus socket'.

Changed.

> > - upstart_open():
> > - Space before '(' of getenv call (2 occurences).

Just one after the fix below, but fixed :)

> > - I'd be tempted to save the value of the first call to getenv to
> > avoid the 2nd call.

Fixed.

> > - 'else' should be on same line as closing brace of 'if'.

Fixed. Working on 3 different C projects each with different coding guideline is a real source of headache ;)

> > - Shouldn't the logic be inverted here to conform to?:
> >
> https://wiki.ubuntu.com/FoundationsTeam/Specs/RaringUpstartUserSessions#
> > Effect_of_UPSTART_SESSION
> > So, by default, if UPSTART_SESSION is set, use the private D-Bus
> > socket, unless the user specifies '--system'.

Yeah, that part is still a bit blurry in my head, I'll try to catch you tomorrow to discuss this some more.

Does that table mean we won't ever look for upstart on the session bus when passed --user?

Also, I'm at a bit of a loss as to how "initctl --user" as root without UPSTART_SESSION isn't failing according to that table?

> > - options: I'd be tempted to change 'start' to 'run' as the former
> > implies a long-running operation.

Done, was a copy/paste from main.c.

> > * init/man/init.5: 'Job environment' section needs to be updated for
> > 'UPSTART_SESSION'.

Done

> > * util/man/initctl.8: Need to document '--user'.

Done

> > * util/tests/test_initctl.c: We could do with a test for '--user'. This
> > will necessitate something like:
> > - Changing _START_UPSTART() into a function and allowing atleast 1 extra
> > argument to be specified or specifying the type (meaning '--user' or
> > '--session') would work, along with a test
> > - Changing WAIT_FOR_UPSTART() into a function to allow the session
> > bus or private socket to be connected to.
> > - Then, a test to simply start upstart, wait for it, create a conf
> > file, check that initctl list shows that job, then stop upstart
> > (see test_list()).

Will look into this once we agree on what initctl should do :)

1436. By Stéphane Graber

Update code to match spec.

1437. By Stéphane Graber

Update upstart code to behave the same way as initctl. That's, don't bind the session bus unless passed --session.

Revision history for this message
Stéphane Graber (stgraber) wrote :

Alright, I think the current version of the branch matches the spec.

I also included a change to upstart itself, so that --user doesn't mean that it'll listen to the session bus, if you want to force it to listen to the session bus and do user session stuff, --session --user is what you want.

Revision history for this message
James Hunt (jamesodhunt) wrote :

Hi Stéphane,

* init/control.c:
  - control_init(): Second call to nih_strcat_sprintf() should be
    nih_strcat() or nih_strdup().
* util/tests/test_initctl.c: Still need a test for 'init --user'.

review: Needs Fixing
1438. By Stéphane Graber

Use nih_strdup instead of nih_strcat_sprintf

1439. By Stéphane Graber

Revert main.c hunk that was making upstart always listen for private connections. It's no longer required now that user_mode is separate from use_session_bus.

1440. By Stéphane Graber

Add check for user-mode failure on missing env variable.

1441. By Stéphane Graber

Add test for UPSTART_SESSION

1442. By Stéphane Graber

Update manpage

Revision history for this message
Stéphane Graber (stgraber) wrote :

I replaced the nih_strcat_sprintf by a nih_strdup.

I also dropped some changes to main.c that weren't relevant after the clear split between use_session_bus and user_session. That makes "/sbin/init --user --session" now possible.

And added two tests:
 - Check that initctl connects to the user bus when user_mode is set to TRUE and UPSTART_SESSION is set.
 - Check that initctl fails when user_mode is set to TRUE and UPSTART_SESSION isn't set.

I also updated the manpage to reflect the change in behaviour (now matching the spec).

1443. By Stéphane Graber

Code style

Revision history for this message
James Hunt (jamesodhunt) wrote :

Thanks! LGTM - merged.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
The diff is not available at this time. You can reload the page or download it.

Subscribers

People subscribed via source and target branches