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

Don't panic #360

Merged
merged 2 commits into from
Jan 27, 2023
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
14 changes: 8 additions & 6 deletions cmd/coordinator/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
package main

import (
"fmt"
"os"
"strings"

Expand Down Expand Up @@ -35,16 +36,17 @@ func run(validator quote.Validator, issuer quote.Issuer, sealDir string, sealer
devMode := util.Getenv(constants.DevMode, constants.DevModeDefault) == "1"

// Setup logging with Zap Logger
// Development Logger shows a stacktrace for warnings & errors, Production Logger only for errors
var log *zap.Logger
var err error
var cfg zap.Config
if devMode {
log, err = zap.NewDevelopment()
cfg = zap.NewDevelopmentConfig()
} else {
log, err = zap.NewProduction()
cfg = zap.NewProductionConfig()
cfg.DisableStacktrace = true // Disable stacktraces in production
}
log, err := cfg.Build()
if err != nil {
panic(err)
fmt.Fprintf(os.Stderr, "failed to create logger: %s\n", err)
os.Exit(1)
}
defer log.Sync() // flushes buffer, if any

Expand Down
19 changes: 14 additions & 5 deletions cmd/premain-libos/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package main

import (
"errors"
"fmt"
"log"
"os"
"path/filepath"
Expand All @@ -26,13 +27,21 @@ const (
occlum
)

func exit(format string, args ...interface{}) {
// Print error message in red and append newline
// then exit with error code 1
msg := fmt.Sprintf("Error: %s\n", format)
_, _ = color.New(color.FgRed).Fprintf(os.Stderr, msg, args...)
os.Exit(1)
}

func main() {
log.SetPrefix("[PreMain] ")

// Automatically detect libOS based on uname
libOS, err := detectLibOS()
if err != nil {
panic(err)
exit("failed to detect libOS: %s", err)
}

// Use filesystem from libOS
Expand All @@ -47,7 +56,7 @@ func main() {
// Gramine: Get service to launch before MarbleRun's premain
service, err = prepareGramine(hostfs)
if err != nil {
panic(err)
exit("activating Gramine Marble failed: %s", err)
}

case occlum:
Expand All @@ -56,13 +65,13 @@ func main() {
// Occlum: Get entrypoint from MarbleRun manifest, adjust it to Occlum's quirks
service, err = prepareOcclum(hostfs)
if err != nil {
panic(err)
exit("activating Occlum Marble failed: %s", err)
}
}

// Launch service
if err := unix.Exec(service, os.Args, os.Environ()); err != nil {
panic(err)
exit("%s", err)
}
}

Expand Down Expand Up @@ -109,7 +118,7 @@ func prepareGramine(hostfs afero.Fs) (string, error) {
func prepareOcclum(hostfs afero.Fs) (string, error) {
// Run MarbleRun premain
if err := marblePremain.PreMainEx(marblePremain.OcclumQuoteIssuer{}, marblePremain.ActivateRPC, hostfs, hostfs); err != nil {
panic(err)
return "", err
}

// Check if the entrypoint defined in os.Args[0] actually exists
Expand Down