diff -Nru lxd-2.1/client.go lxd-2.2/client.go --- lxd-2.1/client.go 2016-08-17 03:04:59.000000000 +0000 +++ lxd-2.2/client.go 2016-09-14 02:26:58.000000000 +0000 @@ -96,6 +96,15 @@ return &op, nil } +func (r *Response) MetadataAsStringSlice() ([]string, error) { + sl := []string{} + if err := json.Unmarshal(r.Metadata, &sl); err != nil { + return nil, err + } + + return sl, nil +} + // ParseResponse parses a lxd style response out of an http.Response. Note that // this does _not_ automatically convert error responses to golang errors. To // do that, use ParseError. Internal client library uses should probably use @@ -1771,6 +1780,7 @@ return err } req.Header.Set("User-Agent", shared.UserAgent) + req.Header.Set("X-LXD-type", "file") if mode != "" { req.Header.Set("X-LXD-mode", mode) @@ -1791,9 +1801,101 @@ return err } -func (c *Client) PullFile(container string, p string) (int, int, int, io.ReadCloser, error) { +func (c *Client) Mkdir(container string, p string, mode os.FileMode) error { + if c.Remote.Public { + return fmt.Errorf("This function isn't supported by public remotes.") + } + + query := url.Values{"path": []string{p}} + uri := c.url(shared.APIVersion, "containers", container, "files") + "?" + query.Encode() + + req, err := http.NewRequest("POST", uri, nil) + if err != nil { + return err + } + + req.Header.Set("User-Agent", shared.UserAgent) + req.Header.Set("X-LXD-type", "directory") + req.Header.Set("X-LXD-mode", fmt.Sprintf("%04o", mode.Perm())) + + raw, err := c.Http.Do(req) + if err != nil { + return err + } + + _, err = HoistResponse(raw, Sync) + return err +} + +func (c *Client) MkdirP(container string, p string, mode os.FileMode) error { + if c.Remote.Public { + return fmt.Errorf("This function isn't supported by public remotes.") + } + + parts := strings.Split(p, "/") + i := len(parts) + + for ; i >= 1; i-- { + cur := filepath.Join(parts[:i]...) + _, _, _, type_, _, _, err := c.PullFile(container, cur) + if err != nil { + continue + } + + if type_ != "directory" { + return fmt.Errorf("%s is not a directory", cur) + } + + i++ + break + } + + for ; i <= len(parts); i++ { + cur := filepath.Join(parts[:i]...) + if err := c.Mkdir(container, cur, mode); err != nil { + return err + } + } + + return nil +} + +func (c *Client) RecursivePushFile(container string, source string, target string) error { if c.Remote.Public { - return 0, 0, 0, nil, fmt.Errorf("This function isn't supported by public remotes.") + return fmt.Errorf("This function isn't supported by public remotes.") + } + + sourceDir := filepath.Dir(source) + + sendFile := func(p string, fInfo os.FileInfo, err error) error { + if err != nil { + return fmt.Errorf("got error sending path %s: %s", p, err) + } + + targetPath := path.Join(target, p[len(sourceDir):]) + if fInfo.IsDir() { + return c.Mkdir(container, targetPath, fInfo.Mode()) + } + + f, err := os.Open(p) + if err != nil { + return err + } + defer f.Close() + + mode := fInfo.Mode() + uid := int(fInfo.Sys().(*syscall.Stat_t).Uid) + gid := int(fInfo.Sys().(*syscall.Stat_t).Gid) + + return c.PushFile(container, targetPath, gid, uid, fmt.Sprintf("0%o", mode), f) + } + + return filepath.Walk(source, sendFile) +} + +func (c *Client) PullFile(container string, p string) (int, int, int, string, io.ReadCloser, []string, error) { + if c.Remote.Public { + return 0, 0, 0, "", nil, nil, fmt.Errorf("This function isn't supported by public remotes.") } uri := c.url(shared.APIVersion, "containers", container, "files") @@ -1801,12 +1903,73 @@ r, err := c.getRaw(uri + "?" + query.Encode()) if err != nil { - return 0, 0, 0, nil, err + return 0, 0, 0, "", nil, nil, err } - uid, gid, mode := shared.ParseLXDFileHeaders(r.Header) + uid, gid, mode, type_ := shared.ParseLXDFileHeaders(r.Header) + if type_ == "directory" { + resp, err := HoistResponse(r, Sync) + if err != nil { + return 0, 0, 0, "", nil, nil, err + } + + entries, err := resp.MetadataAsStringSlice() + if err != nil { + return 0, 0, 0, "", nil, nil, err + } - return uid, gid, mode, r.Body, nil + return uid, gid, mode, type_, nil, entries, nil + } else if type_ == "file" { + return uid, gid, mode, type_, r.Body, nil, nil + } else { + return 0, 0, 0, "", nil, nil, fmt.Errorf("unknown file type '%s'", type_) + } +} + +func (c *Client) RecursivePullFile(container string, p string, targetDir string) error { + if c.Remote.Public { + return fmt.Errorf("This function isn't supported by public remotes.") + } + + _, _, mode, type_, buf, entries, err := c.PullFile(container, p) + if err != nil { + return err + } + + target := filepath.Join(targetDir, filepath.Base(p)) + + if type_ == "directory" { + if err := os.Mkdir(target, os.FileMode(mode)); err != nil { + return err + } + + for _, ent := range entries { + nextP := path.Join(p, ent) + if err := c.RecursivePullFile(container, nextP, target); err != nil { + return err + } + } + } else if type_ == "file" { + f, err := os.Create(target) + if err != nil { + return err + } + defer f.Close() + + err = f.Chmod(os.FileMode(mode)) + if err != nil { + return err + } + + _, err = io.Copy(f, buf) + if err != nil { + return err + } + } else { + return fmt.Errorf("unknown file type '%s'", type_) + } + + return nil } func (c *Client) GetMigrationSourceWS(container string) (*Response, error) { @@ -2414,17 +2577,21 @@ return op.Metadata, nil } -func (c *Client) ImageFromContainer(cname string, public bool, aliases []string, properties map[string]string) (string, error) { +func (c *Client) ImageFromContainer(cname string, public bool, aliases []string, properties map[string]string, compression_algorithm string) (string, error) { if c.Remote.Public { return "", fmt.Errorf("This function isn't supported by public remotes.") } - source := shared.Jmap{"type": "container", "name": cname} if shared.IsSnapshot(cname) { source["type"] = "snapshot" } + body := shared.Jmap{"public": public, "source": source, "properties": properties} + if compression_algorithm != "" { + body["compression_algorithm"] = compression_algorithm + } + resp, err := c.post("images", body, Async) if err != nil { return "", err diff -Nru lxd-2.1/debian/changelog lxd-2.2/debian/changelog --- lxd-2.1/debian/changelog 2016-09-08 21:39:42.000000000 +0000 +++ lxd-2.2/debian/changelog 2016-09-14 03:25:57.000000000 +0000 @@ -1,3 +1,58 @@ +lxd (2.2-0ubuntu1) yakkety; urgency=medium + + * New upstream release (2.2) + - client: Add a "manpage" command + - client: Add a "rename" alias + - client/file: Recursive file push/pull (-r) (LP: #1531364) + - client/file: Support recursive directory creation (-p) + - client/info: Add cpu usage + - client/publish: Allow overriding compression algorithm + - daemon: Make a database backup on schema updates + - daemon/container: Expose CPU usage + - daemon/container: Initial implementation of recursive file push/pull + - daemon/image: Allow overriding compression algorithm + - daemon/init: Ask for images.auto\_update\_interval + - daemon/storage: Add new storage.zfs\_use\_refquota option + - client/exec: Use os.LookupEnv from go 1.5 to find environment vars + - client/help: Change lxc help to go to stdout + - daemon: Consistently handle name conflicts + - daemon/container: Allow unsetting any config key + - daemon/container: Fix USB transposed major/minor + - daemon/container: Handle xattrs on publish + - daemon/container: Retry generating petnames on conflict + - daemon/container: Error on "restart" without force of a paused container + - daemon/container: Rework container operation locking + - daemon/container: Try to remove the usb bus dir after device disconnect + - daemon/container: Various USB hotplug fixes + - daemon/dir: Copy everything on container copy + - daemon: Do our own socket activation + - daemon/image: Fix support for lzma alone file format + - daemon/init: Change default host to all (::) + - daemon/init: Default to "dir" when "zfs" isn't available (LP: #1619958) + - daemon/init: Fix listed default value for ZFS pool (LP: #1619959) + - daemon/init: Use more intelligent logic for partition sizing + - daemon/profile: Cleaner error on existing profile name + - daemon/profile: Properly cleanup on profile removal + - doc: Add txqueuelen tweak + - doc: Clarify that user\_subvol\_rm\_allowed is needed for btrfs nesting + - doc: Fix typos in production-setup.md + - doc: Rename api\_extensions to api-extensions + - i18n: Update po files and Japanese translation + - lxd-bridge: Fix crash in lxd-bridge-proxy + - tests: Fix race in alias test + - tests: Make TestReaderToChannel transfer smaller + - tests: Only check leftovers on active LXD + + * Update debian/copyright + - Drop godbus + - Drop go-systemd + - Drop yaml.v1 + + * Update debian/control + - Drop dependency on go-systemd + + -- Stéphane Graber Tue, 13 Sep 2016 22:38:18 -0400 + lxd (2.1-0ubuntu4) yakkety; urgency=medium * Fix powerpc build by using golang-any-shared-dev instead of diff -Nru lxd-2.1/debian/control lxd-2.2/debian/control --- lxd-2.1/debian/control 2016-09-08 21:38:50.000000000 +0000 +++ lxd-2.2/debian/control 2016-09-14 02:37:43.000000000 +0000 @@ -14,7 +14,6 @@ golang-any-shared-dev, golang-go.crypto-dev, golang-context-dev, - golang-github-coreos-go-systemd-dev, golang-github-gorilla-mux-dev, golang-github-gosexy-gettext-dev, golang-github-mattn-go-colorable-dev, diff -Nru lxd-2.1/debian/copyright lxd-2.2/debian/copyright --- lxd-2.1/debian/copyright 2016-09-08 21:38:35.000000000 +0000 +++ lxd-2.2/debian/copyright 2016-09-14 02:37:22.000000000 +0000 @@ -19,10 +19,6 @@ Copyright: 2014 Dustin Kirkland License: Apache-2 -Files: dist/src/github.com/godbus/dbus/* -Copyright: 2013 Georg Reinke -License: BSD-2-clause - Files: dist/src/github.com/golang/protobuf/* Copyright: 2010 The Go Authors License: BSD-3-clause @@ -67,10 +63,6 @@ Copyright: 2009,2014 Google Inc. All rights reserved. License: BSD-3-clause -Files: dist/src/github.com/coreos/go-systemd/* -Copyright: Various go-systemd contributors -License: Apache-2 - Files: dist/src/github.com/stretchr/testify/* Copyright: 2012 - 2013 Mat Ryer and Tyler Bunnell License: Expat @@ -111,10 +103,6 @@ Copyright: 2010-2011 - Gustavo Niemeyer License: BSD-3-clause -Files: dist/src/gopkg.in/yaml.v1/* -Copyright: 2011-2014 - Canonical Inc. -License: LGPL-3 with static linking exception - Files: dist/src/gopkg.in/yaml.v2/* Copyright: 2011-2014 - Canonical Inc. License: LGPL-3 with static linking exception diff -Nru lxd-2.1/debian/.git-dpm lxd-2.2/debian/.git-dpm --- lxd-2.1/debian/.git-dpm 2016-09-08 21:38:35.000000000 +0000 +++ lxd-2.2/debian/.git-dpm 2016-09-14 02:35:30.000000000 +0000 @@ -1,8 +1,8 @@ # see git-dpm(1) from git-dpm package -91dbdfca42a242070a9c6d50d5102fc4add36e5c -91dbdfca42a242070a9c6d50d5102fc4add36e5c -7a78925d20d4dd66eb9cff249b9a2296e6bed0e7 -7a78925d20d4dd66eb9cff249b9a2296e6bed0e7 -lxd_2.1.orig.tar.gz -53939a602678d913601b0eec76cb77f2e74c13a6 -9137401 +dc96c751ef2bb97fee404f7e394b1e90582b4f63 +dc96c751ef2bb97fee404f7e394b1e90582b4f63 +8d01ba1be56c0b43059014322bbe3ccc7f4d6fc6 +8d01ba1be56c0b43059014322bbe3ccc7f4d6fc6 +lxd_2.2.orig.tar.gz +210e1e9191e3b9287f7fe427884d250903943b70 +9013985 diff -Nru lxd-2.1/debian/patches/0001-init-Allow-running-dpkg-reconfigure.patch lxd-2.2/debian/patches/0001-init-Allow-running-dpkg-reconfigure.patch --- lxd-2.1/debian/patches/0001-init-Allow-running-dpkg-reconfigure.patch 2016-09-08 21:38:35.000000000 +0000 +++ lxd-2.2/debian/patches/0001-init-Allow-running-dpkg-reconfigure.patch 2016-09-14 02:35:30.000000000 +0000 @@ -1,4 +1,4 @@ -From 91dbdfca42a242070a9c6d50d5102fc4add36e5c Mon Sep 17 00:00:00 2001 +From dc96c751ef2bb97fee404f7e394b1e90582b4f63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Graber?= Date: Mon, 4 Apr 2016 21:18:28 -0400 Subject: init: Allow running dpkg-reconfigure @@ -12,18 +12,18 @@ 1 file changed, 21 insertions(+) diff --git a/lxd/main.go b/lxd/main.go -index 12b5b06..c80475d 100644 +index 2283e66..4a6613b 100644 --- a/lxd/main.go +++ b/lxd/main.go -@@ -600,6 +600,7 @@ func cmdInit() error { - var networkAddress string // Address +@@ -601,6 +601,7 @@ func cmdInit() error { var networkPort int64 // Port var trustPassword string // Trust password + var imagesAutoUpdate bool // controls whether we set images.auto_update_interval to 0 + var runReconfigure bool // Whether to call dpkg-reconfigure // Detect userns defaultPrivileged = -1 -@@ -736,6 +737,11 @@ func cmdInit() error { +@@ -738,6 +739,11 @@ func cmdInit() error { } if len(containers) > 0 || len(images) > 0 { @@ -35,9 +35,9 @@ return fmt.Errorf("You have existing containers or images. lxd init requires an empty LXD.") } -@@ -865,6 +871,10 @@ they otherwise would. - networkPort = askInt("Port to bind LXD to [default=8443]: ", 1, 65535, "8443") - trustPassword = askPassword("Trust password for new clients: ") +@@ -896,6 +902,10 @@ they otherwise would. + if !askBool("Would you like stale cached images to be updated automatically? (yes/no) [default=yes]? ", "yes") { + imagesAutoUpdate = false } + + if askBool("Do you want to configure the LXD bridge (yes/no) [default=yes]? ", "yes") { @@ -46,7 +46,7 @@ } if !shared.StringInSlice(storageBackend, []string{"dir", "zfs"}) { -@@ -952,6 +962,17 @@ they otherwise would. +@@ -1001,6 +1011,17 @@ they otherwise would. } } diff -Nru lxd-2.1/debian/rules lxd-2.2/debian/rules --- lxd-2.1/debian/rules 2016-09-08 21:38:37.000000000 +0000 +++ lxd-2.2/debian/rules 2016-09-14 02:37:59.000000000 +0000 @@ -56,7 +56,6 @@ # has installed it, as appropriate. # Packaged dependencies - debian/helpers/link-from-installed github.com/coreos/go-systemd debian/helpers/link-from-installed github.com/dustinkirkland/golang-petname debian/helpers/link-from-installed github.com/golang/protobuf debian/helpers/link-from-installed github.com/gorilla/context diff -Nru lxd-2.1/dist/src/github.com/andybalholm/cascadia/parser.go lxd-2.2/dist/src/github.com/andybalholm/cascadia/parser.go --- lxd-2.1/dist/src/github.com/andybalholm/cascadia/parser.go 2016-08-17 03:07:13.000000000 +0000 +++ lxd-2.2/dist/src/github.com/andybalholm/cascadia/parser.go 2016-09-14 02:28:23.000000000 +0000 @@ -520,19 +520,31 @@ if !p.consumeClosingParenthesis() { return nil, expectedClosingParenthesis } + if a == 0 { + switch name { + case "nth-child": + return simpleNthChildSelector(b, false), nil + case "nth-of-type": + return simpleNthChildSelector(b, true), nil + case "nth-last-child": + return simpleNthLastChildSelector(b, false), nil + case "nth-last-of-type": + return simpleNthLastChildSelector(b, true), nil + } + } return nthChildSelector(a, b, name == "nth-last-child" || name == "nth-last-of-type", name == "nth-of-type" || name == "nth-last-of-type"), nil case "first-child": - return nthChildSelector(0, 1, false, false), nil + return simpleNthChildSelector(1, false), nil case "last-child": - return nthChildSelector(0, 1, true, false), nil + return simpleNthLastChildSelector(1, false), nil case "first-of-type": - return nthChildSelector(0, 1, false, true), nil + return simpleNthChildSelector(1, true), nil case "last-of-type": - return nthChildSelector(0, 1, true, true), nil + return simpleNthLastChildSelector(1, true), nil case "only-child": return onlyChildSelector(false), nil case "only-of-type": diff -Nru lxd-2.1/dist/src/github.com/andybalholm/cascadia/selector.go lxd-2.2/dist/src/github.com/andybalholm/cascadia/selector.go --- lxd-2.1/dist/src/github.com/andybalholm/cascadia/selector.go 2016-08-17 03:07:13.000000000 +0000 +++ lxd-2.2/dist/src/github.com/andybalholm/cascadia/selector.go 2016-09-14 02:28:23.000000000 +0000 @@ -402,6 +402,67 @@ } } +// simpleNthChildSelector returns a selector that implements :nth-child(b). +// If ofType is true, implements :nth-of-type instead. +func simpleNthChildSelector(b int, ofType bool) Selector { + return func(n *html.Node) bool { + if n.Type != html.ElementNode { + return false + } + + parent := n.Parent + if parent == nil { + return false + } + + count := 0 + for c := parent.FirstChild; c != nil; c = c.NextSibling { + if c.Type != html.ElementNode || (ofType && c.Data != n.Data) { + continue + } + count++ + if c == n { + return count == b + } + if count >= b { + return false + } + } + return false + } +} + +// simpleNthLastChildSelector returns a selector that implements +// :nth-last-child(b). If ofType is true, implements :nth-last-of-type +// instead. +func simpleNthLastChildSelector(b int, ofType bool) Selector { + return func(n *html.Node) bool { + if n.Type != html.ElementNode { + return false + } + + parent := n.Parent + if parent == nil { + return false + } + + count := 0 + for c := parent.LastChild; c != nil; c = c.PrevSibling { + if c.Type != html.ElementNode || (ofType && c.Data != n.Data) { + continue + } + count++ + if c == n { + return count == b + } + if count >= b { + return false + } + } + return false + } +} + // onlyChildSelector returns a selector that implements :only-child. // If ofType is true, it implements :only-of-type instead. func onlyChildSelector(ofType bool) Selector { diff -Nru lxd-2.1/dist/src/github.com/coreos/go-systemd/activation/files.go lxd-2.2/dist/src/github.com/coreos/go-systemd/activation/files.go --- lxd-2.1/dist/src/github.com/coreos/go-systemd/activation/files.go 2016-08-17 03:06:10.000000000 +0000 +++ lxd-2.2/dist/src/github.com/coreos/go-systemd/activation/files.go 1970-01-01 00:00:00.000000000 +0000 @@ -1,52 +0,0 @@ -// Copyright 2015 CoreOS, Inc. -// -// 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. - -// Package activation implements primitives for systemd socket activation. -package activation - -import ( - "os" - "strconv" - "syscall" -) - -// based on: https://gist.github.com/alberts/4640792 -const ( - listenFdsStart = 3 -) - -func Files(unsetEnv bool) []*os.File { - if unsetEnv { - defer os.Unsetenv("LISTEN_PID") - defer os.Unsetenv("LISTEN_FDS") - } - - pid, err := strconv.Atoi(os.Getenv("LISTEN_PID")) - if err != nil || pid != os.Getpid() { - return nil - } - - nfds, err := strconv.Atoi(os.Getenv("LISTEN_FDS")) - if err != nil || nfds == 0 { - return nil - } - - files := make([]*os.File, 0, nfds) - for fd := listenFdsStart; fd < listenFdsStart+nfds; fd++ { - syscall.CloseOnExec(fd) - files = append(files, os.NewFile(uintptr(fd), "LISTEN_FD_"+strconv.Itoa(fd))) - } - - return files -} diff -Nru lxd-2.1/dist/src/github.com/coreos/go-systemd/activation/files_test.go lxd-2.2/dist/src/github.com/coreos/go-systemd/activation/files_test.go --- lxd-2.1/dist/src/github.com/coreos/go-systemd/activation/files_test.go 2016-08-17 03:06:10.000000000 +0000 +++ lxd-2.2/dist/src/github.com/coreos/go-systemd/activation/files_test.go 1970-01-01 00:00:00.000000000 +0000 @@ -1,82 +0,0 @@ -// Copyright 2015 CoreOS, Inc. -// -// 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. - -package activation - -import ( - "bytes" - "io" - "os" - "os/exec" - "testing" -) - -// correctStringWritten fails the text if the correct string wasn't written -// to the other side of the pipe. -func correctStringWritten(t *testing.T, r *os.File, expected string) bool { - bytes := make([]byte, len(expected)) - io.ReadAtLeast(r, bytes, len(expected)) - - if string(bytes) != expected { - t.Fatalf("Unexpected string %s", string(bytes)) - } - - return true -} - -// TestActivation forks out a copy of activation.go example and reads back two -// strings from the pipes that are passed in. -func TestActivation(t *testing.T) { - cmd := exec.Command("go", "run", "../examples/activation/activation.go") - - r1, w1, _ := os.Pipe() - r2, w2, _ := os.Pipe() - cmd.ExtraFiles = []*os.File{ - w1, - w2, - } - - cmd.Env = os.Environ() - cmd.Env = append(cmd.Env, "LISTEN_FDS=2", "FIX_LISTEN_PID=1") - - err := cmd.Run() - if err != nil { - t.Fatalf(err.Error()) - } - - correctStringWritten(t, r1, "Hello world") - correctStringWritten(t, r2, "Goodbye world") -} - -func TestActivationNoFix(t *testing.T) { - cmd := exec.Command("go", "run", "../examples/activation/activation.go") - cmd.Env = os.Environ() - cmd.Env = append(cmd.Env, "LISTEN_FDS=2") - - out, _ := cmd.CombinedOutput() - if bytes.Contains(out, []byte("No files")) == false { - t.Fatalf("Child didn't error out as expected") - } -} - -func TestActivationNoFiles(t *testing.T) { - cmd := exec.Command("go", "run", "../examples/activation/activation.go") - cmd.Env = os.Environ() - cmd.Env = append(cmd.Env, "LISTEN_FDS=0", "FIX_LISTEN_PID=1") - - out, _ := cmd.CombinedOutput() - if bytes.Contains(out, []byte("No files")) == false { - t.Fatalf("Child didn't error out as expected") - } -} diff -Nru lxd-2.1/dist/src/github.com/coreos/go-systemd/activation/listeners.go lxd-2.2/dist/src/github.com/coreos/go-systemd/activation/listeners.go --- lxd-2.1/dist/src/github.com/coreos/go-systemd/activation/listeners.go 2016-08-17 03:06:10.000000000 +0000 +++ lxd-2.2/dist/src/github.com/coreos/go-systemd/activation/listeners.go 1970-01-01 00:00:00.000000000 +0000 @@ -1,62 +0,0 @@ -// Copyright 2015 CoreOS, Inc. -// -// 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. - -package activation - -import ( - "crypto/tls" - "net" -) - -// Listeners returns a slice containing a net.Listener for each matching socket type -// passed to this process. -// -// The order of the file descriptors is preserved in the returned slice. -// Nil values are used to fill any gaps. For example if systemd were to return file descriptors -// corresponding with "udp, tcp, tcp", then the slice would contain {nil, net.Listener, net.Listener} -func Listeners(unsetEnv bool) ([]net.Listener, error) { - files := Files(unsetEnv) - listeners := make([]net.Listener, len(files)) - - for i, f := range files { - if pc, err := net.FileListener(f); err == nil { - listeners[i] = pc - } - } - return listeners, nil -} - -// TLSListeners returns a slice containing a net.listener for each matching TCP socket type -// passed to this process. -// It uses default Listeners func and forces TCP sockets handlers to use TLS based on tlsConfig. -func TLSListeners(unsetEnv bool, tlsConfig *tls.Config) ([]net.Listener, error) { - listeners, err := Listeners(unsetEnv) - - if listeners == nil || err != nil { - return nil, err - } - - if tlsConfig != nil && err == nil { - tlsConfig.NextProtos = []string{"http/1.1"} - - for i, l := range listeners { - // Activate TLS only for TCP sockets - if l.Addr().Network() == "tcp" { - listeners[i] = tls.NewListener(l, tlsConfig) - } - } - } - - return listeners, err -} diff -Nru lxd-2.1/dist/src/github.com/coreos/go-systemd/activation/listeners_test.go lxd-2.2/dist/src/github.com/coreos/go-systemd/activation/listeners_test.go --- lxd-2.1/dist/src/github.com/coreos/go-systemd/activation/listeners_test.go 2016-08-17 03:06:10.000000000 +0000 +++ lxd-2.2/dist/src/github.com/coreos/go-systemd/activation/listeners_test.go 1970-01-01 00:00:00.000000000 +0000 @@ -1,86 +0,0 @@ -// Copyright 2015 CoreOS, Inc. -// -// 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. - -package activation - -import ( - "io" - "net" - "os" - "os/exec" - "testing" -) - -// correctStringWritten fails the text if the correct string wasn't written -// to the other side of the pipe. -func correctStringWrittenNet(t *testing.T, r net.Conn, expected string) bool { - bytes := make([]byte, len(expected)) - io.ReadAtLeast(r, bytes, len(expected)) - - if string(bytes) != expected { - t.Fatalf("Unexpected string %s", string(bytes)) - } - - return true -} - -// TestActivation forks out a copy of activation.go example and reads back two -// strings from the pipes that are passed in. -func TestListeners(t *testing.T) { - cmd := exec.Command("go", "run", "../examples/activation/listen.go") - - l1, err := net.Listen("tcp", ":9999") - if err != nil { - t.Fatalf(err.Error()) - } - l2, err := net.Listen("tcp", ":1234") - if err != nil { - t.Fatalf(err.Error()) - } - - t1 := l1.(*net.TCPListener) - t2 := l2.(*net.TCPListener) - - f1, _ := t1.File() - f2, _ := t2.File() - - cmd.ExtraFiles = []*os.File{ - f1, - f2, - } - - r1, err := net.Dial("tcp", "127.0.0.1:9999") - if err != nil { - t.Fatalf(err.Error()) - } - r1.Write([]byte("Hi")) - - r2, err := net.Dial("tcp", "127.0.0.1:1234") - if err != nil { - t.Fatalf(err.Error()) - } - r2.Write([]byte("Hi")) - - cmd.Env = os.Environ() - cmd.Env = append(cmd.Env, "LISTEN_FDS=2", "FIX_LISTEN_PID=1") - - out, err := cmd.Output() - if err != nil { - println(string(out)) - t.Fatalf(err.Error()) - } - - correctStringWrittenNet(t, r1, "Hello world") - correctStringWrittenNet(t, r2, "Goodbye world") -} diff -Nru lxd-2.1/dist/src/github.com/coreos/go-systemd/activation/packetconns.go lxd-2.2/dist/src/github.com/coreos/go-systemd/activation/packetconns.go --- lxd-2.1/dist/src/github.com/coreos/go-systemd/activation/packetconns.go 2016-08-17 03:06:10.000000000 +0000 +++ lxd-2.2/dist/src/github.com/coreos/go-systemd/activation/packetconns.go 1970-01-01 00:00:00.000000000 +0000 @@ -1,37 +0,0 @@ -// Copyright 2015 CoreOS, Inc. -// -// 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. - -package activation - -import ( - "net" -) - -// PacketConns returns a slice containing a net.PacketConn for each matching socket type -// passed to this process. -// -// The order of the file descriptors is preserved in the returned slice. -// Nil values are used to fill any gaps. For example if systemd were to return file descriptors -// corresponding with "udp, tcp, udp", then the slice would contain {net.PacketConn, nil, net.PacketConn} -func PacketConns(unsetEnv bool) ([]net.PacketConn, error) { - files := Files(unsetEnv) - conns := make([]net.PacketConn, len(files)) - - for i, f := range files { - if pc, err := net.FilePacketConn(f); err == nil { - conns[i] = pc - } - } - return conns, nil -} diff -Nru lxd-2.1/dist/src/github.com/coreos/go-systemd/activation/packetconns_test.go lxd-2.2/dist/src/github.com/coreos/go-systemd/activation/packetconns_test.go --- lxd-2.1/dist/src/github.com/coreos/go-systemd/activation/packetconns_test.go 2016-08-17 03:06:10.000000000 +0000 +++ lxd-2.2/dist/src/github.com/coreos/go-systemd/activation/packetconns_test.go 1970-01-01 00:00:00.000000000 +0000 @@ -1,68 +0,0 @@ -// Copyright 2015 CoreOS, Inc. -// -// 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. - -package activation - -import ( - "net" - "os" - "os/exec" - "testing" -) - -// TestActivation forks out a copy of activation.go example and reads back two -// strings from the pipes that are passed in. -func TestPacketConns(t *testing.T) { - cmd := exec.Command("go", "run", "../examples/activation/udpconn.go") - - u1, err := net.ListenUDP("udp", &net.UDPAddr{Port: 9999}) - if err != nil { - t.Fatalf(err.Error()) - } - u2, err := net.ListenUDP("udp", &net.UDPAddr{Port: 1234}) - if err != nil { - t.Fatalf(err.Error()) - } - - f1, _ := u1.File() - f2, _ := u2.File() - - cmd.ExtraFiles = []*os.File{ - f1, - f2, - } - - r1, err := net.Dial("udp", "127.0.0.1:9999") - if err != nil { - t.Fatalf(err.Error()) - } - r1.Write([]byte("Hi")) - - r2, err := net.Dial("udp", "127.0.0.1:1234") - if err != nil { - t.Fatalf(err.Error()) - } - r2.Write([]byte("Hi")) - - cmd.Env = os.Environ() - cmd.Env = append(cmd.Env, "LISTEN_FDS=2", "FIX_LISTEN_PID=1") - - out, err := cmd.CombinedOutput() - if err != nil { - t.Fatalf("Cmd output '%s', err: '%s'\n", out, err) - } - - correctStringWrittenNet(t, r1, "Hello world") - correctStringWrittenNet(t, r2, "Goodbye world") -} diff -Nru lxd-2.1/dist/src/github.com/coreos/go-systemd/CONTRIBUTING.md lxd-2.2/dist/src/github.com/coreos/go-systemd/CONTRIBUTING.md --- lxd-2.1/dist/src/github.com/coreos/go-systemd/CONTRIBUTING.md 2016-08-17 03:06:10.000000000 +0000 +++ lxd-2.2/dist/src/github.com/coreos/go-systemd/CONTRIBUTING.md 1970-01-01 00:00:00.000000000 +0000 @@ -1,77 +0,0 @@ -# How to Contribute - -CoreOS projects are [Apache 2.0 licensed](LICENSE) and accept contributions via -GitHub pull requests. This document outlines some of the conventions on -development workflow, commit message formatting, contact points and other -resources to make it easier to get your contribution accepted. - -# Certificate of Origin - -By contributing to this project you agree to the Developer Certificate of -Origin (DCO). This document was created by the Linux Kernel community and is a -simple statement that you, as a contributor, have the legal right to make the -contribution. See the [DCO](DCO) file for details. - -# Email and Chat - -The project currently uses the general CoreOS email list and IRC channel: -- Email: [coreos-dev](https://groups.google.com/forum/#!forum/coreos-dev) -- IRC: #[coreos](irc://irc.freenode.org:6667/#coreos) IRC channel on freenode.org - -Please avoid emailing maintainers found in the MAINTAINERS file directly. They -are very busy and read the mailing lists. - -## Getting Started - -- Fork the repository on GitHub -- Read the [README](README.md) for build and test instructions -- Play with the project, submit bugs, submit patches! - -## Contribution Flow - -This is a rough outline of what a contributor's workflow looks like: - -- Create a topic branch from where you want to base your work (usually master). -- Make commits of logical units. -- Make sure your commit messages are in the proper format (see below). -- Push your changes to a topic branch in your fork of the repository. -- Make sure the tests pass, and add any new tests as appropriate. -- Submit a pull request to the original repository. - -Thanks for your contributions! - -### Coding Style - -CoreOS projects written in Go follow a set of style guidelines that we've documented -[here](https://github.com/coreos/docs/tree/master/golang). Please follow them when -working on your contributions. - -### Format of the Commit Message - -We follow a rough convention for commit messages that is designed to answer two -questions: what changed and why. The subject line should feature the what and -the body of the commit should describe the why. - -``` -scripts: add the test-cluster command - -this uses tmux to setup a test cluster that you can easily kill and -start for debugging. - -Fixes #38 -``` - -The format can be described more formally as follows: - -``` -: - - - -