Skip to content

Commit 4f238db

Browse files
authored
Merge pull request #1569 from criblio/bug/attach-process-config
non-root process picks up config when attaching via `scope rules --add`
2 parents 3f22548 + 9494d05 commit 4f238db

File tree

1 file changed

+27
-4
lines changed

1 file changed

+27
-4
lines changed

cli/run/setup.go

+27-4
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,13 @@ func (rc *Config) buildEventsDest() string {
318318
}
319319

320320
func (rc *Config) CreateWorkDirBasic(cmd string) {
321+
dirPerms := os.FileMode(0755)
322+
if cmd == "rules" {
323+
dirPerms = 0777
324+
oldmask := syscall.Umask(0)
325+
defer syscall.Umask(oldmask)
326+
}
327+
321328
// Directories named CMD_SESSIONID_PID_TIMESTAMP
322329
ts := strconv.FormatInt(time.Now().UTC().UnixNano(), 10)
323330
pid := strconv.Itoa(os.Getpid())
@@ -334,10 +341,26 @@ func (rc *Config) CreateWorkDirBasic(cmd string) {
334341
util.Warn("WARNING: Session logs will be stored in %s and owned by root\n", histDir)
335342
}
336343

337-
// Create working directory in history/
338-
rc.WorkDir = filepath.Join(HistoryDir(), tmpDirName)
339-
err = os.Mkdir(rc.WorkDir, 0755)
340-
util.CheckErrSprintf(err, "error creating workdir dir: %v", err)
344+
// Create Working directory
345+
if cmd == "rules" {
346+
// Validate /tmp exists
347+
if !util.CheckDirExists("/tmp") {
348+
util.ErrAndExit("/tmp directory does not exist")
349+
}
350+
// Create working directory in /tmp (0777 permissions)
351+
rc.WorkDir = filepath.Join("/tmp", tmpDirName)
352+
err := os.Mkdir(rc.WorkDir, dirPerms)
353+
util.CheckErrSprintf(err, "error creating workdir dir: %v", err)
354+
355+
// Symbolic link between /tmp/tmpDirName and /history/tmpDirName
356+
rootHistDir := filepath.Join(histDir, tmpDirName)
357+
os.Symlink(rc.WorkDir, rootHistDir)
358+
} else {
359+
// Create working directory in history/
360+
rc.WorkDir = filepath.Join(HistoryDir(), tmpDirName)
361+
err = os.Mkdir(rc.WorkDir, 0755)
362+
util.CheckErrSprintf(err, "error creating workdir dir: %v", err)
363+
}
341364

342365
// Populate working directory
343366
// Create Log file

0 commit comments

Comments
 (0)