Comment 9 for bug 1224410

Revision history for this message
Jussi Pakkanen (jpakkane) wrote :

There may be a threading issue here. Feel free to try it yourself with the code below. Here are the steps:

- run in gdb, add a break to main
- step over the call to do_test so you are on the line that says "return 0"
- in a terminal determine the process id of the program
- ls /proc/process_id/fd

Sometimes you get this:

lrwx------ 1 jpakkane jpakkane 64 syys 12 16:48 0 -> /dev/pts/4
lrwx------ 1 jpakkane jpakkane 64 syys 12 16:48 1 -> /dev/pts/4
lrwx------ 1 jpakkane jpakkane 64 syys 12 16:48 10 -> socket:[61063]
lrwx------ 1 jpakkane jpakkane 64 syys 12 16:48 11 -> anon_inode:[eventfd]
lrwx------ 1 jpakkane jpakkane 64 syys 12 16:48 12 -> anon_inode:[eventfd]
l-wx------ 1 jpakkane jpakkane 64 syys 12 16:48 13 -> /tmp/grilo-plugin-cache-7ODM3W/1814837434
lrwx------ 1 jpakkane jpakkane 64 syys 12 16:48 2 -> /dev/pts/4
lrwx------ 1 jpakkane jpakkane 64 syys 12 16:48 3 -> socket:[66649]
lrwx------ 1 jpakkane jpakkane 64 syys 12 16:48 4 -> socket:[66650]
lr-x------ 1 jpakkane jpakkane 64 syys 12 16:48 5 -> pipe:[66651]
l-wx------ 1 jpakkane jpakkane 64 syys 12 16:48 6 -> pipe:[66651]
lrwx------ 1 jpakkane jpakkane 64 syys 12 16:48 7 -> anon_inode:[eventfd]

Note the fd open to grilo-plugin cache.

Other times you get this:

lrwx------ 1 jpakkane jpakkane 64 syys 12 16:47 0 -> /dev/pts/4
lrwx------ 1 jpakkane jpakkane 64 syys 12 16:48 1 -> /dev/pts/4
lrwx------ 1 jpakkane jpakkane 64 syys 12 16:48 10 -> socket:[66165]
lrwx------ 1 jpakkane jpakkane 64 syys 12 16:48 11 -> anon_inode:[eventfd]
lrwx------ 1 jpakkane jpakkane 64 syys 12 16:48 12 -> anon_inode:[eventfd]
lrwx------ 1 jpakkane jpakkane 64 syys 12 16:48 2 -> /dev/pts/4
lrwx------ 1 jpakkane jpakkane 64 syys 12 16:48 3 -> socket:[66649]
lrwx------ 1 jpakkane jpakkane 64 syys 12 16:48 4 -> socket:[66650]
lr-x------ 1 jpakkane jpakkane 64 syys 12 16:48 5 -> pipe:[66651]
l-wx------ 1 jpakkane jpakkane 64 syys 12 16:48 6 -> pipe:[66651]
lrwx------ 1 jpakkane jpakkane 64 syys 12 16:48 7 -> anon_inode:[eventfd]

In this case there is no open fd to the cache file. The behaviour is undeteministic.

Here's the code:

#include<cstdio>
#include<grilo.h>
#include<string>

using namespace std;

GrlRegistry* setup() {
  GrlRegistry *registry = grl_registry_get_default();
  if (!registry) {
    printf("Could not get registry.\n");
    return 0;
  }
  GrlConfig *config = grl_config_new("grl-lastfm-albumart", "grl-lastfm-albumart");
  if (!config) {
    printf("Could not create config.\n");
    return 0;
  }
  if(!grl_registry_add_config(registry, config, 0)) {
    printf("Could not add config.\n");
    return 0;
  }
  if(!grl_registry_load_plugin_by_id(registry, "grl-lastfm-albumart", 0)) {
    printf("Could not load plugin.\n");
    return 0;
  }
  return registry;
}

void print_sources() {
  GrlRegistry *registry = setup();
  if(!registry)
    return;
  printf("List of plugins:\n");
  GList *orig_list = grl_registry_get_sources(registry, 0);
  for(GList *list = orig_list; list != 0; list = list->next) {
    GrlSource *src = (GrlSource*)list->data;
    printf("%s\n", grl_source_get_name(src));
  }
  g_list_free(orig_list);
}

void do_test() {
  string id("grl-lastfm-albumart");
  GrlRegistry *registry = setup();
  if (!registry) {
    printf("Could not get registry.\n");
    return;
  }
  GrlSource *source = grl_registry_lookup_source(registry, id.c_str());
  if (!source) {
    printf("Could not get source.\n");
    return;
  }
  if ((grl_source_supported_operations (source) &
             GRL_OP_RESOLVE) == 0) {
    printf("Metadata source doesn't support metadata resolution.");
    return;
  }
  GrlPlugin *const plugin = grl_source_get_plugin(source);

  printf("Using %s from %s to resolve metadata.\n",
    id.c_str(), grl_plugin_get_filename(plugin));
  GrlMedia *m = grl_media_audio_new();
  GrlData *d = GRL_DATA(m);
  if(!d) {
    printf("Suck.\n");
    return;
  }
  GrlOperationOptions *opts = grl_operation_options_new(0);
  GList *keylist = 0;
  GrlMedia *result;
  keylist = g_list_append(keylist,
                          GRLKEYID_TO_POINTER(GRL_METADATA_KEY_THUMBNAIL));
  grl_data_set_string(d, GRL_METADATA_KEY_ARTIST, "Butterfingers");
  grl_data_set_string(d, GRL_METADATA_KEY_ALBUM, "Breakfast at Fatboys");
  result = grl_source_resolve_sync(source, m, keylist, opts, 0);
  g_list_free(keylist);
  g_object_unref(G_OBJECT(opts));
  if(!grl_data_has_key(GRL_DATA(result), GRL_METADATA_KEY_THUMBNAIL)) {
    printf("Thumbnail not resolved.\n");
  } else {
    printf("Thumbnail resolved.\n");
  }
  g_object_unref(G_OBJECT(result));
}

int main(int argc, char **argv) {
  grl_init(&argc, &argv);
  do_test();
  //print_sources();
  return 0;
}