Skip to content
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

Add a newline after hostname entry #60

Merged
merged 2 commits into from
Jan 27, 2023
Merged
Show file tree
Hide file tree
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
14 changes: 7 additions & 7 deletions src/ucd-data-fetch.c
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,13 @@ static int write_lines(int out, FILE *f, size_t cl, const char *prefix)
if (write(out, buf, len) < (ssize_t)len) {
return 1;
}

/* Make sure this line ends with a newline when we write it */
if (buf[len-1] != '\n') {
if (write(out, "\n", 1) < (ssize_t)1) {
return 1;
}
}
}
}

Expand Down Expand Up @@ -384,13 +391,6 @@ int main(int argc, char *argv[]) {
FAIL("write_lines()");
}

/* Write an extra linefeed in case this didn't end with one */
if (write(out, "\n", 1) < (ssize_t) 1) {
close(out);
fclose(f);
unlink(outpath);
FAIL("write()");
}
close(sockfd);

/* reopen socket */
Expand Down
1 change: 0 additions & 1 deletion tests/fetch_data/expected
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ ssh_authorized_keys:
- SSH_TEST_KEY_STRING_1
- SSH_TEST_KEY_STRING_2
- SSH_TEST_KEY_STRING_3

hostname: myhostname
#cloud-config

Expand Down
2 changes: 1 addition & 1 deletion tests/fetch_data/hostname
Original file line number Diff line number Diff line change
@@ -1 +1 @@
myhostname
myhostname
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason to not have both the newline including file and not (I might not be understanding how tests work).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test spawns a web server that serves the literal contents of the files under tests/fetch_data. It would be good to restructure the test to support multiple scenarios like that, but not presently supported.