1
// Copyright 2015 CoreOS, Inc.
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
7
// http://www.apache.org/licenses/LICENSE-2.0
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
15
// Activation example used by the activation unit tests.
22
"github.com/coreos/go-systemd/activation"
26
if os.Getenv("FIX_LISTEN_PID") != "" {
27
// HACK: real systemd would set LISTEN_PID before exec'ing but
28
// this is too difficult in golang for the purpose of a test.
29
// Do not do this in real code.
30
os.Setenv("LISTEN_PID", fmt.Sprintf("%d", os.Getpid()))
37
files := activation.Files(false)
43
if os.Getenv("LISTEN_PID") == "" || os.Getenv("LISTEN_FDS") == "" {
44
panic("Should not unset envs")
47
files = activation.Files(true)
49
if os.Getenv("LISTEN_PID") != "" || os.Getenv("LISTEN_FDS") != "" {
50
panic("Can not unset envs")
53
// Write out the expected strings to the two pipes
54
files[0].Write([]byte("Hello world"))
55
files[1].Write([]byte("Goodbye world"))