Merge lp:~robert-ancell/lightdm/xauth-no-g_file_set_contents into lp:lightdm

Proposed by Robert Ancell on 2013-06-10
Status: Merged
Approved by: Robert Ancell on 2013-06-10
Approved revision: 1675
Merged at revision: 1675
Proposed branch: lp:~robert-ancell/lightdm/xauth-no-g_file_set_contents
Merge into: lp:lightdm
Diff against target: 101 lines (+33/-22)
1 file modified
src/xauthority.c (+33/-22)
To merge this branch: bzr merge lp:~robert-ancell/lightdm/xauth-no-g_file_set_contents
Reviewer Review Type Date Requested Status
Robert Ancell Approve on 2013-06-10
PS Jenkins bot continuous-integration Approve on 2013-06-10
Review via email: mp+168349@code.launchpad.net

Commit message

Don't write X authority with g_file_set_contents - it can leave intermediate files around if it is interrupted

To post a comment you must log in.
PS Jenkins bot (ps-jenkins) wrote :

PASSED: Continuous integration, rev:1675
http://jenkins.qa.ubuntu.com/job/lightdm-ci/54/
Executed test runs:
    SUCCESS: http://jenkins.qa.ubuntu.com/job/lightdm-raring-amd64-ci/48

Click here to trigger a rebuild:
http://s-jenkins:8080/job/lightdm-ci/54/rebuild

review: Approve (continuous-integration)
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/xauthority.c'
2--- src/xauthority.c 2013-04-18 13:57:46 +0000
3+++ src/xauthority.c 2013-06-10 05:12:24 +0000
4@@ -10,6 +10,7 @@
5 */
6
7 #include <string.h>
8+#include <stdio.h>
9 #include <errno.h>
10 #include <unistd.h>
11 #include <sys/stat.h>
12@@ -210,37 +211,37 @@
13 }
14
15 static void
16-write_uint16 (GByteArray *data, guint16 value)
17+write_uint16 (FILE *file, guint16 value)
18 {
19 guint8 v[2];
20 v[0] = value >> 8;
21 v[1] = value & 0xFF;
22- g_byte_array_append (data, v, 2);
23-}
24-
25-static void
26-write_data (GByteArray *data, const guint8 *value, gsize value_length)
27-{
28- g_byte_array_append (data, value, value_length);
29-}
30-
31-static void
32-write_string (GByteArray *data, const gchar *value)
33-{
34- write_uint16 (data, strlen (value));
35- write_data (data, (guint8 *) value, strlen (value));
36+ fwrite (v, 2, 1, file);
37+}
38+
39+static void
40+write_data (FILE *file, const guint8 *value, gsize value_length)
41+{
42+ fwrite (value, value_length, 1, file);
43+}
44+
45+static void
46+write_string (FILE *file, const gchar *value)
47+{
48+ write_uint16 (file, strlen (value));
49+ write_data (file, (guint8 *) value, strlen (value));
50 }
51
52 gboolean
53 xauth_write (XAuthority *auth, XAuthWriteMode mode, const gchar *filename, GError **error)
54 {
55 gchar *input;
56- gsize input_length = 0, input_offset = 0;
57+ gsize input_length = 0, input_offset = 0, offset;
58 GList *link, *records = NULL;
59 XAuthority *a;
60 gboolean result;
61 gboolean matched = FALSE;
62- GByteArray *output;
63+ FILE *output;
64
65 g_return_val_if_fail (auth != NULL, FALSE);
66 g_return_val_if_fail (filename != NULL, FALSE);
67@@ -311,8 +312,19 @@
68 records = g_list_append (records, g_object_ref (auth));
69
70 /* Write records back */
71- result = TRUE;
72- output = g_byte_array_new ();
73+ errno = 0;
74+ output = fopen (filename, "w");
75+ if (output == NULL)
76+ {
77+ g_set_error (error,
78+ G_FILE_ERROR,
79+ g_file_error_from_errno (errno),
80+ "Failed to write X authority %s: %s",
81+ filename,
82+ g_strerror (errno));
83+ return FALSE;
84+ }
85+
86 for (link = records; link && result; link = link->next)
87 {
88 XAuthority *a = link->data;
89@@ -329,10 +341,9 @@
90 }
91 g_list_free (records);
92
93- result = g_file_set_contents (filename, (gchar *)output->data, output->len, error);
94- g_byte_array_free (output, TRUE);
95+ fclose (output);
96
97- return result;
98+ return TRUE;
99 }
100
101 static void

Subscribers

People subscribed via source and target branches