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

Proposed by Robert Ancell
Status: Merged
Approved by: Robert Ancell
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
PS Jenkins bot continuous-integration Approve
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.
Revision history for this message
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)
Revision history for this message
Robert Ancell (robert-ancell) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/xauthority.c'
--- src/xauthority.c 2013-04-18 13:57:46 +0000
+++ src/xauthority.c 2013-06-10 05:12:24 +0000
@@ -10,6 +10,7 @@
10 */10 */
1111
12#include <string.h>12#include <string.h>
13#include <stdio.h>
13#include <errno.h>14#include <errno.h>
14#include <unistd.h>15#include <unistd.h>
15#include <sys/stat.h>16#include <sys/stat.h>
@@ -210,37 +211,37 @@
210}211}
211212
212static void213static void
213write_uint16 (GByteArray *data, guint16 value)214write_uint16 (FILE *file, guint16 value)
214{215{
215 guint8 v[2];216 guint8 v[2];
216 v[0] = value >> 8;217 v[0] = value >> 8;
217 v[1] = value & 0xFF;218 v[1] = value & 0xFF;
218 g_byte_array_append (data, v, 2);219 fwrite (v, 2, 1, file);
219}220}
220221
221static void222static void
222write_data (GByteArray *data, const guint8 *value, gsize value_length)223write_data (FILE *file, const guint8 *value, gsize value_length)
223{224{
224 g_byte_array_append (data, value, value_length);225 fwrite (value, value_length, 1, file);
225}226}
226227
227static void228static void
228write_string (GByteArray *data, const gchar *value)229write_string (FILE *file, const gchar *value)
229{230{
230 write_uint16 (data, strlen (value));231 write_uint16 (file, strlen (value));
231 write_data (data, (guint8 *) value, strlen (value));232 write_data (file, (guint8 *) value, strlen (value));
232}233}
233234
234gboolean235gboolean
235xauth_write (XAuthority *auth, XAuthWriteMode mode, const gchar *filename, GError **error)236xauth_write (XAuthority *auth, XAuthWriteMode mode, const gchar *filename, GError **error)
236{237{
237 gchar *input;238 gchar *input;
238 gsize input_length = 0, input_offset = 0;239 gsize input_length = 0, input_offset = 0, offset;
239 GList *link, *records = NULL;240 GList *link, *records = NULL;
240 XAuthority *a;241 XAuthority *a;
241 gboolean result;242 gboolean result;
242 gboolean matched = FALSE;243 gboolean matched = FALSE;
243 GByteArray *output;244 FILE *output;
244245
245 g_return_val_if_fail (auth != NULL, FALSE);246 g_return_val_if_fail (auth != NULL, FALSE);
246 g_return_val_if_fail (filename != NULL, FALSE);247 g_return_val_if_fail (filename != NULL, FALSE);
@@ -311,8 +312,19 @@
311 records = g_list_append (records, g_object_ref (auth));312 records = g_list_append (records, g_object_ref (auth));
312313
313 /* Write records back */314 /* Write records back */
314 result = TRUE;315 errno = 0;
315 output = g_byte_array_new ();316 output = fopen (filename, "w");
317 if (output == NULL)
318 {
319 g_set_error (error,
320 G_FILE_ERROR,
321 g_file_error_from_errno (errno),
322 "Failed to write X authority %s: %s",
323 filename,
324 g_strerror (errno));
325 return FALSE;
326 }
327
316 for (link = records; link && result; link = link->next)328 for (link = records; link && result; link = link->next)
317 {329 {
318 XAuthority *a = link->data;330 XAuthority *a = link->data;
@@ -329,10 +341,9 @@
329 }341 }
330 g_list_free (records);342 g_list_free (records);
331343
332 result = g_file_set_contents (filename, (gchar *)output->data, output->len, error);344 fclose (output);
333 g_byte_array_free (output, TRUE);
334345
335 return result;346 return TRUE;
336} 347}
337348
338static void349static void

Subscribers

People subscribed via source and target branches