Skip to content

Commit 045b410

Browse files
authored
Allow ava config file to be in non-default path, by setting AVA_CONFIG_FILE_PATH. Docs fixed. (#146)
1 parent a65b7da commit 045b410

File tree

7 files changed

+23
-10
lines changed

7 files changed

+23
-10
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ project(ava)
44

55
###### Options ######
66

7-
set(CMAKE_BUILD_TYPE Release CACHE STRING "Build configuration (Relase/Debug)")
7+
set(CMAKE_BUILD_TYPE Release CACHE STRING "Build configuration (Release/Debug)")
88
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release")
99
if(NOT CMAKE_BUILD_TYPE)
1010
set(CMAKE_BUILD_TYPE Release)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
all:
22
gcc -o test test.c \
33
-I../../../headers \
4-
-L../../../../../ava-build/install/demo_nw/lib -ldemo \
4+
-L../../../../../ava-build/install/demo/lib -ldemo \
55
-lprotobuf

config/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ Configuration Files
22
===================
33

44
Configuration files are replacing environment variables for AvA's settings.
5-
Guestlib reads `/etc/ava/guest.conf` for user-defined configurations.
5+
The guestlib reads `/etc/ava/guest.conf` by default for user-defined configurations,
6+
this can be changed by setting the environment variable `AVA_CONFIG_FILE_PATH`
7+
to the absolute path to a configuration file.
68

79
Run `setup.sh` to install an example configuration.
810

docs/build_and_setup.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,8 @@ ls install/demo/lib
108108
ls install/bin
109109
```
110110

111-
AvA's base repository includes a tiny standalone demo program.
111+
AvA's base repository includes a tiny standalone demo program. If compilation fails,
112+
make sure the Makefile has the correct path to the `build` folder.
112113

113114
```shell
114115
pushd .
@@ -120,7 +121,7 @@ popd
120121
Start the demo manager by
121122

122123
```shell
123-
./install/bin/demo_manager --worker_path install/demo_nw/bin/worker
124+
./install/bin/demo_manager --worker_path install/demo/bin/worker
124125
```
125126

126127
Add AvA configuration file:
@@ -132,6 +133,10 @@ manager_address = "0.0.0.0:3333";
132133
gpu_memory = [1024L];
133134
EOF
134135
```
136+
The guestlib assumes by default the configuration file is at `/etc/ava/guest.conf`,
137+
but any path can be used as long as the environment variable `AVA_CONFIG_FILE_PATH`
138+
is exported and contains the absolute path to the configuration file.
139+
135140

136141
Run the test program by
137142

guestlib/guest_config.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,17 @@ namespace guestconfig {
66

77
std::shared_ptr<GuestConfig> config;
88

9+
char *getConfigFilePath() {
10+
return std::getenv("AVA_CONFIG_FILE_PATH") ? std::getenv("AVA_CONFIG_FILE_PATH") : (char *)kDefaultConfigFilePath;
11+
}
12+
913
std::shared_ptr<GuestConfig> readGuestConfig() {
1014
libconfig::Config cfg;
1115

1216
try {
13-
cfg.readFile(guestconfig::kConfigFilePath);
17+
cfg.readFile(guestconfig::getConfigFilePath());
1418
} catch (const libconfig::FileIOException &fioex) {
15-
std::cerr << "I/O error when reading " << guestconfig::kConfigFilePath << std::endl;
19+
std::cerr << "I/O error when reading " << guestconfig::getConfigFilePath() << std::endl;
1620
return nullptr;
1721
} catch (const libconfig::ParseException &pex) {
1822
std::cerr << "Parse error at " << pex.getFile() << ":" << pex.getLine() << " - " << pex.getError() << std::endl;

guestlib/guest_config.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
namespace guestconfig {
1313

14-
constexpr char kConfigFilePath[] = "/etc/ava/guest.conf";
14+
constexpr char kDefaultConfigFilePath[] = "/etc/ava/guest.conf";
1515
constexpr char kDefaultChannel[] = "TCP";
1616
constexpr uint64_t kDefaultConnectTimeout = 5000;
1717
constexpr char kDefaultManagerAddress[] = "0.0.0.0:3334";
@@ -49,6 +49,8 @@ class GuestConfig {
4949
plog::Severity logger_severity_;
5050
};
5151

52+
char *getConfigFilePath();
53+
5254
std::shared_ptr<GuestConfig> readGuestConfig();
5355

5456
extern std::shared_ptr<GuestConfig> config;

guestlib/init.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ EXPORTED_WEAKLY void nw_init_guestlib(intptr_t api_id) {
4848
// } else if (guestconfig::config->channel_ == "VSOCK") {
4949
// chan = command_channel_socket_new();
5050
} else {
51-
std::cerr << "Unsupported channel specified in " << guestconfig::kConfigFilePath << ", expect channel = [\"TCP\"]"
52-
<< std::endl;
51+
std::cerr << "Unsupported channel specified in " << guestconfig::getConfigFilePath()
52+
<< ", expect channel = [\"TCP\"]" << std::endl;
5353
exit(0);
5454
}
5555
if (!chan) {

0 commit comments

Comments
 (0)