~ubuntu-branches/ubuntu/utopic/libgtop2/utopic-proposed

« back to all changes in this revision

Viewing changes to sysdeps/linux/glibtop_private.c

  • Committer: Bazaar Package Importer
  • Author(s): Didier Roche
  • Date: 2009-02-17 23:12:12 UTC
  • mfrom: (1.1.14 upstream)
  • Revision ID: james.westby@ubuntu.com-20090217231212-yhcddg53iyuwddsl
Tags: 2.25.91-0ubuntu1
* New upstream release (LP: #330751)
  - Synced with gnome-2-24.
  - Fixed license: libgtop is GPL-2.
  - linux:
    - fixed potential memory leak.
    - fixed read(2) usage. Should fix the missing cpus bug in
      system-monitor.
  - darwin:
    - fixed build. "paul".
* debian/patches/50_linux260_leak_fix.patch removed: upstream fixed it

Show diffs side-by-side

added added

removed removed

Lines of Context:
67
67
        TRY_FILE_TO_BUFFER_READ = -2
68
68
};
69
69
 
 
70
/*
 
71
 * Doesn't handle bufsiz == 0
 
72
 */
70
73
int try_file_to_buffer(char *buffer, size_t bufsiz, const char *format, ...)
71
74
{
72
75
        char path[4096];
73
76
        int fd;
74
 
        ssize_t len;
 
77
        size_t len = 0;
 
78
        ssize_t nread = 0;
75
79
        va_list pa;
76
80
 
77
 
        if (bufsiz <= sizeof(char*))
 
81
        if (G_UNLIKELY(bufsiz <= sizeof(char*)))
78
82
          g_warning("Huhu, bufsiz of %lu looks bad", (gulong)bufsiz);
79
83
 
80
84
        va_start(pa, format);
84
88
 
85
89
        va_end(pa);
86
90
 
 
91
        bufsiz--; /* reserve 1 for trailing NUL */
87
92
        buffer [0] = '\0';
88
93
 
89
94
        if((fd = open (path, O_RDONLY)) < 0)
90
95
                return TRY_FILE_TO_BUFFER_OPEN;
91
96
 
92
 
        len = read (fd, buffer, bufsiz - 1);
 
97
        while (len < bufsiz) {
 
98
                nread = read (fd, buffer + len, bufsiz - len);
 
99
 
 
100
                if (G_UNLIKELY(nread < 0)) {
 
101
                        if (errno == EINTR)
 
102
                                continue;
 
103
                        else
 
104
                                break;
 
105
                }
 
106
 
 
107
                len += nread;
 
108
 
 
109
                if (nread == 0)
 
110
                        break;
 
111
        }
 
112
 
93
113
        close (fd);
94
114
 
95
 
        if (len < 0)
 
115
        if (nread < 0)
96
116
                return TRY_FILE_TO_BUFFER_READ;
97
117
 
98
118
        buffer [len] = '\0';