~ubuntu-branches/ubuntu/precise/util-linux/precise-proposed

« back to all changes in this revision

Viewing changes to text-utils/tailf.c

  • Committer: Bazaar Package Importer
  • Author(s): Steve Langasek
  • Date: 2011-06-20 22:31:50 UTC
  • mfrom: (1.6.3 upstream) (4.5.1 sid)
  • Revision ID: james.westby@ubuntu.com-20110620223150-lz8wrv0946ihcz3z
Tags: 2.19.1-2ubuntu1
* Merge from Debian unstable, remaining changes:
  - Build for multiarch.
  - Add pre-depends on multiarch-support.
  - configure.ac: don't try to be clever about extracting a path name from
    $libdir to append to /usr in a way that's not overridable; instead,
    reuse the built-in configurable libexecdir.
  - Fix up the .pc.in files to know about libexecdir, so our substitutions
    don't leave us with unusable pkg-config files.
  - Install custom blkid.conf to use /dev/.blkid.tab since we don't
    expect device names to survive a reboot
  - Mention mountall(8) in fstab(5) manpages, along with its special
    options.
  - Since upstart is required in Ubuntu, the hwclock.sh init script is not
    called on startup and the hwclockfirst.sh init script is removed.
  - Drop depends on initscripts for the above.
  - Replace hwclock udev rule with an Upstart job.
  - For the case where mount is called with a directory to mount, look
    that directory up in mountall's /lib/init/fstab if we couldn't find
    it mentioned anywhere else.  This means "mount /proc", "mount /sys",
    etc. work.
  - mount.8 points to the cifs-utils package, not the obsolete smbfs one. 
* Dropped changes:
  - mount.preinst: lsb_release has been fixed in lucid and above to be
    usable without configuration, so we don't have to diverge from Debian
    here anymore.
* Changes merged upstream:
  - sfdisk support for '+' with '-N'
  - mount/umount.c: fix a segfault on umount with empty mtab entry
  - Fix arbitrary unmount with fuse security issue

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
#include <stdio.h>
30
30
#include <stdlib.h>
31
31
#include <unistd.h>
32
 
#include <malloc.h>
33
32
#include <string.h>
34
33
#include <sys/types.h>
35
34
#include <sys/stat.h>
40
39
#ifdef HAVE_INOTIFY_INIT
41
40
#include <sys/inotify.h>
42
41
#endif
 
42
 
43
43
#include "nls.h"
 
44
#include "xalloc.h"
44
45
#include "usleep.h"
45
46
 
46
47
#define DEFAULT_LINES  10
57
58
        if (!(str = fopen(filename, "r")))
58
59
                err(EXIT_FAILURE, _("cannot open \"%s\" for read"), filename);
59
60
 
60
 
        buf = malloc(lines * BUFSIZ);
 
61
        buf = xmalloc((lines ? lines : 1) * BUFSIZ);
61
62
        p = buf;
62
63
        while (fgets(p, BUFSIZ, str)) {
63
64
                if (++tail >= lines) {
88
89
        char buf[BUFSIZ];
89
90
        int fd;
90
91
        struct stat st;
 
92
        off_t pos;
91
93
 
92
 
        if (!(fd = open(filename, O_RDONLY)))
 
94
        fd = open(filename, O_RDONLY);
 
95
        if (fd < 0)
93
96
                err(EXIT_FAILURE, _("cannot open \"%s\" for read"), filename);
94
97
 
95
98
        if (fstat(fd, &st) == -1)
111
114
                }
112
115
                fflush(stdout);
113
116
        }
 
117
 
 
118
        pos = lseek(fd, 0, SEEK_CUR);
 
119
 
 
120
        /* If we've successfully read something, use the file position, this
 
121
         * avoids data duplication. If we read nothing or hit an error, reset
 
122
         * to the reported size, this handles truncated files.
 
123
         */
 
124
        *size = (pos != -1 && pos != *size) ? pos : st.st_size;
 
125
 
114
126
        close(fd);
115
 
        *size = st.st_size;
116
127
}
117
128
 
118
129
static void