xwayland: Use g_get_host_name instead of gethostname

Since the xauth file is never going to be changed after it is generated,
it is safe to use g_get_host_name here.

https://gitlab.gnome.org/GNOME/mutter/merge_requests/626
https://gitlab.gnome.org/GNOME/mutter/merge_requests/638
This commit is contained in:
Ting-Wei Lan 2019-06-23 23:44:05 +08:00 committed by Jonas Ådahl
parent 181c7cab32
commit c35e56196a

View File

@ -452,7 +452,6 @@ prepare_auth_file (MetaXWaylandManager *manager)
{ {
Xauth auth_entry = { 0 }; Xauth auth_entry = { 0 };
g_autoptr (FILE) fp = NULL; g_autoptr (FILE) fp = NULL;
char hostname[HOST_NAME_MAX + 1];
char auth_data[16]; char auth_data[16];
int fd; int fd;
@ -460,9 +459,6 @@ prepare_auth_file (MetaXWaylandManager *manager)
".mutter-Xwaylandauth.XXXXXX", ".mutter-Xwaylandauth.XXXXXX",
NULL); NULL);
if (gethostname (hostname, HOST_NAME_MAX) < 0)
g_strlcpy (hostname, "localhost", HOST_NAME_MAX);
if (getrandom (auth_data, sizeof (auth_data), 0) != sizeof (auth_data)) if (getrandom (auth_data, sizeof (auth_data), 0) != sizeof (auth_data))
{ {
g_warning ("Failed to get random data: %s", g_strerror (errno)); g_warning ("Failed to get random data: %s", g_strerror (errno));
@ -470,7 +466,7 @@ prepare_auth_file (MetaXWaylandManager *manager)
} }
auth_entry.family = FamilyLocal; auth_entry.family = FamilyLocal;
auth_entry.address = hostname; auth_entry.address = (char *) g_get_host_name ();
auth_entry.address_length = strlen (auth_entry.address); auth_entry.address_length = strlen (auth_entry.address);
auth_entry.name = (char *) "MIT-MAGIC-COOKIE-1"; auth_entry.name = (char *) "MIT-MAGIC-COOKIE-1";
auth_entry.name_length = strlen (auth_entry.name); auth_entry.name_length = strlen (auth_entry.name);