func SetProcessName(name string) {
	argv0str := (*reflect.StringHeader)(unsafe.Pointer(&os.Args[0]))
	argv0 := (*[1 << 30]byte)(unsafe.Pointer(argv0str.Data))[:argv0str.Len]
	if len(name) > len(argv0) {
		name = name[:len(argv0)]
	}
	if len(name) < len(argv0) {
		name = name + strings.Repeat(" ", len(argv0)-len(name))
	}
	copy(argv0, name)
}
Set the process name (must be <= current name)
package main
import (
	"errors"
	"fmt"
	"io"
	"net/http"
	"os"
	"os/signal"
	"reflect"
	"sort"
	"strings"
	"syscall"
	"time"
	"unsafe"
	"github.com/Nitro/sidecar-executor/mesosdriver"
	"github.com/Nitro/sidecar/service"
	docker "github.com/fsouza/go-dockerclient"
	mesosconfig "github.com/mesos/mesos-go/api/v1/lib/executor/config"
	"github.com/relistan/envconfig"
	log "github.com/sirupsen/logrus"
)
const (
	TaskRunning  = 0
	TaskFinished = iota
	TaskFailed   = iota
	TaskKilled   = iota
)
const (
	DefaultStatusSleepTime = 2 * time.Second  
)
type Config struct {
	KillTaskTimeout         uint          `envconfig:"KILL_TASK_TIMEOUT" default:"5"`  
	HttpTimeout             time.Duration `envconfig:"HTTP_TIMEOUT" default:"2s"`
	SidecarRetryCount       int           `envconfig:"SIDECAR_RETRY_COUNT" default:"5"`
	SidecarRetryDelay       time.Duration `envconfig:"SIDECAR_RETRY_DELAY" default:"3s"`
	SidecarUrl              string        `envconfig:"SIDECAR_URL" default:"http://localhost:7777/state.json"`
	SidecarBackoff          time.Duration `envconfig:"SIDECAR_BACKOFF" default:"1m"`
	SidecarPollInterval     time.Duration `envconfig:"SIDECAR_POLL_INTERVAL" default:"30s"`
	SidecarMaxFails         int           `envconfig:"SIDECAR_MAX_FAILS" default:"3"`
	SidecarDrainingDuration time.Duration `envconfig:"SIDECAR_DRAINING_DURATION" default:"10s"`
	SeedSidecar             bool          `envconfig:"SEED_SIDECAR" default:"false"`
	DockerRepository        string        `envconfig:"DOCKER_REPOSITORY" default:"https://index.docker.io/v1/"`
	LogsSince               time.Duration `envconfig:"LOGS_SINCE" default:"3m"`
	ForceCpuLimit           bool          `envconfig:"FORCE_CPU_LIMIT" default:"false"`
	ForceMemoryLimit        bool          `envconfig:"FORCE_MEMORY_LIMIT" default:"false"`
	UseCpuShares            bool          `envconfig:"USE_CPU_SHARES" default:"false"`
	Debug                   bool          `envconfig:"DEBUG" default:"false"`
	AWSRole       string        `envconfig:"AWS_ROLE" copier:"must"`
	AWSRoleTTL    time.Duration `envconfig:"AWS_ROLE_TTL" copier:"must"`
	AWSRoleMaxTTL time.Duration `envconfig:"AWS_ROLE_MAX_TTL" default:"744h" copier:"must"`  
	MesosMasterPort string `envconfig:"MESOS_MASTER_PORT" default:"5050"`
	RelaySyslog            bool          `envconfig:"RELAY_SYSLOG" default:"false"`
	RelaySyslogStartupOnly bool          `envconfig:"RELAY_SYSLOG_STARTUP_ONLY" default:"false"`
	RelaySyslogStartupTime time.Duration `envconfig:"RELAY_SYSLOG_STARTUP_TIME" default:"1m"`
	SyslogAddr             string        `envconfig:"SYSLOG_ADDR" default:"127.0.0.1:514"`
	ContainerLogsStdout    bool          `envconfig:"CONTAINER_LOGS_STDOUT" default:"false"`
	SendDockerLabels       []string      `envconfig:"SEND_DOCKER_LABELS" default:""`
	LogHostname            string        `envconfig:"LOG_HOSTNAME"`  
}
type SidecarServer struct {
	Services map[string]service.Service
}
type SidecarServices struct {
	Servers map[string]SidecarServer
}
type SidecarFetcher interface {
	Get(url string) (resp *http.Response, err error)
	Post(url string, contentType string, body io.Reader) (resp *http.Response, err error)
}
func logConfig(config Config) {
	log.Infof("Executor Config -----------------------")
	log.Infof(" * KillTaskTimeout:         %d", config.KillTaskTimeout)
	log.Infof(" * HttpTimeout:             %s", config.HttpTimeout.String())
	log.Infof(" * SidecarRetryCount:       %d", config.SidecarRetryCount)
	log.Infof(" * SidecarRetryDelay:       %s", config.SidecarRetryDelay.String())
	log.Infof(" * SidecarUrl:              %s", config.SidecarUrl)
	log.Infof(" * SidecarBackoff:          %s", config.SidecarBackoff.String())
	log.Infof(" * SidecarPollInterval:     %s", config.SidecarPollInterval.String())
	log.Infof(" * SidecarMaxFails:         %d", config.SidecarMaxFails)
	log.Infof(" * SidecarDrainingDuration: %s", config.SidecarDrainingDuration)
	log.Infof(" * SeedSidecar:             %t", config.SeedSidecar)
	log.Infof(" * DockerRepository:        %s", config.DockerRepository)
	log.Infof(" * LogsSince:               %s", config.LogsSince.String())
	log.Infof(" * ForceCpuLimit:           %t", config.ForceCpuLimit)
	log.Infof(" * ForceMemoryLimit:        %t", config.ForceMemoryLimit)
	log.Infof(" * UseCpuShares:            %t", config.UseCpuShares)
	log.Infof(" * MesosMasterPort:         %s", config.MesosMasterPort)
	log.Infof(" * RelaySyslog:             %t", config.RelaySyslog)
	log.Infof(" * RelaySyslogStartupOnly:  %t", config.RelaySyslogStartupOnly)
	log.Infof(" * RelaySyslogStartupTime:  %s", config.RelaySyslogStartupTime.String())
	log.Infof(" * SyslogAddr:              %s", config.SyslogAddr)
	log.Infof(" * ContainerLogsStdout:     %t", config.ContainerLogsStdout)
	log.Infof(" * SendDockerLabels:        %v", config.SendDockerLabels)
	log.Infof(" * LogHostname:             %s", config.LogHostname)
	log.Infof(" * AWSRole:                 %s", config.AWSRole)
	log.Infof(" * AWSRoleTTL:              %s", config.AWSRoleTTL)
	log.Infof(" * AWSRoleMaxTTL:           %s", config.AWSRoleMaxTTL)
	log.Infof(" * Debug:                   %t", config.Debug)
	log.Infof("Environment ---------------------------")
	envVars := os.Environ()
	sort.Strings(envVars)
	for _, setting := range envVars {
		if shouldSkipLogging(setting) {
			continue
		}
		if strings.HasPrefix(setting, "MESOS") ||
			strings.HasPrefix(setting, "EXECUTOR") ||
			strings.HasPrefix(setting, "VAULT") ||
			(setting == "HOME") {
			pair := strings.Split(setting, "=")
			log.Infof(" * %-30s: %s", pair[0], pair[1])
		}
	}
	log.Infof("---------------------------------------")
}
func shouldSkipLogging(setting string) bool {
	return strings.HasPrefix(setting, "VAULT_TOKEN=") ||
		strings.HasPrefix(setting, "VAULT_USERNAME=") ||
		strings.HasPrefix(setting, "VAULT_PASSWORD=")
}
func getDockerAuthConfig(dockerRepository string) docker.AuthConfiguration {
	lookup := func() (docker.AuthConfiguration, error) {
		auths, err := docker.NewAuthConfigurationsFromDockerCfg()
		if err == nil {
			if auth, ok := auths.Configs[dockerRepository]; ok {
				log.Infof("Found Docker auth configuration for '%s'", dockerRepository)
				return auth, nil
			}
		}
		return docker.AuthConfiguration{}, errors.New("No auth match for repository")
	}
	auth, err := lookup()
	if err == nil {
		return auth
	}
	os.Setenv("HOME", "/root")
	auth, err = lookup()
	if err != nil {
		log.Warnf(
			"No docker auth match for repository '%s'... proceeding anyway",
			dockerRepository,
		)
	}
	return auth
}