Skip to content
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

Dispatcher creates parent directory of UNIX socket files #2620

Merged
merged 1 commit into from
Apr 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions go/godispatcher/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ go_library(
"//go/lib/env:go_default_library",
"//go/lib/fatal:go_default_library",
"//go/lib/log:go_default_library",
"//go/lib/util:go_default_library",
"@com_github_burntsushi_toml//:go_default_library",
],
)
Expand Down
6 changes: 6 additions & 0 deletions go/godispatcher/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"github.com/scionproto/scion/go/lib/env"
"github.com/scionproto/scion/go/lib/fatal"
"github.com/scionproto/scion/go/lib/log"
"github.com/scionproto/scion/go/lib/util"
)

var (
Expand Down Expand Up @@ -60,6 +61,11 @@ func realMain() int {
return 1
}

if err := util.CreateParentDirs(cfg.Dispatcher.ApplicationSocket); err != nil {
log.Crit("Unable to create directory tree for socket", "err", err)
return 1
}

go func() {
defer log.LogPanicAndExit()
err := RunDispatcher(
Expand Down
1 change: 1 addition & 0 deletions go/lib/util/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ go_library(
"duration.go",
"duration_wrap.go",
"file.go",
"fs.go",
"map.go",
"padding.go",
"raw.go",
Expand Down
31 changes: 31 additions & 0 deletions go/lib/util/fs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright 2019 ETH Zurich
//
// 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 util

import (
"os"
"path/filepath"
)

// CreateParentDir creates the necessary parent directories for file.
func CreateParentDirs(file string) error {
dir := filepath.Dir(file)
if _, err := os.Stat(dir); os.IsNotExist(err) {
if err = os.MkdirAll(dir, 0755); err != nil {
return err
}
}
return nil
}
17 changes: 4 additions & 13 deletions go/sciond/internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ package config

import (
"io"
"os"
"path/filepath"
"time"

"github.com/scionproto/scion/go/lib/common"
Expand Down Expand Up @@ -147,18 +145,11 @@ func (cfg *SDConfig) ConfigName() string {
}

func (cfg *SDConfig) CreateSocketDirs() error {
reliableDir := filepath.Dir(cfg.Reliable)
if _, err := os.Stat(reliableDir); os.IsNotExist(err) {
if err = os.MkdirAll(reliableDir, 0755); err != nil {
return common.NewBasicError("Cannot create reliable socket dir", err, "dir",
reliableDir)
}
if err := util.CreateParentDirs(cfg.Reliable); err != nil {
return common.NewBasicError("Cannot create reliable socket dir", err)
}
unixDir := filepath.Dir(cfg.Unix)
if _, err := os.Stat(unixDir); os.IsNotExist(err) {
if err = os.MkdirAll(unixDir, 0755); err != nil {
return common.NewBasicError("Cannot create unix socket dir", err, "dir", unixDir)
}
if err := util.CreateParentDirs(cfg.Unix); err != nil {
return common.NewBasicError("Cannot create unix socket dir", err)
}
return nil
}