tizen: notify service readyness after successful config file parsing 42/114242/4 accepted/tizen_3.0_common accepted/tizen_3.0_ivi accepted/tizen_3.0_mobile accepted/tizen_3.0_tv accepted/tizen_3.0_wearable accepted/tizen/3.0/common/20170602.150804 accepted/tizen/3.0/ivi/20170601.235806 accepted/tizen/3.0/mobile/20170601.235758 accepted/tizen/3.0/tv/20170601.235801 accepted/tizen/3.0/wearable/20170601.235803 submit/tizen_3.0/20170601.051643
authorKarol Lewandowski <k.lewandowsk@samsung.com>
Fri, 10 Feb 2017 15:16:55 +0000 (16:16 +0100)
committerHyotaek Shim <hyotaek.shim@samsung.com>
Thu, 1 Jun 2017 03:05:13 +0000 (03:05 +0000)
commite31810e8da630bcc60d13dd315dcc57ae3ce1017
tree3100929686d98a0f86bb54b4aabce95103ee85ad
parente6e9bfea00ef375a8d31ff2307ae12d06eeda09a
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