sysstat/sysstat-8.0.4-write.patch

95 lines
3.6 KiB
Diff

diff -up sysstat-8.0.4/sadc.c.pom sysstat-8.0.4/sadc.c
--- sysstat-8.0.4/sadc.c.pom 2008-01-01 10:26:31.000000000 +0100
+++ sysstat-8.0.4/sadc.c 2008-02-28 10:25:20.000000000 +0100
@@ -99,6 +99,32 @@ void alarm_handler(int sig)
alarm(interval);
}
+
+/*
+ ***************************************************************************
+ * write 'count' bytes from buffer to file fd
+ ***************************************************************************
+ */
+int write_all(int fd, const char *buffer, int count)
+{
+ int block, offset = 0;
+
+ while (count > 0) {
+ block = write(fd, &buffer[offset], count);
+
+ if (block < 0) {
+ if (errno == EINTR) continue;
+ return block;
+ }
+ if (block == 0) return offset;
+
+ offset += block;
+ count -= block;
+ }
+
+ return offset;
+}
+
/*
***************************************************************************
@@ -357,7 +383,7 @@ void setup_file_hdr(int fd, size_t *file
file_hdr.sa_release[UTSNAME_LEN - 1] = '\0';
/* Write file header */
- if ((nb = write(fd, &file_hdr, FILE_HDR_SIZE)) != FILE_HDR_SIZE) {
+ if ((nb = write_all(fd, &file_hdr, FILE_HDR_SIZE)) != FILE_HDR_SIZE) {
fprintf(stderr, _("Cannot write system activity file header: %s\n"),
strerror(errno));
exit(2);
@@ -404,7 +430,7 @@ void write_special_record(int ofd, size_
}
/* Write record now */
- if ((nb = write(ofd, &file_stats, file_stats_size)) != file_stats_size)
+ if ((nb = write_all(ofd, &file_stats, file_stats_size)) != file_stats_size)
p_write_error();
}
@@ -432,32 +458,32 @@ void write_stats(int ofd, size_t file_st
/* Unable to lock file: wait for next iteration to try again to save data */
return;
}
- if ((nb = write(ofd, &file_stats, file_stats_size)) != file_stats_size)
+ if ((nb = write_all(ofd, &file_stats, file_stats_size)) != file_stats_size)
p_write_error();
if (cpu_nr) {
- if ((nb = write(ofd, st_cpu, STATS_ONE_CPU_SIZE * cpu_nr)) != (STATS_ONE_CPU_SIZE * cpu_nr))
+ if ((nb = write_all(ofd, st_cpu, STATS_ONE_CPU_SIZE * cpu_nr)) != (STATS_ONE_CPU_SIZE * cpu_nr))
p_write_error();
}
if (GET_ONE_IRQ(sadc_actflag)) {
- if ((nb = write(ofd, interrupts, STATS_ONE_IRQ_SIZE)) != STATS_ONE_IRQ_SIZE)
+ if ((nb = write_all(ofd, interrupts, STATS_ONE_IRQ_SIZE)) != STATS_ONE_IRQ_SIZE)
p_write_error();
}
if (serial_nr) {
- if ((nb = write(ofd, st_serial, STATS_SERIAL_SIZE * serial_nr)) != (STATS_SERIAL_SIZE * serial_nr))
+ if ((nb = write_all(ofd, st_serial, STATS_SERIAL_SIZE * serial_nr)) != (STATS_SERIAL_SIZE * serial_nr))
p_write_error();
}
if (irqcpu_nr) {
- if ((nb = write(ofd, st_irq_cpu, STATS_IRQ_CPU_SIZE * cpu_nr * irqcpu_nr))
+ if ((nb = write_all(ofd, st_irq_cpu, STATS_IRQ_CPU_SIZE * cpu_nr * irqcpu_nr))
!= (STATS_IRQ_CPU_SIZE * cpu_nr * irqcpu_nr))
p_write_error();
}
if (iface_nr) {
- if ((nb = write(ofd, st_net_dev, STATS_NET_DEV_SIZE * iface_nr)) != (STATS_NET_DEV_SIZE * iface_nr))
+ if ((nb = write_all(ofd, st_net_dev, STATS_NET_DEV_SIZE * iface_nr)) != (STATS_NET_DEV_SIZE * iface_nr))
p_write_error();
}
if (disk_nr && GET_DISK(sadc_actflag)) {
/* Disk stats written only if -d option used */
- if ((nb = write(ofd, st_disk, DISK_STATS_SIZE * disk_nr)) != (DISK_STATS_SIZE * disk_nr))
+ if ((nb = write_all(ofd, st_disk, DISK_STATS_SIZE * disk_nr)) != (DISK_STATS_SIZE * disk_nr))
p_write_error();
}
}