-
Notifications
You must be signed in to change notification settings - Fork 1.1k
conmon: implement logging #162
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
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
70883db
lint: bump cyclo
cyphar 8f280dc
oci: ignore silly lint errors
cyphar 00589b3
test: fix runtimeversion test
cyphar 266c757
runc: update to 31980a53ae7887b2c8f8715d13c3eb486c27b6cf
cyphar c290c0d
conmon: implement logging to logPath
cyphar 14a37fb
conmon: use pipes rather than socketpairs for !terminal
cyphar 1dc4c87
conmon: add timestamps to logs
mrunalp c31f2cf
test: unset log_* in configurations
cyphar 65527da
test: add logging tests
cyphar 7679a84
server: issues.k8s.io/44043 workaround
cyphar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,6 +7,7 @@ | |
| /ocic | ||
| /ocid | ||
| /ocid.conf | ||
| *.o | ||
| *.orig | ||
| /pause/pause | ||
| /pause/pause.o | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,149 @@ | ||
| /* | ||
| * Copyright 2016 SUSE LLC | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| /* NOTE: This code comes directly from runc/libcontainer/utils/cmsg.c. */ | ||
|
|
||
| #include <errno.h> | ||
| #include <stdio.h> | ||
| #include <stdlib.h> | ||
| #include <string.h> | ||
| #include <sys/socket.h> | ||
| #include <sys/types.h> | ||
| #include <unistd.h> | ||
|
|
||
| #include "cmsg.h" | ||
|
|
||
| #define error(fmt, ...) \ | ||
| ({ \ | ||
| fprintf(stderr, "nsenter: " fmt ": %m\n", ##__VA_ARGS__); \ | ||
| errno = ECOMM; \ | ||
| goto err; /* return value */ \ | ||
| }) | ||
|
|
||
| /* | ||
| * Sends a file descriptor along the sockfd provided. Returns the return | ||
| * value of sendmsg(2). Any synchronisation and preparation of state | ||
| * should be done external to this (we expect the other side to be in | ||
| * recvfd() in the code). | ||
| */ | ||
| ssize_t sendfd(int sockfd, struct file_t file) | ||
| { | ||
| struct msghdr msg = {0}; | ||
| struct iovec iov[1] = {0}; | ||
| struct cmsghdr *cmsg; | ||
| int *fdptr; | ||
|
|
||
| union { | ||
| char buf[CMSG_SPACE(sizeof(file.fd))]; | ||
| struct cmsghdr align; | ||
| } u; | ||
|
|
||
| /* | ||
| * We need to send some other data along with the ancillary data, | ||
| * otherwise the other side won't recieve any data. This is very | ||
| * well-hidden in the documentation (and only applies to | ||
| * SOCK_STREAM). See the bottom part of unix(7). | ||
| */ | ||
| iov[0].iov_base = file.name; | ||
| iov[0].iov_len = strlen(file.name) + 1; | ||
|
|
||
| msg.msg_name = NULL; | ||
| msg.msg_namelen = 0; | ||
| msg.msg_iov = iov; | ||
| msg.msg_iovlen = 1; | ||
| msg.msg_control = u.buf; | ||
| msg.msg_controllen = sizeof(u.buf); | ||
|
|
||
| cmsg = CMSG_FIRSTHDR(&msg); | ||
| cmsg->cmsg_level = SOL_SOCKET; | ||
| cmsg->cmsg_type = SCM_RIGHTS; | ||
| cmsg->cmsg_len = CMSG_LEN(sizeof(int)); | ||
|
|
||
| fdptr = (int *) CMSG_DATA(cmsg); | ||
| memcpy(fdptr, &file.fd, sizeof(int)); | ||
|
|
||
| return sendmsg(sockfd, &msg, 0); | ||
| } | ||
|
|
||
| /* | ||
| * Receives a file descriptor from the sockfd provided. Returns the file | ||
| * descriptor as sent from sendfd(). It will return the file descriptor | ||
| * or die (literally) trying. Any synchronisation and preparation of | ||
| * state should be done external to this (we expect the other side to be | ||
| * in sendfd() in the code). | ||
| */ | ||
| struct file_t recvfd(int sockfd) | ||
| { | ||
| struct msghdr msg = {0}; | ||
| struct iovec iov[1] = {0}; | ||
| struct cmsghdr *cmsg; | ||
| struct file_t file = {0}; | ||
| int *fdptr; | ||
| int olderrno; | ||
|
|
||
| union { | ||
| char buf[CMSG_SPACE(sizeof(file.fd))]; | ||
| struct cmsghdr align; | ||
| } u; | ||
|
|
||
| /* Allocate a buffer. */ | ||
| /* TODO: Make this dynamic with MSG_PEEK. */ | ||
| file.name = malloc(TAG_BUFFER); | ||
| if (!file.name) | ||
| error("recvfd: failed to allocate file.tag buffer\n"); | ||
|
|
||
| /* | ||
| * We need to "recieve" the non-ancillary data even though we don't | ||
| * plan to use it at all. Otherwise, things won't work as expected. | ||
| * See unix(7) and other well-hidden documentation. | ||
| */ | ||
| iov[0].iov_base = file.name; | ||
| iov[0].iov_len = TAG_BUFFER; | ||
|
|
||
| msg.msg_name = NULL; | ||
| msg.msg_namelen = 0; | ||
| msg.msg_iov = iov; | ||
| msg.msg_iovlen = 1; | ||
| msg.msg_control = u.buf; | ||
| msg.msg_controllen = sizeof(u.buf); | ||
|
|
||
| ssize_t ret = recvmsg(sockfd, &msg, 0); | ||
| if (ret < 0) | ||
| goto err; | ||
|
|
||
| cmsg = CMSG_FIRSTHDR(&msg); | ||
| if (!cmsg) | ||
| error("recvfd: got NULL from CMSG_FIRSTHDR"); | ||
| if (cmsg->cmsg_level != SOL_SOCKET) | ||
| error("recvfd: expected SOL_SOCKET in cmsg: %d", cmsg->cmsg_level); | ||
| if (cmsg->cmsg_type != SCM_RIGHTS) | ||
| error("recvfd: expected SCM_RIGHTS in cmsg: %d", cmsg->cmsg_type); | ||
| if (cmsg->cmsg_len != CMSG_LEN(sizeof(int))) | ||
| error("recvfd: expected correct CMSG_LEN in cmsg: %lu", cmsg->cmsg_len); | ||
|
|
||
| fdptr = (int *) CMSG_DATA(cmsg); | ||
| if (!fdptr || *fdptr < 0) | ||
| error("recvfd: recieved invalid pointer"); | ||
|
|
||
| file.fd = *fdptr; | ||
| return file; | ||
|
|
||
| err: | ||
| olderrno = errno; | ||
| free(file.name); | ||
| errno = olderrno; | ||
| return (struct file_t){0}; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| /* | ||
| * Copyright 2016 SUSE LLC | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| /* NOTE: This code comes directly from runc/libcontainer/utils/cmsg.h. */ | ||
|
|
||
| #pragma once | ||
|
|
||
| #if !defined(CMSG_H) | ||
| #define CMSG_H | ||
|
|
||
| #include <sys/types.h> | ||
|
|
||
| /* TODO: Implement this properly with MSG_PEEK. */ | ||
| #define TAG_BUFFER 4096 | ||
|
|
||
| /* This mirrors Go's (*os.File). */ | ||
| struct file_t { | ||
| char *name; | ||
| int fd; | ||
| }; | ||
|
|
||
| struct file_t recvfd(int sockfd); | ||
| ssize_t sendfd(int sockfd, struct file_t file); | ||
|
|
||
| #endif /* !defined(CMSG_H) */ |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we keep this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code comes from runC. If you want I can drop it (though personally I prefer having license headers in all source files).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mrunalp wdyt?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This may need to be referred to legal. If the code was written during work hours or on equipment provided by SUSE LLC, they will generally own copyright (and this is usually stipulated as part of employment agreements). It's not permissible to change the statement without approval from the copyright owner (being the legal representative acting on behalf of SUSE LLC). This is especially true if the code was extracted from runC and already carries this sort of statement. This is generally why many projects require a Contributor License Agreement or at least a Developer Certificate of Origin.
@cyphar I don't have any personal opinion on individual copyright statements in files, but I will say that some vendors (Debian in particular) require a comprehensive machine-readable copyright file, which includes the names of all rights holders, and having additional copyright statements means more work for packagers. Just something to consider.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jawnsy In general, it's just the style within SUSE (and the GNU project, and Linux, and systemd, and ...) to include a copyright statement in all files (and also RedHat AFAIK, though in the Go community people appear to not like including copyright statements in comments because comments actually affect compilation). That's why I included it in the original file, so sorry for any inconvenience.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cyphar I'm not arguing with common practice, but someone (a Debian contributor, maintainer, or developer) needs to collate all those copyright statements, so it's manual work for somebody; for example: http://metadata.ftp-master.debian.org/changelogs/main/s/systemd/systemd_232-8_copyright
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, you could actually automate it because according to US copyright laws only strings formatted in a certain way are considered to be a legally enforceable copyright statements.
However, to make this simpler do you want to do something like how Kubernetes handles it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As these projects (SUSE, Debian, Fedora) are not US-only, we do have to worry about international copyright law as well, and related concepts like moral rights.
I think the Kubernetes statement is good, and would definitely prefer something like that. A similar, generic, all-encompassing statement is used for the Gradle project, and this seems to be accepted by the Debian folk: http://metadata.ftp-master.debian.org/changelogs/main/g/gradle/gradle_3.2.1-1_copyright