1
0
mirror of https://blitiri.com.ar/repos/chasquid synced 2025-12-17 14:37:02 +00:00

chasquid: Do a Chdir into the configuration directory

In some cases, it's be useful to have references to directories relative
to the configuration itself.

So this patch makes chasquid do a Chdir into it, so we can assume it in
the rest of the code and config.
This commit is contained in:
Alberto Bertogli
2016-09-18 06:07:59 +01:00
parent f375f276af
commit e9d62e0467
3 changed files with 17 additions and 7 deletions

View File

@@ -60,6 +60,13 @@ func main() {
glog.Fatalf("Error reading config") glog.Fatalf("Error reading config")
} }
// Change to the config dir.
// This allow us to use relative paths for configuration directories.
// It also can be useful in unusual environments and for testing purposes,
// where paths inside the configuration itself could be relative, and this
// fixes the point of reference.
os.Chdir(*configDir)
if conf.MonitoringAddress != "" { if conf.MonitoringAddress != "" {
glog.Infof("Monitoring HTTP server listening on %s", glog.Infof("Monitoring HTTP server listening on %s",
conf.MonitoringAddress) conf.MonitoringAddress)
@@ -74,7 +81,8 @@ func main() {
s.MaxDataSize = conf.MaxDataSizeMb * 1024 * 1024 s.MaxDataSize = conf.MaxDataSizeMb * 1024 * 1024
// Load domains. // Load domains.
domainDirs, err := ioutil.ReadDir(*configDir + "/domains/") // They live inside the config directory, so the relative path works.
domainDirs, err := ioutil.ReadDir("domains/")
if err != nil { if err != nil {
glog.Fatalf("Error in glob: %v", err) glog.Fatalf("Error in glob: %v", err)
} }
@@ -85,7 +93,7 @@ func main() {
glog.Infof("Domain config paths:") glog.Infof("Domain config paths:")
for _, info := range domainDirs { for _, info := range domainDirs {
name := info.Name() name := info.Name()
dir := filepath.Join(*configDir, "domains", name) dir := filepath.Join("domains", name)
loadDomain(s, name, dir) loadDomain(s, name, dir)
} }
} }

View File

@@ -27,8 +27,10 @@ function generate_cert() {
function chasquid() { function chasquid() {
# HOSTALIASES: so we "fake" hostnames. # HOSTALIASES: so we "fake" hostnames.
# PATH: so chasquid can call test-mda without path issues. # PATH: so chasquid can call test-mda without path issues.
# MDA_DIR: so our test-mda knows where to deliver emails.
HOSTALIASES=${TBASE}/hosts \ HOSTALIASES=${TBASE}/hosts \
PATH=${UTILDIR}:${PATH} \ PATH=${UTILDIR}:${PATH} \
MDA_DIR=${TBASE}/.mail \
go run ${TBASE}/../../chasquid.go "$@" go run ${TBASE}/../../chasquid.go "$@"
} }

View File

@@ -2,13 +2,13 @@
set -e set -e
mkdir -p .mail mkdir -p ${MDA_DIR}
# TODO: use flock to lock the file, to prevent atomic writes. # TODO: use flock to lock the file, to prevent atomic writes.
echo "From ${1}" >> .mail/.tmp-${1} echo "From ${1}" >> ${MDA_DIR}/.tmp-${1}
cat >> .mail/.tmp-${1} cat >> ${MDA_DIR}/.tmp-${1}
X=$? X=$?
if [ -e .mail/.tmp-${1} ]; then if [ -e ${MDA_DIR}/.tmp-${1} ]; then
mv .mail/.tmp-${1} .mail/${1} mv ${MDA_DIR}/.tmp-${1} ${MDA_DIR}/${1}
fi fi
exit $X exit $X