Skip to content
Browse files

Make chroot() availability non-obligatory.

  • Loading branch information...
1 parent feb972c commit 2a48885e7e1328eca25ea8f2dcf7f841e9b34ea9 @mgorny committed Dec 10, 2010
Showing with 5 additions and 0 deletions.
  1. +1 −0 configure.ac
  2. +4 −0 sw-notify-send.c
View
1 configure.ac
@@ -6,6 +6,7 @@ AM_INIT_AUTOMAKE([1.6 foreign dist-bzip2 no-dependencies])
AC_PROG_CC_C99
AC_USE_SYSTEM_EXTENSIONS
+AC_CHECK_FUNCS([chroot])
AC_CHECK_LIB([proc], [readproc],,
[AC_MSG_ERROR([Error: required library proc not found! Please install procps.])])
View
4 sw-notify-send.c
@@ -70,12 +70,14 @@ char *_findenv(const proc_t* const p, const char* const keystr) {
/* Get the /proc/<pid>/root path suitable for chroot() call or return
* NULL if chroot not possible/necessary. */
const char* getroot(int pid) {
+#ifdef HAVE_CHROOT
static char fnbuf[11 + sizeof(pid) * 3];
char rlbuf[2];
snprintf(fnbuf, sizeof(fnbuf), "/proc/%d/root", pid);
if (readlink(fnbuf, rlbuf, sizeof(rlbuf)) != 1 || rlbuf[0] != '/')
return fnbuf;
else
+#endif
return NULL;
}
@@ -84,8 +86,10 @@ void send_notify(char* const display, char* const xauth,
uid_t uid, const char* const root, char* const argv[]) {
if (fork() == 0) {
+#ifdef HAVE_CHROOT
if (root)
canfail(chroot(root));
+#endif
canfail(setuid(uid));
cantfail(putenv(display));
cantfail(putenv(xauth));

0 comments on commit 2a48885

Please sign in to comment.
Something went wrong with that request. Please try again.