From bf4c2f93e394f517755bb840886c533a8bdbc586 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Tue, 29 Nov 2016 23:15:52 +0100 Subject: [PATCH] launch_roster: Added restart, start/stop works on targets. * If the launch_daemon returns B_NAME_NOT_FOUND for a job, it'll retry the same name as target. --- src/bin/launch_roster.cpp | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/bin/launch_roster.cpp b/src/bin/launch_roster.cpp index 9a04bfc4dd..3d272c8726 100644 --- a/src/bin/launch_roster.cpp +++ b/src/bin/launch_roster.cpp @@ -92,6 +92,9 @@ start_job(const char* name) { BLaunchRoster roster; status_t status = roster.Start(name); + if (status == B_NAME_NOT_FOUND) + status = roster.Target(name); + if (status != B_OK) { fprintf(stderr, "%s: Starting job \"%s\" failed: %s\n", kProgramName, name, strerror(status)); @@ -105,6 +108,9 @@ stop_job(const char* name) { BLaunchRoster roster; status_t status = roster.Stop(name); + if (status == B_NAME_NOT_FOUND) + status = roster.StopTarget(name); + if (status != B_OK) { fprintf(stderr, "%s: Stopping job \"%s\" failed: %s\n", kProgramName, name, strerror(status)); @@ -113,6 +119,14 @@ stop_job(const char* name) } +static void +restart_job(const char* name) +{ + stop_job(name); + start_job(name); +} + + static void enable_job(const char* name, bool enable) { @@ -134,8 +148,9 @@ usage(int status) " list - Lists all jobs (the default command)\n" " list-targets - Lists all targets\n" "The following s have a argument:\n" - " start - Starts a job\n" - " stop - Stops a running job\n" + " start - Starts a job/target\n" + " stop - Stops a running job/target\n" + " restart - Restarts a running job/target\n" " info - Shows info for a job/target\n", kProgramName); @@ -187,6 +202,8 @@ main(int argc, char** argv) start_job(name); } else if (strcmp(command, "stop") == 0) { stop_job(name); + } else if (strcmp(command, "restart") == 0) { + restart_job(name); } else if (strcmp(command, "enable") == 0) { enable_job(name, true); } else if (strcmp(command, "disable") == 0) {