diff --git a/src/sc/sc.cpp b/src/sc/sc.cpp index 5343a819..1f30dc47 100644 --- a/src/sc/sc.cpp +++ b/src/sc/sc.cpp @@ -168,13 +168,6 @@ namespace sc // Set up the process environment and overlay the contract binary program with execv(). - // Set user execution user/group if specified (Must set gid before setting uid). - if (!conf::cfg.contract.run_as.empty() && (setgid(conf::cfg.contract.run_as.gid) == -1 || setuid(conf::cfg.contract.run_as.uid) == -1)) - { - std::cerr << errno << ": Contract process setgid/uid failed." << (ctx.args.readonly ? " (rdonly)" : "") << "\n"; - exit(1); - } - if (create_contract_log_files(ctx) == -1) { std::cerr << errno << ": Contract process output redirection failed." << (ctx.args.readonly ? " (rdonly)" : "") << "\n"; @@ -222,6 +215,14 @@ namespace sc exit(1); } + // Just before we execv the contract binary, we set user execution user/group if specified in hp config. + // (Must set gid before setting uid) + if (!conf::cfg.contract.run_as.empty() && (setgid(conf::cfg.contract.run_as.gid) == -1 || setuid(conf::cfg.contract.run_as.uid) == -1)) + { + std::cerr << errno << ": Contract process setgid/uid failed." << (ctx.args.readonly ? " (rdonly)" : "") << "\n"; + exit(1); + } + execv(execv_args[0], execv_args); std::cerr << errno << ": Contract process execv failed." << (ctx.args.readonly ? " (rdonly)" : "") << "\n"; exit(1);