Skip to content

Commit

Permalink
shutdown_media_server: Rework shutdown process
Browse files Browse the repository at this point in the history
* Fixes issues with launch_daemon restart.
* Rely on what the actual response from the server is
instead to naively try to kill it.
* Remove snoozing and make the restart process very fast.
* Any app should rely on notifications anyway.
* Due to some reason a few months ago the media_addon_server
locked up very often making the notification service unreliable,
today this issue looks like solved. This made possible the recent
improvements.
  • Loading branch information
Numerio committed Apr 5, 2016
1 parent 8c7bdb7 commit 99741be
Showing 1 changed file with 20 additions and 29 deletions.
49 changes: 20 additions & 29 deletions src/kits/media/MediaDefs.cpp
Expand Up @@ -1268,13 +1268,13 @@ progress_shutdown(int stage,
string = B_TRANSLATE("Stopping media server" B_UTF8_ELLIPSIS);
break;
case 20:
string = B_TRANSLATE("Telling media_addon_server to quit.");
string = B_TRANSLATE("Waiting for media_server to quit.");
break;
case 40:
string = B_TRANSLATE("Waiting for media_server to quit.");
string = B_TRANSLATE("Telling media_addon_server to quit.");
break;
case 50:
string = B_TRANSLATE("Waiting for media_server to quit.");
string = B_TRANSLATE("Waiting for media_addon_server to quit.");
break;
case 70:
string = B_TRANSLATE("Cleaning up.");
Expand All @@ -1299,6 +1299,7 @@ shutdown_media_server(bigtime_t timeout,
BMessage msg(B_QUIT_REQUESTED);
BMessage reply;
status_t err;
bool shutdown = false;

if ((err = msg.AddBool("be:_user_request", true)) != B_OK)
return err;
Expand All @@ -1308,51 +1309,41 @@ shutdown_media_server(bigtime_t timeout,
progress_shutdown(10, progress, cookie);

err = messenger.SendMessage(&msg, &reply, 2000000, 2000000);
if (err != B_OK)
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));
} else if (err != B_OK)
return err;

progress_shutdown(20, progress, cookie);

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

shutdown = false;
if (be_roster->IsRunning(B_MEDIA_ADDON_SERVER_SIGNATURE)) {
BMessenger messenger(B_MEDIA_ADDON_SERVER_SIGNATURE);
progress_shutdown(20, progress, cookie);
progress_shutdown(40, progress, cookie);

err = messenger.SendMessage(&msg, &reply, 2000000, 2000000);
if (err != B_OK)
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;
}

if (be_roster->IsRunning(B_MEDIA_SERVER_SIGNATURE)) {
progress_shutdown(40, progress, cookie);
snooze(200000);
}

if (be_roster->IsRunning(B_MEDIA_ADDON_SERVER_SIGNATURE)) {
progress_shutdown(50, progress, cookie);
snooze(200000);
}

progress_shutdown(70, progress, cookie);
snooze(1000000);

if (be_roster->IsRunning(B_MEDIA_SERVER_SIGNATURE)) {
kill_team(be_roster->TeamFor(B_MEDIA_SERVER_SIGNATURE));
}

if (be_roster->IsRunning(B_MEDIA_ADDON_SERVER_SIGNATURE)) {
kill_team(be_roster->TeamFor(B_MEDIA_ADDON_SERVER_SIGNATURE));
}

progress_shutdown(100, progress, cookie);
snooze(1000000);

return B_OK;
}

Expand Down

0 comments on commit 99741be

Please sign in to comment.