D-Bus 1.13.18

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 /* 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. */
190 static 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. */
195 static dbus_bool_t fatal_warnings = FALSE;
196 static dbus_bool_t fatal_warnings_on_check_failed = TRUE;
197
198 static void
199 init_warnings(void)
200 {
201 if (!warn_initted)
202 {
203 const char *s;
204 s = _dbus_getenv ("DBUS_FATAL_WARNINGS");
205 if (s && *s)
206 {
207 if (*s == '0')
208 {
209 fatal_warnings = FALSE;
210 fatal_warnings_on_check_failed = FALSE;
211 }
212 else if (*s == '1')
213 {
214 fatal_warnings = TRUE;
215 fatal_warnings_on_check_failed = TRUE;
216 }
217 else
218 {
219 fprintf(stderr, "DBUS_FATAL_WARNINGS should be set to 0 or 1 if set, not '%s'",
220 s);
221 }
222 }
223
224 warn_initted = TRUE;
225 }
226 }
227
237 void
238 _dbus_warn (const char *format,
239 ...)
240 {
241 DBusSystemLogSeverity severity = DBUS_SYSTEM_LOG_WARNING;
242 va_list args;
243
244 if (!warn_initted)
245 init_warnings ();
246
247 if (fatal_warnings)
248 severity = DBUS_SYSTEM_LOG_ERROR;
249
250 va_start (args, format);
251 _dbus_logv (severity, format, args);
252 va_end (args);
253
254 if (fatal_warnings)
255 {
256 fflush (stderr);
257 _dbus_abort ();
258 }
259 }
260
269 void
270 _dbus_warn_check_failed(const char *format,
271 ...)
272 {
273 DBusSystemLogSeverity severity = DBUS_SYSTEM_LOG_WARNING;
274 va_list args;
275
276 if (!warn_initted)
277 init_warnings ();
278
279 if (fatal_warnings_on_check_failed)
280 severity = DBUS_SYSTEM_LOG_ERROR;
281
282 va_start (args, format);
283 _dbus_logv (severity, format, args);
284 va_end (args);
285
286 if (fatal_warnings_on_check_failed)
287 {
288 fflush (stderr);
289 _dbus_abort ();
290 }
291 }
292
293 #ifdef DBUS_ENABLE_VERBOSE_MODE
294
295 static dbus_bool_t verbose_initted = FALSE;
296 static dbus_bool_t verbose = TRUE;
297
298 #ifdef DBUS_USE_OUTPUT_DEBUG_STRING
299 static char module_name[1024];
300 #endif
301
302 static inline void
303 _dbus_verbose_init (void)
304 {
305 if (!verbose_initted)
306 {
307 const char *p = _dbus_getenv ("DBUS_VERBOSE");
308 verbose = p != NULL && *p == '1';
309 verbose_initted = TRUE;
310 #ifdef DBUS_USE_OUTPUT_DEBUG_STRING
311 {
312 char *last_period, *last_slash;
313 GetModuleFileName(0,module_name,sizeof(module_name)-1);
314 last_period = _mbsrchr(module_name,'.');
315 if (last_period)
316 *last_period ='\0';
317 last_slash = _mbsrchr(module_name,'\\');
318 if (last_slash)
319 strcpy(module_name,last_slash+1);
320 strcat(module_name,": ");
321 }
322 #endif
323 }
324 }
325
331 #ifdef DBUS_WIN
332 #define DBUS_IS_DIR_SEPARATOR(c) (c == '\\' || c == '/')
333 #else
334 #define DBUS_IS_DIR_SEPARATOR(c) (c == '/')
335 #endif
336
341 static 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
367 dbus_bool_t
368 _dbus_is_verbose_real (void)
369 {
370 _dbus_verbose_init ();
371 return verbose;
372 }
373
374 void _dbus_set_verbose (dbus_bool_t state)
375 {
376 verbose = state;
377 }
378
379 dbus_bool_t _dbus_get_verbose (void)
380 {
381 return verbose;
382 }
383
395 void
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
416 void
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);
475 out:
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
506 void
507 _dbus_verbose_reset_real (void)
508 {
509 verbose_initted = FALSE;
510 }
511
512 void
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
588 char*
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
616 void*
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
639 char**
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 {
662 dbus_free_string_array (copy);
663 return NULL;
664 }
665
666 ++i;
667 }
668
669 return copy;
670 }
671
679 dbus_bool_t
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
702 size_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
719 dbus_bool_t
720 _dbus_generate_uuid (DBusGUID *uuid,
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 */
731 _dbus_get_real_time (&now, NULL);
732
733 uuid->as_uint32s[DBUS_UUID_LENGTH_WORDS - 1] = DBUS_UINT32_TO_BE (now);
734
735 if (!_dbus_generate_random_bytes_buffer (uuid->as_bytes,
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
755 dbus_bool_t
756 _dbus_uuid_encode (const DBusGUID *uuid,
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
764 static 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 {
793 dbus_set_error (error, DBUS_ERROR_INVALID_FILE_CONTENT,
794 "UUID file '%s' should contain a hex string of length %d, not length %d, with no other text",
795 _dbus_string_get_const_data (filename),
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 {
809 dbus_set_error (error, DBUS_ERROR_INVALID_FILE_CONTENT,
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 {
817 dbus_set_error (error, DBUS_ERROR_INVALID_FILE_CONTENT,
818 "UUID file '%s' contains %d bytes of hex-encoded data instead of %d",
819 _dbus_string_get_const_data (filename),
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
849 dbus_bool_t
850 _dbus_write_uuid_file (const DBusString *filename,
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
898 dbus_bool_t
899 _dbus_read_uuid_file (const DBusString *filename,
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 */
919 if (dbus_error_has_name (&read_error, DBUS_ERROR_INVALID_FILE_CONTENT))
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) */
936 static int machine_uuid_initialized_generation = 0;
937 static DBusGUID machine_uuid;
938
950 dbus_bool_t
951 _dbus_get_local_machine_uuid_encoded (DBusString *uuid_str,
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
983 void
984 _dbus_warn_return_if_fail (const char *function,
985 const char *assertion,
986 const char *file,
987 int line)
988 {
989 _dbus_warn_check_failed (
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
997
1009 void
1010 _dbus_real_assert (dbus_bool_t condition,
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
1034 void
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
1046 static dbus_bool_t
1047 run_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
1086 dbus_bool_t
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
_dbus_uuid_encode
dbus_bool_t _dbus_uuid_encode(const DBusGUID *uuid, DBusString *encoded)
Hex-encode a UUID.
Definition: dbus-internals.c:756
_dbus_string_hex_decode
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:2359
_dbus_string_copy_to_buffer
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:721
_dbus_dup_string_array
char ** _dbus_dup_string_array(const char **array)
Duplicates a string array.
Definition: dbus-internals.c:640
_dbus_string_free
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:271
_dbus_current_generation
int _dbus_current_generation
_dbus_current_generation is used to track each time that dbus_shutdown() is called,...
Definition: dbus-memory.c:784
_dbus_generate_uuid
dbus_bool_t _dbus_generate_uuid(DBusGUID *uuid, DBusError *error)
Generates a new UUID.
Definition: dbus-internals.c:720
_DBUS_INT_MAX
#define _DBUS_INT_MAX
Definition: dbus-internals.h:302
_dbus_string_save_to_file
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.
Definition: dbus-file-unix.c:164
DBUS_ERROR_INVALID_FILE_CONTENT
#define DBUS_ERROR_INVALID_FILE_CONTENT
A file contains invalid syntax or is otherwise broken.
Definition: dbus-protocol.h:448
_dbus_logv
void _dbus_logv(DBusSystemLogSeverity severity, const char *msg, va_list args)
Log a message to the system log file (e.g.
Definition: dbus-sysdeps-unix.c:5037
DBusGUID
A globally unique ID ; we have one for each DBusServer, and also one for each machine with libdbus in...
Definition: dbus-internals.h:433
_dbus_file_get_contents
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.
Definition: dbus-file-unix.c:55
_dbus_string_parse_int
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
dbus_error_init
void dbus_error_init(DBusError *error)
Initializes a DBusError structure.
Definition: dbus-errors.c:188
_dbus_string_append_byte
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:1181
_dbus_string_init
dbus_bool_t _dbus_string_init(DBusString *str)
Initializes a string.
Definition: dbus-string.c:182
_dbus_string_append_printf_valist
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:1096
_dbus_string_chop_white
void _dbus_string_chop_white(DBusString *str)
Deletes leading and trailing whitespace.
Definition: dbus-string.c:2013
_DBUS_LOCK
#define _DBUS_LOCK(name)
Definition: dbus-internals.h:412
_dbus_real_assert_not_reached
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 ...
Definition: dbus-internals.c:1035
_dbus_string_array_contains
dbus_bool_t _dbus_string_array_contains(const char **array, const char *str)
Checks whether a string array contains the given string.
Definition: dbus-internals.c:680
TRUE
#define TRUE
dbus_error_has_name
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_malloc
void * dbus_malloc(size_t bytes)
Allocates the given number of bytes, as with standard malloc().
Definition: dbus-memory.c:464
DBusGUID::as_uint32s
dbus_uint32_t as_uint32s[DBUS_UUID_LENGTH_WORDS]
guid as four uint32 values
Definition: dbus-internals.h:434
DBusString
Definition: dbus-string.h:43
_dbus_string_append_printf
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:1138
_dbus_no_memory_message
const char * _dbus_no_memory_message
Fixed "out of memory" error message, just to avoid making up a different string every time and wastin...
Definition: dbus-internals.c:185
DBusError::name
const char * name
public error name field
Definition: dbus-errors.h:50
_dbus_read_uuid_file
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.
Definition: dbus-internals.c:899
FALSE
#define FALSE
DBusGUID::as_bytes
char as_bytes[DBUS_UUID_LENGTH_BYTES]
guid as 16 single-byte values
Definition: dbus-internals.h:435
DBUS_ERROR_INIT
#define DBUS_ERROR_INIT
Definition: dbus-errors.h:62
_dbus_getenv
const char * _dbus_getenv(const char *varname)
Wrapper for getenv().
Definition: dbus-sysdeps.c:195
_dbus_abort
void _dbus_abort(void)
Aborts the program with SIGABRT (dumping core).
Definition: dbus-sysdeps.c:87
_dbus_generate_random_bytes_buffer
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
_dbus_get_real_time
void _dbus_get_real_time(long *tv_sec, long *tv_usec)
Get current time, as in gettimeofday().
Definition: dbus-sysdeps-unix.c:3251
_dbus_assert
#define _dbus_assert(condition)
Definition: dbus-internals.h:153
dbus_error_free
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_warn
void _dbus_warn(const char *format,...)
Prints a warning message to stderr.
Definition: dbus-internals.c:238
_dbus_strdup
char * _dbus_strdup(const char *str)
Duplicates a string.
Definition: dbus-internals.c:589
DBusError
Object representing an exception.
Definition: dbus-errors.h:49
_dbus_string_hex_encode
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:2309
dbus_set_error
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_free_string_array
void dbus_free_string_array(char **str_array)
Frees a NULL-terminated array of strings.
Definition: dbus-memory.c:752
_dbus_write_uuid_file
dbus_bool_t _dbus_write_uuid_file(const DBusString *filename, const DBusGUID *uuid, DBusError *error)
Write the give UUID to a file.
Definition: dbus-internals.c:850
_dbus_real_assert
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...
Definition: dbus-internals.c:1010
_DBUS_UNLOCK
#define _DBUS_UNLOCK(name)
Definition: dbus-internals.h:413
_dbus_read_local_machine_uuid
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.
Definition: dbus-sysdeps-unix.c:4257
DBusError::message
const char * message
public error message field
Definition: dbus-errors.h:51
_dbus_get_local_machine_uuid_encoded
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.
Definition: dbus-internals.c:951
_dbus_string_init_const
void _dbus_string_init_const(DBusString *str, const char *value)
Initializes a constant string.
Definition: dbus-string.c:197
dbus_new0
#define dbus_new0(type, count)
Definition: dbus-memory.h:58
_dbus_memdup
void * _dbus_memdup(const void *mem, size_t n_bytes)
Duplicates a block of memory.
Definition: dbus-internals.c:617
_dbus_string_append
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:959
_dbus_string_array_length
size_t _dbus_string_array_length(const char **array)
Returns the size of a string array.
Definition: dbus-internals.c:703
_dbus_string_init_const_len
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
_dbus_warn_check_failed
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...
Definition: dbus-internals.c:270
dbus_move_error
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_uint32_t dbus_bool_t
Definition: dbus-types.h:35
NULL
#define NULL