1 /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
2 /* dbus-sysdeps-util-unix.c Would be in dbus-sysdeps-unix.c, but not used in libdbus
4 * Copyright (C) 2002, 2003, 2004, 2005 Red Hat, Inc.
5 * Copyright (C) 2003 CodeFactory AB
7 * Licensed under the Academic Free License version 2.1
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.
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.
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24 #include "dbus-sysdeps.h"
25 #include "dbus-sysdeps-unix.h"
26 #include "dbus-internals.h"
27 #include "dbus-protocol.h"
28 #include "dbus-string.h"
29 #define DBUS_USERDB_INCLUDES_PRIVATE 1
30 #include "dbus-userdb.h"
31 #include "dbus-test.h"
33 #include <sys/types.h>
43 #include <sys/socket.h>
48 #ifdef HAVE_SYS_SYSLIMITS_H
49 #include <sys/syslimits.h>
57 * @addtogroup DBusInternalsUtils
63 * Does the chdir, fork, setsid, etc. to become a daemon process.
65 * @param pidfile #NULL, or pidfile to create
66 * @param print_pid_pipe pipe to print daemon's pid to, or -1 for none
67 * @param error return location for errors
68 * @param keep_umask #TRUE to keep the original umask
69 * @returns #FALSE on failure
72 _dbus_become_daemon (const DBusString *pidfile,
73 DBusPipe *print_pid_pipe,
75 dbus_bool_t keep_umask)
81 _dbus_verbose ("Becoming a daemon...\n");
83 _dbus_verbose ("chdir to /\n");
86 dbus_set_error (error, DBUS_ERROR_FAILED,
87 "Could not chdir() to root directory");
91 _dbus_verbose ("forking...\n");
92 switch ((child_pid = fork ()))
95 _dbus_verbose ("fork failed\n");
96 dbus_set_error (error, _dbus_error_from_errno (errno),
97 "Failed to fork daemon: %s", _dbus_strerror (errno));
102 _dbus_verbose ("in child, closing std file descriptors\n");
104 /* silently ignore failures here, if someone
105 * doesn't have /dev/null we may as well try
109 dev_null_fd = open ("/dev/null", O_RDWR);
110 if (dev_null_fd >= 0)
112 dup2 (dev_null_fd, 0);
113 dup2 (dev_null_fd, 1);
115 s = _dbus_getenv ("DBUS_DEBUG_OUTPUT");
116 if (s == NULL || *s == '\0')
117 dup2 (dev_null_fd, 2);
119 _dbus_verbose ("keeping stderr open due to DBUS_DEBUG_OUTPUT\n");
124 /* Get a predictable umask */
125 _dbus_verbose ("setting umask\n");
129 _dbus_verbose ("calling setsid()\n");
131 _dbus_assert_not_reached ("setsid() failed");
136 if (!_dbus_write_pid_to_file_and_pipe (pidfile, print_pid_pipe,
139 _dbus_verbose ("pid file or pipe write failed: %s\n",
141 kill (child_pid, SIGTERM);
145 _dbus_verbose ("parent exiting\n");
155 * Creates a file containing the process ID.
157 * @param filename the filename to write to
158 * @param pid our process ID
159 * @param error return location for errors
160 * @returns #FALSE on failure
163 _dbus_write_pid_file (const DBusString *filename,
167 const char *cfilename;
171 cfilename = _dbus_string_get_const_data (filename);
173 fd = open (cfilename, O_WRONLY|O_CREAT|O_EXCL|O_BINARY, 0644);
177 dbus_set_error (error, _dbus_error_from_errno (errno),
178 "Failed to open \"%s\": %s", cfilename,
179 _dbus_strerror (errno));
183 if ((f = fdopen (fd, "w")) == NULL)
185 dbus_set_error (error, _dbus_error_from_errno (errno),
186 "Failed to fdopen fd %d: %s", fd, _dbus_strerror (errno));
187 _dbus_close (fd, NULL);
191 if (fprintf (f, "%lu\n", pid) < 0)
193 dbus_set_error (error, _dbus_error_from_errno (errno),
194 "Failed to write to \"%s\": %s", cfilename,
195 _dbus_strerror (errno));
201 if (fclose (f) == EOF)
203 dbus_set_error (error, _dbus_error_from_errno (errno),
204 "Failed to close \"%s\": %s", cfilename,
205 _dbus_strerror (errno));
213 * Writes the given pid_to_write to a pidfile (if non-NULL) and/or to a
214 * pipe (if non-NULL). Does nothing if pidfile and print_pid_pipe are both
217 * @param pidfile the file to write to or #NULL
218 * @param print_pid_pipe the pipe to write to or #NULL
219 * @param pid_to_write the pid to write out
220 * @param error error on failure
221 * @returns FALSE if error is set
224 _dbus_write_pid_to_file_and_pipe (const DBusString *pidfile,
225 DBusPipe *print_pid_pipe,
226 dbus_pid_t pid_to_write,
231 _dbus_verbose ("writing pid file %s\n", _dbus_string_get_const_data (pidfile));
232 if (!_dbus_write_pid_file (pidfile,
236 _dbus_verbose ("pid file write failed\n");
237 _DBUS_ASSERT_ERROR_IS_SET(error);
243 _dbus_verbose ("No pid file requested\n");
246 if (print_pid_pipe != NULL && _dbus_pipe_is_valid (print_pid_pipe))
251 _dbus_verbose ("writing our pid to pipe %d\n", print_pid_pipe->fd_or_handle);
253 if (!_dbus_string_init (&pid))
255 _DBUS_SET_OOM (error);
259 if (!_dbus_string_append_int (&pid, pid_to_write) ||
260 !_dbus_string_append (&pid, "\n"))
262 _dbus_string_free (&pid);
263 _DBUS_SET_OOM (error);
267 bytes = _dbus_string_get_length (&pid);
268 if (_dbus_pipe_write (print_pid_pipe, &pid, 0, bytes, error) != bytes)
270 /* _dbus_pipe_write sets error only on failure, not short write */
271 if (error != NULL && !dbus_error_is_set(error))
273 dbus_set_error (error, DBUS_ERROR_FAILED,
274 "Printing message bus PID: did not write enough bytes\n");
276 _dbus_string_free (&pid);
280 _dbus_string_free (&pid);
284 _dbus_verbose ("No pid pipe to write to\n");
291 * Verify that after the fork we can successfully change to this user.
293 * @param user the username given in the daemon configuration
294 * @returns #TRUE if username is valid
297 _dbus_verify_daemon_user (const char *user)
301 _dbus_string_init_const (&u, user);
303 return _dbus_get_user_id_and_primary_group (&u, NULL, NULL);
307 /* The HAVE_LIBAUDIT case lives in selinux.c */
308 #ifndef HAVE_LIBAUDIT
310 * Changes the user and group the bus is running as.
312 * @param user the user to become
313 * @param error return location for errors
314 * @returns #FALSE on failure
317 _dbus_change_to_daemon_user (const char *user,
324 _dbus_string_init_const (&u, user);
326 if (!_dbus_get_user_id_and_primary_group (&u, &uid, &gid))
328 dbus_set_error (error, DBUS_ERROR_FAILED,
329 "User '%s' does not appear to exist?",
334 /* setgroups() only works if we are a privileged process,
335 * so we don't return error on failure; the only possible
336 * failure is that we don't have perms to do it.
338 * not sure this is right, maybe if setuid()
339 * is going to work then setgroups() should also work.
341 if (setgroups (0, NULL) < 0)
342 _dbus_warn ("Failed to drop supplementary groups: %s\n",
343 _dbus_strerror (errno));
345 /* Set GID first, or the setuid may remove our permission
348 if (setgid (gid) < 0)
350 dbus_set_error (error, _dbus_error_from_errno (errno),
351 "Failed to set GID to %lu: %s", gid,
352 _dbus_strerror (errno));
356 if (setuid (uid) < 0)
358 dbus_set_error (error, _dbus_error_from_errno (errno),
359 "Failed to set UID to %lu: %s", uid,
360 _dbus_strerror (errno));
366 #endif /* !HAVE_LIBAUDIT */
369 _dbus_init_system_log (void)
371 openlog ("dbus", LOG_PID, LOG_DAEMON);
374 * Log a message to the system log file (e.g. syslog on Unix).
376 * @param severity a severity value
377 * @param msg a printf-style format string
378 * @param args arguments for the format string
382 _dbus_system_log (DBusSystemLogSeverity severity, const char *msg, ...)
386 va_start (args, msg);
388 _dbus_system_logv (severity, msg, args);
394 * Log a message to the system log file (e.g. syslog on Unix).
396 * @param severity a severity value
397 * @param msg a printf-style format string
398 * @param args arguments for the format string
400 * If the FATAL severity is given, this function will terminate the program
401 * with an error code.
404 _dbus_system_logv (DBusSystemLogSeverity severity, const char *msg, va_list args)
409 case DBUS_SYSTEM_LOG_INFO:
410 flags = LOG_DAEMON | LOG_NOTICE;
412 case DBUS_SYSTEM_LOG_SECURITY:
413 flags = LOG_AUTH | LOG_NOTICE;
415 case DBUS_SYSTEM_LOG_FATAL:
416 flags = LOG_DAEMON|LOG_CRIT;
421 vsyslog (flags, msg, args);
423 if (severity == DBUS_SYSTEM_LOG_FATAL)
427 /** Installs a UNIX signal handler
429 * @param sig the signal to handle
430 * @param handler the handler
433 _dbus_set_signal_handler (int sig,
434 DBusSignalHandler handler)
436 struct sigaction act;
439 sigemptyset (&empty_mask);
440 act.sa_handler = handler;
441 act.sa_mask = empty_mask;
443 sigaction (sig, &act, NULL);
448 * Removes a directory; Directory must be empty
450 * @param filename directory filename
451 * @param error initialized error object
452 * @returns #TRUE on success
455 _dbus_delete_directory (const DBusString *filename,
458 const char *filename_c;
460 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
462 filename_c = _dbus_string_get_const_data (filename);
464 if (rmdir (filename_c) != 0)
466 dbus_set_error (error, DBUS_ERROR_FAILED,
467 "Failed to remove directory %s: %s\n",
468 filename_c, _dbus_strerror (errno));
475 /** Checks if a file exists
477 * @param file full path to the file
478 * @returns #TRUE if file exists
481 _dbus_file_exists (const char *file)
483 return (access (file, F_OK) == 0);
486 /** Checks if user is at the console
488 * @param username user to check
489 * @param error return location for errors
490 * @returns #TRUE is the user is at the consolei and there are no errors
493 _dbus_user_at_console (const char *username,
501 if (!_dbus_string_init (&f))
503 _DBUS_SET_OOM (error);
507 if (!_dbus_string_append (&f, DBUS_CONSOLE_AUTH_DIR))
509 _DBUS_SET_OOM (error);
514 if (!_dbus_string_append (&f, username))
516 _DBUS_SET_OOM (error);
520 result = _dbus_file_exists (_dbus_string_get_const_data (&f));
523 _dbus_string_free (&f);
530 * Checks whether the filename is an absolute path
532 * @param filename the filename
533 * @returns #TRUE if an absolute path
536 _dbus_path_is_absolute (const DBusString *filename)
538 if (_dbus_string_get_length (filename) > 0)
539 return _dbus_string_get_byte (filename, 0) == '/';
547 * @param filename the filename to stat
548 * @param statbuf the stat info to fill in
549 * @param error return location for error
550 * @returns #FALSE if error was set
553 _dbus_stat (const DBusString *filename,
557 const char *filename_c;
560 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
562 filename_c = _dbus_string_get_const_data (filename);
564 if (stat (filename_c, &sb) < 0)
566 dbus_set_error (error, _dbus_error_from_errno (errno),
567 "%s", _dbus_strerror (errno));
571 statbuf->mode = sb.st_mode;
572 statbuf->nlink = sb.st_nlink;
573 statbuf->uid = sb.st_uid;
574 statbuf->gid = sb.st_gid;
575 statbuf->size = sb.st_size;
576 statbuf->atime = sb.st_atime;
577 statbuf->mtime = sb.st_mtime;
578 statbuf->ctime = sb.st_ctime;
585 * Internals of directory iterator
589 DIR *d; /**< The DIR* from opendir() */
594 * Open a directory to iterate over.
596 * @param filename the directory name
597 * @param error exception return object or #NULL
598 * @returns new iterator, or #NULL on error
601 _dbus_directory_open (const DBusString *filename,
606 const char *filename_c;
608 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
610 filename_c = _dbus_string_get_const_data (filename);
612 d = opendir (filename_c);
615 dbus_set_error (error, _dbus_error_from_errno (errno),
616 "Failed to read directory \"%s\": %s",
618 _dbus_strerror (errno));
621 iter = dbus_new0 (DBusDirIter, 1);
625 dbus_set_error (error, DBUS_ERROR_NO_MEMORY,
626 "Could not allocate memory for directory iterator");
635 /* Calculate the required buffer size (in bytes) for directory
636 * entries read from the given directory handle. Return -1 if this
637 * this cannot be done.
639 * If you use autoconf, include fpathconf and dirfd in your
640 * AC_CHECK_FUNCS list. Otherwise use some other method to detect
641 * and use them where available.
644 dirent_buf_size(DIR * dirp, size_t *size)
647 # if defined(HAVE_FPATHCONF) && defined(_PC_NAME_MAX)
648 # if defined(HAVE_DIRFD)
649 name_max = fpathconf(dirfd(dirp), _PC_NAME_MAX);
650 # elif defined(HAVE_DDFD)
651 name_max = fpathconf(dirp->dd_fd, _PC_NAME_MAX);
653 name_max = fpathconf(dirp->__dd_fd, _PC_NAME_MAX);
654 # endif /* HAVE_DIRFD */
656 # if defined(NAME_MAX)
661 # elif defined(MAXNAMELEN)
662 name_max = MAXNAMELEN;
664 # if defined(NAME_MAX)
667 # error "buffer size for readdir_r cannot be determined"
671 *size = (size_t)offsetof(struct dirent, d_name) + name_max + 1;
679 * Get next file in the directory. Will not return "." or ".." on
680 * UNIX. If an error occurs, the contents of "filename" are
681 * undefined. The error is never set if the function succeeds.
683 * @param iter the iterator
684 * @param filename string to be set to the next file in the dir
685 * @param error return location for error
686 * @returns #TRUE if filename was filled in with a new filename
689 _dbus_directory_get_next_file (DBusDirIter *iter,
690 DBusString *filename,
693 struct dirent *d, *ent;
697 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
699 if (!dirent_buf_size (iter->d, &buf_size))
701 dbus_set_error (error, DBUS_ERROR_FAILED,
702 "Can't calculate buffer size when reading directory");
706 d = (struct dirent *)dbus_malloc (buf_size);
709 dbus_set_error (error, DBUS_ERROR_NO_MEMORY,
710 "No memory to read directory entry");
715 err = readdir_r (iter->d, d, &ent);
719 dbus_set_error (error,
720 _dbus_error_from_errno (err),
721 "%s", _dbus_strerror (err));
726 else if (ent->d_name[0] == '.' &&
727 (ent->d_name[1] == '\0' ||
728 (ent->d_name[1] == '.' && ent->d_name[2] == '\0')))
732 _dbus_string_set_length (filename, 0);
733 if (!_dbus_string_append (filename, ent->d_name))
735 dbus_set_error (error, DBUS_ERROR_NO_MEMORY,
736 "No memory to read directory entry");
749 * Closes a directory iteration.
752 _dbus_directory_close (DBusDirIter *iter)
759 fill_user_info_from_group (struct group *g,
763 _dbus_assert (g->gr_name != NULL);
765 info->gid = g->gr_gid;
766 info->groupname = _dbus_strdup (g->gr_name);
768 /* info->members = dbus_strdupv (g->gr_mem) */
770 if (info->groupname == NULL)
772 dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
780 fill_group_info (DBusGroupInfo *info,
782 const DBusString *groupname,
785 const char *group_c_str;
787 _dbus_assert (groupname != NULL || gid != DBUS_GID_UNSET);
788 _dbus_assert (groupname == NULL || gid == DBUS_GID_UNSET);
791 group_c_str = _dbus_string_get_const_data (groupname);
795 /* For now assuming that the getgrnam() and getgrgid() flavors
796 * always correspond to the pwnam flavors, if not we have
797 * to add more configure checks.
800 #if defined (HAVE_POSIX_GETPWNAM_R) || defined (HAVE_NONPOSIX_GETPWNAM_R)
809 /* retrieve maximum needed size for buf */
810 buflen = sysconf (_SC_GETGR_R_SIZE_MAX);
812 /* sysconf actually returns a long, but everything else expects size_t,
813 * so just recast here.
814 * https://bugs.freedesktop.org/show_bug.cgi?id=17061
816 if ((long) buflen <= 0)
822 buf = dbus_malloc (buflen);
825 dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
830 #ifdef HAVE_POSIX_GETPWNAM_R
832 result = getgrnam_r (group_c_str, &g_str, buf, buflen,
835 result = getgrgid_r (gid, &g_str, buf, buflen,
838 g = getgrnam_r (group_c_str, &g_str, buf, buflen);
840 #endif /* !HAVE_POSIX_GETPWNAM_R */
841 /* Try a bigger buffer if ERANGE was returned:
842 https://bugs.freedesktop.org/show_bug.cgi?id=16727
844 if (result == ERANGE && buflen < 512 * 1024)
855 if (result == 0 && g == &g_str)
857 b = fill_user_info_from_group (g, info, error);
863 dbus_set_error (error, _dbus_error_from_errno (errno),
864 "Group %s unknown or failed to look it up\n",
865 group_c_str ? group_c_str : "???");
870 #else /* ! HAVE_GETPWNAM_R */
872 /* I guess we're screwed on thread safety here */
875 g = getgrnam (group_c_str);
879 return fill_user_info_from_group (g, info, error);
883 dbus_set_error (error, _dbus_error_from_errno (errno),
884 "Group %s unknown or failed to look it up\n",
885 group_c_str ? group_c_str : "???");
889 #endif /* ! HAVE_GETPWNAM_R */
893 * Initializes the given DBusGroupInfo struct
894 * with information about the given group name.
896 * @param info the group info struct
897 * @param groupname name of group
898 * @param error the error return
899 * @returns #FALSE if error is set
902 _dbus_group_info_fill (DBusGroupInfo *info,
903 const DBusString *groupname,
906 return fill_group_info (info, DBUS_GID_UNSET,
912 * Initializes the given DBusGroupInfo struct
913 * with information about the given group ID.
915 * @param info the group info struct
916 * @param gid group ID
917 * @param error the error return
918 * @returns #FALSE if error is set
921 _dbus_group_info_fill_gid (DBusGroupInfo *info,
925 return fill_group_info (info, gid, NULL, error);
929 * Parse a UNIX user from the bus config file. On Windows, this should
930 * simply always fail (just return #FALSE).
932 * @param username the username text
933 * @param uid_p place to return the uid
934 * @returns #TRUE on success
937 _dbus_parse_unix_user_from_config (const DBusString *username,
940 return _dbus_get_user_id (username, uid_p);
945 * Parse a UNIX group from the bus config file. On Windows, this should
946 * simply always fail (just return #FALSE).
948 * @param groupname the groupname text
949 * @param gid_p place to return the gid
950 * @returns #TRUE on success
953 _dbus_parse_unix_group_from_config (const DBusString *groupname,
956 return _dbus_get_group_id (groupname, gid_p);
960 * Gets all groups corresponding to the given UNIX user ID. On UNIX,
961 * just calls _dbus_groups_from_uid(). On Windows, should always
962 * fail since we don't know any UNIX groups.
965 * @param group_ids return location for array of group IDs
966 * @param n_group_ids return location for length of returned array
967 * @returns #TRUE if the UID existed and we got some credentials
970 _dbus_unix_groups_from_uid (dbus_uid_t uid,
971 dbus_gid_t **group_ids,
974 return _dbus_groups_from_uid (uid, group_ids, n_group_ids);
978 * Checks to see if the UNIX user ID is at the console.
979 * Should always fail on Windows (set the error to
980 * #DBUS_ERROR_NOT_SUPPORTED).
982 * @param uid UID of person to check
983 * @param error return location for errors
984 * @returns #TRUE if the UID is the same as the console user and there are no errors
987 _dbus_unix_user_is_at_console (dbus_uid_t uid,
990 return _dbus_is_console_user (uid, error);
995 * Checks to see if the UNIX user ID matches the UID of
996 * the process. Should always return #FALSE on Windows.
998 * @param uid the UNIX user ID
999 * @returns #TRUE if this uid owns the process.
1002 _dbus_unix_user_is_process_owner (dbus_uid_t uid)
1004 return uid == _dbus_geteuid ();
1008 * Checks to see if the Windows user SID matches the owner of
1009 * the process. Should always return #FALSE on UNIX.
1011 * @param windows_sid the Windows user SID
1012 * @returns #TRUE if this user owns the process.
1015 _dbus_windows_user_is_process_owner (const char *windows_sid)
1020 /** @} */ /* End of DBusInternalsUtils functions */
1023 * @addtogroup DBusString
1028 * Get the directory name from a complete filename
1029 * @param filename the filename
1030 * @param dirname string to append directory name to
1031 * @returns #FALSE if no memory
1034 _dbus_string_get_dirname (const DBusString *filename,
1035 DBusString *dirname)
1039 _dbus_assert (filename != dirname);
1040 _dbus_assert (filename != NULL);
1041 _dbus_assert (dirname != NULL);
1043 /* Ignore any separators on the end */
1044 sep = _dbus_string_get_length (filename);
1046 return _dbus_string_append (dirname, "."); /* empty string passed in */
1048 while (sep > 0 && _dbus_string_get_byte (filename, sep - 1) == '/')
1051 _dbus_assert (sep >= 0);
1054 return _dbus_string_append (dirname, "/");
1056 /* Now find the previous separator */
1057 _dbus_string_find_byte_backward (filename, sep, '/', &sep);
1059 return _dbus_string_append (dirname, ".");
1061 /* skip multiple separators */
1062 while (sep > 0 && _dbus_string_get_byte (filename, sep - 1) == '/')
1065 _dbus_assert (sep >= 0);
1068 _dbus_string_get_byte (filename, 0) == '/')
1069 return _dbus_string_append (dirname, "/");
1071 return _dbus_string_copy_len (filename, 0, sep - 0,
1072 dirname, _dbus_string_get_length (dirname));
1074 /** @} */ /* DBusString stuff */
1077 string_squash_nonprintable (DBusString *str)
1082 buf = _dbus_string_get_data (str);
1083 len = _dbus_string_get_length (str);
1085 for (i = 0; i < len; i++)
1087 unsigned char c = (unsigned char) buf[i];
1090 else if (c < 0x20 || c > 127)
1096 * Get a printable string describing the command used to execute
1097 * the process with pid. This string should only be used for
1098 * informative purposes such as logging; it may not be trusted.
1100 * The command is guaranteed to be printable ASCII and no longer
1103 * @param pid Process id
1104 * @param str Append command to this string
1105 * @param max_len Maximum length of returned command
1106 * @param error return location for errors
1107 * @returns #FALSE on error
1110 _dbus_command_for_pid (unsigned long pid,
1115 /* This is all Linux-specific for now */
1120 if (!_dbus_string_init (&path))
1122 _DBUS_SET_OOM (error);
1126 if (!_dbus_string_init (&cmdline))
1128 _DBUS_SET_OOM (error);
1129 _dbus_string_free (&path);
1133 if (!_dbus_string_append_printf (&path, "/proc/%ld/cmdline", pid))
1136 fd = open (_dbus_string_get_const_data (&path), O_RDONLY);
1139 dbus_set_error (error,
1140 _dbus_error_from_errno (errno),
1141 "Failed to open \"%s\": %s",
1142 _dbus_string_get_const_data (&path),
1143 _dbus_strerror (errno));
1147 if (!_dbus_read (fd, &cmdline, max_len))
1149 dbus_set_error (error,
1150 _dbus_error_from_errno (errno),
1151 "Failed to read from \"%s\": %s",
1152 _dbus_string_get_const_data (&path),
1153 _dbus_strerror (errno));
1157 if (!_dbus_close (fd, error))
1160 string_squash_nonprintable (&cmdline);
1162 if (!_dbus_string_copy (&cmdline, 0, str, _dbus_string_get_length (str)))
1165 _dbus_string_free (&cmdline);
1166 _dbus_string_free (&path);
1169 _DBUS_SET_OOM (error);
1171 _dbus_string_free (&cmdline);
1172 _dbus_string_free (&path);