Replace the plugin atomically instead of writing in-place

To say nothing of atomicity, lots of Bad Things happen when you replace
libraries in-place. gdb apparently gets upset at you, and you get random
crashes in programs which have the library loaded. Evidently libdl.so
can't even handle it. It's unspecified whether changes to a file mmapped
as MAP_PRIVATE are visible to the process.

Fixes #35.
This commit is contained in:
David Benjamin 2011-08-16 10:14:50 -07:00
parent 37b70dee71
commit f40a1f6089
1 changed files with 4 additions and 7 deletions

View File

@ -721,13 +721,10 @@ static int do_install_plugin(const char *plugin_path, const char *plugin_dir, NP
!is_root_only_accessible_plugin(plugin_dir))
mode = 0755;
int d_fd = open(d_plugin_path, O_CREAT | O_WRONLY, mode);
if (d_fd < 0)
return 4;
if (write(d_fd, plugin_data, w_size) != w_size)
return 13;
close(d_fd);
// TODO: Don't swallow the error message. Also get rid of these ridiculous
// return codes. They're never acted on anyway. Use GError or something.
if (!g_file_set_contents(d_plugin_path, plugin_data, w_size, NULL))
return 4;
if (g_verbose)
printf(" into %s\n", d_plugin_path);