D-Bus 1.15.8
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 * SPDX-License-Identifier: AFL-2.1 OR GPL-2.0-or-later
7 *
8 * Licensed under the Academic Free License version 2.1
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 *
24 */
25
26#include <config.h>
27#include "dbus-internals.h"
28#include "dbus-protocol.h"
29#include "dbus-marshal-basic.h"
30#include "dbus-test.h"
31#include "dbus-test-tap.h"
32#include "dbus-valgrind-internal.h"
33#include <stdio.h>
34#include <stdarg.h>
35#include <string.h>
36#include <stdlib.h>
37#ifdef DBUS_USE_OUTPUT_DEBUG_STRING
38#include <windows.h>
39#include <mbstring.h>
40#endif
41
182/* The build system should have checked for DBUS_SIZEOF_VOID_P */
183_DBUS_STATIC_ASSERT (sizeof (void *) == DBUS_SIZEOF_VOID_P);
184
185/* dbus currently assumes that function pointers are essentially
186 * interchangeable with data pointers. There's nothing special about
187 * DBusShutdownFunction, it's just an arbitrary function pointer type.
188 * If this assertion fails on your platform, some porting will be required. */
189_DBUS_STATIC_ASSERT (sizeof (void *) == sizeof (DBusShutdownFunction));
190_DBUS_STATIC_ASSERT (_DBUS_ALIGNOF (void *) == _DBUS_ALIGNOF (DBusShutdownFunction));
191
192/* This is meant to be true by definition. */
193_DBUS_STATIC_ASSERT (sizeof (void *) == sizeof (intptr_t));
194_DBUS_STATIC_ASSERT (sizeof (void *) == sizeof (uintptr_t));
195
196/*
197 * Some frequent assumptions that we should *avoid* making include these,
198 * all of which are false on CHERI (which has 128-bit tagged pointers,
199 * but a 64-bit address space and therefore 64-bit sizes):
200 *
201 * sizeof (void *) <= sizeof (size_t)
202 * sizeof (void *) <= 8
203 * _DBUS_ALIGNOF (void *) <= 8
204 *
205 * We should also avoid making these assumptions, although we don't currently
206 * know a concrete example of platforms where they're false:
207 *
208 * sizeof (ptrdiff_t) == sizeof (size_t)
209 */
210
216const char *_dbus_no_memory_message = "Not enough memory";
217
218/* Not necessarily thread-safe, but if writes don't propagate between
219 * threads, the worst that will happen is that we duplicate work in more than
220 * one thread. */
221static dbus_bool_t warn_initted = FALSE;
222
223/* Not necessarily thread-safe, but if writes don't propagate between
224 * threads, the worst that will happen is that warnings get their default
225 * fatal/non-fatal nature. */
226static dbus_bool_t fatal_warnings = FALSE;
227static dbus_bool_t fatal_warnings_on_check_failed = TRUE;
228
229static int check_failed_count = 0;
230
231int _dbus_get_check_failed_count (void)
232{
233 return check_failed_count;
234}
235
236static void
237init_warnings(void)
238{
239 if (!warn_initted)
240 {
241 const char *s;
242 s = _dbus_getenv ("DBUS_FATAL_WARNINGS");
243 if (s && *s)
244 {
245 if (*s == '0')
246 {
247 fatal_warnings = FALSE;
248 fatal_warnings_on_check_failed = FALSE;
249 }
250 else if (*s == '1')
251 {
252 fatal_warnings = TRUE;
253 fatal_warnings_on_check_failed = TRUE;
254 }
255 else
256 {
257 fprintf(stderr, "DBUS_FATAL_WARNINGS should be set to 0 or 1 if set, not '%s'",
258 s);
259 }
260 }
261
262 check_failed_count = 0;
263
264 warn_initted = TRUE;
265 }
266}
267
277void
278_dbus_warn (const char *format,
279 ...)
280{
281 DBusSystemLogSeverity severity = DBUS_SYSTEM_LOG_WARNING;
282 va_list args;
283
284 if (!warn_initted)
285 init_warnings ();
286
287 if (fatal_warnings)
288 severity = DBUS_SYSTEM_LOG_ERROR;
289
290 va_start (args, format);
291 _dbus_logv (severity, format, args);
292 va_end (args);
293
294 if (fatal_warnings)
295 {
296 fflush (stderr);
297 _dbus_abort ();
298 }
299}
300
309void
310_dbus_warn_check_failed(const char *format,
311 ...)
312{
313 DBusSystemLogSeverity severity = DBUS_SYSTEM_LOG_WARNING;
314 va_list args;
315
316 if (!warn_initted)
317 init_warnings ();
318
319 if (fatal_warnings_on_check_failed)
320 severity = DBUS_SYSTEM_LOG_ERROR;
321
322 va_start (args, format);
323 _dbus_logv (severity, format, args);
324 va_end (args);
325
326 if (fatal_warnings_on_check_failed)
327 {
328 fflush (stderr);
329 _dbus_abort ();
330 }
331 else
332 check_failed_count++;
333}
334
335#ifdef DBUS_ENABLE_VERBOSE_MODE
336
337static dbus_bool_t verbose_initted = FALSE;
338static dbus_bool_t verbose = TRUE;
339
340#ifdef DBUS_USE_OUTPUT_DEBUG_STRING
341static char module_name[1024];
342#endif
343
344static inline void
345_dbus_verbose_init (void)
346{
347 if (!verbose_initted)
348 {
349 const char *p = _dbus_getenv ("DBUS_VERBOSE");
350 verbose = p != NULL && *p == '1';
351 verbose_initted = TRUE;
352#ifdef DBUS_USE_OUTPUT_DEBUG_STRING
353 {
354 char *last_period, *last_slash;
355 GetModuleFileName(0,module_name,sizeof(module_name)-1);
356 last_period = _mbsrchr(module_name,'.');
357 if (last_period)
358 *last_period ='\0';
359 last_slash = _mbsrchr(module_name,'\\');
360 if (last_slash)
361 strcpy(module_name,last_slash+1);
362 strcat(module_name,": ");
363 }
364#endif
365 }
366}
367
372static char *_dbus_file_path_extract_elements_from_tail(const char *file,int level)
373{
374 int prefix = 0;
375 char *p = (char *)file + strlen(file);
376 int i = 0;
377
378 for (;p >= file;p--)
379 {
380 if (DBUS_IS_DIR_SEPARATOR(*p))
381 {
382 if (++i >= level)
383 {
384 prefix = p-file+1;
385 break;
386 }
387 }
388 }
389
390 return (char *)file+prefix;
391}
392
399_dbus_is_verbose_real (void)
400{
401 _dbus_verbose_init ();
402 return verbose;
403}
404
405void _dbus_set_verbose (dbus_bool_t state)
406{
407 verbose = state;
408}
409
410dbus_bool_t _dbus_get_verbose (void)
411{
412 return verbose;
413}
414
426void
427_dbus_verbose_raw (const char *s)
428{
429 if (!_dbus_is_verbose_real ())
430 return;
431#ifdef DBUS_USE_OUTPUT_DEBUG_STRING
432 OutputDebugStringA (s);
433#else
434 fputs (s, stderr);
435 fflush (stderr);
436#endif
437}
438
447void
448_dbus_verbose_real (
449#ifdef DBUS_CPP_SUPPORTS_VARIABLE_MACRO_ARGUMENTS
450 const char *file,
451 const int line,
452 const char *function,
453#endif
454 const char *format,
455 ...)
456{
457 va_list args;
458 static dbus_bool_t need_pid = TRUE;
459 int len;
460 long sec, usec;
461
462 /* things are written a bit oddly here so that
463 * in the non-verbose case we just have the one
464 * conditional and return immediately.
465 */
466 if (!_dbus_is_verbose_real())
467 return;
468
469#ifndef DBUS_USE_OUTPUT_DEBUG_STRING
470 /* Print out pid before the line */
471 if (need_pid)
472 {
473 _dbus_print_thread ();
474 }
475 _dbus_get_real_time (&sec, &usec);
476 fprintf (stderr, "%ld.%06ld ", sec, usec);
477#endif
478
479 /* Only print pid again if the next line is a new line */
480 len = strlen (format);
481 if (format[len-1] == '\n')
482 need_pid = TRUE;
483 else
484 need_pid = FALSE;
485
486 va_start (args, format);
487
488#ifdef DBUS_USE_OUTPUT_DEBUG_STRING
489 {
490 DBusString out = _DBUS_STRING_INIT_INVALID;
491 const char *message = NULL;
492
493 if (!_dbus_string_init (&out))
494 goto out;
495
496 if (!_dbus_string_append (&out, module_name))
497 goto out;
498
499#ifdef DBUS_CPP_SUPPORTS_VARIABLE_MACRO_ARGUMENTS
500 if (!_dbus_string_append_printf (&out, "[%s(%d):%s] ", _dbus_file_path_extract_elements_from_tail (file, 2), line, function))
501 goto out;
502#endif
503 if (!_dbus_string_append_printf_valist (&out, format, args))
504 goto out;
505 message = _dbus_string_get_const_data (&out);
506out:
507 if (message == NULL)
508 {
509 OutputDebugStringA ("Out of memory while formatting verbose message: '''");
510 OutputDebugStringA (format);
511 OutputDebugStringA ("'''");
512 }
513 else
514 {
515 OutputDebugStringA (message);
516 }
517 _dbus_string_free (&out);
518 }
519#else
520#ifdef DBUS_CPP_SUPPORTS_VARIABLE_MACRO_ARGUMENTS
521 fprintf (stderr, "[%s(%d):%s] ",_dbus_file_path_extract_elements_from_tail(file,2),line,function);
522#endif
523
524 vfprintf (stderr, format, args);
525 fflush (stderr);
526#endif
527
528 va_end (args);
529}
530
537void
538_dbus_verbose_reset_real (void)
539{
540 verbose_initted = FALSE;
541}
542
543void
544_dbus_trace_ref (const char *obj_name,
545 void *obj,
546 int old_refcount,
547 int new_refcount,
548 const char *why,
549 const char *env_var,
550 int *enabled)
551{
552 _dbus_assert (obj_name != NULL);
553 _dbus_assert (obj != NULL);
554 _dbus_assert (old_refcount >= -1);
555 _dbus_assert (new_refcount >= -1);
556
557 if (old_refcount == -1)
558 {
559 _dbus_assert (new_refcount == -1);
560 }
561 else
562 {
563 _dbus_assert (new_refcount >= 0);
564 _dbus_assert (old_refcount >= 0);
565 _dbus_assert (old_refcount > 0 || new_refcount > 0);
566 }
567
568 _dbus_assert (why != NULL);
569 _dbus_assert (env_var != NULL);
570 _dbus_assert (enabled != NULL);
571
572 if (*enabled < 0)
573 {
574 const char *s = _dbus_getenv (env_var);
575
576 *enabled = FALSE;
577
578 if (s && *s)
579 {
580 if (*s == '0')
581 *enabled = FALSE;
582 else if (*s == '1')
583 *enabled = TRUE;
584 else
585 _dbus_warn ("%s should be 0 or 1 if set, not '%s'", env_var, s);
586 }
587 }
588
589 if (*enabled)
590 {
591 if (old_refcount == -1)
592 {
593 VALGRIND_PRINTF_BACKTRACE ("%s %p ref stolen (%s)",
594 obj_name, obj, why);
595 _dbus_verbose ("%s %p ref stolen (%s)\n",
596 obj_name, obj, why);
597 }
598 else
599 {
600 VALGRIND_PRINTF_BACKTRACE ("%s %p %d -> %d refs (%s)",
601 obj_name, obj,
602 old_refcount, new_refcount, why);
603 _dbus_verbose ("%s %p %d -> %d refs (%s)\n",
604 obj_name, obj, old_refcount, new_refcount, why);
605 }
606 }
607}
608
609#endif /* DBUS_ENABLE_VERBOSE_MODE */
610
619char*
620_dbus_strdup (const char *str)
621{
622 size_t len;
623 char *copy;
624
625 if (str == NULL)
626 return NULL;
627
628 len = strlen (str);
629
630 copy = dbus_malloc (len + 1);
631 if (copy == NULL)
632 return NULL;
633
634 memcpy (copy, str, len + 1);
635
636 return copy;
637}
638
647void*
648_dbus_memdup (const void *mem,
649 size_t n_bytes)
650{
651 void *copy;
652
653 copy = dbus_malloc (n_bytes);
654 if (copy == NULL)
655 return NULL;
656
657 memcpy (copy, mem, n_bytes);
658
659 return copy;
660}
661
670char**
671_dbus_dup_string_array (const char **array)
672{
673 int len;
674 int i;
675 char **copy;
676
677 if (array == NULL)
678 return NULL;
679
680 for (len = 0; array[len] != NULL; ++len)
681 ;
682
683 copy = dbus_new0 (char*, len + 1);
684 if (copy == NULL)
685 return NULL;
686
687 i = 0;
688 while (i < len)
689 {
690 copy[i] = _dbus_strdup (array[i]);
691 if (copy[i] == NULL)
692 {
694 return NULL;
695 }
696
697 ++i;
698 }
699
700 return copy;
701}
702
711_dbus_string_array_contains (const char **array,
712 const char *str)
713{
714 int i;
715
716 i = 0;
717 while (array[i] != NULL)
718 {
719 if (strcmp (array[i], str) == 0)
720 return TRUE;
721 ++i;
722 }
723
724 return FALSE;
725}
726
733size_t
734_dbus_string_array_length (const char **array)
735{
736 size_t i;
737 for (i = 0; array[i]; i++) {}
738 return i;
739}
740
741
752 DBusError *error)
753{
754 DBusError rand_error;
755 long now;
756
757 dbus_error_init (&rand_error);
758
759 /* don't use monotonic time because the UUID may be saved to disk, e.g.
760 * it may persist across reboots
761 */
763
764 uuid->as_uint32s[DBUS_UUID_LENGTH_WORDS - 1] = DBUS_UINT32_TO_BE (now);
765
767 DBUS_UUID_LENGTH_BYTES - 4,
768 &rand_error))
769 {
770 dbus_set_error (error, rand_error.name,
771 "Failed to generate UUID: %s", rand_error.message);
772 dbus_error_free (&rand_error);
773 return FALSE;
774 }
775
776 return TRUE;
777}
778
788 DBusString *encoded)
789{
790 DBusString binary;
791 _dbus_string_init_const_len (&binary, uuid->as_bytes, DBUS_UUID_LENGTH_BYTES);
792 return _dbus_string_hex_encode (&binary, 0, encoded, _dbus_string_get_length (encoded));
793}
794
795static dbus_bool_t
796_dbus_read_uuid_file_without_creating (const DBusString *filename,
797 DBusGUID *uuid,
798 DBusError *error)
799{
800 DBusString contents;
801 DBusString decoded;
802 int end;
803
804 if (!_dbus_string_init (&contents))
805 {
806 _DBUS_SET_OOM (error);
807 return FALSE;
808 }
809
810 if (!_dbus_string_init (&decoded))
811 {
812 _dbus_string_free (&contents);
813 _DBUS_SET_OOM (error);
814 return FALSE;
815 }
816
817 if (!_dbus_file_get_contents (&contents, filename, error))
818 goto error;
819
820 _dbus_string_chop_white (&contents);
821
822 if (_dbus_string_get_length (&contents) != DBUS_UUID_LENGTH_HEX)
823 {
825 "UUID file '%s' should contain a hex string of length %d, not length %d, with no other text",
827 DBUS_UUID_LENGTH_HEX,
828 _dbus_string_get_length (&contents));
829 goto error;
830 }
831
832 if (!_dbus_string_hex_decode (&contents, 0, &end, &decoded, 0))
833 {
834 _DBUS_SET_OOM (error);
835 goto error;
836 }
837
838 if (end == 0)
839 {
841 "UUID file '%s' contains invalid hex data",
842 _dbus_string_get_const_data (filename));
843 goto error;
844 }
845
846 if (_dbus_string_get_length (&decoded) != DBUS_UUID_LENGTH_BYTES)
847 {
849 "UUID file '%s' contains %d bytes of hex-encoded data instead of %d",
851 _dbus_string_get_length (&decoded),
852 DBUS_UUID_LENGTH_BYTES);
853 goto error;
854 }
855
856 _dbus_string_copy_to_buffer (&decoded, uuid->as_bytes, DBUS_UUID_LENGTH_BYTES);
857
858 _dbus_string_free (&decoded);
859 _dbus_string_free (&contents);
860
861 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
862
863 return TRUE;
864
865 error:
866 _DBUS_ASSERT_ERROR_IS_SET (error);
867 _dbus_string_free (&contents);
868 _dbus_string_free (&decoded);
869 return FALSE;
870}
871
882 const DBusGUID *uuid,
883 DBusError *error)
884{
885 DBusString encoded;
886
887 if (!_dbus_string_init (&encoded))
888 {
889 _DBUS_SET_OOM (error);
890 return FALSE;
891 }
892
893 if (!_dbus_uuid_encode (uuid, &encoded))
894 {
895 _DBUS_SET_OOM (error);
896 goto error;
897 }
898
899 if (!_dbus_string_append_byte (&encoded, '\n'))
900 {
901 _DBUS_SET_OOM (error);
902 goto error;
903 }
904
905 if (!_dbus_string_save_to_file (&encoded, filename, TRUE, error))
906 goto error;
907
908 _dbus_string_free (&encoded);
909
910 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
911 return TRUE;
912
913 error:
914 _DBUS_ASSERT_ERROR_IS_SET (error);
915 _dbus_string_free (&encoded);
916 return FALSE;
917}
918
931 DBusGUID *uuid,
932 dbus_bool_t create_if_not_found,
933 DBusError *error)
934{
935 DBusError read_error = DBUS_ERROR_INIT;
936
937 if (_dbus_read_uuid_file_without_creating (filename, uuid, &read_error))
938 return TRUE;
939
940 if (!create_if_not_found)
941 {
942 dbus_move_error (&read_error, error);
943 return FALSE;
944 }
945
946 /* If the file exists and contains junk, we want to keep that error
947 * message instead of overwriting it with a "file exists" error
948 * message when we try to write
949 */
951 {
952 dbus_move_error (&read_error, error);
953 return FALSE;
954 }
955 else
956 {
957 dbus_error_free (&read_error);
958
959 if (!_dbus_generate_uuid (uuid, error))
960 return FALSE;
961
962 return _dbus_write_uuid_file (filename, uuid, error);
963 }
964}
965
966/* Protected by _DBUS_LOCK (machine_uuid) */
967static int machine_uuid_initialized_generation = 0;
968static DBusGUID machine_uuid;
969
983 DBusError *error)
984{
985 dbus_bool_t ok = TRUE;
986
987 if (!_DBUS_LOCK (machine_uuid))
988 {
989 _DBUS_SET_OOM (error);
990 return FALSE;
991 }
992
993 if (machine_uuid_initialized_generation != _dbus_current_generation)
994 {
995 if (!_dbus_read_local_machine_uuid (&machine_uuid, FALSE, error))
996 ok = FALSE;
997 }
998
999 if (ok)
1000 {
1001 if (!_dbus_uuid_encode (&machine_uuid, uuid_str))
1002 {
1003 ok = FALSE;
1004 _DBUS_SET_OOM (error);
1005 }
1006 }
1007
1008 _DBUS_UNLOCK (machine_uuid);
1009
1010 return ok;
1011}
1012
1013#ifndef DBUS_DISABLE_CHECKS
1014void
1015_dbus_warn_return_if_fail (const char *function,
1016 const char *assertion,
1017 const char *file,
1018 int line)
1019{
1021 "arguments to %s() were incorrect, assertion \"%s\" failed in file %s line %d.\n"
1022 "This is normally a bug in some application using the D-Bus library.\n",
1023 function, assertion, file, line);
1024}
1025#endif
1026
1027#ifndef DBUS_DISABLE_ASSERT
1040void
1042 const char *condition_text,
1043 const char *file,
1044 int line,
1045 const char *func)
1046{
1047 if (_DBUS_UNLIKELY (!condition))
1048 {
1049 _dbus_warn ("assertion failed \"%s\" file \"%s\" line %d function %s",
1050 condition_text, file, line, func);
1051 _dbus_abort ();
1052 }
1053}
1054
1065void
1066_dbus_real_assert_not_reached (const char *explanation,
1067 const char *file,
1068 int line)
1069{
1070 _dbus_warn ("File \"%s\" line %d should not have been reached: %s",
1071 file, line, explanation);
1072 _dbus_abort ();
1073}
1074#endif /* DBUS_DISABLE_ASSERT */
1075
1076#ifdef DBUS_ENABLE_EMBEDDED_TESTS
1077static dbus_bool_t
1078run_failing_each_malloc (int n_mallocs,
1079 const char *description,
1080 DBusTestMemoryFunction func,
1081 void *data)
1082{
1083 n_mallocs += 10; /* fudge factor to ensure reallocs etc. are covered */
1084
1085 while (n_mallocs >= 0)
1086 {
1087 _dbus_set_fail_alloc_counter (n_mallocs);
1088
1089 _dbus_test_diag ("%s: will fail malloc %d and %d that follow",
1090 description, n_mallocs,
1091 _dbus_get_fail_alloc_failures () - 1);
1092
1093 if (!(* func) (data, FALSE))
1094 return FALSE;
1095
1096 n_mallocs -= 1;
1097 }
1098
1099 _dbus_set_fail_alloc_counter (_DBUS_INT_MAX);
1100
1101 return TRUE;
1102}
1103
1118_dbus_test_oom_handling (const char *description,
1119 DBusTestMemoryFunction func,
1120 void *data)
1121{
1122 int approx_mallocs;
1123 const char *setting;
1124 int max_failures_to_try;
1125 int i;
1126
1127 /* Run once to see about how many mallocs are involved */
1128
1129 _dbus_set_fail_alloc_counter (_DBUS_INT_MAX);
1130
1131 _dbus_test_diag ("Running \"%s\" once to count mallocs", description);
1132
1133 if (!(* func) (data, TRUE))
1134 return FALSE;
1135
1136 approx_mallocs = _DBUS_INT_MAX - _dbus_get_fail_alloc_counter ();
1137
1138 _dbus_test_diag ("\"%s\" has about %d mallocs in total",
1139 description, approx_mallocs);
1140
1141 setting = _dbus_getenv ("DBUS_TEST_MALLOC_FAILURES");
1142
1143 if (setting != NULL)
1144 {
1145 DBusString str;
1146 long v;
1147 _dbus_string_init_const (&str, setting);
1148 v = 4;
1149 if (!_dbus_string_parse_int (&str, 0, &v, NULL))
1150 _dbus_warn ("couldn't parse '%s' as integer\n", setting);
1151 max_failures_to_try = v;
1152 }
1153 else
1154 {
1155 max_failures_to_try = 4;
1156 }
1157
1158 if (RUNNING_ON_VALGRIND && _dbus_getenv ("DBUS_TEST_SLOW") == NULL)
1159 {
1160 /* The full OOM testing is slow, valgrind is slow, so the
1161 * combination is just horrible. Only do this if the user
1162 * asked for extra-slow tests. */
1163 max_failures_to_try = 0;
1164 }
1165
1166 if (max_failures_to_try < 1)
1167 {
1168 _dbus_test_diag ("not testing OOM handling");
1169 return TRUE;
1170 }
1171
1172 _dbus_test_diag ("testing \"%s\" with up to %d consecutive malloc failures",
1173 description, max_failures_to_try);
1174
1175 i = setting ? max_failures_to_try - 1 : 1;
1176 while (i < max_failures_to_try)
1177 {
1178 _dbus_test_diag ("testing \"%s\" with %d consecutive malloc failures",
1179 description, i + 1);
1180
1181 _dbus_set_fail_alloc_failures (i);
1182 if (!run_failing_each_malloc (approx_mallocs, description, func, data))
1183 return FALSE;
1184 ++i;
1185 }
1186
1187 _dbus_verbose ("\"%s\" coped OK with malloc failures\n", description);
1188
1189 return TRUE;
1190}
1191#endif /* DBUS_ENABLE_EMBEDDED_TESTS */
1192
#define DBUS_ERROR_INIT
Expands to a suitable initializer for a DBusError on the stack.
Definition: dbus-errors.h:64
void dbus_move_error(DBusError *src, DBusError *dest)
Moves an error src into dest, freeing src and overwriting dest.
Definition: dbus-errors.c:281
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:304
void dbus_error_init(DBusError *error)
Initializes a DBusError structure.
Definition: dbus-errors.c:190
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:356
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:213
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:527
#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:774
#define dbus_new0(type, count)
Safe macro for using dbus_malloc0().
Definition: dbus-memory.h:60
void dbus_free_string_array(char **str_array)
Frees a NULL-terminated array of strings.
Definition: dbus-memory.c:742
void * dbus_malloc(size_t bytes)
Allocates the given number of bytes, as with standard malloc().
Definition: dbus-memory.c:454
#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:2432
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:980
dbus_bool_t _dbus_string_init(DBusString *str)
Initializes a string.
Definition: dbus-string.c:182
void _dbus_string_init_const(DBusString *str, const char *value)
Initializes a constant string.
Definition: dbus-string.c:197
void _dbus_string_init_const_len(DBusString *str, const char *value, int len)
Initializes a constant string with a length.
Definition: dbus-string.c:217
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:278
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:1105
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:446
int _dbus_string_get_length(const DBusString *str)
Gets the length of a string (not including nul termination).
Definition: dbus-string.c:784
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:1190
void _dbus_string_chop_white(DBusString *str)
Deletes leading and trailing whitespace.
Definition: dbus-string.c:2051
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:2382
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:1147
const char * _dbus_string_get_const_data(const DBusString *str)
Gets the raw character buffer from a const string.
Definition: dbus-string.c:513
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:742
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:197
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:89
dbus_uint32_t dbus_bool_t
A boolean, valid values are TRUE and FALSE.
Definition: dbus-types.h:37
Object representing an exception.
Definition: dbus-errors.h:51
const char * name
public error name field
Definition: dbus-errors.h:52
const char * message
public error message field
Definition: dbus-errors.h:53
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