dbus-launch-Move-dbus-autolaunch-stuff-to-runuser.patch 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. From f595065ab70c6c310f14610f8acc46a94ede7070 Mon Sep 17 00:00:00 2001
  2. From: Colin Walters <walters@verbum.org>
  3. Date: Fri, 27 Apr 2012 14:36:01 -0400
  4. Subject: [PATCH] dbus-launch: Move ~/.dbus autolaunch stuff to /run/user
  5. We shouldn't be polluting the user's home directory when we have a
  6. per-machine per-user directory available in XDG_RUNTIME_DIR.
  7. https://bugs.freedesktop.org/show_bug.cgi?id=35887
  8. ---
  9. tools/dbus-launch-x11.c | 148 +++++++++++++++++++++++++++++++----------------
  10. 1 files changed, 97 insertions(+), 51 deletions(-)
  11. diff --git a/tools/dbus-launch-x11.c b/tools/dbus-launch-x11.c
  12. index c7e3330..b50d43a 100644
  13. --- a/tools/dbus-launch-x11.c
  14. +++ b/tools/dbus-launch-x11.c
  15. @@ -30,6 +30,8 @@
  16. #include <sys/stat.h>
  17. #include <unistd.h>
  18. #include <fcntl.h>
  19. +#include <limits.h>
  20. +#include <stdarg.h>
  21. #include <errno.h>
  22. #include <stdio.h>
  23. #include <string.h>
  24. @@ -87,16 +89,98 @@ get_homedir (void)
  25. return home;
  26. }
  27. -#define DBUS_DIR ".dbus"
  28. -#define DBUS_SESSION_BUS_DIR "session-bus"
  29. +static char *
  30. +wish_i_had_g_build_filename (const char *first,
  31. + ...)
  32. +{
  33. + const char *arg;
  34. + const char *next;
  35. + char *p;
  36. + char buf[PATH_MAX+1];
  37. + va_list args;
  38. +
  39. + va_start (args, first);
  40. +
  41. + p = &(buf[0]);
  42. +
  43. + arg = first;
  44. + do
  45. + {
  46. + next = va_arg (args, const char *);
  47. + strcpy (p, arg);
  48. + p += strlen (arg);
  49. + if (next)
  50. + {
  51. + *p = '/';
  52. + p++;
  53. + }
  54. + arg = next;
  55. + }
  56. + while (arg != NULL);
  57. +
  58. + va_end (args);
  59. +
  60. + *p = '\0';
  61. +
  62. + return strdup ((char*)buf);
  63. +}
  64. +
  65. +static char *
  66. +wish_i_had_g_strconcat (const char *first,
  67. + ...)
  68. +{
  69. + char *result;
  70. + const char *arg;
  71. + va_list args;
  72. +
  73. + va_start (args, first);
  74. +
  75. + result = strdup (first);
  76. +
  77. + while ((arg = va_arg (args, const char *)) != NULL)
  78. + {
  79. + char *end = result + strlen (result);
  80. + result = realloc (result, strlen (result) + strlen (arg) + 1);
  81. + strcpy (end, arg);
  82. + }
  83. +
  84. + va_end (args);
  85. + return result;
  86. +}
  87. +
  88. +/* This used to live in ~/.dbus, but we don't want to put stuff
  89. + * in the user home directory for multiple reasons; see
  90. + * https://bugs.freedesktop.org/show_bug.cgi?id=35887
  91. + */
  92. +static char *autolaunch_data_dir = NULL;
  93. +static const char *
  94. +get_autolaunch_data_dir (void)
  95. +{
  96. + if (autolaunch_data_dir == NULL)
  97. + {
  98. + const char *datadir;
  99. + const char *home;
  100. + /* http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html */
  101. + datadir = getenv ("XDG_RUNTIME_DIR");
  102. +
  103. + if (datadir)
  104. + autolaunch_data_dir = wish_i_had_g_build_filename (datadir, "dbus-autolaunch", NULL);
  105. + else
  106. + {
  107. + home = get_homedir ();
  108. + autolaunch_data_dir = wish_i_had_g_build_filename (home, ".dbus", "session-bus", NULL);
  109. + }
  110. + }
  111. + return autolaunch_data_dir;
  112. +}
  113. static char *
  114. get_session_file (void)
  115. {
  116. - static const char prefix[] = "/" DBUS_DIR "/" DBUS_SESSION_BUS_DIR "/";
  117. + const char *autolaunch_data_dir;
  118. const char *machine;
  119. - const char *home;
  120. char *display;
  121. + char *session_filename;
  122. char *result;
  123. char *p;
  124. @@ -149,23 +233,13 @@ get_session_file (void)
  125. *p = '_';
  126. }
  127. - home = get_homedir ();
  128. -
  129. - result = malloc (strlen (home) + strlen (prefix) + strlen (machine) +
  130. - strlen (display) + 2);
  131. - if (result == NULL)
  132. - {
  133. - /* out of memory */
  134. - free (display);
  135. - return NULL;
  136. - }
  137. + autolaunch_data_dir = get_autolaunch_data_dir ();
  138. - strcpy (result, home);
  139. - strcat (result, prefix);
  140. - strcat (result, machine);
  141. - strcat (result, "-");
  142. - strcat (result, display);
  143. - free (display);
  144. + session_filename = wish_i_had_g_strconcat (machine, "-", display, NULL);
  145. +
  146. + result = wish_i_had_g_build_filename (autolaunch_data_dir, session_filename, NULL);
  147. +
  148. + free (session_filename);
  149. verbose ("session file: %s\n", result);
  150. return result;
  151. @@ -174,41 +248,13 @@ get_session_file (void)
  152. static void
  153. ensure_session_directory (void)
  154. {
  155. - const char *home;
  156. - char *dir;
  157. -
  158. - home = get_homedir ();
  159. -
  160. - /* be sure we have space for / and nul */
  161. - dir = malloc (strlen (home) + strlen (DBUS_DIR) + strlen (DBUS_SESSION_BUS_DIR) + 3);
  162. - if (dir == NULL)
  163. - {
  164. - fprintf (stderr, "no memory\n");
  165. - exit (1);
  166. - }
  167. -
  168. - strcpy (dir, home);
  169. - strcat (dir, "/");
  170. - strcat (dir, DBUS_DIR);
  171. -
  172. - if (mkdir (dir, 0700) < 0)
  173. + const char *autolaunch_dir = get_autolaunch_data_dir();
  174. + if (mkdir (autolaunch_dir, 0700) < 0)
  175. {
  176. /* only print a warning here, writing the session file itself will fail later */
  177. if (errno != EEXIST)
  178. - fprintf (stderr, "Unable to create %s\n", dir);
  179. + fprintf (stderr, "Unable to create %s\n", autolaunch_dir);
  180. }
  181. -
  182. - strcat (dir, "/");
  183. - strcat (dir, DBUS_SESSION_BUS_DIR);
  184. -
  185. - if (mkdir (dir, 0700) < 0)
  186. - {
  187. - /* only print a warning here, writing the session file itself will fail later */
  188. - if (errno != EEXIST)
  189. - fprintf (stderr, "Unable to create %s\n", dir);
  190. - }
  191. -
  192. - free (dir);
  193. }
  194. static Display *
  195. --
  196. 1.7.7.6