Skip to content

Commit ec4446e

Browse files
authored
cmd/sync: set umask in sync cluster mode (#6400)
1 parent 60878e8 commit ec4446e

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

pkg/sync/config.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package sync
1919
import (
2020
"math"
2121
"os"
22+
"strconv"
2223
"strings"
2324
"time"
2425

@@ -76,6 +77,8 @@ type Config struct {
7677
Registerer prometheus.Registerer
7778
}
7879

80+
const JFS_UMASK = "JFS_UMASK"
81+
7982
func envList() []string {
8083
return []string{
8184
"ACCESS_KEY",
@@ -234,6 +237,13 @@ func NewConfigFromCli(c *cli.Context) *Config {
234237
cfg.Env[key] = os.Getenv(key)
235238
}
236239
}
240+
// pass umask to workers
241+
cfg.Env[JFS_UMASK] = strconv.Itoa(utils.GetUmask())
242+
243+
// workers: set umask for the current process
244+
if umask := os.Getenv(JFS_UMASK); umask != "" {
245+
utils.SetUmask(cast.ToInt(umask))
246+
}
237247

238248
return cfg
239249
}

pkg/utils/utils_unix.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ func GetUmask() int {
6969
return umask
7070
}
7171

72+
func SetUmask(umask int) int {
73+
return syscall.Umask(umask)
74+
}
75+
7276
func ErrnoName(err syscall.Errno) string {
7377
errName := unix.ErrnoName(err)
7478
if errName == "" {

pkg/utils/utils_windows.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ func GetSysInfo() string {
5353

5454
func GetUmask() int { return 0 }
5555

56+
func SetUmask(umask int) int {
57+
return 0
58+
}
59+
5660
func ErrnoName(err syscall.Errno) string {
5761
return strconv.Itoa(int(err))
5862
}

0 commit comments

Comments
 (0)