]> git.alsa-project.org Git - alsa-utils.git/commitdiff
alsactl: add -L (no-lock) and change -D (lock-dir) to -O (state-lock-file)
authorJaroslav Kysela <perex@perex.cz>
Wed, 7 May 2014 09:13:41 +0000 (11:13 +0200)
committerJaroslav Kysela <perex@perex.cz>
Wed, 7 May 2014 09:20:16 +0000 (11:20 +0200)
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
alsactl/Makefile.am
alsactl/alsactl.1
alsactl/alsactl.c
alsactl/alsactl.h
alsactl/lock.c

index 5ec3b804819b2a076a8277340b8ef514cfb14a04..b8624126e5d764a43d144905a5afd610e38555e3 100644 (file)
@@ -12,7 +12,7 @@ alsactl_SOURCES=alsactl.c state.c lock.c utils.c init_parse.c daemon.c \
 
 alsactl_CFLAGS=$(AM_CFLAGS) -D__USE_GNU \
                -DSYS_ASOUNDRC=\"$(ASOUND_STATE_DIR)/asound.state\" \
-               -DSYS_LOCKPATH=\"$(ASOUND_LOCK_DIR)\" \
+               -DSYS_LOCKFILE=\"$(ASOUND_LOCK_DIR)/asound.state.lock\" \
                -DSYS_PIDFILE=\"$(ALSACTL_PIDFILE_DIR)/alsactl.pid\"
 
 noinst_HEADERS=alsactl.h list.h init_sysdeps.c init_utils_string.c \
index b1e17945c2fb76fb7a57c17114d97061495f5fcd..c515fdde7e2be4aa34f8d62364ceca05c0096b92 100644 (file)
@@ -1,4 +1,4 @@
-.TH ALSACTL 1 "05 Apr 2013"
+.TH ALSACTL 1 "07 May 2014"
 .SH NAME
 alsactl \- advanced controls for ALSA soundcard driver
 
@@ -60,6 +60,20 @@ Print alsactl version number.
 \fI\-f, \-\-file\fP
 Select the configuration file to use. The default is /var/lib/alsa/asound.state.
 
+.TP
+\fI\-l, \-\-lock\fP
+Use the file locking to serialize the concurrent access to the state file (this
+option is default for the global state file).
+
+.TP
+\fI\-L, \-\-no-lock\fP
+Do not use the file locking to serialize the concurrent access to the state
+file (including the global state file).
+
+.TP
+\fI\-O, \-\-lock-state-file\fP
+Select the state lock file path.
+
 .TP
 \fI\-F, \-\-force\fP
 Used with restore command.  Try to restore the matching control elements
index 415dfb8fe2219bac2873bb66958fdb3406bc9821..bcbc187ad623d48e943dc88fc092e6587b44a560 100644 (file)
@@ -49,7 +49,7 @@ int do_lock = 0;
 int use_syslog = 0;
 char *command;
 char *statefile = NULL;
-char *lockpath = SYS_LOCKPATH;
+char *lockfile = SYS_LOCKFILE;
 
 #define TITLE  0x0100
 #define HEADER 0x0200
@@ -75,7 +75,8 @@ static struct arg args[] = {
 { 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 ")" },
+{ 'L', "no-lock", "do not use file locking to serialize concurrent access" },
+{ FILEARG | 'O', "lock-state-file", "state lock file path (default " SYS_LOCKFILE ")" },
 { 'F', "force", "try to restore the matching controls as much as possible" },
 { 0, NULL, "  (default mode)" },
 { 'g', "ignore", "ignore 'No soundcards found' error" },
@@ -237,8 +238,12 @@ int main(int argc, char *argv[])
                case 'l':
                        do_lock = 1;
                        break;
-               case 'D':
-                       lockpath = optarg;
+               case 'L':
+                       do_lock = -1;
+                       break;
+               case 'O':
+                       lockfile = optarg;
+                       break;
                case 'F':
                        force_restore = 1;
                        break;
@@ -331,7 +336,7 @@ int main(int argc, char *argv[])
        }
 
        /* the global system file should be always locked */
-       if (strcmp(cfgfile, SYS_ASOUNDRC) == 0)
+       if (strcmp(cfgfile, SYS_ASOUNDRC) == 0 && do_lock >= 0)
                do_lock = 1;
 
        /* when running in background, use syslog for reports */
index 6c6bee58e51826b43f0c54a97bf0bc92a5a33c2d..76e8c36100f9f43229270b718ce68e7eba0eef86 100644 (file)
@@ -5,7 +5,7 @@ extern int do_lock;
 extern int use_syslog;
 extern char *command;
 extern char *statefile;
-extern char *lockpath;
+extern char *lockfile;
 
 void info_(const char *fcn, long line, const char *fmt, ...);
 void error_(const char *fcn, long line, const char *fmt, ...);
index c69e285c20e04b37000346113c7a0cdcd6233516..6f85f202576dcf3e64967d84fb8698f99b850ffa 100644 (file)
@@ -36,24 +36,11 @@ static int state_lock_(const char *file, int lock, int timeout)
        struct flock lck;
        struct stat st;
        char lcktxt[12];
-       char *filename;
-       char *nfile;
+       char *nfile = lockfile;
 
-       if (!do_lock)
+       if (do_lock <= 0)
                return 0;
 
-       /* 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;
-       }
-
-       sprintf(nfile, "%s/%s.lock", lockpath, filename);
        lck.l_type = lock ? F_WRLCK : F_UNLCK;
        lck.l_whence = SEEK_SET;
        lck.l_start = 0;
@@ -114,7 +101,6 @@ static int state_lock_(const char *file, int lock, int timeout)
                goto out;
        }
 out:
-       free(nfile);
        return err;
 }