Whamcloud - gitweb
ext2fs: don't ignore return value in ext2fs_count_blocks
[tools/e2fsprogs.git] / lib / ss / pager.c
index 9aaa72a..b9b8899 100644 (file)
@@ -14,6 +14,7 @@
  * express or implied warranty.
  */
 
+#include "config.h"
 #ifdef HAVE_UNISTD_H
 #include <unistd.h>
 #endif
@@ -38,7 +39,6 @@ extern int errno;
 #endif
 
 static char MORE[] = "more";
-extern char *_ss_pager_name;
 extern char *getenv PROTOTYPE((const char *));
 
 char *ss_safe_getenv(const char *arg)
@@ -46,19 +46,21 @@ char *ss_safe_getenv(const char *arg)
        if ((getuid() != geteuid()) || (getgid() != getegid()))
                return NULL;
 #if HAVE_PRCTL
-       if (prctl(PR_GET_DUMPABLE) == 0)
+       if (prctl(PR_GET_DUMPABLE, 0, 0, 0, 0) == 0)
                return NULL;
 #else
 #if (defined(linux) && defined(SYS_prctl))
-       if (syscall(SYS_prctl, PR_GET_DUMPABLE) == 0)
+       if (syscall(SYS_prctl, PR_GET_DUMPABLE, 0, 0, 0, 0) == 0)
                return NULL;
 #endif
 #endif
 
-#ifdef HAVE___SECURE_GETENV
-       return __secure_getenv("BLKID_FILE");
+#if defined(HAVE_SECURE_GETENV)
+       return secure_getenv(arg);
+#elif defined(HAVE___SECURE_GETENV)
+       return __secure_getenv(arg);
 #else
-       return getenv("BLKID_FILE");
+       return getenv(arg);
 #endif
 }
 
@@ -71,10 +73,10 @@ char *ss_safe_getenv(const char *arg)
  */
 
 #ifndef NO_FORK
-int ss_pager_create(void) 
+int ss_pager_create(void)
 {
        int filedes[2];
-     
+
        if (pipe(filedes) != 0)
                return(-1);
 
@@ -106,11 +108,30 @@ int ss_pager_create()
 }
 #endif
 
-void ss_page_stdin()
+static int write_all(int fd, char *buf, size_t count)
+{
+       ssize_t ret;
+       int c = 0;
+
+       while (count > 0) {
+               ret = write(fd, buf, count);
+               if (ret < 0) {
+                       if ((errno == EAGAIN) || (errno == EINTR))
+                               continue;
+                       return -1;
+               }
+               count -= ret;
+               buf += ret;
+               c += ret;
+       }
+       return c;
+}
+
+void ss_page_stdin(void)
 {
        int i;
        sigset_t mask;
-       
+
        for (i = 3; i < 32; i++)
                (void) close(i);
        (void) signal(SIGINT, SIG_DFL);
@@ -127,7 +148,7 @@ void ss_page_stdin()
                char buf[80];
                register int n;
                while ((n = read(0, buf, 80)) > 0)
-                       write(1, buf, n);
+                       write_all(1, buf, n);
        }
        exit(errno);
 }