bfc87801d7ba20d48b0c849a40892adbadf2a89e
[platform/upstream/dbus.git] / dbus / dbus-sysdeps-util.c
1 /* -*- mode: C; c-file-style: "gnu" -*- */
2 /* dbus-sysdeps-util.c Would be in dbus-sysdeps.c, but not used in libdbus
3  * 
4  * Copyright (C) 2002, 2003, 2004, 2005  Red Hat, Inc.
5  * Copyright (C) 2003 CodeFactory AB
6  *
7  * Licensed under the Academic Free License version 2.1
8  * 
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  * 
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
22  *
23  */
24 #include "dbus-sysdeps.h"
25 #include "dbus-internals.h"
26 #include "dbus-protocol.h"
27 #include "dbus-string.h"
28 #define DBUS_USERDB_INCLUDES_PRIVATE 1
29 #include "dbus-userdb.h"
30 #include "dbus-test.h"
31
32 #include <sys/types.h>
33 #include <stdlib.h>
34 #include <string.h>
35 #include <signal.h>
36 #include <unistd.h>
37 #include <stdio.h>
38 #include <errno.h>
39 #include <fcntl.h>
40 #include <sys/stat.h>
41 #include <grp.h>
42 #include <sys/socket.h>
43 #include <dirent.h>
44 #include <sys/un.h>
45
46 #ifndef O_BINARY
47 #define O_BINARY 0
48 #endif
49
50 /**
51  * @addtogroup DBusInternalsUtils
52  * @{
53  */
54
55 /**
56  * Does the chdir, fork, setsid, etc. to become a daemon process.
57  *
58  * @param pidfile #NULL, or pidfile to create
59  * @param print_pid_fd file descriptor to print daemon's pid to, or -1 for none
60  * @param error return location for errors
61  * @returns #FALSE on failure
62  */
63 dbus_bool_t
64 _dbus_become_daemon (const DBusString *pidfile,
65                      int               print_pid_fd,
66                      DBusError        *error)
67 {
68   const char *s;
69   pid_t child_pid;
70   int dev_null_fd;
71
72   _dbus_verbose ("Becoming a daemon...\n");
73
74   _dbus_verbose ("chdir to /\n");
75   if (chdir ("/") < 0)
76     {
77       dbus_set_error (error, DBUS_ERROR_FAILED,
78                       "Could not chdir() to root directory");
79       return FALSE;
80     }
81
82   _dbus_verbose ("forking...\n");
83   switch ((child_pid = fork ()))
84     {
85     case -1:
86       _dbus_verbose ("fork failed\n");
87       dbus_set_error (error, _dbus_error_from_errno (errno),
88                       "Failed to fork daemon: %s", _dbus_strerror (errno));
89       return FALSE;
90       break;
91
92     case 0:
93       _dbus_verbose ("in child, closing std file descriptors\n");
94
95       /* silently ignore failures here, if someone
96        * doesn't have /dev/null we may as well try
97        * to continue anyhow
98        */
99       
100       dev_null_fd = open ("/dev/null", O_RDWR);
101       if (dev_null_fd >= 0)
102         {
103           dup2 (dev_null_fd, 0);
104           dup2 (dev_null_fd, 1);
105           
106           s = _dbus_getenv ("DBUS_DEBUG_OUTPUT");
107           if (s == NULL || *s == '\0')
108             dup2 (dev_null_fd, 2);
109           else
110             _dbus_verbose ("keeping stderr open due to DBUS_DEBUG_OUTPUT\n");
111         }
112
113       /* Get a predictable umask */
114       _dbus_verbose ("setting umask\n");
115       umask (022);
116       break;
117
118     default:
119       if (pidfile)
120         {
121           _dbus_verbose ("parent writing pid file\n");
122           if (!_dbus_write_pid_file (pidfile,
123                                      child_pid,
124                                      error))
125             {
126               _dbus_verbose ("pid file write failed, killing child\n");
127               kill (child_pid, SIGTERM);
128               return FALSE;
129             }
130         }
131
132       /* Write PID if requested */
133       if (print_pid_fd >= 0)
134         {
135           DBusString pid;
136           int bytes;
137           
138           if (!_dbus_string_init (&pid))
139             {
140               _DBUS_SET_OOM (error);
141               kill (child_pid, SIGTERM);
142               return FALSE;
143             }
144           
145           if (!_dbus_string_append_int (&pid, child_pid) ||
146               !_dbus_string_append (&pid, "\n"))
147             {
148               _dbus_string_free (&pid);
149               _DBUS_SET_OOM (error);
150               kill (child_pid, SIGTERM);
151               return FALSE;
152             }
153           
154           bytes = _dbus_string_get_length (&pid);
155           if (_dbus_write (print_pid_fd, &pid, 0, bytes) != bytes)
156             {
157               dbus_set_error (error, DBUS_ERROR_FAILED,
158                               "Printing message bus PID: %s\n",
159                               _dbus_strerror (errno));
160               _dbus_string_free (&pid);
161               kill (child_pid, SIGTERM);
162               return FALSE;
163             }
164           
165           _dbus_string_free (&pid);
166         }
167       _dbus_verbose ("parent exiting\n");
168       _exit (0);
169       break;
170     }
171
172   _dbus_verbose ("calling setsid()\n");
173   if (setsid () == -1)
174     _dbus_assert_not_reached ("setsid() failed");
175   
176   return TRUE;
177 }
178
179
180 /**
181  * Creates a file containing the process ID.
182  *
183  * @param filename the filename to write to
184  * @param pid our process ID
185  * @param error return location for errors
186  * @returns #FALSE on failure
187  */
188 dbus_bool_t
189 _dbus_write_pid_file (const DBusString *filename,
190                       unsigned long     pid,
191                       DBusError        *error)
192 {
193   const char *cfilename;
194   int fd;
195   FILE *f;
196
197   cfilename = _dbus_string_get_const_data (filename);
198   
199   fd = open (cfilename, O_WRONLY|O_CREAT|O_EXCL|O_BINARY, 0644);
200   
201   if (fd < 0)
202     {
203       dbus_set_error (error, _dbus_error_from_errno (errno),
204                       "Failed to open \"%s\": %s", cfilename,
205                       _dbus_strerror (errno));
206       return FALSE;
207     }
208
209   if ((f = fdopen (fd, "w")) == NULL)
210     {
211       dbus_set_error (error, _dbus_error_from_errno (errno),
212                       "Failed to fdopen fd %d: %s", fd, _dbus_strerror (errno));
213       close (fd);
214       return FALSE;
215     }
216   
217   if (fprintf (f, "%lu\n", pid) < 0)
218     {
219       dbus_set_error (error, _dbus_error_from_errno (errno),
220                       "Failed to write to \"%s\": %s", cfilename,
221                       _dbus_strerror (errno));
222       
223       fclose (f);
224       return FALSE;
225     }
226
227   if (fclose (f) == EOF)
228     {
229       dbus_set_error (error, _dbus_error_from_errno (errno),
230                       "Failed to close \"%s\": %s", cfilename,
231                       _dbus_strerror (errno));
232       return FALSE;
233     }
234   
235   return TRUE;
236 }
237
238
239 /**
240  * Changes the user and group the bus is running as.
241  *
242  * @param uid the new user ID
243  * @param gid the new group ID
244  * @param error return location for errors
245  * @returns #FALSE on failure
246  */
247 dbus_bool_t
248 _dbus_change_identity  (dbus_uid_t     uid,
249                         dbus_gid_t     gid,
250                         DBusError     *error)
251 {
252   /* setgroups() only works if we are a privileged process,
253    * so we don't return error on failure; the only possible
254    * failure is that we don't have perms to do it.
255    * FIXME not sure this is right, maybe if setuid()
256    * is going to work then setgroups() should also work.
257    */
258   if (setgroups (0, NULL) < 0)
259     _dbus_warn ("Failed to drop supplementary groups: %s\n",
260                 _dbus_strerror (errno));
261   
262   /* Set GID first, or the setuid may remove our permission
263    * to change the GID
264    */
265   if (setgid (gid) < 0)
266     {
267       dbus_set_error (error, _dbus_error_from_errno (errno),
268                       "Failed to set GID to %lu: %s", gid,
269                       _dbus_strerror (errno));
270       return FALSE;
271     }
272   
273   if (setuid (uid) < 0)
274     {
275       dbus_set_error (error, _dbus_error_from_errno (errno),
276                       "Failed to set UID to %lu: %s", uid,
277                       _dbus_strerror (errno));
278       return FALSE;
279     }
280   
281   return TRUE;
282 }
283
284 /** Installs a UNIX signal handler
285  *
286  * @param sig the signal to handle
287  * @param handler the handler
288  */
289 void
290 _dbus_set_signal_handler (int               sig,
291                           DBusSignalHandler handler)
292 {
293   struct sigaction act;
294   sigset_t empty_mask;
295   
296   sigemptyset (&empty_mask);
297   act.sa_handler = handler;
298   act.sa_mask    = empty_mask;
299   act.sa_flags   = 0;
300   sigaction (sig,  &act, 0);
301 }
302
303
304 /**
305  * Removes a directory; Directory must be empty
306  * 
307  * @param filename directory filename
308  * @param error initialized error object
309  * @returns #TRUE on success
310  */
311 dbus_bool_t
312 _dbus_delete_directory (const DBusString *filename,
313                         DBusError        *error)
314 {
315   const char *filename_c;
316   
317   _DBUS_ASSERT_ERROR_IS_CLEAR (error);
318
319   filename_c = _dbus_string_get_const_data (filename);
320
321   if (rmdir (filename_c) != 0)
322     {
323       dbus_set_error (error, DBUS_ERROR_FAILED,
324                       "Failed to remove directory %s: %s\n",
325                       filename_c, _dbus_strerror (errno));
326       return FALSE;
327     }
328   
329   return TRUE;
330 }
331
332 /** Checks if a file exists
333 *
334 * @param file full path to the file
335 * @returns #TRUE if file exists
336 */
337 dbus_bool_t 
338 _dbus_file_exists (const char *file)
339 {
340   return (access (file, F_OK) == 0);
341 }
342
343 /** Checks if user is at the console
344 *
345 * @param username user to check
346 * @param error return location for errors
347 * @returns #TRUE is the user is at the consolei and there are no errors
348 */
349 dbus_bool_t 
350 _dbus_user_at_console (const char *username,
351                        DBusError  *error)
352 {
353
354   DBusString f;
355   dbus_bool_t result;
356
357   result = FALSE;
358   if (!_dbus_string_init (&f))
359     {
360       _DBUS_SET_OOM (error);
361       return FALSE;
362     }
363
364   if (!_dbus_string_append (&f, DBUS_CONSOLE_AUTH_DIR))
365     {
366       _DBUS_SET_OOM (error);
367       goto out;
368     }
369
370
371   if (!_dbus_string_append (&f, username))
372     {
373       _DBUS_SET_OOM (error);
374       goto out;
375     }
376
377   result = _dbus_file_exists (_dbus_string_get_const_data (&f));
378
379  out:
380   _dbus_string_free (&f);
381
382   return result;
383 }
384
385
386 /**
387  * Checks whether the filename is an absolute path
388  *
389  * @param filename the filename
390  * @returns #TRUE if an absolute path
391  */
392 dbus_bool_t
393 _dbus_path_is_absolute (const DBusString *filename)
394 {
395   if (_dbus_string_get_length (filename) > 0)
396     return _dbus_string_get_byte (filename, 0) == '/';
397   else
398     return FALSE;
399 }
400
401 /**
402  * stat() wrapper.
403  *
404  * @param filename the filename to stat
405  * @param statbuf the stat info to fill in
406  * @param error return location for error
407  * @returns #FALSE if error was set
408  */
409 dbus_bool_t
410 _dbus_stat (const DBusString *filename,
411             DBusStat         *statbuf,
412             DBusError        *error)
413 {
414   const char *filename_c;
415   struct stat sb;
416
417   _DBUS_ASSERT_ERROR_IS_CLEAR (error);
418   
419   filename_c = _dbus_string_get_const_data (filename);
420
421   if (stat (filename_c, &sb) < 0)
422     {
423       dbus_set_error (error, _dbus_error_from_errno (errno),
424                       "%s", _dbus_strerror (errno));
425       return FALSE;
426     }
427
428   statbuf->mode = sb.st_mode;
429   statbuf->nlink = sb.st_nlink;
430   statbuf->uid = sb.st_uid;
431   statbuf->gid = sb.st_gid;
432   statbuf->size = sb.st_size;
433   statbuf->atime = sb.st_atime;
434   statbuf->mtime = sb.st_mtime;
435   statbuf->ctime = sb.st_ctime;
436
437   return TRUE;
438 }
439
440
441 /**
442  * Internals of directory iterator
443  */
444 struct DBusDirIter
445 {
446   DIR *d; /**< The DIR* from opendir() */
447   
448 };
449
450 /**
451  * Open a directory to iterate over.
452  *
453  * @param filename the directory name
454  * @param error exception return object or #NULL
455  * @returns new iterator, or #NULL on error
456  */
457 DBusDirIter*
458 _dbus_directory_open (const DBusString *filename,
459                       DBusError        *error)
460 {
461   DIR *d;
462   DBusDirIter *iter;
463   const char *filename_c;
464
465   _DBUS_ASSERT_ERROR_IS_CLEAR (error);
466   
467   filename_c = _dbus_string_get_const_data (filename);
468
469   d = opendir (filename_c);
470   if (d == NULL)
471     {
472       dbus_set_error (error, _dbus_error_from_errno (errno),
473                       "Failed to read directory \"%s\": %s",
474                       filename_c,
475                       _dbus_strerror (errno));
476       return NULL;
477     }
478   iter = dbus_new0 (DBusDirIter, 1);
479   if (iter == NULL)
480     {
481       closedir (d);
482       dbus_set_error (error, DBUS_ERROR_NO_MEMORY,
483                       "Could not allocate memory for directory iterator");
484       return NULL;
485     }
486
487   iter->d = d;
488
489   return iter;
490 }
491
492 /**
493  * Get next file in the directory. Will not return "." or ".."  on
494  * UNIX. If an error occurs, the contents of "filename" are
495  * undefined. The error is never set if the function succeeds.
496  *
497  * @todo for thread safety, I think we have to use
498  * readdir_r(). (GLib has the same issue, should file a bug.)
499  *
500  * @param iter the iterator
501  * @param filename string to be set to the next file in the dir
502  * @param error return location for error
503  * @returns #TRUE if filename was filled in with a new filename
504  */
505 dbus_bool_t
506 _dbus_directory_get_next_file (DBusDirIter      *iter,
507                                DBusString       *filename,
508                                DBusError        *error)
509 {
510   struct dirent *ent;
511
512   _DBUS_ASSERT_ERROR_IS_CLEAR (error);
513   
514  again:
515   errno = 0;
516   ent = readdir (iter->d);
517   if (ent == NULL)
518     {
519       if (errno != 0)
520         dbus_set_error (error,
521                         _dbus_error_from_errno (errno),
522                         "%s", _dbus_strerror (errno));
523       return FALSE;
524     }
525   else if (ent->d_name[0] == '.' &&
526            (ent->d_name[1] == '\0' ||
527             (ent->d_name[1] == '.' && ent->d_name[2] == '\0')))
528     goto again;
529   else
530     {
531       _dbus_string_set_length (filename, 0);
532       if (!_dbus_string_append (filename, ent->d_name))
533         {
534           dbus_set_error (error, DBUS_ERROR_NO_MEMORY,
535                           "No memory to read directory entry");
536           return FALSE;
537         }
538       else
539         return TRUE;
540     }
541 }
542
543 /**
544  * Closes a directory iteration.
545  */
546 void
547 _dbus_directory_close (DBusDirIter *iter)
548 {
549   closedir (iter->d);
550   dbus_free (iter);
551 }
552
553 static dbus_bool_t
554 fill_user_info_from_group (struct group  *g,
555                            DBusGroupInfo *info,
556                            DBusError     *error)
557 {
558   _dbus_assert (g->gr_name != NULL);
559   
560   info->gid = g->gr_gid;
561   info->groupname = _dbus_strdup (g->gr_name);
562
563   /* info->members = dbus_strdupv (g->gr_mem) */
564   
565   if (info->groupname == NULL)
566     {
567       dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
568       return FALSE;
569     }
570
571   return TRUE;
572 }
573
574 static dbus_bool_t
575 fill_group_info (DBusGroupInfo    *info,
576                  dbus_gid_t        gid,
577                  const DBusString *groupname,
578                  DBusError        *error)
579 {
580   const char *group_c_str;
581
582   _dbus_assert (groupname != NULL || gid != DBUS_GID_UNSET);
583   _dbus_assert (groupname == NULL || gid == DBUS_GID_UNSET);
584
585   if (groupname)
586     group_c_str = _dbus_string_get_const_data (groupname);
587   else
588     group_c_str = NULL;
589   
590   /* For now assuming that the getgrnam() and getgrgid() flavors
591    * always correspond to the pwnam flavors, if not we have
592    * to add more configure checks.
593    */
594   
595 #if defined (HAVE_POSIX_GETPWNAM_R) || defined (HAVE_NONPOSIX_GETPWNAM_R)
596   {
597     struct group *g;
598     int result;
599     char buf[1024];
600     struct group g_str;
601
602     g = NULL;
603 #ifdef HAVE_POSIX_GETPWNAM_R
604
605     if (group_c_str)
606       result = getgrnam_r (group_c_str, &g_str, buf, sizeof (buf),
607                            &g);
608     else
609       result = getgrgid_r (gid, &g_str, buf, sizeof (buf),
610                            &g);
611 #else
612     g = getgrnam_r (group_c_str, &g_str, buf, sizeof (buf));
613     result = 0;
614 #endif /* !HAVE_POSIX_GETPWNAM_R */
615     if (result == 0 && g == &g_str)
616       {
617         return fill_user_info_from_group (g, info, error);
618       }
619     else
620       {
621         dbus_set_error (error, _dbus_error_from_errno (errno),
622                         "Group %s unknown or failed to look it up\n",
623                         group_c_str ? group_c_str : "???");
624         return FALSE;
625       }
626   }
627 #else /* ! HAVE_GETPWNAM_R */
628   {
629     /* I guess we're screwed on thread safety here */
630     struct group *g;
631
632     g = getgrnam (group_c_str);
633
634     if (g != NULL)
635       {
636         return fill_user_info_from_group (g, info, error);
637       }
638     else
639       {
640         dbus_set_error (error, _dbus_error_from_errno (errno),
641                         "Group %s unknown or failed to look it up\n",
642                         group_c_str ? group_c_str : "???");
643         return FALSE;
644       }
645   }
646 #endif  /* ! HAVE_GETPWNAM_R */
647 }
648
649 /**
650  * Initializes the given DBusGroupInfo struct
651  * with information about the given group name.
652  *
653  * @param info the group info struct
654  * @param groupname name of group
655  * @param error the error return
656  * @returns #FALSE if error is set
657  */
658 dbus_bool_t
659 _dbus_group_info_fill (DBusGroupInfo    *info,
660                        const DBusString *groupname,
661                        DBusError        *error)
662 {
663   return fill_group_info (info, DBUS_GID_UNSET,
664                           groupname, error);
665
666 }
667
668 /**
669  * Initializes the given DBusGroupInfo struct
670  * with information about the given group ID.
671  *
672  * @param info the group info struct
673  * @param gid group ID
674  * @param error the error return
675  * @returns #FALSE if error is set
676  */
677 dbus_bool_t
678 _dbus_group_info_fill_gid (DBusGroupInfo *info,
679                            dbus_gid_t     gid,
680                            DBusError     *error)
681 {
682   return fill_group_info (info, gid, NULL, error);
683 }
684
685 /** @} */ /* End of DBusInternalsUtils functions */
686
687 /**
688  * @addtogroup DBusString
689  *
690  * @{
691  */
692 /**
693  * Get the directory name from a complete filename
694  * @param filename the filename
695  * @param dirname string to append directory name to
696  * @returns #FALSE if no memory
697  */
698 dbus_bool_t
699 _dbus_string_get_dirname  (const DBusString *filename,
700                            DBusString       *dirname)
701 {
702   int sep;
703   
704   _dbus_assert (filename != dirname);
705   _dbus_assert (filename != NULL);
706   _dbus_assert (dirname != NULL);
707
708   /* Ignore any separators on the end */
709   sep = _dbus_string_get_length (filename);
710   if (sep == 0)
711     return _dbus_string_append (dirname, "."); /* empty string passed in */
712     
713   while (sep > 0 && _dbus_string_get_byte (filename, sep - 1) == '/')
714     --sep;
715
716   _dbus_assert (sep >= 0);
717   
718   if (sep == 0)
719     return _dbus_string_append (dirname, "/");
720   
721   /* Now find the previous separator */
722   _dbus_string_find_byte_backward (filename, sep, '/', &sep);
723   if (sep < 0)
724     return _dbus_string_append (dirname, ".");
725   
726   /* skip multiple separators */
727   while (sep > 0 && _dbus_string_get_byte (filename, sep - 1) == '/')
728     --sep;
729
730   _dbus_assert (sep >= 0);
731   
732   if (sep == 0 &&
733       _dbus_string_get_byte (filename, 0) == '/')
734     return _dbus_string_append (dirname, "/");
735   else
736     return _dbus_string_copy_len (filename, 0, sep - 0,
737                                   dirname, _dbus_string_get_length (dirname));
738 }
739 /** @} */ /* DBusString stuff */
740
741
742 #ifdef DBUS_BUILD_TESTS
743 #include <stdlib.h>
744 static void
745 check_dirname (const char *filename,
746                const char *dirname)
747 {
748   DBusString f, d;
749   
750   _dbus_string_init_const (&f, filename);
751
752   if (!_dbus_string_init (&d))
753     _dbus_assert_not_reached ("no memory");
754
755   if (!_dbus_string_get_dirname (&f, &d))
756     _dbus_assert_not_reached ("no memory");
757
758   if (!_dbus_string_equal_c_str (&d, dirname))
759     {
760       _dbus_warn ("For filename \"%s\" got dirname \"%s\" and expected \"%s\"\n",
761                   filename,
762                   _dbus_string_get_const_data (&d),
763                   dirname);
764       exit (1);
765     }
766
767   _dbus_string_free (&d);
768 }
769
770 static void
771 check_path_absolute (const char *path,
772                      dbus_bool_t expected)
773 {
774   DBusString p;
775
776   _dbus_string_init_const (&p, path);
777
778   if (_dbus_path_is_absolute (&p) != expected)
779     {
780       _dbus_warn ("For path \"%s\" expected absolute = %d got %d\n",
781                   path, expected, _dbus_path_is_absolute (&p));
782       exit (1);
783     }
784 }
785
786 /**
787  * Unit test for dbus-sysdeps.c.
788  * 
789  * @returns #TRUE on success.
790  */
791 dbus_bool_t
792 _dbus_sysdeps_test (void)
793 {
794   DBusString str;
795   double val;
796   int pos;
797   
798   check_dirname ("foo", ".");
799   check_dirname ("foo/bar", "foo");
800   check_dirname ("foo//bar", "foo");
801   check_dirname ("foo///bar", "foo");
802   check_dirname ("foo/bar/", "foo");
803   check_dirname ("foo//bar/", "foo");
804   check_dirname ("foo///bar/", "foo");
805   check_dirname ("foo/bar//", "foo");
806   check_dirname ("foo//bar////", "foo");
807   check_dirname ("foo///bar///////", "foo");
808   check_dirname ("/foo", "/");
809   check_dirname ("////foo", "/");
810   check_dirname ("/foo/bar", "/foo");
811   check_dirname ("/foo//bar", "/foo");
812   check_dirname ("/foo///bar", "/foo");
813   check_dirname ("/", "/");
814   check_dirname ("///", "/");
815   check_dirname ("", ".");  
816
817
818   _dbus_string_init_const (&str, "3.5");
819   if (!_dbus_string_parse_double (&str,
820                                   0, &val, &pos))
821     {
822       _dbus_warn ("Failed to parse double");
823       exit (1);
824     }
825   if (ABS(3.5 - val) > 1e-6)
826     {
827       _dbus_warn ("Failed to parse 3.5 correctly, got: %f", val);
828       exit (1);
829     }
830   if (pos != 3)
831     {
832       _dbus_warn ("_dbus_string_parse_double of \"3.5\" returned wrong position %d", pos);
833       exit (1);
834     }
835
836   _dbus_string_init_const (&str, "0xff");
837   if (!_dbus_string_parse_double (&str,
838                                   0, &val, &pos))
839     {
840       _dbus_warn ("Failed to parse double");
841       exit (1);
842     }
843   if (ABS (0xff - val) > 1e-6)
844     {
845       _dbus_warn ("Failed to parse 0xff correctly, got: %f\n", val);
846       exit (1);
847     }
848   if (pos != 4)
849     {
850       _dbus_warn ("_dbus_string_parse_double of \"0xff\" returned wrong position %d", pos);
851       exit (1);
852     }
853   
854   check_path_absolute ("/", TRUE);
855   check_path_absolute ("/foo", TRUE);
856   check_path_absolute ("", FALSE);
857   check_path_absolute ("foo", FALSE);
858   check_path_absolute ("foo/bar", FALSE);
859   
860   return TRUE;
861 }
862 #endif /* DBUS_BUILD_TESTS */