Skip to content

Commit eaa2e80

Browse files
committed
Add send2vsock to send systemd journal from a guest to the host
Signed-off-by: Kazuyoshi Kato <[email protected]>
1 parent e80d4cc commit eaa2e80

File tree

2 files changed

+86
-0
lines changed

2 files changed

+86
-0
lines changed

send2vsock/Makefile

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Copyright 2018-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License"). You may
4+
# not use this file except in compliance with the License. A copy of the
5+
# License is located at
6+
#
7+
# http://aws.amazon.com/apache2.0/
8+
#
9+
# or in the "license" file accompanying this file. This file is distributed
10+
# on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
11+
# express or implied. See the License for the specific language governing
12+
# permissions and limitations under the License.
13+
14+
EXTRAGOARGS?=
15+
16+
SOURCES:=$(shell find . -name '*.go')
17+
18+
all: send2vsock
19+
20+
send2vsock: $(SOURCES)
21+
go build $(EXTRAGOARGS) -o $@
22+
23+
test:
24+
go test ./... $(EXTRAGOARGS)
25+
26+
clean:
27+
-rm -f send2vsock
28+
29+
distclean: clean
30+
31+
# Install is a noop here, for now.
32+
install:
33+
34+
.PHONY: clean distclean all install test integ-test
35+

send2vsock/main.go

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// Copyright 2018-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License"). You may
4+
// not use this file except in compliance with the License. A copy of the
5+
// License is located at
6+
//
7+
// http://aws.amazon.com/apache2.0/
8+
//
9+
// or in the "license" file accompanying this file. This file is distributed
10+
// on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
11+
// express or implied. See the License for the specific language governing
12+
// permissions and limitations under the License.
13+
14+
package main
15+
16+
import (
17+
"fmt"
18+
"io"
19+
"os"
20+
"strconv"
21+
22+
"github.com/mdlayher/vsock"
23+
)
24+
25+
func main() {
26+
if len(os.Args) != 3 {
27+
fmt.Fprintf(os.Stderr, "Usage: send2vsock CID PORT\n")
28+
os.Exit(1)
29+
}
30+
31+
cid, err := strconv.Atoi(os.Args[1])
32+
if err != nil {
33+
fmt.Fprintf(os.Stderr, "invalid CID: %+v\n", err)
34+
os.Exit(1)
35+
}
36+
37+
port, err := strconv.Atoi(os.Args[2])
38+
if err != nil {
39+
fmt.Fprintf(os.Stderr, "invalid port: %+v\n", err)
40+
os.Exit(1)
41+
}
42+
43+
conn, err := vsock.Dial(uint32(cid), uint32(port))
44+
if err != nil {
45+
fmt.Fprintf(os.Stderr, "failed to connect to the vsock: %+v\n", err)
46+
os.Exit(1)
47+
}
48+
defer conn.Close()
49+
50+
io.Copy(conn, os.Stdin)
51+
}

0 commit comments

Comments
 (0)