(struct activity * [], unsigned int, int);
int get_activity_position
(struct activity * [], unsigned int, int);
-int set_default_file
- (char *, int, int);
void handle_invalid_sa_file
(int, struct file_magic *, char *, int);
void print_collect_error
(void);
+int set_default_file
+ (char *, int, int);
+int write_all
+ (int, const void *, int);
#ifndef SOURCE_SADC
int add_list_item
fm->sysstat_extraversion = atoi(v) & 0xff;
}
+/*
+ ***************************************************************************
+ * Write data to file. If the write() call was interrupted by a signal, try
+ * again so that the whole buffer can be written.
+ *
+ * IN:
+ * @fd Output file descriptor.
+ * @buf Data buffer.
+ * @nr_bytes Number of bytes to write.
+ *
+ * RETURNS:
+ * Number of bytes written to file, or -1 on error.
+ ***************************************************************************
+ */
+int write_all(int fd, const void *buf, int nr_bytes)
+{
+ int block, offset = 0;
+ char *buffer = (char *) buf;
+
+ while (nr_bytes > 0) {
+ block = write(fd, &buffer[offset], nr_bytes);
+
+ if (block < 0) {
+ if (errno == EINTR)
+ continue;
+ return block;
+ }
+ if (block == 0)
+ return offset;
+
+ offset += block;
+ nr_bytes -= block;
+ }
+
+ return offset;
+}
+
#ifndef SOURCE_SADC
/*
***************************************************************************
}
/* Write file's magic structure */
- if (write(stdfd, &fm, FILE_MAGIC_SIZE) != FILE_MAGIC_SIZE) {
+ if (write_all(stdfd, &fm, FILE_MAGIC_SIZE) != FILE_MAGIC_SIZE) {
fprintf(stderr, "\nwrite: %s\n", strerror(errno));
return -1;
}
}
/* Write file_header structure */
- if ((n = write(stdfd, &fh, FILE_HEADER_SIZE)) != FILE_HEADER_SIZE) {
+ if ((n = write_all(stdfd, &fh, FILE_HEADER_SIZE)) != FILE_HEADER_SIZE) {
fprintf(stderr, "\nwrite: %s\n", strerror(errno));
return -1;
}
* Even unknown activities must be written
* (they are counted in sa_act_nr).
*/
- if (write(stdfd, &fa, FILE_ACTIVITY_SIZE) != FILE_ACTIVITY_SIZE) {
+ if (write_all(stdfd, &fa, FILE_ACTIVITY_SIZE) != FILE_ACTIVITY_SIZE) {
fprintf(stderr, "\nwrite: %s\n", strerror(errno));
return -1;
}
}
/* Write record header */
- if (write(stdfd, &rec_hdr, RECORD_HEADER_SIZE) != RECORD_HEADER_SIZE) {
+ if (write_all(stdfd, &rec_hdr, RECORD_HEADER_SIZE) != RECORD_HEADER_SIZE) {
fprintf(stderr, "\nwrite: %s\n", strerror(errno));
return -1;
}
file_comment[MAX_COMMENT_LEN - 1] = '\0';
/* Then write it. No changes at this time */
- if (write(stdfd, file_comment, MAX_COMMENT_LEN) != MAX_COMMENT_LEN) {
+ if (write_all(stdfd, file_comment, MAX_COMMENT_LEN) != MAX_COMMENT_LEN) {
fprintf(stderr, "\nwrite: %s\n", strerror(errno));
return -1;
}
}
/* Write new number of CPU following the restart record */
- if (write(stdfd, &cpu_nr, sizeof(__nr_t)) != sizeof(__nr_t)) {
+ if (write_all(stdfd, &cpu_nr, sizeof(__nr_t)) != sizeof(__nr_t)) {
fprintf(stderr, "\nwrite: %s\n", strerror(errno));
return -1;
}
}
/* Write number of structures for current activity */
- if (write(stdfd, &nr, sizeof(__nr_t)) != sizeof(__nr_t))
+ if (write_all(stdfd, &nr, sizeof(__nr_t)) != sizeof(__nr_t))
goto write_error;
fprintf(stderr, "n");
for (j = 0; j < nr_struct; j++) {
for (k = 0; k < act[p]->nr2; k++) {
- if (write(stdfd,
- (char *) act[p]->buf[1] + (j * act[p]->nr2 + k) * act[p]->fsize,
- act[p]->fsize) != act[p]->fsize)
+ if (write_all(stdfd,
+ (char *) act[p]->buf[1] + (j * act[p]->nr2 + k) * act[p]->fsize,
+ act[p]->fsize) != act[p]->fsize)
goto write_error;
}
}
}
}
-/*
- ***************************************************************************
- * Write data to file. If the write() call was interrupted by a signal, try
- * again so that the whole buffer can be written.
- *
- * IN:
- * @fd Output file descriptor.
- * @buf Data buffer.
- * @nr_bytes Number of bytes to write.
- *
- * RETURNS:
- * Number of bytes written to file, or -1 on error.
- ***************************************************************************
- */
-int write_all(int fd, const void *buf, int nr_bytes)
-{
- int block, offset = 0;
- char *buffer = (char *) buf;
-
- while (nr_bytes > 0) {
- block = write(fd, &buffer[offset], nr_bytes);
-
- if (block < 0) {
- if (errno == EINTR)
- continue;
- return block;
- }
- if (block == 0)
- return offset;
-
- offset += block;
- nr_bytes -= block;
- }
-
- return offset;
-}
-
/*
***************************************************************************
* If -L option used, request a non-blocking, exclusive lock on the file.