D-Bus  1.6.12
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-valgrind-internal.h"
30 #include <stdio.h>
31 #include <stdarg.h>
32 #include <string.h>
33 #include <stdlib.h>
34 #ifdef DBUS_USE_OUTPUT_DEBUG_STRING
35 #include <windows.h>
36 #include <mbstring.h>
37 #endif
38 
199 const char *_dbus_no_memory_message = "Not enough memory";
200 
201 static dbus_bool_t warn_initted = FALSE;
202 static dbus_bool_t fatal_warnings = FALSE;
203 static dbus_bool_t fatal_warnings_on_check_failed = TRUE;
204 
205 static void
206 init_warnings(void)
207 {
208  if (!warn_initted)
209  {
210  const char *s;
211  s = _dbus_getenv ("DBUS_FATAL_WARNINGS");
212  if (s && *s)
213  {
214  if (*s == '0')
215  {
216  fatal_warnings = FALSE;
217  fatal_warnings_on_check_failed = FALSE;
218  }
219  else if (*s == '1')
220  {
221  fatal_warnings = TRUE;
222  fatal_warnings_on_check_failed = TRUE;
223  }
224  else
225  {
226  fprintf(stderr, "DBUS_FATAL_WARNINGS should be set to 0 or 1 if set, not '%s'",
227  s);
228  }
229  }
230 
231  warn_initted = TRUE;
232  }
233 }
234 
244 void
245 _dbus_warn (const char *format,
246  ...)
247 {
248  va_list args;
249 
250  if (!warn_initted)
251  init_warnings ();
252 
253  va_start (args, format);
254  vfprintf (stderr, format, args);
255  va_end (args);
256 
257  if (fatal_warnings)
258  {
259  fflush (stderr);
260  _dbus_abort ();
261  }
262 }
263 
272 void
273 _dbus_warn_check_failed(const char *format,
274  ...)
275 {
276  va_list args;
277 
278  if (!warn_initted)
279  init_warnings ();
280 
281  fprintf (stderr, "process %lu: ", _dbus_pid_for_log ());
282 
283  va_start (args, format);
284  vfprintf (stderr, format, args);
285  va_end (args);
286 
287  if (fatal_warnings_on_check_failed)
288  {
289  fflush (stderr);
290  _dbus_abort ();
291  }
292 }
293 
294 #ifdef DBUS_ENABLE_VERBOSE_MODE
295 
296 static dbus_bool_t verbose_initted = FALSE;
297 static dbus_bool_t verbose = TRUE;
298 
300 #define PTHREAD_IN_VERBOSE 0
301 #if PTHREAD_IN_VERBOSE
302 #include <pthread.h>
303 #endif
304 
305 #ifdef DBUS_USE_OUTPUT_DEBUG_STRING
306 static char module_name[1024];
307 #endif
308 
309 static inline void
310 _dbus_verbose_init (void)
311 {
312  if (!verbose_initted)
313  {
314  const char *p = _dbus_getenv ("DBUS_VERBOSE");
315  verbose = p != NULL && *p == '1';
316  verbose_initted = TRUE;
317 #ifdef DBUS_USE_OUTPUT_DEBUG_STRING
318  {
319  char *last_period, *last_slash;
320  GetModuleFileName(0,module_name,sizeof(module_name)-1);
321  last_period = _mbsrchr(module_name,'.');
322  if (last_period)
323  *last_period ='\0';
324  last_slash = _mbsrchr(module_name,'\\');
325  if (last_slash)
326  strcpy(module_name,last_slash+1);
327  strcat(module_name,": ");
328  }
329 #endif
330  }
331 }
332 
338 #ifdef DBUS_WIN
339 #define DBUS_IS_DIR_SEPARATOR(c) (c == '\\' || c == '/')
340 #else
341 #define DBUS_IS_DIR_SEPARATOR(c) (c == '/')
342 #endif
343 
348 static char *_dbus_file_path_extract_elements_from_tail(const char *file,int level)
349 {
350  static int prefix = -1;
351 
352  if (prefix == -1)
353  {
354  char *p = (char *)file + strlen(file);
355  int i = 0;
356  prefix = 0;
357  for (;p >= file;p--)
358  {
359  if (DBUS_IS_DIR_SEPARATOR(*p))
360  {
361  if (++i >= level)
362  {
363  prefix = p-file+1;
364  break;
365  }
366  }
367  }
368  }
369  return (char *)file+prefix;
370 }
371 
378 _dbus_is_verbose_real (void)
379 {
380  _dbus_verbose_init ();
381  return verbose;
382 }
383 
392 void
393 _dbus_verbose_real (
394 #ifdef DBUS_CPP_SUPPORTS_VARIABLE_MACRO_ARGUMENTS
395  const char *file,
396  const int line,
397  const char *function,
398 #endif
399  const char *format,
400  ...)
401 {
402  va_list args;
403  static dbus_bool_t need_pid = TRUE;
404  int len;
405 
406  /* things are written a bit oddly here so that
407  * in the non-verbose case we just have the one
408  * conditional and return immediately.
409  */
410  if (!_dbus_is_verbose_real())
411  return;
412 
413 #ifndef DBUS_USE_OUTPUT_DEBUG_STRING
414  /* Print out pid before the line */
415  if (need_pid)
416  {
417 #if PTHREAD_IN_VERBOSE
418  fprintf (stderr, "%lu: 0x%lx: ", _dbus_pid_for_log (), pthread_self ());
419 #else
420  fprintf (stderr, "%lu: ", _dbus_pid_for_log ());
421 #endif
422  }
423 #endif
424 
425  /* Only print pid again if the next line is a new line */
426  len = strlen (format);
427  if (format[len-1] == '\n')
428  need_pid = TRUE;
429  else
430  need_pid = FALSE;
431 
432  va_start (args, format);
433 #ifdef DBUS_USE_OUTPUT_DEBUG_STRING
434  {
435  char buf[1024];
436  strcpy(buf,module_name);
437 #ifdef DBUS_CPP_SUPPORTS_VARIABLE_MACRO_ARGUMENTS
438  sprintf (buf+strlen(buf), "[%s(%d):%s] ",_dbus_file_path_extract_elements_from_tail(file,2),line,function);
439 #endif
440  vsprintf (buf+strlen(buf),format, args);
441  va_end (args);
442  OutputDebugStringA(buf);
443  }
444 #else
445 #ifdef DBUS_CPP_SUPPORTS_VARIABLE_MACRO_ARGUMENTS
446  fprintf (stderr, "[%s(%d):%s] ",_dbus_file_path_extract_elements_from_tail(file,2),line,function);
447 #endif
448 
449  vfprintf (stderr, format, args);
450  va_end (args);
451 
452  fflush (stderr);
453 #endif
454 }
455 
462 void
463 _dbus_verbose_reset_real (void)
464 {
465  verbose_initted = FALSE;
466 }
467 
468 void
469 _dbus_trace_ref (const char *obj_name,
470  void *obj,
471  int old_refcount,
472  int new_refcount,
473  const char *why,
474  const char *env_var,
475  int *enabled)
476 {
477  _dbus_assert (obj_name != NULL);
478  _dbus_assert (obj != NULL);
479  _dbus_assert (old_refcount >= -1);
480  _dbus_assert (new_refcount >= -1);
481 
482  if (old_refcount == -1)
483  {
484  _dbus_assert (new_refcount == -1);
485  }
486  else
487  {
488  _dbus_assert (new_refcount >= 0);
489  _dbus_assert (old_refcount >= 0);
490  _dbus_assert (old_refcount > 0 || new_refcount > 0);
491  }
492 
493  _dbus_assert (why != NULL);
494  _dbus_assert (env_var != NULL);
495  _dbus_assert (enabled != NULL);
496 
497  if (*enabled < 0)
498  {
499  const char *s = _dbus_getenv (env_var);
500 
501  *enabled = FALSE;
502 
503  if (s && *s)
504  {
505  if (*s == '0')
506  *enabled = FALSE;
507  else if (*s == '1')
508  *enabled = TRUE;
509  else
510  _dbus_warn ("%s should be 0 or 1 if set, not '%s'", env_var, s);
511  }
512  }
513 
514  if (*enabled)
515  {
516  if (old_refcount == -1)
517  {
518  VALGRIND_PRINTF_BACKTRACE ("%s %p ref stolen (%s)",
519  obj_name, obj, why);
520  _dbus_verbose ("%s %p ref stolen (%s)",
521  obj_name, obj, why);
522  }
523  else
524  {
525  VALGRIND_PRINTF_BACKTRACE ("%s %p %d -> %d refs (%s)",
526  obj_name, obj,
527  old_refcount, new_refcount, why);
528  _dbus_verbose ("%s %p %d -> %d refs (%s)",
529  obj_name, obj, old_refcount, new_refcount, why);
530  }
531  }
532 }
533 
534 #endif /* DBUS_ENABLE_VERBOSE_MODE */
535 
544 char*
545 _dbus_strdup (const char *str)
546 {
547  size_t len;
548  char *copy;
549 
550  if (str == NULL)
551  return NULL;
552 
553  len = strlen (str);
554 
555  copy = dbus_malloc (len + 1);
556  if (copy == NULL)
557  return NULL;
558 
559  memcpy (copy, str, len + 1);
560 
561  return copy;
562 }
563 
572 void*
573 _dbus_memdup (const void *mem,
574  size_t n_bytes)
575 {
576  void *copy;
577 
578  copy = dbus_malloc (n_bytes);
579  if (copy == NULL)
580  return NULL;
581 
582  memcpy (copy, mem, n_bytes);
583 
584  return copy;
585 }
586 
595 char**
596 _dbus_dup_string_array (const char **array)
597 {
598  int len;
599  int i;
600  char **copy;
601 
602  if (array == NULL)
603  return NULL;
604 
605  for (len = 0; array[len] != NULL; ++len)
606  ;
607 
608  copy = dbus_new0 (char*, len + 1);
609  if (copy == NULL)
610  return NULL;
611 
612  i = 0;
613  while (i < len)
614  {
615  copy[i] = _dbus_strdup (array[i]);
616  if (copy[i] == NULL)
617  {
618  dbus_free_string_array (copy);
619  return NULL;
620  }
621 
622  ++i;
623  }
624 
625  return copy;
626 }
627 
636 _dbus_string_array_contains (const char **array,
637  const char *str)
638 {
639  int i;
640 
641  i = 0;
642  while (array[i] != NULL)
643  {
644  if (strcmp (array[i], str) == 0)
645  return TRUE;
646  ++i;
647  }
648 
649  return FALSE;
650 }
651 
658 void
660 {
661  long now;
662 
663  /* don't use monotonic time because the UUID may be saved to disk, e.g.
664  * it may persist across reboots
665  */
666  _dbus_get_real_time (&now, NULL);
667 
668  uuid->as_uint32s[DBUS_UUID_LENGTH_WORDS - 1] = DBUS_UINT32_TO_BE (now);
669 
670  _dbus_generate_random_bytes_buffer (uuid->as_bytes, DBUS_UUID_LENGTH_BYTES - 4);
671 }
672 
682  DBusString *encoded)
683 {
684  DBusString binary;
685  _dbus_string_init_const_len (&binary, uuid->as_bytes, DBUS_UUID_LENGTH_BYTES);
686  return _dbus_string_hex_encode (&binary, 0, encoded, _dbus_string_get_length (encoded));
687 }
688 
689 static dbus_bool_t
690 _dbus_read_uuid_file_without_creating (const DBusString *filename,
691  DBusGUID *uuid,
692  DBusError *error)
693 {
694  DBusString contents;
695  DBusString decoded;
696  int end;
697 
698  if (!_dbus_string_init (&contents))
699  {
700  _DBUS_SET_OOM (error);
701  return FALSE;
702  }
703 
704  if (!_dbus_string_init (&decoded))
705  {
706  _dbus_string_free (&contents);
707  _DBUS_SET_OOM (error);
708  return FALSE;
709  }
710 
711  if (!_dbus_file_get_contents (&contents, filename, error))
712  goto error;
713 
714  _dbus_string_chop_white (&contents);
715 
716  if (_dbus_string_get_length (&contents) != DBUS_UUID_LENGTH_HEX)
717  {
719  "UUID file '%s' should contain a hex string of length %d, not length %d, with no other text",
720  _dbus_string_get_const_data (filename),
721  DBUS_UUID_LENGTH_HEX,
722  _dbus_string_get_length (&contents));
723  goto error;
724  }
725 
726  if (!_dbus_string_hex_decode (&contents, 0, &end, &decoded, 0))
727  {
728  _DBUS_SET_OOM (error);
729  goto error;
730  }
731 
732  if (end == 0)
733  {
735  "UUID file '%s' contains invalid hex data",
736  _dbus_string_get_const_data (filename));
737  goto error;
738  }
739 
740  if (_dbus_string_get_length (&decoded) != DBUS_UUID_LENGTH_BYTES)
741  {
743  "UUID file '%s' contains %d bytes of hex-encoded data instead of %d",
744  _dbus_string_get_const_data (filename),
745  _dbus_string_get_length (&decoded),
746  DBUS_UUID_LENGTH_BYTES);
747  goto error;
748  }
749 
750  _dbus_string_copy_to_buffer (&decoded, uuid->as_bytes, DBUS_UUID_LENGTH_BYTES);
751 
752  _dbus_string_free (&decoded);
753  _dbus_string_free (&contents);
754 
755  _DBUS_ASSERT_ERROR_IS_CLEAR (error);
756 
757  return TRUE;
758 
759  error:
760  _DBUS_ASSERT_ERROR_IS_SET (error);
761  _dbus_string_free (&contents);
762  _dbus_string_free (&decoded);
763  return FALSE;
764 }
765 
766 static dbus_bool_t
767 _dbus_create_uuid_file_exclusively (const DBusString *filename,
768  DBusGUID *uuid,
769  DBusError *error)
770 {
771  DBusString encoded;
772 
773  if (!_dbus_string_init (&encoded))
774  {
775  _DBUS_SET_OOM (error);
776  return FALSE;
777  }
778 
779  _dbus_generate_uuid (uuid);
780 
781  if (!_dbus_uuid_encode (uuid, &encoded))
782  {
783  _DBUS_SET_OOM (error);
784  goto error;
785  }
786 
787  if (!_dbus_string_append_byte (&encoded, '\n'))
788  {
789  _DBUS_SET_OOM (error);
790  goto error;
791  }
792 
793  if (!_dbus_string_save_to_file (&encoded, filename, TRUE, error))
794  goto error;
795 
796  _dbus_string_free (&encoded);
797 
798  _DBUS_ASSERT_ERROR_IS_CLEAR (error);
799  return TRUE;
800 
801  error:
802  _DBUS_ASSERT_ERROR_IS_SET (error);
803  _dbus_string_free (&encoded);
804  return FALSE;
805 }
806 
819  DBusGUID *uuid,
820  dbus_bool_t create_if_not_found,
821  DBusError *error)
822 {
823  DBusError read_error = DBUS_ERROR_INIT;
824 
825  if (_dbus_read_uuid_file_without_creating (filename, uuid, &read_error))
826  return TRUE;
827 
828  if (!create_if_not_found)
829  {
830  dbus_move_error (&read_error, error);
831  return FALSE;
832  }
833 
834  /* If the file exists and contains junk, we want to keep that error
835  * message instead of overwriting it with a "file exists" error
836  * message when we try to write
837  */
839  {
840  dbus_move_error (&read_error, error);
841  return FALSE;
842  }
843  else
844  {
845  dbus_error_free (&read_error);
846  return _dbus_create_uuid_file_exclusively (filename, uuid, error);
847  }
848 }
849 
850 _DBUS_DEFINE_GLOBAL_LOCK (machine_uuid);
851 static int machine_uuid_initialized_generation = 0;
852 static DBusGUID machine_uuid;
853 
866 {
867  dbus_bool_t ok;
868 
869  _DBUS_LOCK (machine_uuid);
870  if (machine_uuid_initialized_generation != _dbus_current_generation)
871  {
872  DBusError error = DBUS_ERROR_INIT;
873 
874  if (!_dbus_read_local_machine_uuid (&machine_uuid, FALSE,
875  &error))
876  {
877 #ifndef DBUS_BUILD_TESTS
878  /* For the test suite, we may not be installed so just continue silently
879  * here. But in a production build, we want to be nice and loud about
880  * this.
881  */
882  _dbus_warn_check_failed ("D-Bus library appears to be incorrectly set up; failed to read machine uuid: %s\n"
883  "See the manual page for dbus-uuidgen to correct this issue.\n",
884  error.message);
885 #endif
886 
887  dbus_error_free (&error);
888 
889  _dbus_generate_uuid (&machine_uuid);
890  }
891  }
892 
893  ok = _dbus_uuid_encode (&machine_uuid, uuid_str);
894 
895  _DBUS_UNLOCK (machine_uuid);
896 
897  return ok;
898 }
899 
900 #ifndef DBUS_DISABLE_CHECKS
901 
903 "arguments to %s() were incorrect, assertion \"%s\" failed in file %s line %d.\n"
904 "This is normally a bug in some application using the D-Bus library.\n";
905 #endif
906 
907 #ifndef DBUS_DISABLE_ASSERT
908 
920 void
922  const char *condition_text,
923  const char *file,
924  int line,
925  const char *func)
926 {
927  if (_DBUS_UNLIKELY (!condition))
928  {
929  _dbus_warn ("%lu: assertion failed \"%s\" file \"%s\" line %d function %s\n",
930  _dbus_pid_for_log (), condition_text, file, line, func);
931  _dbus_abort ();
932  }
933 }
934 
945 void
946 _dbus_real_assert_not_reached (const char *explanation,
947  const char *file,
948  int line)
949 {
950  _dbus_warn ("File \"%s\" line %d process %lu should not have been reached: %s\n",
951  file, line, _dbus_pid_for_log (), explanation);
952  _dbus_abort ();
953 }
954 #endif /* DBUS_DISABLE_ASSERT */
955 
956 #ifdef DBUS_BUILD_TESTS
957 static dbus_bool_t
958 run_failing_each_malloc (int n_mallocs,
959  const char *description,
960  DBusTestMemoryFunction func,
961  void *data)
962 {
963  n_mallocs += 10; /* fudge factor to ensure reallocs etc. are covered */
964 
965  while (n_mallocs >= 0)
966  {
967  _dbus_set_fail_alloc_counter (n_mallocs);
968 
969  _dbus_verbose ("\n===\n%s: (will fail malloc %d with %d failures)\n===\n",
970  description, n_mallocs,
971  _dbus_get_fail_alloc_failures ());
972 
973  if (!(* func) (data))
974  return FALSE;
975 
976  n_mallocs -= 1;
977  }
978 
979  _dbus_set_fail_alloc_counter (_DBUS_INT_MAX);
980 
981  return TRUE;
982 }
983 
998 _dbus_test_oom_handling (const char *description,
999  DBusTestMemoryFunction func,
1000  void *data)
1001 {
1002  int approx_mallocs;
1003  const char *setting;
1004  int max_failures_to_try;
1005  int i;
1006 
1007  /* Run once to see about how many mallocs are involved */
1008 
1009  _dbus_set_fail_alloc_counter (_DBUS_INT_MAX);
1010 
1011  _dbus_verbose ("Running once to count mallocs\n");
1012 
1013  if (!(* func) (data))
1014  return FALSE;
1015 
1016  approx_mallocs = _DBUS_INT_MAX - _dbus_get_fail_alloc_counter ();
1017 
1018  _dbus_verbose ("\n=================\n%s: about %d mallocs total\n=================\n",
1019  description, approx_mallocs);
1020 
1021  setting = _dbus_getenv ("DBUS_TEST_MALLOC_FAILURES");
1022  if (setting != NULL)
1023  {
1024  DBusString str;
1025  long v;
1026  _dbus_string_init_const (&str, setting);
1027  v = 4;
1028  if (!_dbus_string_parse_int (&str, 0, &v, NULL))
1029  _dbus_warn ("couldn't parse '%s' as integer\n", setting);
1030  max_failures_to_try = v;
1031  }
1032  else
1033  {
1034  max_failures_to_try = 4;
1035  }
1036 
1037  i = setting ? max_failures_to_try - 1 : 1;
1038  while (i < max_failures_to_try)
1039  {
1040  _dbus_set_fail_alloc_failures (i);
1041  if (!run_failing_each_malloc (approx_mallocs, description, func, data))
1042  return FALSE;
1043  ++i;
1044  }
1045 
1046  _dbus_verbose ("\n=================\n%s: all iterations passed\n=================\n",
1047  description);
1048 
1049  return TRUE;
1050 }
1051 #endif /* DBUS_BUILD_TESTS */
1052 
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_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:433
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:675
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++.
#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:2256
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_uint32_t as_uint32s[DBUS_UUID_LENGTH_WORDS]
guid as four uint32 values
const char * _dbus_return_if_fail_warning_format
String used in _dbus_return_if_fail macro.
void _dbus_string_chop_white(DBusString *str)
Deletes leading and trailing whitespace.
Definition: dbus-string.c:1986
#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 &quot;critical&quot; 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
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 &quot;int&quot;.
const char * _dbus_getenv(const char *varname)
Wrapper for getenv().
Definition: dbus-sysdeps.c:183
dbus_bool_t _dbus_get_local_machine_uuid_encoded(DBusString *uuid_str)
Gets the hex-encoded UUID of the machine this function is executed on.
void _dbus_abort(void)
Aborts the program with SIGABRT (dumping core).
Definition: dbus-sysdeps.c:80
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_get_real_time(long *tv_sec, long *tv_usec)
Get current time, as in gettimeofday().
void * dbus_malloc(size_t bytes)
Allocates the given number of bytes, as with standard malloc().
Definition: dbus-memory.c:460
#define dbus_new0(type, count)
Safe macro for using dbus_malloc0().
Definition: dbus-memory.h:59
void _dbus_generate_random_bytes_buffer(char *buffer, int n_bytes)
Fills n_bytes of the given buffer with random bytes.
Definition: dbus-sysdeps.c:541
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 &quot;out of memory&quot; 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_string_get_length(const DBusString *str)
Gets the length of a string (not including nul termination).
Definition: dbus-string.c:717
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:780
Object representing an exception.
Definition: dbus-errors.h:48
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:1154
#define _DBUS_UNLOCK(name)
Unlocks a global lock.
void _dbus_string_free(DBusString *str)
Frees a string created by _dbus_string_init().
Definition: dbus-string.c:242
char ** _dbus_dup_string_array(const char **array)
Duplicates a string array.
#define TRUE
Expands to &quot;1&quot;.
void dbus_move_error(DBusError *src, DBusError *dest)
Moves an error src into dest, freeing src and overwriting dest.
Definition: dbus-errors.c:279
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.
#define _DBUS_DEFINE_GLOBAL_LOCK(name)
Defines a global lock variable with the given name.
unsigned long _dbus_pid_for_log(void)
The only reason this is separate from _dbus_getpid() is to allow it on Windows for logging but not fo...
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:2306
void dbus_free_string_array(char **str_array)
Frees a NULL-terminated array of strings.
Definition: dbus-memory.c:748
dbus_bool_t _dbus_string_array_contains(const char **array, const char *str)
Checks whether a string array contains the given string.
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.
#define FALSE
Expands to &quot;0&quot;.
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_generate_uuid(DBusGUID *uuid)
Generates a new UUID.
#define _DBUS_LOCK(name)
Locks a global lock.
char * _dbus_strdup(const char *str)
Duplicates a string.
const char * _dbus_string_get_const_data(const DBusString *str)
Gets the raw character buffer from a const string.
Definition: dbus-string.c:446
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