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
26 #include "dbus-sysdeps.h"
27 #include "dbus-sysdeps-unix.h"
28 #include "dbus-internals.h"
29 #include "dbus-pipe.h"
30 #include "dbus-protocol.h"
31 #include "dbus-string.h"
32 #define DBUS_USERDB_INCLUDES_PRIVATE 1
33 #include "dbus-userdb.h"
34 #include "dbus-test.h"
36 #include <sys/types.h>
45 #ifdef HAVE_SYS_RESOURCE_H
46 #include <sys/resource.h>
49 #include <sys/socket.h>
54 #ifdef HAVE_SYS_SYSLIMITS_H
55 #include <sys/syslimits.h>
63 * @addtogroup DBusInternalsUtils
69 * Does the chdir, fork, setsid, etc. to become a daemon process.
71 * @param pidfile #NULL, or pidfile to create
72 * @param print_pid_pipe pipe to print daemon's pid to, or -1 for none
73 * @param error return location for errors
74 * @param keep_umask #TRUE to keep the original umask
75 * @returns #FALSE on failure
78 _dbus_become_daemon (const DBusString *pidfile,
79 DBusPipe *print_pid_pipe,
81 dbus_bool_t keep_umask)
87 _dbus_verbose ("Becoming a daemon...\n");
89 _dbus_verbose ("chdir to /\n");
92 dbus_set_error (error, DBUS_ERROR_FAILED,
93 "Could not chdir() to root directory");
97 _dbus_verbose ("forking...\n");
98 switch ((child_pid = fork ()))
101 _dbus_verbose ("fork failed\n");
102 dbus_set_error (error, _dbus_error_from_errno (errno),
103 "Failed to fork daemon: %s", _dbus_strerror (errno));
108 _dbus_verbose ("in child, closing std file descriptors\n");
110 /* silently ignore failures here, if someone
111 * doesn't have /dev/null we may as well try
115 dev_null_fd = open ("/dev/null", O_RDWR);
116 if (dev_null_fd >= 0)
118 dup2 (dev_null_fd, 0);
119 dup2 (dev_null_fd, 1);
121 s = _dbus_getenv ("DBUS_DEBUG_OUTPUT");
122 if (s == NULL || *s == '\0')
123 dup2 (dev_null_fd, 2);
125 _dbus_verbose ("keeping stderr open due to DBUS_DEBUG_OUTPUT\n");
130 /* Get a predictable umask */
131 _dbus_verbose ("setting umask\n");
135 _dbus_verbose ("calling setsid()\n");
137 _dbus_assert_not_reached ("setsid() failed");
142 if (!_dbus_write_pid_to_file_and_pipe (pidfile, print_pid_pipe,
145 _dbus_verbose ("pid file or pipe write failed: %s\n",
147 kill (child_pid, SIGTERM);
151 _dbus_verbose ("parent exiting\n");
161 * Creates a file containing the process ID.
163 * @param filename the filename to write to
164 * @param pid our process ID
165 * @param error return location for errors
166 * @returns #FALSE on failure
169 _dbus_write_pid_file (const DBusString *filename,
173 const char *cfilename;
177 cfilename = _dbus_string_get_const_data (filename);
179 fd = open (cfilename, O_WRONLY|O_CREAT|O_EXCL|O_BINARY, 0644);
183 dbus_set_error (error, _dbus_error_from_errno (errno),
184 "Failed to open \"%s\": %s", cfilename,
185 _dbus_strerror (errno));
189 if ((f = fdopen (fd, "w")) == NULL)
191 dbus_set_error (error, _dbus_error_from_errno (errno),
192 "Failed to fdopen fd %d: %s", fd, _dbus_strerror (errno));
193 _dbus_close (fd, NULL);
197 if (fprintf (f, "%lu\n", pid) < 0)
199 dbus_set_error (error, _dbus_error_from_errno (errno),
200 "Failed to write to \"%s\": %s", cfilename,
201 _dbus_strerror (errno));
207 if (fclose (f) == EOF)
209 dbus_set_error (error, _dbus_error_from_errno (errno),
210 "Failed to close \"%s\": %s", cfilename,
211 _dbus_strerror (errno));
219 * Writes the given pid_to_write to a pidfile (if non-NULL) and/or to a
220 * pipe (if non-NULL). Does nothing if pidfile and print_pid_pipe are both
223 * @param pidfile the file to write to or #NULL
224 * @param print_pid_pipe the pipe to write to or #NULL
225 * @param pid_to_write the pid to write out
226 * @param error error on failure
227 * @returns FALSE if error is set
230 _dbus_write_pid_to_file_and_pipe (const DBusString *pidfile,
231 DBusPipe *print_pid_pipe,
232 dbus_pid_t pid_to_write,
237 _dbus_verbose ("writing pid file %s\n", _dbus_string_get_const_data (pidfile));
238 if (!_dbus_write_pid_file (pidfile,
242 _dbus_verbose ("pid file write failed\n");
243 _DBUS_ASSERT_ERROR_IS_SET(error);
249 _dbus_verbose ("No pid file requested\n");
252 if (print_pid_pipe != NULL && _dbus_pipe_is_valid (print_pid_pipe))
257 _dbus_verbose ("writing our pid to pipe %d\n",
260 if (!_dbus_string_init (&pid))
262 _DBUS_SET_OOM (error);
266 if (!_dbus_string_append_int (&pid, pid_to_write) ||
267 !_dbus_string_append (&pid, "\n"))
269 _dbus_string_free (&pid);
270 _DBUS_SET_OOM (error);
274 bytes = _dbus_string_get_length (&pid);
275 if (_dbus_pipe_write (print_pid_pipe, &pid, 0, bytes, error) != bytes)
277 /* _dbus_pipe_write sets error only on failure, not short write */
278 if (error != NULL && !dbus_error_is_set(error))
280 dbus_set_error (error, DBUS_ERROR_FAILED,
281 "Printing message bus PID: did not write enough bytes\n");
283 _dbus_string_free (&pid);
287 _dbus_string_free (&pid);
291 _dbus_verbose ("No pid pipe to write to\n");
298 * Verify that after the fork we can successfully change to this user.
300 * @param user the username given in the daemon configuration
301 * @returns #TRUE if username is valid
304 _dbus_verify_daemon_user (const char *user)
308 _dbus_string_init_const (&u, user);
310 return _dbus_get_user_id_and_primary_group (&u, NULL, NULL);
314 /* The HAVE_LIBAUDIT case lives in selinux.c */
315 #ifndef HAVE_LIBAUDIT
317 * Changes the user and group the bus is running as.
319 * @param user the user to become
320 * @param error return location for errors
321 * @returns #FALSE on failure
324 _dbus_change_to_daemon_user (const char *user,
331 _dbus_string_init_const (&u, user);
333 if (!_dbus_get_user_id_and_primary_group (&u, &uid, &gid))
335 dbus_set_error (error, DBUS_ERROR_FAILED,
336 "User '%s' does not appear to exist?",
341 /* setgroups() only works if we are a privileged process,
342 * so we don't return error on failure; the only possible
343 * failure is that we don't have perms to do it.
345 * not sure this is right, maybe if setuid()
346 * is going to work then setgroups() should also work.
348 if (setgroups (0, NULL) < 0)
349 _dbus_warn ("Failed to drop supplementary groups: %s\n",
350 _dbus_strerror (errno));
352 /* Set GID first, or the setuid may remove our permission
355 if (setgid (gid) < 0)
357 dbus_set_error (error, _dbus_error_from_errno (errno),
358 "Failed to set GID to %lu: %s", gid,
359 _dbus_strerror (errno));
363 if (setuid (uid) < 0)
365 dbus_set_error (error, _dbus_error_from_errno (errno),
366 "Failed to set UID to %lu: %s", uid,
367 _dbus_strerror (errno));
373 #endif /* !HAVE_LIBAUDIT */
377 * Attempt to ensure that the current process can open
378 * at least @limit file descriptors.
380 * If @limit is lower than the current, it will not be
381 * lowered. No error is returned if the request can
384 * @limit Number of file descriptors
387 _dbus_request_file_descriptor_limit (unsigned int limit)
389 #ifdef HAVE_SETRLIMIT
391 struct rlimit target_lim;
393 /* No point to doing this practically speaking
394 * if we're not uid 0. We expect the system
395 * bus to use this before we change UID, and
396 * the session bus takes the Linux default
397 * of 1024 for both cur and max.
402 if (getrlimit (RLIMIT_NOFILE, &lim) < 0)
405 if (lim.rlim_cur >= limit)
408 /* Ignore "maximum limit", assume we have the "superuser"
409 * privileges. On Linux this is CAP_SYS_RESOURCE.
411 target_lim.rlim_cur = target_lim.rlim_max = limit;
412 /* Also ignore errors; if we fail, we will at least work
413 * up to whatever limit we had, which seems better than
414 * just outright aborting.
416 * However, in the future we should probably log this so OS builders
417 * have a chance to notice any misconfiguration like dbus-daemon
418 * being started without CAP_SYS_RESOURCE.
420 setrlimit (RLIMIT_NOFILE, &target_lim);
425 _dbus_init_system_log (void)
427 #ifdef HAVE_DECL_LOG_PERROR
428 openlog ("dbus", LOG_PID | LOG_PERROR, LOG_DAEMON);
430 openlog ("dbus", LOG_PID, LOG_DAEMON);
435 * Log a message to the system log file (e.g. syslog on Unix).
437 * @param severity a severity value
438 * @param msg a printf-style format string
439 * @param args arguments for the format string
443 _dbus_system_log (DBusSystemLogSeverity severity, const char *msg, ...)
447 va_start (args, msg);
449 _dbus_system_logv (severity, msg, args);
455 * Log a message to the system log file (e.g. syslog on Unix).
457 * @param severity a severity value
458 * @param msg a printf-style format string
459 * @param args arguments for the format string
461 * If the FATAL severity is given, this function will terminate the program
462 * with an error code.
465 _dbus_system_logv (DBusSystemLogSeverity severity, const char *msg, va_list args)
470 case DBUS_SYSTEM_LOG_INFO:
471 flags = LOG_DAEMON | LOG_NOTICE;
473 case DBUS_SYSTEM_LOG_SECURITY:
474 flags = LOG_AUTH | LOG_NOTICE;
476 case DBUS_SYSTEM_LOG_FATAL:
477 flags = LOG_DAEMON|LOG_CRIT;
483 #ifndef HAVE_DECL_LOG_PERROR
485 /* vsyslog() won't write to stderr, so we'd better do it */
488 DBUS_VA_COPY (tmp, args);
489 fprintf (stderr, "dbus[" DBUS_PID_FORMAT "]: ", _dbus_getpid ());
490 vfprintf (stderr, msg, tmp);
491 fputc ('\n', stderr);
496 vsyslog (flags, msg, args);
498 if (severity == DBUS_SYSTEM_LOG_FATAL)
502 /** Installs a UNIX signal handler
504 * @param sig the signal to handle
505 * @param handler the handler
508 _dbus_set_signal_handler (int sig,
509 DBusSignalHandler handler)
511 struct sigaction act;
514 sigemptyset (&empty_mask);
515 act.sa_handler = handler;
516 act.sa_mask = empty_mask;
518 sigaction (sig, &act, NULL);
521 /** Checks if a file exists
523 * @param file full path to the file
524 * @returns #TRUE if file exists
527 _dbus_file_exists (const char *file)
529 return (access (file, F_OK) == 0);
532 /** Checks if user is at the console
534 * @param username user to check
535 * @param error return location for errors
536 * @returns #TRUE is the user is at the consolei and there are no errors
539 _dbus_user_at_console (const char *username,
547 if (!_dbus_string_init (&f))
549 _DBUS_SET_OOM (error);
553 if (!_dbus_string_append (&f, DBUS_CONSOLE_AUTH_DIR))
555 _DBUS_SET_OOM (error);
560 if (!_dbus_string_append (&f, username))
562 _DBUS_SET_OOM (error);
566 result = _dbus_file_exists (_dbus_string_get_const_data (&f));
569 _dbus_string_free (&f);
576 * Checks whether the filename is an absolute path
578 * @param filename the filename
579 * @returns #TRUE if an absolute path
582 _dbus_path_is_absolute (const DBusString *filename)
584 if (_dbus_string_get_length (filename) > 0)
585 return _dbus_string_get_byte (filename, 0) == '/';
593 * @param filename the filename to stat
594 * @param statbuf the stat info to fill in
595 * @param error return location for error
596 * @returns #FALSE if error was set
599 _dbus_stat (const DBusString *filename,
603 const char *filename_c;
606 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
608 filename_c = _dbus_string_get_const_data (filename);
610 if (stat (filename_c, &sb) < 0)
612 dbus_set_error (error, _dbus_error_from_errno (errno),
613 "%s", _dbus_strerror (errno));
617 statbuf->mode = sb.st_mode;
618 statbuf->nlink = sb.st_nlink;
619 statbuf->uid = sb.st_uid;
620 statbuf->gid = sb.st_gid;
621 statbuf->size = sb.st_size;
622 statbuf->atime = sb.st_atime;
623 statbuf->mtime = sb.st_mtime;
624 statbuf->ctime = sb.st_ctime;
631 * Internals of directory iterator
635 DIR *d; /**< The DIR* from opendir() */
640 * Open a directory to iterate over.
642 * @param filename the directory name
643 * @param error exception return object or #NULL
644 * @returns new iterator, or #NULL on error
647 _dbus_directory_open (const DBusString *filename,
652 const char *filename_c;
654 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
656 filename_c = _dbus_string_get_const_data (filename);
658 d = opendir (filename_c);
661 dbus_set_error (error, _dbus_error_from_errno (errno),
662 "Failed to read directory \"%s\": %s",
664 _dbus_strerror (errno));
667 iter = dbus_new0 (DBusDirIter, 1);
671 dbus_set_error (error, DBUS_ERROR_NO_MEMORY,
672 "Could not allocate memory for directory iterator");
682 * Get next file in the directory. Will not return "." or ".." on
683 * UNIX. If an error occurs, the contents of "filename" are
684 * undefined. The error is never set if the function succeeds.
686 * This function is not re-entrant, and not necessarily thread-safe.
687 * Only use it for test code or single-threaded utilities.
689 * @param iter the iterator
690 * @param filename string to be set to the next file in the dir
691 * @param error return location for error
692 * @returns #TRUE if filename was filled in with a new filename
695 _dbus_directory_get_next_file (DBusDirIter *iter,
696 DBusString *filename,
702 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
706 ent = readdir (iter->d);
713 dbus_set_error (error,
714 _dbus_error_from_errno (err),
715 "%s", _dbus_strerror (err));
719 else if (ent->d_name[0] == '.' &&
720 (ent->d_name[1] == '\0' ||
721 (ent->d_name[1] == '.' && ent->d_name[2] == '\0')))
725 _dbus_string_set_length (filename, 0);
726 if (!_dbus_string_append (filename, ent->d_name))
728 dbus_set_error (error, DBUS_ERROR_NO_MEMORY,
729 "No memory to read directory entry");
740 * Closes a directory iteration.
743 _dbus_directory_close (DBusDirIter *iter)
750 fill_user_info_from_group (struct group *g,
754 _dbus_assert (g->gr_name != NULL);
756 info->gid = g->gr_gid;
757 info->groupname = _dbus_strdup (g->gr_name);
759 /* info->members = dbus_strdupv (g->gr_mem) */
761 if (info->groupname == NULL)
763 dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
771 fill_group_info (DBusGroupInfo *info,
773 const DBusString *groupname,
776 const char *group_c_str;
778 _dbus_assert (groupname != NULL || gid != DBUS_GID_UNSET);
779 _dbus_assert (groupname == NULL || gid == DBUS_GID_UNSET);
782 group_c_str = _dbus_string_get_const_data (groupname);
786 /* For now assuming that the getgrnam() and getgrgid() flavors
787 * always correspond to the pwnam flavors, if not we have
788 * to add more configure checks.
791 #if defined (HAVE_POSIX_GETPWNAM_R) || defined (HAVE_NONPOSIX_GETPWNAM_R)
800 /* retrieve maximum needed size for buf */
801 buflen = sysconf (_SC_GETGR_R_SIZE_MAX);
803 /* sysconf actually returns a long, but everything else expects size_t,
804 * so just recast here.
805 * https://bugs.freedesktop.org/show_bug.cgi?id=17061
807 if ((long) buflen <= 0)
813 buf = dbus_malloc (buflen);
816 dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
821 #ifdef HAVE_POSIX_GETPWNAM_R
823 result = getgrnam_r (group_c_str, &g_str, buf, buflen,
826 result = getgrgid_r (gid, &g_str, buf, buflen,
829 g = getgrnam_r (group_c_str, &g_str, buf, buflen);
831 #endif /* !HAVE_POSIX_GETPWNAM_R */
832 /* Try a bigger buffer if ERANGE was returned:
833 https://bugs.freedesktop.org/show_bug.cgi?id=16727
835 if (result == ERANGE && buflen < 512 * 1024)
846 if (result == 0 && g == &g_str)
848 b = fill_user_info_from_group (g, info, error);
854 dbus_set_error (error, _dbus_error_from_errno (errno),
855 "Group %s unknown or failed to look it up\n",
856 group_c_str ? group_c_str : "???");
861 #else /* ! HAVE_GETPWNAM_R */
863 /* I guess we're screwed on thread safety here */
866 g = getgrnam (group_c_str);
870 return fill_user_info_from_group (g, info, error);
874 dbus_set_error (error, _dbus_error_from_errno (errno),
875 "Group %s unknown or failed to look it up\n",
876 group_c_str ? group_c_str : "???");
880 #endif /* ! HAVE_GETPWNAM_R */
884 * Initializes the given DBusGroupInfo struct
885 * with information about the given group name.
887 * @param info the group info struct
888 * @param groupname name of group
889 * @param error the error return
890 * @returns #FALSE if error is set
893 _dbus_group_info_fill (DBusGroupInfo *info,
894 const DBusString *groupname,
897 return fill_group_info (info, DBUS_GID_UNSET,
903 * Initializes the given DBusGroupInfo struct
904 * with information about the given group ID.
906 * @param info the group info struct
907 * @param gid group ID
908 * @param error the error return
909 * @returns #FALSE if error is set
912 _dbus_group_info_fill_gid (DBusGroupInfo *info,
916 return fill_group_info (info, gid, NULL, error);
920 * Parse a UNIX user from the bus config file. On Windows, this should
921 * simply always fail (just return #FALSE).
923 * @param username the username text
924 * @param uid_p place to return the uid
925 * @returns #TRUE on success
928 _dbus_parse_unix_user_from_config (const DBusString *username,
931 return _dbus_get_user_id (username, uid_p);
936 * Parse a UNIX group from the bus config file. On Windows, this should
937 * simply always fail (just return #FALSE).
939 * @param groupname the groupname text
940 * @param gid_p place to return the gid
941 * @returns #TRUE on success
944 _dbus_parse_unix_group_from_config (const DBusString *groupname,
947 return _dbus_get_group_id (groupname, gid_p);
951 * Gets all groups corresponding to the given UNIX user ID. On UNIX,
952 * just calls _dbus_groups_from_uid(). On Windows, should always
953 * fail since we don't know any UNIX groups.
956 * @param group_ids return location for array of group IDs
957 * @param n_group_ids return location for length of returned array
958 * @returns #TRUE if the UID existed and we got some credentials
961 _dbus_unix_groups_from_uid (dbus_uid_t uid,
962 dbus_gid_t **group_ids,
965 return _dbus_groups_from_uid (uid, group_ids, n_group_ids);
969 * Checks to see if the UNIX user ID is at the console.
970 * Should always fail on Windows (set the error to
971 * #DBUS_ERROR_NOT_SUPPORTED).
973 * @param uid UID of person to check
974 * @param error return location for errors
975 * @returns #TRUE if the UID is the same as the console user and there are no errors
978 _dbus_unix_user_is_at_console (dbus_uid_t uid,
981 return _dbus_is_console_user (uid, error);
986 * Checks to see if the UNIX user ID matches the UID of
987 * the process. Should always return #FALSE on Windows.
989 * @param uid the UNIX user ID
990 * @returns #TRUE if this uid owns the process.
993 _dbus_unix_user_is_process_owner (dbus_uid_t uid)
995 return uid == _dbus_geteuid ();
999 * Checks to see if the Windows user SID matches the owner of
1000 * the process. Should always return #FALSE on UNIX.
1002 * @param windows_sid the Windows user SID
1003 * @returns #TRUE if this user owns the process.
1006 _dbus_windows_user_is_process_owner (const char *windows_sid)
1011 /** @} */ /* End of DBusInternalsUtils functions */
1014 * @addtogroup DBusString
1019 * Get the directory name from a complete filename
1020 * @param filename the filename
1021 * @param dirname string to append directory name to
1022 * @returns #FALSE if no memory
1025 _dbus_string_get_dirname (const DBusString *filename,
1026 DBusString *dirname)
1030 _dbus_assert (filename != dirname);
1031 _dbus_assert (filename != NULL);
1032 _dbus_assert (dirname != NULL);
1034 /* Ignore any separators on the end */
1035 sep = _dbus_string_get_length (filename);
1037 return _dbus_string_append (dirname, "."); /* empty string passed in */
1039 while (sep > 0 && _dbus_string_get_byte (filename, sep - 1) == '/')
1042 _dbus_assert (sep >= 0);
1045 return _dbus_string_append (dirname, "/");
1047 /* Now find the previous separator */
1048 _dbus_string_find_byte_backward (filename, sep, '/', &sep);
1050 return _dbus_string_append (dirname, ".");
1052 /* skip multiple separators */
1053 while (sep > 0 && _dbus_string_get_byte (filename, sep - 1) == '/')
1056 _dbus_assert (sep >= 0);
1059 _dbus_string_get_byte (filename, 0) == '/')
1060 return _dbus_string_append (dirname, "/");
1062 return _dbus_string_copy_len (filename, 0, sep - 0,
1063 dirname, _dbus_string_get_length (dirname));
1065 /** @} */ /* DBusString stuff */
1068 string_squash_nonprintable (DBusString *str)
1073 buf = _dbus_string_get_data (str);
1074 len = _dbus_string_get_length (str);
1076 for (i = 0; i < len; i++)
1078 unsigned char c = (unsigned char) buf[i];
1081 else if (c < 0x20 || c > 127)
1087 * Get a printable string describing the command used to execute
1088 * the process with pid. This string should only be used for
1089 * informative purposes such as logging; it may not be trusted.
1091 * The command is guaranteed to be printable ASCII and no longer
1094 * @param pid Process id
1095 * @param str Append command to this string
1096 * @param max_len Maximum length of returned command
1097 * @param error return location for errors
1098 * @returns #FALSE on error
1101 _dbus_command_for_pid (unsigned long pid,
1106 /* This is all Linux-specific for now */
1111 if (!_dbus_string_init (&path))
1113 _DBUS_SET_OOM (error);
1117 if (!_dbus_string_init (&cmdline))
1119 _DBUS_SET_OOM (error);
1120 _dbus_string_free (&path);
1124 if (!_dbus_string_append_printf (&path, "/proc/%ld/cmdline", pid))
1127 fd = open (_dbus_string_get_const_data (&path), O_RDONLY);
1130 dbus_set_error (error,
1131 _dbus_error_from_errno (errno),
1132 "Failed to open \"%s\": %s",
1133 _dbus_string_get_const_data (&path),
1134 _dbus_strerror (errno));
1138 if (!_dbus_read (fd, &cmdline, max_len))
1140 dbus_set_error (error,
1141 _dbus_error_from_errno (errno),
1142 "Failed to read from \"%s\": %s",
1143 _dbus_string_get_const_data (&path),
1144 _dbus_strerror (errno));
1148 if (!_dbus_close (fd, error))
1151 string_squash_nonprintable (&cmdline);
1153 if (!_dbus_string_copy (&cmdline, 0, str, _dbus_string_get_length (str)))
1156 _dbus_string_free (&cmdline);
1157 _dbus_string_free (&path);
1160 _DBUS_SET_OOM (error);
1162 _dbus_string_free (&cmdline);
1163 _dbus_string_free (&path);