D-Bus 1.15.2
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
185const char *_dbus_no_memory_message = "Not enough memory";
186
187/* Not necessarily thread-safe, but if writes don't propagate between
188 * threads, the worst that will happen is that we duplicate work in more than
189 * one thread. */
190static dbus_bool_t warn_initted = FALSE;
191
192/* Not necessarily thread-safe, but if writes don't propagate between
193 * threads, the worst that will happen is that warnings get their default
194 * fatal/non-fatal nature. */
195static dbus_bool_t fatal_warnings = FALSE;
196static dbus_bool_t fatal_warnings_on_check_failed = TRUE;
197
198static int check_failed_count = 0;
199
200int _dbus_get_check_failed_count (void)
201{
202 return check_failed_count;
203}
204
205static void
206init_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 check_failed_count = 0;
232
233 warn_initted = TRUE;
234 }
235}
236
246void
247_dbus_warn (const char *format,
248 ...)
249{
250 DBusSystemLogSeverity severity = DBUS_SYSTEM_LOG_WARNING;
251 va_list args;
252
253 if (!warn_initted)
254 init_warnings ();
255
256 if (fatal_warnings)
257 severity = DBUS_SYSTEM_LOG_ERROR;
258
259 va_start (args, format);
260 _dbus_logv (severity, format, args);
261 va_end (args);
262
263 if (fatal_warnings)
264 {
265 fflush (stderr);
266 _dbus_abort ();
267 }
268}
269
278void
279_dbus_warn_check_failed(const char *format,
280 ...)
281{
282 DBusSystemLogSeverity severity = DBUS_SYSTEM_LOG_WARNING;
283 va_list args;
284
285 if (!warn_initted)
286 init_warnings ();
287
288 if (fatal_warnings_on_check_failed)
289 severity = DBUS_SYSTEM_LOG_ERROR;
290
291 va_start (args, format);
292 _dbus_logv (severity, format, args);
293 va_end (args);
294
295 if (fatal_warnings_on_check_failed)
296 {
297 fflush (stderr);
298 _dbus_abort ();
299 }
300 else
301 check_failed_count++;
302}
303
304#ifdef DBUS_ENABLE_VERBOSE_MODE
305
306static dbus_bool_t verbose_initted = FALSE;
307static dbus_bool_t verbose = TRUE;
308
309#ifdef DBUS_USE_OUTPUT_DEBUG_STRING
310static char module_name[1024];
311#endif
312
313static inline void
314_dbus_verbose_init (void)
315{
316 if (!verbose_initted)
317 {
318 const char *p = _dbus_getenv ("DBUS_VERBOSE");
319 verbose = p != NULL && *p == '1';
320 verbose_initted = TRUE;
321#ifdef DBUS_USE_OUTPUT_DEBUG_STRING
322 {
323 char *last_period, *last_slash;
324 GetModuleFileName(0,module_name,sizeof(module_name)-1);
325 last_period = _mbsrchr(module_name,'.');
326 if (last_period)
327 *last_period ='\0';
328 last_slash = _mbsrchr(module_name,'\\');
329 if (last_slash)
330 strcpy(module_name,last_slash+1);
331 strcat(module_name,": ");
332 }
333#endif
334 }
335}
336
341static char *_dbus_file_path_extract_elements_from_tail(const char *file,int level)
342{
343 int prefix = 0;
344 char *p = (char *)file + strlen(file);
345 int i = 0;
346
347 for (;p >= file;p--)
348 {
349 if (DBUS_IS_DIR_SEPARATOR(*p))
350 {
351 if (++i >= level)
352 {
353 prefix = p-file+1;
354 break;
355 }
356 }
357 }
358
359 return (char *)file+prefix;
360}
361
368_dbus_is_verbose_real (void)
369{
370 _dbus_verbose_init ();
371 return verbose;
372}
373
374void _dbus_set_verbose (dbus_bool_t state)
375{
376 verbose = state;
377}
378
379dbus_bool_t _dbus_get_verbose (void)
380{
381 return verbose;
382}
383
395void
396_dbus_verbose_raw (const char *s)
397{
398 if (!_dbus_is_verbose_real ())
399 return;
400#ifdef DBUS_USE_OUTPUT_DEBUG_STRING
401 OutputDebugStringA (s);
402#else
403 fputs (s, stderr);
404 fflush (stderr);
405#endif
406}
407
416void
417_dbus_verbose_real (
418#ifdef DBUS_CPP_SUPPORTS_VARIABLE_MACRO_ARGUMENTS
419 const char *file,
420 const int line,
421 const char *function,
422#endif
423 const char *format,
424 ...)
425{
426 va_list args;
427 static dbus_bool_t need_pid = TRUE;
428 int len;
429 long sec, usec;
430
431 /* things are written a bit oddly here so that
432 * in the non-verbose case we just have the one
433 * conditional and return immediately.
434 */
435 if (!_dbus_is_verbose_real())
436 return;
437
438#ifndef DBUS_USE_OUTPUT_DEBUG_STRING
439 /* Print out pid before the line */
440 if (need_pid)
441 {
442 _dbus_print_thread ();
443 }
444 _dbus_get_real_time (&sec, &usec);
445 fprintf (stderr, "%ld.%06ld ", sec, usec);
446#endif
447
448 /* Only print pid again if the next line is a new line */
449 len = strlen (format);
450 if (format[len-1] == '\n')
451 need_pid = TRUE;
452 else
453 need_pid = FALSE;
454
455 va_start (args, format);
456
457#ifdef DBUS_USE_OUTPUT_DEBUG_STRING
458 {
459 DBusString out = _DBUS_STRING_INIT_INVALID;
460 const char *message = NULL;
461
462 if (!_dbus_string_init (&out))
463 goto out;
464
465 if (!_dbus_string_append (&out, module_name))
466 goto out;
467
468#ifdef DBUS_CPP_SUPPORTS_VARIABLE_MACRO_ARGUMENTS
469 if (!_dbus_string_append_printf (&out, "[%s(%d):%s] ", _dbus_file_path_extract_elements_from_tail (file, 2), line, function))
470 goto out;
471#endif
472 if (!_dbus_string_append_printf_valist (&out, format, args))
473 goto out;
474 message = _dbus_string_get_const_data (&out);
475out:
476 if (message == NULL)
477 {
478 OutputDebugStringA ("Out of memory while formatting verbose message: '''");
479 OutputDebugStringA (format);
480 OutputDebugStringA ("'''");
481 }
482 else
483 {
484 OutputDebugStringA (message);
485 }
486 _dbus_string_free (&out);
487 }
488#else
489#ifdef DBUS_CPP_SUPPORTS_VARIABLE_MACRO_ARGUMENTS
490 fprintf (stderr, "[%s(%d):%s] ",_dbus_file_path_extract_elements_from_tail(file,2),line,function);
491#endif
492
493 vfprintf (stderr, format, args);
494 fflush (stderr);
495#endif
496
497 va_end (args);
498}
499
506void
507_dbus_verbose_reset_real (void)
508{
509 verbose_initted = FALSE;
510}
511
512void
513_dbus_trace_ref (const char *obj_name,
514 void *obj,
515 int old_refcount,
516 int new_refcount,
517 const char *why,
518 const char *env_var,
519 int *enabled)
520{
521 _dbus_assert (obj_name != NULL);
522 _dbus_assert (obj != NULL);
523 _dbus_assert (old_refcount >= -1);
524 _dbus_assert (new_refcount >= -1);
525
526 if (old_refcount == -1)
527 {
528 _dbus_assert (new_refcount == -1);
529 }
530 else
531 {
532 _dbus_assert (new_refcount >= 0);
533 _dbus_assert (old_refcount >= 0);
534 _dbus_assert (old_refcount > 0 || new_refcount > 0);
535 }
536
537 _dbus_assert (why != NULL);
538 _dbus_assert (env_var != NULL);
539 _dbus_assert (enabled != NULL);
540
541 if (*enabled < 0)
542 {
543 const char *s = _dbus_getenv (env_var);
544
545 *enabled = FALSE;
546
547 if (s && *s)
548 {
549 if (*s == '0')
550 *enabled = FALSE;
551 else if (*s == '1')
552 *enabled = TRUE;
553 else
554 _dbus_warn ("%s should be 0 or 1 if set, not '%s'", env_var, s);
555 }
556 }
557
558 if (*enabled)
559 {
560 if (old_refcount == -1)
561 {
562 VALGRIND_PRINTF_BACKTRACE ("%s %p ref stolen (%s)",
563 obj_name, obj, why);
564 _dbus_verbose ("%s %p ref stolen (%s)\n",
565 obj_name, obj, why);
566 }
567 else
568 {
569 VALGRIND_PRINTF_BACKTRACE ("%s %p %d -> %d refs (%s)",
570 obj_name, obj,
571 old_refcount, new_refcount, why);
572 _dbus_verbose ("%s %p %d -> %d refs (%s)\n",
573 obj_name, obj, old_refcount, new_refcount, why);
574 }
575 }
576}
577
578#endif /* DBUS_ENABLE_VERBOSE_MODE */
579
588char*
589_dbus_strdup (const char *str)
590{
591 size_t len;
592 char *copy;
593
594 if (str == NULL)
595 return NULL;
596
597 len = strlen (str);
598
599 copy = dbus_malloc (len + 1);
600 if (copy == NULL)
601 return NULL;
602
603 memcpy (copy, str, len + 1);
604
605 return copy;
606}
607
616void*
617_dbus_memdup (const void *mem,
618 size_t n_bytes)
619{
620 void *copy;
621
622 copy = dbus_malloc (n_bytes);
623 if (copy == NULL)
624 return NULL;
625
626 memcpy (copy, mem, n_bytes);
627
628 return copy;
629}
630
639char**
640_dbus_dup_string_array (const char **array)
641{
642 int len;
643 int i;
644 char **copy;
645
646 if (array == NULL)
647 return NULL;
648
649 for (len = 0; array[len] != NULL; ++len)
650 ;
651
652 copy = dbus_new0 (char*, len + 1);
653 if (copy == NULL)
654 return NULL;
655
656 i = 0;
657 while (i < len)
658 {
659 copy[i] = _dbus_strdup (array[i]);
660 if (copy[i] == NULL)
661 {
663 return NULL;
664 }
665
666 ++i;
667 }
668
669 return copy;
670}
671
680_dbus_string_array_contains (const char **array,
681 const char *str)
682{
683 int i;
684
685 i = 0;
686 while (array[i] != NULL)
687 {
688 if (strcmp (array[i], str) == 0)
689 return TRUE;
690 ++i;
691 }
692
693 return FALSE;
694}
695
702size_t
703_dbus_string_array_length (const char **array)
704{
705 size_t i;
706 for (i = 0; array[i]; i++) {}
707 return i;
708}
709
710
721 DBusError *error)
722{
723 DBusError rand_error;
724 long now;
725
726 dbus_error_init (&rand_error);
727
728 /* don't use monotonic time because the UUID may be saved to disk, e.g.
729 * it may persist across reboots
730 */
732
733 uuid->as_uint32s[DBUS_UUID_LENGTH_WORDS - 1] = DBUS_UINT32_TO_BE (now);
734
736 DBUS_UUID_LENGTH_BYTES - 4,
737 &rand_error))
738 {
739 dbus_set_error (error, rand_error.name,
740 "Failed to generate UUID: %s", rand_error.message);
741 dbus_error_free (&rand_error);
742 return FALSE;
743 }
744
745 return TRUE;
746}
747
757 DBusString *encoded)
758{
759 DBusString binary;
760 _dbus_string_init_const_len (&binary, uuid->as_bytes, DBUS_UUID_LENGTH_BYTES);
761 return _dbus_string_hex_encode (&binary, 0, encoded, _dbus_string_get_length (encoded));
762}
763
764static dbus_bool_t
765_dbus_read_uuid_file_without_creating (const DBusString *filename,
766 DBusGUID *uuid,
767 DBusError *error)
768{
769 DBusString contents;
770 DBusString decoded;
771 int end;
772
773 if (!_dbus_string_init (&contents))
774 {
775 _DBUS_SET_OOM (error);
776 return FALSE;
777 }
778
779 if (!_dbus_string_init (&decoded))
780 {
781 _dbus_string_free (&contents);
782 _DBUS_SET_OOM (error);
783 return FALSE;
784 }
785
786 if (!_dbus_file_get_contents (&contents, filename, error))
787 goto error;
788
789 _dbus_string_chop_white (&contents);
790
791 if (_dbus_string_get_length (&contents) != DBUS_UUID_LENGTH_HEX)
792 {
794 "UUID file '%s' should contain a hex string of length %d, not length %d, with no other text",
796 DBUS_UUID_LENGTH_HEX,
797 _dbus_string_get_length (&contents));
798 goto error;
799 }
800
801 if (!_dbus_string_hex_decode (&contents, 0, &end, &decoded, 0))
802 {
803 _DBUS_SET_OOM (error);
804 goto error;
805 }
806
807 if (end == 0)
808 {
810 "UUID file '%s' contains invalid hex data",
811 _dbus_string_get_const_data (filename));
812 goto error;
813 }
814
815 if (_dbus_string_get_length (&decoded) != DBUS_UUID_LENGTH_BYTES)
816 {
818 "UUID file '%s' contains %d bytes of hex-encoded data instead of %d",
820 _dbus_string_get_length (&decoded),
821 DBUS_UUID_LENGTH_BYTES);
822 goto error;
823 }
824
825 _dbus_string_copy_to_buffer (&decoded, uuid->as_bytes, DBUS_UUID_LENGTH_BYTES);
826
827 _dbus_string_free (&decoded);
828 _dbus_string_free (&contents);
829
830 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
831
832 return TRUE;
833
834 error:
835 _DBUS_ASSERT_ERROR_IS_SET (error);
836 _dbus_string_free (&contents);
837 _dbus_string_free (&decoded);
838 return FALSE;
839}
840
851 const DBusGUID *uuid,
852 DBusError *error)
853{
854 DBusString encoded;
855
856 if (!_dbus_string_init (&encoded))
857 {
858 _DBUS_SET_OOM (error);
859 return FALSE;
860 }
861
862 if (!_dbus_uuid_encode (uuid, &encoded))
863 {
864 _DBUS_SET_OOM (error);
865 goto error;
866 }
867
868 if (!_dbus_string_append_byte (&encoded, '\n'))
869 {
870 _DBUS_SET_OOM (error);
871 goto error;
872 }
873
874 if (!_dbus_string_save_to_file (&encoded, filename, TRUE, error))
875 goto error;
876
877 _dbus_string_free (&encoded);
878
879 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
880 return TRUE;
881
882 error:
883 _DBUS_ASSERT_ERROR_IS_SET (error);
884 _dbus_string_free (&encoded);
885 return FALSE;
886}
887
900 DBusGUID *uuid,
901 dbus_bool_t create_if_not_found,
902 DBusError *error)
903{
904 DBusError read_error = DBUS_ERROR_INIT;
905
906 if (_dbus_read_uuid_file_without_creating (filename, uuid, &read_error))
907 return TRUE;
908
909 if (!create_if_not_found)
910 {
911 dbus_move_error (&read_error, error);
912 return FALSE;
913 }
914
915 /* If the file exists and contains junk, we want to keep that error
916 * message instead of overwriting it with a "file exists" error
917 * message when we try to write
918 */
920 {
921 dbus_move_error (&read_error, error);
922 return FALSE;
923 }
924 else
925 {
926 dbus_error_free (&read_error);
927
928 if (!_dbus_generate_uuid (uuid, error))
929 return FALSE;
930
931 return _dbus_write_uuid_file (filename, uuid, error);
932 }
933}
934
935/* Protected by _DBUS_LOCK (machine_uuid) */
936static int machine_uuid_initialized_generation = 0;
937static DBusGUID machine_uuid;
938
952 DBusError *error)
953{
954 dbus_bool_t ok = TRUE;
955
956 if (!_DBUS_LOCK (machine_uuid))
957 {
958 _DBUS_SET_OOM (error);
959 return FALSE;
960 }
961
962 if (machine_uuid_initialized_generation != _dbus_current_generation)
963 {
964 if (!_dbus_read_local_machine_uuid (&machine_uuid, FALSE, error))
965 ok = FALSE;
966 }
967
968 if (ok)
969 {
970 if (!_dbus_uuid_encode (&machine_uuid, uuid_str))
971 {
972 ok = FALSE;
973 _DBUS_SET_OOM (error);
974 }
975 }
976
977 _DBUS_UNLOCK (machine_uuid);
978
979 return ok;
980}
981
982#ifndef DBUS_DISABLE_CHECKS
983void
984_dbus_warn_return_if_fail (const char *function,
985 const char *assertion,
986 const char *file,
987 int line)
988{
990 "arguments to %s() were incorrect, assertion \"%s\" failed in file %s line %d.\n"
991 "This is normally a bug in some application using the D-Bus library.\n",
992 function, assertion, file, line);
993}
994#endif
995
996#ifndef DBUS_DISABLE_ASSERT
1009void
1011 const char *condition_text,
1012 const char *file,
1013 int line,
1014 const char *func)
1015{
1016 if (_DBUS_UNLIKELY (!condition))
1017 {
1018 _dbus_warn ("assertion failed \"%s\" file \"%s\" line %d function %s",
1019 condition_text, file, line, func);
1020 _dbus_abort ();
1021 }
1022}
1023
1034void
1035_dbus_real_assert_not_reached (const char *explanation,
1036 const char *file,
1037 int line)
1038{
1039 _dbus_warn ("File \"%s\" line %d should not have been reached: %s",
1040 file, line, explanation);
1041 _dbus_abort ();
1042}
1043#endif /* DBUS_DISABLE_ASSERT */
1044
1045#ifdef DBUS_ENABLE_EMBEDDED_TESTS
1046static dbus_bool_t
1047run_failing_each_malloc (int n_mallocs,
1048 const char *description,
1049 DBusTestMemoryFunction func,
1050 void *data)
1051{
1052 n_mallocs += 10; /* fudge factor to ensure reallocs etc. are covered */
1053
1054 while (n_mallocs >= 0)
1055 {
1056 _dbus_set_fail_alloc_counter (n_mallocs);
1057
1058 _dbus_test_diag ("%s: will fail malloc %d and %d that follow",
1059 description, n_mallocs,
1060 _dbus_get_fail_alloc_failures () - 1);
1061
1062 if (!(* func) (data, FALSE))
1063 return FALSE;
1064
1065 n_mallocs -= 1;
1066 }
1067
1068 _dbus_set_fail_alloc_counter (_DBUS_INT_MAX);
1069
1070 return TRUE;
1071}
1072
1087_dbus_test_oom_handling (const char *description,
1088 DBusTestMemoryFunction func,
1089 void *data)
1090{
1091 int approx_mallocs;
1092 const char *setting;
1093 int max_failures_to_try;
1094 int i;
1095
1096 /* Run once to see about how many mallocs are involved */
1097
1098 _dbus_set_fail_alloc_counter (_DBUS_INT_MAX);
1099
1100 _dbus_test_diag ("Running \"%s\" once to count mallocs", description);
1101
1102 if (!(* func) (data, TRUE))
1103 return FALSE;
1104
1105 approx_mallocs = _DBUS_INT_MAX - _dbus_get_fail_alloc_counter ();
1106
1107 _dbus_test_diag ("\"%s\" has about %d mallocs in total",
1108 description, approx_mallocs);
1109
1110 setting = _dbus_getenv ("DBUS_TEST_MALLOC_FAILURES");
1111
1112 if (setting != NULL)
1113 {
1114 DBusString str;
1115 long v;
1116 _dbus_string_init_const (&str, setting);
1117 v = 4;
1118 if (!_dbus_string_parse_int (&str, 0, &v, NULL))
1119 _dbus_warn ("couldn't parse '%s' as integer\n", setting);
1120 max_failures_to_try = v;
1121 }
1122 else
1123 {
1124 max_failures_to_try = 4;
1125 }
1126
1127 if (RUNNING_ON_VALGRIND && _dbus_getenv ("DBUS_TEST_SLOW") == NULL)
1128 {
1129 /* The full OOM testing is slow, valgrind is slow, so the
1130 * combination is just horrible. Only do this if the user
1131 * asked for extra-slow tests. */
1132 max_failures_to_try = 0;
1133 }
1134
1135 if (max_failures_to_try < 1)
1136 {
1137 _dbus_test_diag ("not testing OOM handling");
1138 return TRUE;
1139 }
1140
1141 _dbus_test_diag ("testing \"%s\" with up to %d consecutive malloc failures",
1142 description, max_failures_to_try);
1143
1144 i = setting ? max_failures_to_try - 1 : 1;
1145 while (i < max_failures_to_try)
1146 {
1147 _dbus_test_diag ("testing \"%s\" with %d consecutive malloc failures",
1148 description, i + 1);
1149
1150 _dbus_set_fail_alloc_failures (i);
1151 if (!run_failing_each_malloc (approx_mallocs, description, func, data))
1152 return FALSE;
1153 ++i;
1154 }
1155
1156 _dbus_verbose ("\"%s\" coped OK with malloc failures\n", description);
1157
1158 return TRUE;
1159}
1160#endif /* DBUS_ENABLE_EMBEDDED_TESTS */
1161
#define DBUS_ERROR_INIT
Expands to a suitable initializer for a DBusError on the stack.
Definition: dbus-errors.h:62
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_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
void dbus_error_init(DBusError *error)
Initializes a DBusError structure.
Definition: dbus-errors.c:188
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
void dbus_error_free(DBusError *error)
Frees an error that's been set (or just initialized), then reinitializes the error as in dbus_error_i...
Definition: dbus-errors.c:211
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_file_get_contents(DBusString *str, const DBusString *filename, DBusError *error)
Appends the contents of the given file to the string, returning error code.
#define _dbus_assert(condition)
Aborts with an error message if the condition is false.
#define _DBUS_UNLOCK(name)
Unlocks a global lock.
#define _DBUS_LOCK(name)
Locks a global lock, initializing it first if necessary.
void _dbus_real_assert_not_reached(const char *explanation, const char *file, int line)
Internals of _dbus_assert_not_reached(); it's a function rather than a macro with the inline code so ...
dbus_bool_t _dbus_generate_uuid(DBusGUID *uuid, DBusError *error)
Generates a new UUID.
#define _DBUS_INT_MAX
Maximum value of type "int".
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...
char * _dbus_strdup(const char *str)
Duplicates a string.
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.
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_get_local_machine_uuid_encoded(DBusString *uuid_str, DBusError *error)
Gets the hex-encoded UUID of the machine this function is executed on.
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's a function rather than a macro with the inline code so that the ass...
dbus_bool_t _dbus_write_uuid_file(const DBusString *filename, const DBusGUID *uuid, DBusError *error)
Write the give UUID to a file.
void _dbus_warn(const char *format,...)
Prints a warning message to stderr.
size_t _dbus_string_array_length(const char **array)
Returns the size of a string array.
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_memdup(const void *mem, size_t n_bytes)
Duplicates a block of memory.
dbus_bool_t _dbus_uuid_encode(const DBusGUID *uuid, DBusString *encoded)
Hex-encode a UUID.
char ** _dbus_dup_string_array(const char **array)
Duplicates a string array.
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
#define NULL
A null pointer, defined appropriately for C or C++.
#define TRUE
Expands to "1".
#define FALSE
Expands to "0".
int _dbus_current_generation
_dbus_current_generation is used to track each time that dbus_shutdown() is called,...
Definition: dbus-memory.c:772
#define dbus_new0(type, count)
Safe macro for using dbus_malloc0().
Definition: dbus-memory.h:58
void dbus_free_string_array(char **str_array)
Frees a NULL-terminated array of strings.
Definition: dbus-memory.c:740
void * dbus_malloc(size_t bytes)
Allocates the given number of bytes, as with standard malloc().
Definition: dbus-memory.c:452
#define DBUS_ERROR_INVALID_FILE_CONTENT
A file contains invalid syntax or is otherwise broken.
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:2430
dbus_bool_t _dbus_string_append(DBusString *str, const char *buffer)
Appends a nul-terminated C-style string to a DBusString.
Definition: dbus-string.c:978
dbus_bool_t _dbus_string_init(DBusString *str)
Initializes a string.
Definition: dbus-string.c:180
void _dbus_string_init_const(DBusString *str, const char *value)
Initializes a constant string.
Definition: dbus-string.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:215
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:276
dbus_bool_t _dbus_string_append_printf_valist(DBusString *str, const char *format, va_list args)
Appends a printf-style formatted string to the DBusString.
Definition: dbus-string.c:1103
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
int _dbus_string_get_length(const DBusString *str)
Gets the length of a string (not including nul termination).
Definition: dbus-string.c:782
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:1188
void _dbus_string_chop_white(DBusString *str)
Deletes leading and trailing whitespace.
Definition: dbus-string.c:2049
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:2380
dbus_bool_t _dbus_string_append_printf(DBusString *str, const char *format,...)
Appends a printf-style formatted string to the DBusString.
Definition: dbus-string.c:1145
const char * _dbus_string_get_const_data(const DBusString *str)
Gets the raw character buffer from a const string.
Definition: dbus-string.c:511
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:740
void _dbus_logv(DBusSystemLogSeverity severity, const char *msg, va_list args)
Log a message to the system log file (e.g.
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're running on from the dbus configuration.
const char * _dbus_getenv(const char *varname)
Wrapper for getenv().
Definition: dbus-sysdeps.c:195
void _dbus_get_real_time(long *tv_sec, long *tv_usec)
Get current time, as in gettimeofday().
void _dbus_abort(void)
Aborts the program with SIGABRT (dumping core).
Definition: dbus-sysdeps.c:87
dbus_uint32_t dbus_bool_t
A boolean, valid values are TRUE and FALSE.
Definition: dbus-types.h:35
Object representing an exception.
Definition: dbus-errors.h:49
const char * name
public error name field
Definition: dbus-errors.h:50
const char * message
public error message field
Definition: dbus-errors.h:51
A globally unique ID ; we have one for each DBusServer, and also one for each machine with libdbus in...
dbus_uint32_t as_uint32s[DBUS_UUID_LENGTH_WORDS]
guid as four uint32 values
char as_bytes[DBUS_UUID_LENGTH_BYTES]
guid as 16 single-byte values