Skip to content

gvfs-helper-client: clean up server process #756

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: vfs-2.49.0
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions gvfs-helper-client.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,39 @@ static struct object_directory *gh_client__chosen_odb;
#define CAP_OBJECTS__VERB_POST_NAME "post"
#define CAP_OBJECTS__VERB_PREFETCH_NAME "prefetch"

static void stop_gh_server_subprocesses(void)
{
struct gh_server__process *entry, **entries;
struct hashmap_iter iter;
size_t i = 0, size;

if (!gh_server__subprocess_map_initialized)
return;

/*
* Since `subprocess_stop()` modifies the hashmap by removing the
* respective subprocess, we cannot use `hashmap_for_each_entry()`
* directly, but have to copy the entries to an array first.
*/
size = hashmap_get_size(&gh_server__subprocess_map);
ALLOC_ARRAY(entries, size);
hashmap_for_each_entry(&gh_server__subprocess_map,
&iter, entry, subprocess)
entries[i++] = entry;
if (i != size)
BUG("gh_server__subprocess_map: size mismatch: "
"%"PRIuMAX" != %"PRIuMAX,
(uintmax_t)i, (uintmax_t)size);
while(i--)
subprocess_stop(&gh_server__subprocess_map,
&entries[i]->subprocess);
FREE_AND_NULL(entries);

hashmap_clear_and_free(&gh_server__subprocess_map,
struct gh_server__process, subprocess);
gh_server__subprocess_map_initialized = 0;
}

static int gh_client__start_fn(struct subprocess_entry *subprocess)
{
static int versions[] = {1, 0};
Expand All @@ -48,6 +81,8 @@ static int gh_client__start_fn(struct subprocess_entry *subprocess)

struct gh_server__process *entry = (struct gh_server__process *)subprocess;

atexit(stop_gh_server_subprocesses);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should move this all the way into the cmd_main() function, to be 100% sure that it is registered, and registered one time only?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That could work, or I could add a static int registered = 0; into this method. This is definitely on the critical path for starting a process.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I do not understand is: the previous location was in the code path that initializes the hashmap, and the new location is in the gh_client__start_fn() function which is passed as a callback a couple lines further down from the previous location. So how is it possible that it was not called early enough in the previous location but it is early enough in the new location?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was also confused by this, since I specifically traced that the hashing location was being called but somehow wasn't sticking. I'll look into it some more later this week.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!


return subprocess_handshake(subprocess, "gvfs-helper", versions,
NULL, capabilities,
&entry->supported_capabilities);
Expand Down
Loading