thermferm/rdconfig.c

changeset 55
11d7cc3bdf31
parent 54
c06190a58f22
child 56
f7711c6ac93c
equal deleted inserted replaced
54:c06190a58f22 55:11d7cc3bdf31
118 int rc = 0; 118 int rc = 0;
119 FILE *fp; 119 FILE *fp;
120 w1_therm *tmp1; 120 w1_therm *tmp1;
121 rc_switch *tmp2; 121 rc_switch *tmp2;
122 122
123 mypath = xstrcpy(getenv((char *)"HOME")); 123 if (getenv((char *)"HOME") == NULL) {
124 mypath = xstrcpy((char *)"/root");
125 } else {
126 mypath = xstrcpy(getenv((char *)"HOME"));
127 }
124 mypath = xstrcat(mypath, (char *)"/mbsepi-apps/"); 128 mypath = xstrcat(mypath, (char *)"/mbsepi-apps/");
125 mypath = xstrcat(mypath, config); 129 mypath = xstrcat(mypath, config);
126 130
127 if (debug) 131 if (debug)
128 fprintf(stdout, "Writing %s\n", mypath); 132 fprintf(stdout, "Writing %s\n", mypath);
200 killconfig(); 204 killconfig();
201 205
202 /* 206 /*
203 * Search config file 207 * Search config file
204 */ 208 */
205 mypath = xstrcpy(getenv((char *)"HOME")); 209 if (getenv((char *)"HOME") == NULL) {
210 mypath = xstrcpy((char *)"/root");
211 } else {
212 mypath = xstrcpy(getenv((char *)"HOME"));
213 }
206 mypath = xstrcat(mypath, (char *)"/mbsepi-apps/"); 214 mypath = xstrcat(mypath, (char *)"/mbsepi-apps/");
207 mypath = xstrcat(mypath, config); 215 mypath = xstrcat(mypath, config);
208 if ((fp = fopen(mypath, "r")) == NULL) { 216 if ((fp = fopen(mypath, "r")) == NULL) {
209 /* 217 /*
210 * Not in the users home directory 218 * Not in the users home directory
218 */ 226 */
219 free(mypath); 227 free(mypath);
220 mypath = xstrcpy((char *)"/usr/local/etc/mbsepi-apps/"); 228 mypath = xstrcpy((char *)"/usr/local/etc/mbsepi-apps/");
221 mypath = xstrcat(mypath, config); 229 mypath = xstrcat(mypath, config);
222 if ((fp = fopen(mypath, "r")) == NULL) { 230 if ((fp = fopen(mypath, "r")) == NULL) {
223 syslog(LOG_NOTICE, "rdconfig: could not open %s", mypath); 231 syslog(LOG_NOTICE, "rdconfig: could find %s", config);
224 return 1; 232 return 1;
225 } 233 }
226 } 234 }
227 } 235 }
236 syslog(LOG_NOTICE, "rdconfig: using %s", mypath);
228 237
229 linecnt = 0; 238 linecnt = 0;
230 while (fgets(buf, sizeof(buf) -1, fp)) { 239 while (fgets(buf, sizeof(buf) -1, fp)) {
231 linecnt++; 240 linecnt++;
232 if (*(p = buf + strlen(buf) -1) != '\n') { 241 if (*(p = buf + strlen(buf) -1) != '\n') {

mercurial