Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 31 additions & 4 deletions src/dinitctl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1627,10 +1627,18 @@ static int service_status(dinit_conn_t &dinit_conn, const char *service_name, ct
return 1;
}

// Issue STATUS request
Comment thread
davmac314 marked this conversation as resolved.
{
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)
Expand All @@ -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

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The 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.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The 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]);

Expand Down Expand Up @@ -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:
Expand Down
Loading