brewco/brewco.c

changeset 464
4a624c071ca9
parent 459
1f88be70f253
child 465
3aac3276689d
--- a/brewco/brewco.c	Thu Dec 17 22:45:54 2015 +0100
+++ b/brewco/brewco.c	Sun Dec 20 20:37:40 2015 +0100
@@ -46,6 +46,9 @@
 #ifdef USE_SIMULATOR
 extern int		SIM_cooler;
 #endif
+char			*etcpath = NULL;
+char			*varpath = NULL;
+
 
 
 #ifndef HAVE_WIRINGPI_H
@@ -564,6 +567,7 @@
 int main(int argc, char *argv[])
 {
     int		rc = 0, c, i;
+    char	*homepath = NULL;
 
     while (1) {
 	int option_index = 0;
@@ -590,6 +594,22 @@
     if (debug)
 	fprintf(stdout, "mbsePi-apps brewco v%s starting\n", VERSION);
 
+    /*
+     * Set home directory path
+     */
+    if (getenv((char *)"USER") == NULL) {
+	homepath = xstrcpy((char *)"/root");
+    } else {
+	homepath = xstrcpy(getenv((char *)"HOME"));
+    }
+    varpath = xstrcpy(homepath);
+    varpath = xstrcat(varpath, (char *)"/.brewco/var/");
+    etcpath = xstrcpy(homepath);
+    etcpath = xstrcat(etcpath, (char *)"/.brewco/etc/");
+    mkdirs(varpath, 0755);
+    mkdirs(etcpath, 0755);
+
+fprintf(stdout, "home: %s etc=%s var=%s\n", homepath, etcpath, varpath);
     if (rdconfig()) {
 	fprintf(stderr, "Error reading configuration\n");
 	syslog(LOG_NOTICE, "Error reading configuration: halted");

mercurial