#ifndef SYS_PIDFILE
#define SYS_PIDFILE "/var/run/alsactl.pid"
#endif
+#ifndef SYS_LOCKPATH
+#define SYS_LOCKPATH "/var/lock"
+#endif
int debugflag = 0;
int force_restore = 1;
int use_syslog = 0;
char *command;
char *statefile = NULL;
+char *lockpath = SYS_LOCKPATH;
#define TITLE 0x0100
#define HEADER 0x0200
{ HEADER, NULL, "Available state options:" },
{ FILEARG | 'f', "file", "configuration file (default " SYS_ASOUNDRC ")" },
{ 'l', "lock", "use file locking to serialize concurrent access" },
+{ FILEARG | 'D', "lock-dir", "directory to use for lock files (default " SYS_LOCKPATH ")" },
{ 'F', "force", "try to restore the matching controls as much as possible" },
{ 0, NULL, " (default mode)" },
{ 'g', "ignore", "ignore 'No soundcards found' error" },
case 'l':
do_lock = 1;
break;
+ case 'D':
+ lockpath = optarg;
case 'F':
force_restore = 1;
break;
extern int use_syslog;
extern char *command;
extern char *statefile;
+extern char *lockpath;
void info_(const char *fcn, long line, const char *fmt, ...);
void error_(const char *fcn, long line, const char *fmt, ...);
struct flock lck;
struct stat st;
char lcktxt[12];
+ char *filename;
char *nfile;
if (!do_lock)
return 0;
- nfile = malloc(strlen(file) + 6);
+
+ /* only use the actual filename, not the path */
+ filename = strrchr(file, '/');
+ if (!filename)
+ filename = file;
+
+ nfile = malloc(strlen(lockpath) + strlen(filename) + 7);
if (nfile == NULL) {
error("No enough memory...");
return -ENOMEM;
}
- strcpy(nfile, file);
- strcat(nfile, ".lock");
+
+ sprintf(nfile, "%s/%s.lock", lockpath, filename);
lck.l_type = lock ? F_WRLCK : F_UNLCK;
lck.l_whence = SEEK_SET;
lck.l_start = 0;