summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Ancell <robert.ancell@canonical.com>2013-06-17 17:41:05 +1200
committerRobert Ancell <robert.ancell@canonical.com>2013-06-17 17:41:05 +1200
commit416ec8a1bfb8b79d769b9d2557df785d63dacc4d (patch)
tree4e1938eef10f274857ff1480c3d21e6a7b762b12
parent9df2edd82edde4c8a1b0793b529d5ddcc1a40c70 (diff)
downloadlightdm-git-416ec8a1bfb8b79d769b9d2557df785d63dacc4d.tar.gz
Don't write X authority with g_file_set_contents - it can leave intermediate files around if it is interrupted.
-rw-r--r--src/xauthority.c39
1 files changed, 25 insertions, 14 deletions
diff --git a/src/xauthority.c b/src/xauthority.c
index 21d7457a..08a56886 100644
--- a/src/xauthority.c
+++ b/src/xauthority.c
@@ -10,6 +10,7 @@
*/
#include <string.h>
+#include <stdio.h>
#include <errno.h>
#include <unistd.h>
#include <sys/stat.h>
@@ -210,37 +211,37 @@ read_string (gchar *data, gsize data_length, gsize *offset, gchar **value)
}
static void
-write_uint16 (GByteArray *data, guint16 value)
+write_uint16 (FILE *file, guint16 value)
{
guint8 v[2];
v[0] = value >> 8;
v[1] = value & 0xFF;
- g_byte_array_append (data, v, 2);
+ fwrite (v, 2, 1, file);
}
static void
-write_data (GByteArray *data, const guint8 *value, gsize value_length)
+write_data (FILE *file, const guint8 *value, gsize value_length)
{
- g_byte_array_append (data, value, value_length);
+ fwrite (value, value_length, 1, file);
}
static void
-write_string (GByteArray *data, const gchar *value)
+write_string (FILE *file, const gchar *value)
{
- write_uint16 (data, strlen (value));
- write_data (data, (guint8 *) value, strlen (value));
+ write_uint16 (file, strlen (value));
+ write_data (file, (guint8 *) value, strlen (value));
}
gboolean
xauth_write (XAuthority *auth, XAuthWriteMode mode, const gchar *filename, GError **error)
{
gchar *input;
- gsize input_length = 0, input_offset = 0;
+ gsize input_length = 0, input_offset = 0, offset;
GList *link, *records = NULL;
XAuthority *a;
gboolean result;
gboolean matched = FALSE;
- GByteArray *output;
+ FILE *output;
g_return_val_if_fail (auth != NULL, FALSE);
g_return_val_if_fail (filename != NULL, FALSE);
@@ -311,8 +312,19 @@ xauth_write (XAuthority *auth, XAuthWriteMode mode, const gchar *filename, GErro
records = g_list_append (records, g_object_ref (auth));
/* Write records back */
- result = TRUE;
- output = g_byte_array_new ();
+ errno = 0;
+ output = fopen (filename, "w");
+ if (output == NULL)
+ {
+ g_set_error (error,
+ G_FILE_ERROR,
+ g_file_error_from_errno (errno),
+ "Failed to write X authority %s: %s",
+ filename,
+ g_strerror (errno));
+ return FALSE;
+ }
+
for (link = records; link && result; link = link->next)
{
XAuthority *a = link->data;
@@ -329,10 +341,9 @@ xauth_write (XAuthority *auth, XAuthWriteMode mode, const gchar *filename, GErro
}
g_list_free (records);
- result = g_file_set_contents (filename, output->data, output->len, error);
- g_byte_array_free (output, TRUE);
+ fclose (output);
- return result;
+ return TRUE;
}
static void