# HG changeset patch # User Michiel Broek # Date 1450641157 -3600 # Node ID 3aac3276689d4ad14e48b0f3341161aa91963d8d # Parent 4a624c071ca9f8e5625176cdcb2c9b711beeed0e Added program locking. diff -r 4a624c071ca9 -r 3aac3276689d brewco/brewco.c --- a/brewco/brewco.c Sun Dec 20 20:37:40 2015 +0100 +++ b/brewco/brewco.c Sun Dec 20 20:52:37 2015 +0100 @@ -282,10 +282,10 @@ slcdCharDef(slcdHandle, 6, RevHeatONOFF); slcdCharDef(slcdHandle, 7, Language); -// if (lockprog((char *)"brewco")) { -// syslog(LOG_NOTICE, "Can't lock"); -// return 1; -// } + if (lockprog((char *)"brewco")) { + syslog(LOG_NOTICE, "Can't lock"); + return 1; + } if (debug) fprintf(stdout, "Begin server()\n"); @@ -558,7 +558,7 @@ wrrecipes(); wrconfig(); -// ulockprog((char *)"brewco"); + ulockprog((char *)"brewco"); return 0; } @@ -609,7 +609,6 @@ 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"); diff -r 4a624c071ca9 -r 3aac3276689d brewco/lock.c --- a/brewco/lock.c Sun Dec 20 20:37:40 2015 +0100 +++ b/brewco/lock.c Sun Dec 20 20:52:37 2015 +0100 @@ -23,6 +23,9 @@ #include "lock.h" #include "brewco.h" +extern char *varpath; + + /* * Put a lock on this program. */ @@ -35,8 +38,8 @@ tempfile = calloc(PATH_MAX, sizeof(char)); lockfile = calloc(PATH_MAX, sizeof(char)); - snprintf(tempfile, PATH_MAX, "/var/run/%s.tmp", name); - snprintf(lockfile, PATH_MAX, "/var/run/%s.pid", name); + snprintf(tempfile, PATH_MAX, "%s%s.tmp", varpath, name); + snprintf(lockfile, PATH_MAX, "%s%s.pid", varpath, name); if ((fp = fopen(tempfile, "w")) == NULL) { perror(name); @@ -105,7 +108,7 @@ FILE *fp; lockfile = calloc(PATH_MAX, sizeof(char)); - snprintf(lockfile, PATH_MAX, "/var/run/%s.pid", name); + snprintf(lockfile, PATH_MAX, "%s%s.pid", varpath, name); if ((fp = fopen(lockfile, "r")) == NULL) { syslog(LOG_NOTICE, "Can't open lockfile \"%s\"", lockfile); diff -r 4a624c071ca9 -r 3aac3276689d brewco/rdconfig.c --- a/brewco/rdconfig.c Sun Dec 20 20:37:40 2015 +0100 +++ b/brewco/rdconfig.c Sun Dec 20 20:52:37 2015 +0100 @@ -1284,12 +1284,12 @@ /* * Make upto 10 backups of the configuration. */ - fpath = calloc(1024, sizeof(char)); - tpath = calloc(1024, sizeof(char)); + fpath = calloc(PATH_MAX, sizeof(char)); + tpath = calloc(PATH_MAX, sizeof(char)); for (i = 9; i > 0; i--) { - snprintf(tpath, 1023, "%s.%d", mypath, i+1); - snprintf(fpath, 1023, "%s.%d", mypath, i); + snprintf(tpath, PATH_MAX, "%s.%d", mypath, i+1); + snprintf(fpath, PATH_MAX, "%s.%d", mypath, i); if (file_exist(fpath, R_OK) == 0) { unlink(tpath); if (file_cp(fpath, tpath)) { @@ -1297,8 +1297,8 @@ } } } - snprintf(tpath, 1023, "%s.1", mypath); - snprintf(fpath, 1023, "%s", mypath); + snprintf(tpath, PATH_MAX, "%s.1", mypath); + snprintf(fpath, PATH_MAX, "%s", mypath); if (file_exist(fpath, R_OK) == 0) { unlink(tpath); if (file_cp(fpath, tpath)) {