Skip to contentSkip to conversation

Restore PID to jack client name when not specified explicitly

PATCH Applied [email protected] 2 participants 2 messages Aug 8, 2014 – Aug 12, 2014

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Restore PID to jack client name when not specified explicitly

From: Branan Purvine-Riley <[email protected]>

Commit 14190cd8 added a facility to explicitly name Jack clients with a 'name' option, but did so in a way that was not fully backwards-compatible with older versions of the alsa-plugins. There were two issues:

1. Re-using the magical "name" variable, which comes preloaded with the name of the PCM

2. The code assumed snd_config_get_string sets a variable to NULL if the config entry does not exist. Instead, this function leaves the variable unchanged.

The result of these two errors meant that the PCM name would be treated as if it were a user-defined name, and the old code which embedded the PID would never be run

This code uses a completely new variable to store the explicitly-set client name, so that the two code paths no longer collide.

jack/pcm_jack.c +6 -4
index f5b7129..33f87b1 100644
@@ -372,6 +372,7 @@ static int make_nonblock(int fd)
 }
 
 static int snd_pcm_jack_open(snd_pcm_t **pcmp, const char *name,
+			     const char* client_name,
 			     snd_config_t *playback_conf,
 			     snd_config_t *capture_conf,
 			     snd_pcm_stream_t stream, int mode)
@@ -405,14 +406,14 @@ static int snd_pcm_jack_open(snd_pcm_t **pcmp, const char *name,
 		return -EINVAL;
 	}
 
-	if (name == NULL)
+	if (client_name == NULL)
 		err = snprintf(jack_client_name, sizeof(jack_client_name),
 			       "alsa-jack.%s%s.%d.%d", name,
 			       stream == SND_PCM_STREAM_PLAYBACK ? "P" : "C",
 			       getpid(), num++);
 	else
 		err = snprintf(jack_client_name, sizeof(jack_client_name),
-			       "%s", name);
+			       "%s", client_name);
 
 	if (err >= (int)sizeof(jack_client_name)) {
 		fprintf(stderr, "%s: WARNING: JACK client name '%s' truncated to %d characters, might not be unique\n",
@@ -470,6 +471,7 @@ SND_PCM_PLUGIN_DEFINE_FUNC(jack)
 	snd_config_iterator_t i, next;
 	snd_config_t *playback_conf = NULL;
 	snd_config_t *capture_conf = NULL;
+	const char* client_name = NULL;
 	int err;
 	
 	snd_config_for_each(i, next, conf) {
@@ -480,7 +482,7 @@ SND_PCM_PLUGIN_DEFINE_FUNC(jack)
 		if (strcmp(id, "comment") == 0 || strcmp(id, "type") == 0 || strcmp(id, "hint") == 0)
 			continue;
 		if (strcmp(id, "name") == 0) {
-			snd_config_get_string(n, &name);
+			snd_config_get_string(n, &client_name);
 			continue;
 		}
 		if (strcmp(id, "playback_ports") == 0) {
@@ -503,7 +505,7 @@ SND_PCM_PLUGIN_DEFINE_FUNC(jack)
 		return -EINVAL;
 	}
 
-	err = snd_pcm_jack_open(pcmp, name, playback_conf, capture_conf, stream, mode);
+	err = snd_pcm_jack_open(pcmp, name, client_name, playback_conf, capture_conf, stream, mode);
 
 	return err;
 }
Signature · 1 line
2.0.4
Applied
#1 lore raw

At Fri, 8 Aug 2014 14:31:06 -0700,

Quoted 15 lines · [email protected] wrote:

From: Branan Purvine-Riley <[email protected]>

Commit 14190cd8 added a facility to explicitly name Jack clients with a 'name' option, but did so in a way that was not fully backwards-compatible with older versions of the alsa-plugins. There were two issues:

1. Re-using the magical "name" variable, which comes preloaded with the name of the PCM

2. The code assumed snd_config_get_string sets a variable to NULL if the config entry does not exist. Instead, this function leaves the variable unchanged.

Quoted 8 lines

The result of these two errors meant that the PCM name would be treated as if it were a user-defined name, and the old code which embedded the PID would never be run

This code uses a completely new variable to store the explicitly-set client name, so that the two code paths no longer collide.

Thanks, applied.

Takashi

Quoted 59 lines
jack/pcm_jack.c +6 -4
index f5b7129..33f87b1 100644
@@ -372,6 +372,7 @@ static int make_nonblock(int fd)
 }
 
 static int snd_pcm_jack_open(snd_pcm_t **pcmp, const char *name,
+			     const char* client_name,
 			     snd_config_t *playback_conf,
 			     snd_config_t *capture_conf,
 			     snd_pcm_stream_t stream, int mode)
@@ -405,14 +406,14 @@ static int snd_pcm_jack_open(snd_pcm_t **pcmp, const char *name,
 		return -EINVAL;
 	}
 
-	if (name == NULL)
+	if (client_name == NULL)
 		err = snprintf(jack_client_name, sizeof(jack_client_name),
 			       "alsa-jack.%s%s.%d.%d", name,
 			       stream == SND_PCM_STREAM_PLAYBACK ? "P" : "C",
 			       getpid(), num++);
 	else
 		err = snprintf(jack_client_name, sizeof(jack_client_name),
-			       "%s", name);
+			       "%s", client_name);
 
 	if (err >= (int)sizeof(jack_client_name)) {
 		fprintf(stderr, "%s: WARNING: JACK client name '%s' truncated to %d characters, might not be unique\n",
@@ -470,6 +471,7 @@ SND_PCM_PLUGIN_DEFINE_FUNC(jack)
 	snd_config_iterator_t i, next;
 	snd_config_t *playback_conf = NULL;
 	snd_config_t *capture_conf = NULL;
+	const char* client_name = NULL;
 	int err;
 
 	snd_config_for_each(i, next, conf) {
@@ -480,7 +482,7 @@ SND_PCM_PLUGIN_DEFINE_FUNC(jack)
 		if (strcmp(id, "comment") == 0 || strcmp(id, "type") == 0 || strcmp(id, "hint") == 0)
 			continue;
 		if (strcmp(id, "name") == 0) {
-			snd_config_get_string(n, &name);
+			snd_config_get_string(n, &client_name);
 			continue;
 		}
 		if (strcmp(id, "playback_ports") == 0) {
@@ -503,7 +505,7 @@ SND_PCM_PLUGIN_DEFINE_FUNC(jack)
 		return -EINVAL;
 	}
 
-	err = snd_pcm_jack_open(pcmp, name, playback_conf, capture_conf, stream, mode);
+	err = snd_pcm_jack_open(pcmp, name, client_name, playback_conf, capture_conf, stream, mode);
 
 	return err;
 }
Signature · 1 line
2.0.4