Skip to content

Commit

Permalink
Fix instance directory permission for privacy and exit when container…
Browse files Browse the repository at this point in the history
… instance doesn't contain processes
  • Loading branch information
cclerget committed Jan 2, 2019
1 parent 6896067 commit b4dcb0e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
4 changes: 0 additions & 4 deletions etc/actions/start
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
#!/bin/sh

# if we are here start notify PID 1 to continue
# DON'T REMOVE
kill -CONT 1

for script in /.singularity.d/env/*.sh; do
if [ -f "$script" ]; then
. "$script"
Expand Down
12 changes: 12 additions & 0 deletions internal/pkg/instance/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,18 @@ func (i *File) Update() error {
if err := os.MkdirAll(path, 0755); err != nil {
return err
}
if i.PrivilegedPath() {
pw, err := user.GetPwNam(i.User)
if err != nil {
return err
}
if err := os.Chmod(path, 0550); err != nil {
return err
}
if err := os.Chown(path, int(pw.UID), 0); err != nil {
return err
}
}
file, err := os.OpenFile(i.Path, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0644)
if err != nil {
return err
Expand Down
5 changes: 3 additions & 2 deletions internal/pkg/runtime/engines/singularity/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,9 @@ func (engine *EngineOperations) StartProcess(masterConn net.Conn) error {
}
default:
if isInstance {
if s != syscall.SIGCONT {
syscall.Kill(-1, s.(syscall.Signal))
if err := syscall.Kill(-1, s.(syscall.Signal)); err == syscall.ESRCH {
sylog.Debugf("No child process, exiting ...")
os.Exit(128 + int(s.(syscall.Signal)))
}
} else {
// kill ourself with SIGKILL whatever signal was received
Expand Down

0 comments on commit b4dcb0e

Please sign in to comment.