tizen: notify service readyness after successful config file parsing 57/115757/1
authorKarol Lewandowski <k.lewandowsk@samsung.com>
Fri, 10 Feb 2017 15:16:55 +0000 (16:16 +0100)
committerHyotaek Shim <hyotaek.shim@samsung.com>
Tue, 21 Feb 2017 08:05:35 +0000 (00:05 -0800)
commitbbacc6024e474f4e7dd1387618209cab9524a95c
tree2cb707e77d7682199882d65b4a73e63db4a1be47
parent9f35da3aea7e5a30be531b5a858a4fa94707fcee
tizen: notify service readyness after successful config file parsing

This commit works around systemd -> dbus -> (nss) -> systemd deadlock
occuring in Tizen.

Situation is depicted on diagram below:

  systemd               dbus               nss
    |                     .                  .
    |                     .                  .
    1> reads config       .                  .
    |                     .                  .
    2> reg. nofification  .                  .
    |  for dbus.service   .                  .
    |                     .                  .
    |                     .                  .
    3> exec. services     .                  .
    |    |                .                  .
    |    (start srv...)   .                  .
    |    |                .                  .
    |    4>------------(exec)                .
    |                     |                  .
    *-<---(notification)=<|                  .
    \                     |                  .
    .\> call dbus.serv    |                  .
    .   handler           |                  .
    .    |                4a> read config    .
    .    |> conn. to bus  |                  .
    .    |                4b> resolve user   .
    .    |> call dbus     .   and groups     .
    .       \             .   initgroups()   .
    .        ------------>.    |             .
    .         (blocking)  .    \---------->select module
    .                     .    (blocking)  based on conf.
    .                     .                  |
  (below not executed)    .                  |> security-manager
    .                     .                  |  module selected
    .                     .                  |
    .                     .                  |
  [sec-manager.socket]<---------------------<| call security-manager
    .                     .  (DEADLOCK)      . on unix socket
    .                     .                  .

Solid line (|) means active thread of execution, dot (.) means
code not executed (blocked).

The root cause of the problem is that systemd calls external
API in blocking manner, which, due to system configuration, requires
systemd to handle its request for successful completion.
(systemd should start security-manager service via sec-manager.socket
 activation).

The exact place this situation is triggered is in dbus' initialization.

This commits works around this problem by delaying dbus.service readyness
notification - effectively - resolving the problem.

Situation becomes:

 systemd               dbus               nss                          security-manager
    |                     .                  .                           .
    |                     .                  .                           .
    1> reads config       .                  .                           .
    |                     .                  .                           .
    2> reg. nofification  .                  .                           .
    |  for dbus.service   .                  .                           .
    |                     .                  .                           .
    |                     .                  .                           .
    3> exec. services     .                  .                           .
    |    |                .                  .                           .
    |    (start srv...)   .                  .                           .
    |    |                .                  .                           .
    |    4>------------(exec)                .                           .
    |                     |                  .                           .
    |                     |                  .                           .
    |                     |                  .                           .
    |                     |                  .                           .
    |                     |                  .                           .
    |                     4a> read config    .                           .
    |                     |                  .                           .
    |                     4b> resolve user   .                           .
    |                     .   and groups     .                           .
    |                     .   initgroups()   .                           .
    |                     .    |             .                           .
    |                     .    \---------->select module                 .
    |                     .    (blocking)  based on conf.                .
    |                     .                  |                           .
    |                     .                  |> security-manager         .
    |                     .                  |  module selected          .
    |                     .                  |                           .
    |                     .                  |                           .
  [sec-manager.socket]<---------------------<| call security-manager     .
    .  |                  .                  . on unix socket            .
    .  |                  .                  .
    .  |> exec service ----------------------------------------------->(exec)
    .  |                  .                  .                           |
    <--|                  .                  |<-------------------------<| handle call
    |                     .                  |                           |
    |                     |<-----------------|                           |
    |                     |                  .                           |
    |                     |                  .                           |
    .\> call dbus.serv    |>finish conf. file.                           |
    .   handler           | parsing          .                           |
    .    |                |                  .                           |
    *-<---(notification)-<|> explicitly      .                           |
    .\   |                |  notify startup  .                           |
    . \> call dbus.serv   |  finished        .                           |
    |    handler          |                  .                           |
    .    |                |                  .                           |
    .    |> conn. to bus  |                  .                           |
    .    |                |                  .                           |
    .    |> call dbus     |                  .                           |
    .       \             |                  .                           |
    .        ------------>* dispatch loop    .                           |
    .         (blocking)  |                  .                           |
    .                     |                  .                           |
    |<--------------------< handle call      .                           |
    |                     |                  .                           |

Change-Id: Ifeaf299fc8653b583cd06ca9fd4f9f8045a2bde0
bus/dbus.service.in
bus/main.c