Skip to content

Commit

Permalink
shutdown_media_server: Rely on actual instance
Browse files Browse the repository at this point in the history
* Makes the shutdown process to rely on the instance that was
running at the time the function is called. While it's unlikely
anyone will see any change from that, this way we will not conflict
in any case with the launch_daemon.
* The reply could have been confused in a remote situation, make
every request to use an it's own object.
* In launch_media_server there was a wrong variable redefinition
too.
  • Loading branch information
Numerio committed Apr 22, 2016
1 parent e4704eb commit 2080295
Showing 1 changed file with 29 additions and 21 deletions.
50 changes: 29 additions & 21 deletions src/kits/media/MediaDefs.cpp
Expand Up @@ -1298,7 +1298,6 @@ shutdown_media_server(bigtime_t timeout,
void* cookie)
{
BMessage msg(B_QUIT_REQUESTED);
BMessage reply;
status_t err = B_MEDIA_SYSTEM_FAILURE;
bool shutdown = false;

Expand All @@ -1314,15 +1313,19 @@ shutdown_media_server(bigtime_t timeout,
if ((err = msg.AddBool("be:_user_request", true)) != B_OK)
return err;

if (be_roster->IsRunning(B_MEDIA_SERVER_SIGNATURE)) {
BMessenger messenger(B_MEDIA_SERVER_SIGNATURE);
team_id mediaServer = be_roster->TeamFor(B_MEDIA_SERVER_SIGNATURE);
team_id addOnServer = be_roster->TeamFor(B_MEDIA_ADDON_SERVER_SIGNATURE);

if (mediaServer != B_ERROR) {
BMessage reply;
BMessenger messenger(B_MEDIA_SERVER_SIGNATURE, mediaServer);
progress_shutdown(10, progress, cookie);

err = messenger.SendMessage(&msg, &reply, 2000000, 2000000);
reply.FindBool("_shutdown", &shutdown);
if (err == B_TIMED_OUT || shutdown == false) {
if (be_roster->IsRunning(B_MEDIA_SERVER_SIGNATURE))
kill_team(be_roster->TeamFor(B_MEDIA_SERVER_SIGNATURE));
if (messenger.IsValid())
kill_team(mediaServer);
} else if (err != B_OK)
return err;

Expand All @@ -1333,24 +1336,29 @@ shutdown_media_server(bigtime_t timeout,
return rv;
}

if (be_roster->IsRunning(B_MEDIA_ADDON_SERVER_SIGNATURE)) {
if (addOnServer != B_ERROR) {
shutdown = false;
BMessenger messenger(B_MEDIA_ADDON_SERVER_SIGNATURE);
BMessage reply;
BMessenger messenger(B_MEDIA_ADDON_SERVER_SIGNATURE, addOnServer);
progress_shutdown(40, progress, cookie);

err = messenger.SendMessage(&msg, &reply, 2000000, 2000000);
reply.FindBool("_shutdown", &shutdown);
if (err == B_TIMED_OUT || shutdown == false) {
if (be_roster->IsRunning(B_MEDIA_ADDON_SERVER_SIGNATURE))
kill_team(be_roster->TeamFor(B_MEDIA_ADDON_SERVER_SIGNATURE));
} else if (err != B_OK)
return err;

progress_shutdown(50, progress, cookie);

int32 rv;
if (reply.FindInt32("error", &rv) == B_OK && rv != B_OK)
return rv;
// The media_server usually shutdown the media_addon_server,
// if not let's do something.
if (messenger.IsValid()) {
err = messenger.SendMessage(&msg, &reply, 2000000, 2000000);
reply.FindBool("_shutdown", &shutdown);
if (err == B_TIMED_OUT || shutdown == false) {
if (messenger.IsValid())
kill_team(addOnServer);
} else if (err != B_OK)
return err;

progress_shutdown(50, progress, cookie);

int32 rv;
if (reply.FindInt32("error", &rv) == B_OK && rv != B_OK)
return rv;
}
}

progress_shutdown(100, progress, cookie);
Expand Down Expand Up @@ -1430,7 +1438,7 @@ launch_media_server(bigtime_t timeout,
// At this point, it might be that the launch_daemon isn't
// restarting us, then we'll attempt at launching the server
// ourselves.
status_t err = be_roster->Launch(B_MEDIA_SERVER_SIGNATURE);
err = be_roster->Launch(B_MEDIA_SERVER_SIGNATURE);
if (err != B_OK)
return err;

Expand Down

0 comments on commit 2080295

Please sign in to comment.