Skip to content

Commit d477a90

Browse files
authored
Merge pull request #41 from edwintorok/offhost
CA-336056: off-host xe wasn't working when run as non-root
2 parents 1e3d196 + 456d183 commit d477a90

File tree

7 files changed

+29
-17
lines changed

7 files changed

+29
-17
lines changed

.travis.yml

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
language: c
22
services: docker
33
install:
4-
- wget https://raw.githubusercontent.com/xenserver/xenserver-build-env/master/utils/travis-build-repo.sh
5-
script: bash travis-build-repo.sh
4+
- wget https://raw.githubusercontent.com/ocaml/ocaml-ci-scripts/master/.travis-docker.sh
5+
- wget https://raw.githubusercontent.com/xapi-project/xs-opam/master/tools/xs-opam-ci.env
6+
- source xs-opam-ci.env
7+
script: bash -ex .travis-docker.sh
68
sudo: true
79
env:
8-
global:
9-
- REPO_PACKAGE_NAME=forkexecd
10-
- REPO_CONFIGURE_CMD=true
11-
- REPO_BUILD_CMD='make'
12-
- REPO_TEST_CMD='make test'
10+
global:
11+
- PINS="forkexec:. xapi-forkexecd:."
12+
jobs:
13+
- PACKAGE="xapi-forkexecd"

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ clean:
2020
dune clean
2121

2222
test:
23-
dune runtest --profile=release
23+
dune runtest --profile=release --no-buffer
2424

2525
# requires odoc
2626
doc:

lib/forkhelpers.ml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,18 @@ let getpid (_sock, pid) = pid
7070

7171
type 'a result = Success of string * 'a | Failure of string * exn
7272

73-
let temp_dir = "/var/run/nonpersistent/forkexecd/"
73+
let temp_dir_server = "/var/run/nonpersistent/forkexecd/"
74+
let temp_dir =
75+
try
76+
Unix.access temp_dir_server [Unix.W_OK; Unix.R_OK; Unix.X_OK];
77+
Some temp_dir_server
78+
with _ -> None
7479

7580
(** Creates a temporary file and opens it for logging. The fd is passed to the function
7681
'f'. The logfile is guaranteed to be closed afterwards, and unlinked if either the delete flag is set or the call fails. If the
7782
function 'f' throws an error then the log file contents are read in *)
7883
let with_logfile_fd ?(delete = true) prefix f =
79-
let logfile = Filename.temp_file ~temp_dir prefix ".log" in
84+
let logfile = Filename.temp_file ?temp_dir prefix ".log" in
8085
let read_logfile () =
8186
let contents = Xapi_stdext_unix.Unixext.string_of_file logfile in
8287
Unix.unlink logfile;

lib/forkhelpers.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,6 @@ type 'a result =
107107
val with_logfile_fd : ?delete:bool -> string -> (Unix.file_descr -> 'a) -> 'a result
108108

109109
(** Temporary directory used for communication *)
110-
val temp_dir: string
110+
val temp_dir_server: string
111111

112112

src/fe_main.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
open Fe_debug
22

33
let setup sock cmdargs id_to_fd_map syslog_stdout redirect_stderr_to_stdout env =
4-
let fd_sock_path = Printf.sprintf "%s/fd_%s" Forkhelpers.temp_dir
4+
let fd_sock_path = Printf.sprintf "%s/fd_%s" Forkhelpers.temp_dir_server
55
(Uuidm.to_string (Uuidm.create `V4)) in
66
let fd_sock = Fecomms.open_unix_domain_sock () in
77
Xapi_stdext_unix.Unixext.unlink_safe fd_sock_path;
@@ -44,7 +44,7 @@ let _ =
4444
Sys.set_signal Sys.sigpipe (Sys.Signal_ignore);
4545

4646
let main_sock = Fecomms.open_unix_domain_sock_server "/var/xapi/forker/main" in
47-
Xapi_stdext_unix.Unixext.mkdir_rec (Forkhelpers.temp_dir) 0o755;
47+
Xapi_stdext_unix.Unixext.mkdir_rec (Forkhelpers.temp_dir_server) 0o755;
4848

4949
Daemon.notify Daemon.State.Ready |> ignore;
5050

test/fe_test.ml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ type config = {
1717
}
1818

1919
let min_fds = 7
20-
let max_fds = 1024 - 8 (* fe daemon has a bunch for its own use *)
20+
let max_fds = 1024 - 11 (* fe daemon has a bunch for its own use *)
2121

2222
let all_combinations fds =
2323
let y = {
@@ -114,12 +114,13 @@ let test_exitcode () =
114114
Printf.printf "\nCompleted exitcode tests\n"
115115

116116
let master fds =
117+
Printf.printf "\nPerforming timeout tests\n%!";
117118
test_delay ();
118119
test_notimeout ();
119-
Printf.printf "\nCompleted timeout test\n";
120+
Printf.printf "\nCompleted timeout test\n%!";
120121
test_exitcode ();
121122
let combinations = shuffle (all_combinations fds) in
122-
Printf.printf "Starting %d tests\n" (List.length combinations);
123+
Printf.printf "Starting %d tests\n%!" (List.length combinations);
123124
let i = ref 0 in
124125
let update_progress f x =
125126
incr i;

test/fe_test.sh

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
#!/bin/sh
22

33
../src/fe_main.exe &
4-
for x in `seq 1 10`; do
4+
MAIN=$!
5+
cleanup () {
6+
kill $MAIN
7+
}
8+
trap cleanup EXIT
9+
for _ in $(seq 1 10); do
510
test -S /var/xapi/forker/main || sleep 1
611
done
712
./fe_test.exe 16

0 commit comments

Comments
 (0)