-
-
Notifications
You must be signed in to change notification settings - Fork 69
dinitctl: show the service path in the "status" command output #550
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1627,10 +1627,18 @@ static int service_status(dinit_conn_t &dinit_conn, const char *service_name, ct | |
| return 1; | ||
| } | ||
|
|
||
| // Issue STATUS request | ||
| { | ||
| char status_req_id = proto_version < 5 ? (char)cp_cmd::SERVICESTATUS : (char)cp_cmd::SERVICESTATUS5; | ||
| unsigned status_buf_size = proto_version < 5 ? STATUS_BUFFER_SIZE : STATUS_BUFFER5_SIZE; | ||
| // Determine the service description path | ||
| std::string sdf_path = get_service_description_dir(socknum, rbuffer, handle); | ||
| sdf_path.append(1, '/'); | ||
| sdf_path.append(service_name, strip_service_arg(service_name)); | ||
|
|
||
| // Issue STATUS request | ||
| char status_req_id = proto_version >= 6 ? (char)cp_cmd::SERVICESTATUS6 | ||
| : (proto_version == 5 ? (char)cp_cmd::SERVICESTATUS5 | ||
| : (char)cp_cmd::SERVICESTATUS); | ||
| unsigned status_buf_size = proto_version >= 6 ? STATUS_BUFFER6_SIZE | ||
| : (proto_version == 5 ? STATUS_BUFFER5_SIZE : STATUS_BUFFER_SIZE); | ||
|
|
||
| auto m = membuf() | ||
| .append(status_req_id) | ||
|
|
@@ -1647,6 +1655,23 @@ static int service_status(dinit_conn_t &dinit_conn, const char *service_name, ct | |
| fill_buffer_to(rbuffer, socknum, status_buf_size + 1 /* reserved */); | ||
| rbuffer.consume(1); | ||
|
|
||
| // Check the service description file hasn't changed. We already located said file, so stat | ||
| // it to find the modification time, then compare that with the modification time according | ||
| // to dinit. | ||
|
Comment on lines
+1658
to
+1660
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: You've basically copied the comment from start_stop_service, but this is a different context. In that context a few things need to be done to do the modification check: locate the service file (get the service directory and append the service name), issue a SERVICESTATUS6 request, and then check the file time. That's why the comment is more than just a single line. In this context, the code block is nice and short and doesn't need the same level of explanation. You don't have to change this, but in future please don't blindly take comments from elsewhere. It's much better if you try to come up with a reasonable comment yourself, I think practicing that would be worthwhile.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't change this and I will try to come up with a reasonable comment myself next time. |
||
| bool sdf_has_changed = false; | ||
| if (proto_version >= 6) { | ||
| struct stat sdf_statbuf; | ||
| if (stat(sdf_path.c_str(), &sdf_statbuf) == 0) { | ||
| struct timespec dinit_sdf_time; | ||
| rbuffer.extract(&dinit_sdf_time, STATUS_BUFFER5_SIZE, sizeof(dinit_sdf_time)); | ||
|
|
||
| auto &file_time = get_timespec(sdf_statbuf); | ||
|
|
||
| sdf_has_changed = (dinit_sdf_time.tv_sec != file_time.tv_sec | ||
| || dinit_sdf_time.tv_nsec != file_time.tv_nsec); | ||
| } | ||
| } | ||
|
|
||
| service_state_t current = static_cast<service_state_t>(rbuffer[0]); | ||
| service_state_t target = static_cast<service_state_t>(rbuffer[1]); | ||
|
|
||
|
|
@@ -1720,7 +1745,9 @@ static int service_status(dinit_conn_t &dinit_conn, const char *service_name, ct | |
| } | ||
|
|
||
| cout << "Service: " << service_name << "\n" | ||
| " State: "; | ||
| " File: " << sdf_path; | ||
| if (sdf_has_changed) cout << " (modified since loaded)"; | ||
| cout << "\n State: "; | ||
|
|
||
| switch (current) { | ||
| case service_state_t::STOPPED: | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.