D-Bus  1.13.7
dbus-internals.c
1 /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
2 /* dbus-internals.c random utility stuff (internal to D-Bus implementation)
3  *
4  * Copyright (C) 2002, 2003 Red Hat, Inc.
5  *
6  * Licensed under the Academic Free License version 2.1
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21  *
22  */
23 
24 #include <config.h>
25 #include "dbus-internals.h"
26 #include "dbus-protocol.h"
27 #include "dbus-marshal-basic.h"
28 #include "dbus-test.h"
29 #include "dbus-test-tap.h"
30 #include "dbus-valgrind-internal.h"
31 #include <stdio.h>
32 #include <stdarg.h>
33 #include <string.h>
34 #include <stdlib.h>
35 #ifdef DBUS_USE_OUTPUT_DEBUG_STRING
36 #include <windows.h>
37 #include <mbstring.h>
38 #endif
39 
185 const char *_dbus_no_memory_message = "Not enough memory";
186 
187 static dbus_bool_t warn_initted = FALSE;
188 static dbus_bool_t fatal_warnings = FALSE;
189 static dbus_bool_t fatal_warnings_on_check_failed = TRUE;
190 
191 static void
192 init_warnings(void)
193 {
194  if (!warn_initted)
195  {
196  const char *s;
197  s = _dbus_getenv ("DBUS_FATAL_WARNINGS");
198  if (s && *s)
199  {
200  if (*s == '0')
201  {
202  fatal_warnings = FALSE;
203  fatal_warnings_on_check_failed = FALSE;
204  }
205  else if (*s == '1')
206  {
207  fatal_warnings = TRUE;
208  fatal_warnings_on_check_failed = TRUE;
209  }
210  else
211  {
212  fprintf(stderr, "DBUS_FATAL_WARNINGS should be set to 0 or 1 if set, not '%s'",
213  s);
214  }
215  }
216 
217  warn_initted = TRUE;
218  }
219 }
220 
230 void
231 _dbus_warn (const char *format,
232  ...)
233 {
234  DBusSystemLogSeverity severity = DBUS_SYSTEM_LOG_WARNING;
235  va_list args;
236 
237  if (!warn_initted)
238  init_warnings ();
239 
240  if (fatal_warnings)
241  severity = DBUS_SYSTEM_LOG_ERROR;
242 
243  va_start (args, format);
244  _dbus_logv (severity, format, args);
245  va_end (args);
246 
247  if (fatal_warnings)
248  {
249  fflush (stderr);
250  _dbus_abort ();
251  }
252 }
253 
262 void
263 _dbus_warn_check_failed(const char *format,
264  ...)
265 {
266  DBusSystemLogSeverity severity = DBUS_SYSTEM_LOG_WARNING;
267  va_list args;
268 
269  if (!warn_initted)
270  init_warnings ();
271 
272  if (fatal_warnings_on_check_failed)
273  severity = DBUS_SYSTEM_LOG_ERROR;
274 
275  va_start (args, format);
276  _dbus_logv (severity, format, args);
277  va_end (args);
278 
279  if (fatal_warnings_on_check_failed)
280  {
281  fflush (stderr);
282  _dbus_abort ();
283  }
284 }
285 
286 #ifdef DBUS_ENABLE_VERBOSE_MODE
287 
288 static dbus_bool_t verbose_initted = FALSE;
289 static dbus_bool_t verbose = TRUE;
290 
291 #ifdef DBUS_USE_OUTPUT_DEBUG_STRING
292 static char module_name[1024];
293 #endif
294 
295 static inline void
296 _dbus_verbose_init (void)
297 {
298  if (!verbose_initted)
299  {
300  const char *p = _dbus_getenv ("DBUS_VERBOSE");
301  verbose = p != NULL && *p == '1';
302  verbose_initted = TRUE;
303 #ifdef DBUS_USE_OUTPUT_DEBUG_STRING
304  {
305  char *last_period, *last_slash;
306  GetModuleFileName(0,module_name,sizeof(module_name)-1);
307  last_period = _mbsrchr(module_name,'.');
308  if (last_period)
309  *last_period ='\0';
310  last_slash = _mbsrchr(module_name,'\\');
311  if (last_slash)
312  strcpy(module_name,last_slash+1);
313  strcat(module_name,": ");
314  }
315 #endif
316  }
317 }
318 
324 #ifdef DBUS_WIN
325 #define DBUS_IS_DIR_SEPARATOR(c) (c == '\\' || c == '/')
326 #else
327 #define DBUS_IS_DIR_SEPARATOR(c) (c == '/')
328 #endif
329 
334 static char *_dbus_file_path_extract_elements_from_tail(const char *file,int level)
335 {
336  int prefix = 0;
337  char *p = (char *)file + strlen(file);
338  int i = 0;
339 
340  for (;p >= file;p--)
341  {
342  if (DBUS_IS_DIR_SEPARATOR(*p))
343  {
344  if (++i >= level)
345  {
346  prefix = p-file+1;
347  break;
348  }
349  }
350  }
351 
352  return (char *)file+prefix;
353 }
354 
361 _dbus_is_verbose_real (void)
362 {
363  _dbus_verbose_init ();
364  return verbose;
365 }
366 
367 void _dbus_set_verbose (dbus_bool_t state)
368 {
369  verbose = state;
370 }
371 
372 dbus_bool_t _dbus_get_verbose (void)
373 {
374  return verbose;
375 }
376 
385 void
386 _dbus_verbose_real (
387 #ifdef DBUS_CPP_SUPPORTS_VARIABLE_MACRO_ARGUMENTS
388  const char *file,
389  const int line,
390  const char *function,
391 #endif
392  const char *format,
393  ...)
394 {
395  va_list args;
396  static dbus_bool_t need_pid = TRUE;
397  int len;
398  long sec, usec;
399 
400  /* things are written a bit oddly here so that
401  * in the non-verbose case we just have the one
402  * conditional and return immediately.
403  */
404  if (!_dbus_is_verbose_real())
405  return;
406 
407 #ifndef DBUS_USE_OUTPUT_DEBUG_STRING
408  /* Print out pid before the line */
409  if (need_pid)
410  {
411  _dbus_print_thread ();
412  }
413  _dbus_get_real_time (&sec, &usec);
414  fprintf (stderr, "%ld.%06ld ", sec, usec);
415 #endif
416 
417  /* Only print pid again if the next line is a new line */
418  len = strlen (format);
419  if (format[len-1] == '\n')
420  need_pid = TRUE;
421  else
422  need_pid = FALSE;
423 
424  va_start (args, format);
425 #ifdef DBUS_USE_OUTPUT_DEBUG_STRING
426  {
427  char buf[1024];
428  strcpy(buf,module_name);
429 #ifdef DBUS_CPP_SUPPORTS_VARIABLE_MACRO_ARGUMENTS
430  sprintf (buf+strlen(buf), "[%s(%d):%s] ",_dbus_file_path_extract_elements_from_tail(file,2),line,function);
431 #endif
432  vsprintf (buf+strlen(buf),format, args);
433  va_end (args);
434  OutputDebugStringA(buf);
435  }
436 #else
437 #ifdef DBUS_CPP_SUPPORTS_VARIABLE_MACRO_ARGUMENTS
438  fprintf (stderr, "[%s(%d):%s] ",_dbus_file_path_extract_elements_from_tail(file,2),line,function);
439 #endif
440 
441  vfprintf (stderr, format, args);
442  va_end (args);
443 
444  fflush (stderr);
445 #endif
446 }
447 
454 void
455 _dbus_verbose_reset_real (void)
456 {
457  verbose_initted = FALSE;
458 }
459 
460 void
461 _dbus_trace_ref (const char *obj_name,
462  void *obj,
463  int old_refcount,
464  int new_refcount,
465  const char *why,
466  const char *env_var,
467  int *enabled)
468 {
469  _dbus_assert (obj_name != NULL);
470  _dbus_assert (obj != NULL);
471  _dbus_assert (old_refcount >= -1);
472  _dbus_assert (new_refcount >= -1);
473 
474  if (old_refcount == -1)
475  {
476  _dbus_assert (new_refcount == -1);
477  }
478  else
479  {
480  _dbus_assert (new_refcount >= 0);
481  _dbus_assert (old_refcount >= 0);
482  _dbus_assert (old_refcount > 0 || new_refcount > 0);
483  }
484 
485  _dbus_assert (why != NULL);
486  _dbus_assert (env_var != NULL);
487  _dbus_assert (enabled != NULL);
488 
489  if (*enabled < 0)
490  {
491  const char *s = _dbus_getenv (env_var);
492 
493  *enabled = FALSE;
494 
495  if (s && *s)
496  {
497  if (*s == '0')
498  *enabled = FALSE;
499  else if (*s == '1')
500  *enabled = TRUE;
501  else
502  _dbus_warn ("%s should be 0 or 1 if set, not '%s'", env_var, s);
503  }
504  }
505 
506  if (*enabled)
507  {
508  if (old_refcount == -1)
509  {
510  VALGRIND_PRINTF_BACKTRACE ("%s %p ref stolen (%s)",
511  obj_name, obj, why);
512  _dbus_verbose ("%s %p ref stolen (%s)\n",
513  obj_name, obj, why);
514  }
515  else
516  {
517  VALGRIND_PRINTF_BACKTRACE ("%s %p %d -> %d refs (%s)",
518  obj_name, obj,
519  old_refcount, new_refcount, why);
520  _dbus_verbose ("%s %p %d -> %d refs (%s)\n",
521  obj_name, obj, old_refcount, new_refcount, why);
522  }
523  }
524 }
525 
526 #endif /* DBUS_ENABLE_VERBOSE_MODE */
527 
536 char*
537 _dbus_strdup (const char *str)
538 {
539  size_t len;
540  char *copy;
541 
542  if (str == NULL)
543  return NULL;
544 
545  len = strlen (str);
546 
547  copy = dbus_malloc (len + 1);
548  if (copy == NULL)
549  return NULL;
550 
551  memcpy (copy, str, len + 1);
552 
553  return copy;
554 }
555 
564 void*
565 _dbus_memdup (const void *mem,
566  size_t n_bytes)
567 {
568  void *copy;
569 
570  copy = dbus_malloc (n_bytes);
571  if (copy == NULL)
572  return NULL;
573 
574  memcpy (copy, mem, n_bytes);
575 
576  return copy;
577 }
578 
587 char**
588 _dbus_dup_string_array (const char **array)
589 {
590  int len;
591  int i;
592  char **copy;
593 
594  if (array == NULL)
595  return NULL;
596 
597  for (len = 0; array[len] != NULL; ++len)
598  ;
599 
600  copy = dbus_new0 (char*, len + 1);
601  if (copy == NULL)
602  return NULL;
603 
604  i = 0;
605  while (i < len)
606  {
607  copy[i] = _dbus_strdup (array[i]);
608  if (copy[i] == NULL)
609  {
610  dbus_free_string_array (copy);
611  return NULL;
612  }
613 
614  ++i;
615  }
616 
617  return copy;
618 }
619 
628 _dbus_string_array_contains (const char **array,
629  const char *str)
630 {
631  int i;
632 
633  i = 0;
634  while (array[i] != NULL)
635  {
636  if (strcmp (array[i], str) == 0)
637  return TRUE;
638  ++i;
639  }
640 
641  return FALSE;
642 }
643 
650 size_t
651 _dbus_string_array_length (const char **array)
652 {
653  size_t i;
654  for (i = 0; array[i]; i++) {}
655  return i;
656 }
657 
658 
669  DBusError *error)
670 {
671  DBusError rand_error;
672  long now;
673 
674  dbus_error_init (&rand_error);
675 
676  /* don't use monotonic time because the UUID may be saved to disk, e.g.
677  * it may persist across reboots
678  */
679  _dbus_get_real_time (&now, NULL);
680 
681  uuid->as_uint32s[DBUS_UUID_LENGTH_WORDS - 1] = DBUS_UINT32_TO_BE (now);
682 
684  DBUS_UUID_LENGTH_BYTES - 4,
685  &rand_error))
686  {
687  dbus_set_error (error, rand_error.name,
688  "Failed to generate UUID: %s", rand_error.message);
689  dbus_error_free (&rand_error);
690  return FALSE;
691  }
692 
693  return TRUE;
694 }
695 
705  DBusString *encoded)
706 {
707  DBusString binary;
708  _dbus_string_init_const_len (&binary, uuid->as_bytes, DBUS_UUID_LENGTH_BYTES);
709  return _dbus_string_hex_encode (&binary, 0, encoded, _dbus_string_get_length (encoded));
710 }
711 
712 static dbus_bool_t
713 _dbus_read_uuid_file_without_creating (const DBusString *filename,
714  DBusGUID *uuid,
715  DBusError *error)
716 {
717  DBusString contents;
718  DBusString decoded;
719  int end;
720 
721  if (!_dbus_string_init (&contents))
722  {
723  _DBUS_SET_OOM (error);
724  return FALSE;
725  }
726 
727  if (!_dbus_string_init (&decoded))
728  {
729  _dbus_string_free (&contents);
730  _DBUS_SET_OOM (error);
731  return FALSE;
732  }
733 
734  if (!_dbus_file_get_contents (&contents, filename, error))
735  goto error;
736 
737  _dbus_string_chop_white (&contents);
738 
739  if (_dbus_string_get_length (&contents) != DBUS_UUID_LENGTH_HEX)
740  {
742  "UUID file '%s' should contain a hex string of length %d, not length %d, with no other text",
743  _dbus_string_get_const_data (filename),
744  DBUS_UUID_LENGTH_HEX,
745  _dbus_string_get_length (&contents));
746  goto error;
747  }
748 
749  if (!_dbus_string_hex_decode (&contents, 0, &end, &decoded, 0))
750  {
751  _DBUS_SET_OOM (error);
752  goto error;
753  }
754 
755  if (end == 0)
756  {
758  "UUID file '%s' contains invalid hex data",
759  _dbus_string_get_const_data (filename));
760  goto error;
761  }
762 
763  if (_dbus_string_get_length (&decoded) != DBUS_UUID_LENGTH_BYTES)
764  {
766  "UUID file '%s' contains %d bytes of hex-encoded data instead of %d",
767  _dbus_string_get_const_data (filename),
768  _dbus_string_get_length (&decoded),
769  DBUS_UUID_LENGTH_BYTES);
770  goto error;
771  }
772 
773  _dbus_string_copy_to_buffer (&decoded, uuid->as_bytes, DBUS_UUID_LENGTH_BYTES);
774 
775  _dbus_string_free (&decoded);
776  _dbus_string_free (&contents);
777 
778  _DBUS_ASSERT_ERROR_IS_CLEAR (error);
779 
780  return TRUE;
781 
782  error:
783  _DBUS_ASSERT_ERROR_IS_SET (error);
784  _dbus_string_free (&contents);
785  _dbus_string_free (&decoded);
786  return FALSE;
787 }
788 
799  const DBusGUID *uuid,
800  DBusError *error)
801 {
802  DBusString encoded;
803 
804  if (!_dbus_string_init (&encoded))
805  {
806  _DBUS_SET_OOM (error);
807  return FALSE;
808  }
809 
810  if (!_dbus_uuid_encode (uuid, &encoded))
811  {
812  _DBUS_SET_OOM (error);
813  goto error;
814  }
815 
816  if (!_dbus_string_append_byte (&encoded, '\n'))
817  {
818  _DBUS_SET_OOM (error);
819  goto error;
820  }
821 
822  if (!_dbus_string_save_to_file (&encoded, filename, TRUE, error))
823  goto error;
824 
825  _dbus_string_free (&encoded);
826 
827  _DBUS_ASSERT_ERROR_IS_CLEAR (error);
828  return TRUE;
829 
830  error:
831  _DBUS_ASSERT_ERROR_IS_SET (error);
832  _dbus_string_free (&encoded);
833  return FALSE;
834 }
835 
848  DBusGUID *uuid,
849  dbus_bool_t create_if_not_found,
850  DBusError *error)
851 {
852  DBusError read_error = DBUS_ERROR_INIT;
853 
854  if (_dbus_read_uuid_file_without_creating (filename, uuid, &read_error))
855  return TRUE;
856 
857  if (!create_if_not_found)
858  {
859  dbus_move_error (&read_error, error);
860  return FALSE;
861  }
862 
863  /* If the file exists and contains junk, we want to keep that error
864  * message instead of overwriting it with a "file exists" error
865  * message when we try to write
866  */
868  {
869  dbus_move_error (&read_error, error);
870  return FALSE;
871  }
872  else
873  {
874  dbus_error_free (&read_error);
875 
876  if (!_dbus_generate_uuid (uuid, error))
877  return FALSE;
878 
879  return _dbus_write_uuid_file (filename, uuid, error);
880  }
881 }
882 
883 /* Protected by _DBUS_LOCK (machine_uuid) */
884 static int machine_uuid_initialized_generation = 0;
885 static DBusGUID machine_uuid;
886 
900  DBusError *error)
901 {
902  dbus_bool_t ok = TRUE;
903 
904  if (!_DBUS_LOCK (machine_uuid))
905  {
906  _DBUS_SET_OOM (error);
907  return FALSE;
908  }
909 
910  if (machine_uuid_initialized_generation != _dbus_current_generation)
911  {
912  if (!_dbus_read_local_machine_uuid (&machine_uuid, FALSE, error))
913  ok = FALSE;
914  }
915 
916  if (ok)
917  {
918  if (!_dbus_uuid_encode (&machine_uuid, uuid_str))
919  {
920  ok = FALSE;
921  _DBUS_SET_OOM (error);
922  }
923  }
924 
925  _DBUS_UNLOCK (machine_uuid);
926 
927  return ok;
928 }
929 
930 #ifndef DBUS_DISABLE_CHECKS
931 void
932 _dbus_warn_return_if_fail (const char *function,
933  const char *assertion,
934  const char *file,
935  int line)
936 {
938  "arguments to %s() were incorrect, assertion \"%s\" failed in file %s line %d.\n"
939  "This is normally a bug in some application using the D-Bus library.\n",
940  function, assertion, file, line);
941 }
942 #endif
943 
944 #ifndef DBUS_DISABLE_ASSERT
945 
957 void
959  const char *condition_text,
960  const char *file,
961  int line,
962  const char *func)
963 {
964  if (_DBUS_UNLIKELY (!condition))
965  {
966  _dbus_warn ("assertion failed \"%s\" file \"%s\" line %d function %s",
967  condition_text, file, line, func);
968  _dbus_abort ();
969  }
970 }
971 
982 void
983 _dbus_real_assert_not_reached (const char *explanation,
984  const char *file,
985  int line)
986 {
987  _dbus_warn ("File \"%s\" line %d should not have been reached: %s",
988  file, line, explanation);
989  _dbus_abort ();
990 }
991 #endif /* DBUS_DISABLE_ASSERT */
992 
993 #ifdef DBUS_ENABLE_EMBEDDED_TESTS
994 static dbus_bool_t
995 run_failing_each_malloc (int n_mallocs,
996  const char *description,
997  DBusTestMemoryFunction func,
998  void *data)
999 {
1000  n_mallocs += 10; /* fudge factor to ensure reallocs etc. are covered */
1001 
1002  while (n_mallocs >= 0)
1003  {
1004  _dbus_set_fail_alloc_counter (n_mallocs);
1005 
1006  _dbus_verbose ("\n===\n%s: (will fail malloc %d with %d failures)\n===\n",
1007  description, n_mallocs,
1008  _dbus_get_fail_alloc_failures ());
1009 
1010  if (!(* func) (data, FALSE))
1011  return FALSE;
1012 
1013  n_mallocs -= 1;
1014  }
1015 
1016  _dbus_set_fail_alloc_counter (_DBUS_INT_MAX);
1017 
1018  return TRUE;
1019 }
1020 
1035 _dbus_test_oom_handling (const char *description,
1036  DBusTestMemoryFunction func,
1037  void *data)
1038 {
1039  int approx_mallocs;
1040  const char *setting;
1041  int max_failures_to_try;
1042  int i;
1043 
1044  /* Run once to see about how many mallocs are involved */
1045 
1046  _dbus_set_fail_alloc_counter (_DBUS_INT_MAX);
1047 
1048  _dbus_test_diag ("Running \"%s\" once to count mallocs", description);
1049 
1050  if (!(* func) (data, TRUE))
1051  return FALSE;
1052 
1053  approx_mallocs = _DBUS_INT_MAX - _dbus_get_fail_alloc_counter ();
1054 
1055  _dbus_test_diag ("\"%s\" has about %d mallocs in total",
1056  description, approx_mallocs);
1057 
1058  setting = _dbus_getenv ("DBUS_TEST_MALLOC_FAILURES");
1059 
1060  if (setting != NULL)
1061  {
1062  DBusString str;
1063  long v;
1064  _dbus_string_init_const (&str, setting);
1065  v = 4;
1066  if (!_dbus_string_parse_int (&str, 0, &v, NULL))
1067  _dbus_warn ("couldn't parse '%s' as integer\n", setting);
1068  max_failures_to_try = v;
1069  }
1070  else
1071  {
1072  max_failures_to_try = 4;
1073  }
1074 
1075  if (RUNNING_ON_VALGRIND && _dbus_getenv ("DBUS_TEST_SLOW") == NULL)
1076  {
1077  /* The full OOM testing is slow, valgrind is slow, so the
1078  * combination is just horrible. Only do this if the user
1079  * asked for extra-slow tests. */
1080  max_failures_to_try = 0;
1081  }
1082 
1083  if (max_failures_to_try < 1)
1084  {
1085  _dbus_test_diag ("not testing OOM handling");
1086  return TRUE;
1087  }
1088 
1089  _dbus_test_diag ("testing \"%s\" with up to %d consecutive malloc failures",
1090  description, max_failures_to_try);
1091 
1092  i = setting ? max_failures_to_try - 1 : 1;
1093  while (i < max_failures_to_try)
1094  {
1095  _dbus_test_diag ("testing \"%s\" with %d consecutive malloc failures",
1096  description, i + 1);
1097 
1098  _dbus_set_fail_alloc_failures (i);
1099  if (!run_failing_each_malloc (approx_mallocs, description, func, data))
1100  return FALSE;
1101  ++i;
1102  }
1103 
1104  _dbus_verbose ("\"%s\" coped OK with malloc failures", description);
1105 
1106  return TRUE;
1107 }
1108 #endif /* DBUS_ENABLE_EMBEDDED_TESTS */
1109 
dbus_bool_t dbus_error_has_name(const DBusError *error, const char *name)
Checks whether the error is set and has the given name.
Definition: dbus-errors.c:302
DBUS_PRIVATE_EXPORT dbus_bool_t _dbus_string_parse_int(const DBusString *str, int start, long *value_return, int *end_return)
Parses an integer contained in a DBusString.
Definition: dbus-sysdeps.c:444
void _dbus_string_copy_to_buffer(const DBusString *str, char *buffer, int avail_len)
Copies the contents of a DBusString into a different buffer.
Definition: dbus-string.c:714
dbus_bool_t _dbus_uuid_encode(const DBusGUID *uuid, DBusString *encoded)
Hex-encode a UUID.
const char * message
public error message field
Definition: dbus-errors.h:51
#define NULL
A null pointer, defined appropriately for C or C++.
dbus_bool_t _dbus_read_local_machine_uuid(DBusGUID *machine_id, dbus_bool_t create_if_not_found, DBusError *error)
Reads the uuid of the machine we&#39;re running on from the dbus configuration.
void _dbus_abort(void)
Aborts the program with SIGABRT (dumping core).
Definition: dbus-sysdeps.c:87
#define DBUS_ERROR_INVALID_FILE_CONTENT
A file contains invalid syntax or is otherwise broken.
dbus_bool_t _dbus_string_save_to_file(const DBusString *str, const DBusString *filename, dbus_bool_t world_readable, DBusError *error)
Writes a string out to a file.
dbus_bool_t _dbus_string_hex_encode(const DBusString *source, int start, DBusString *dest, int insert_at)
Encodes a string in hex, the way MD5 and SHA-1 are usually encoded.
Definition: dbus-string.c:2276
void _dbus_real_assert(dbus_bool_t condition, const char *condition_text, const char *file, int line, const char *func)
Internals of _dbus_assert(); it&#39;s a function rather than a macro with the inline code so that the ass...
dbus_bool_t _dbus_generate_uuid(DBusGUID *uuid, DBusError *error)
Generates a new UUID.
dbus_bool_t _dbus_get_local_machine_uuid_encoded(DBusString *uuid_str, DBusError *error)
Gets the hex-encoded UUID of the machine this function is executed on.
dbus_uint32_t as_uint32s[DBUS_UUID_LENGTH_WORDS]
guid as four uint32 values
void _dbus_string_chop_white(DBusString *str)
Deletes leading and trailing whitespace.
Definition: dbus-string.c:2006
#define _dbus_assert(condition)
Aborts with an error message if the condition is false.
#define DBUS_ERROR_INIT
Expands to a suitable initializer for a DBusError on the stack.
Definition: dbus-errors.h:62
char as_bytes[DBUS_UUID_LENGTH_BYTES]
guid as 16 single-byte values
void _dbus_warn_check_failed(const char *format,...)
Prints a "critical" warning to stderr when an assertion fails; differs from _dbus_warn primarily in t...
void dbus_error_free(DBusError *error)
Frees an error that&#39;s been set (or just initialized), then reinitializes the error as in dbus_error_i...
Definition: dbus-errors.c:211
dbus_bool_t _dbus_file_get_contents(DBusString *str, const DBusString *filename, DBusError *error)
Appends the contents of the given file to the string, returning error code.
A globally unique ID ; we have one for each DBusServer, and also one for each machine with libdbus in...
dbus_bool_t _dbus_string_init(DBusString *str)
Initializes a string.
Definition: dbus-string.c:175
#define _DBUS_INT_MAX
Maximum value of type "int".
void _dbus_real_assert_not_reached(const char *explanation, const char *file, int line)
Internals of _dbus_assert_not_reached(); it&#39;s a function rather than a macro with the inline code so ...
void * dbus_malloc(size_t bytes)
Allocates the given number of bytes, as with standard malloc().
Definition: dbus-memory.c:463
#define dbus_new0(type, count)
Safe macro for using dbus_malloc0().
Definition: dbus-memory.h:58
dbus_uint32_t dbus_bool_t
A boolean, valid values are TRUE and FALSE.
Definition: dbus-types.h:35
void _dbus_string_init_const(DBusString *str, const char *value)
Initializes a constant string.
Definition: dbus-string.c:190
const char * _dbus_no_memory_message
Fixed "out of memory" error message, just to avoid making up a different string every time and wastin...
void _dbus_warn(const char *format,...)
Prints a warning message to stderr.
void * _dbus_memdup(const void *mem, size_t n_bytes)
Duplicates a block of memory.
int _dbus_current_generation
_dbus_current_generation is used to track each time that dbus_shutdown() is called, so we can reinit things after it&#39;s been called.
Definition: dbus-memory.c:783
Object representing an exception.
Definition: dbus-errors.h:48
size_t _dbus_string_array_length(const char **array)
Returns the size of a string array.
void dbus_set_error(DBusError *error, const char *name, const char *format,...)
Assigns an error name and message to a DBusError.
Definition: dbus-errors.c:354
dbus_bool_t _dbus_string_append_byte(DBusString *str, unsigned char byte)
Appends a single byte to the string, returning FALSE if not enough memory.
Definition: dbus-string.c:1174
#define _DBUS_UNLOCK(name)
Unlocks a global lock.
void _dbus_string_free(DBusString *str)
Frees a string created by _dbus_string_init(), and fills it with the same contents as #_DBUS_STRING_I...
Definition: dbus-string.c:264
char ** _dbus_dup_string_array(const char **array)
Duplicates a string array.
#define TRUE
Expands to "1".
void dbus_move_error(DBusError *src, DBusError *dest)
Moves an error src into dest, freeing src and overwriting dest.
Definition: dbus-errors.c:279
const char * name
public error name field
Definition: dbus-errors.h:50
dbus_bool_t _dbus_read_uuid_file(const DBusString *filename, DBusGUID *uuid, dbus_bool_t create_if_not_found, DBusError *error)
Reads (and optionally writes) a uuid to a file.
void dbus_error_init(DBusError *error)
Initializes a DBusError structure.
Definition: dbus-errors.c:188
dbus_bool_t _dbus_string_hex_decode(const DBusString *source, int start, int *end_return, DBusString *dest, int insert_at)
Decodes a string from hex encoding.
Definition: dbus-string.c:2326
void dbus_free_string_array(char **str_array)
Frees a NULL-terminated array of strings.
Definition: dbus-memory.c:751
dbus_bool_t _dbus_string_array_contains(const char **array, const char *str)
Checks whether a string array contains the given string.
void _dbus_logv(DBusSystemLogSeverity severity, const char *msg, va_list args)
Log a message to the system log file (e.g.
#define FALSE
Expands to "0".
dbus_bool_t _dbus_write_uuid_file(const DBusString *filename, const DBusGUID *uuid, DBusError *error)
Write the give UUID to a file.
#define _DBUS_LOCK(name)
Locks a global lock, initializing it first if necessary.
dbus_bool_t _dbus_generate_random_bytes_buffer(char *buffer, int n_bytes, DBusError *error)
Fills n_bytes of the given buffer with random bytes.
Definition: dbus-sysdeps.c:525
char * _dbus_strdup(const char *str)
Duplicates a string.
const char * _dbus_getenv(const char *varname)
Wrapper for getenv().
Definition: dbus-sysdeps.c:195
void _dbus_string_init_const_len(DBusString *str, const char *value, int len)
Initializes a constant string with a length.
Definition: dbus-string.c:210
void _dbus_get_real_time(long *tv_sec, long *tv_usec)
Get current time, as in gettimeofday().