/* read a string */ static amf_data * amf_string_read(amf_read_proc read_proc, void * user_data) { uint16_be strsize; byte * buffer; if (read_proc(&strsize, sizeof(uint16_be), user_data) < sizeof(uint16_be)) { return amf_data_error(AMF_ERROR_EOF); } strsize = swap_uint16(strsize); if (strsize == 0) { return amf_string_new(NULL, 0); } buffer = (byte*)calloc(strsize, sizeof(byte)); if (buffer == NULL) { return NULL; } if (read_proc(buffer, strsize, user_data) == strsize) { amf_data * data = amf_string_new(buffer, strsize); free(buffer); return data; } else { free(buffer); return amf_data_error(AMF_ERROR_EOF); } }
static int grant_estimate(int thread) { unsigned long long avail, grant; char proc_path[50]; int rc; static int ran = 0; /* I don't really care about protecting this with a mutex */ if (ran) return 0; if (o_verbose < 2) return 0; /* Divide /proc/fs/lustre/osc/o_0001/kbytesavail by /proc/fs/lustre/osc/o_0001/cur_grant_bytes to find max clients */ sprintf(proc_path, "/proc/fs/lustre/osc/o%.5d/kbytesavail", thread); rc = read_proc(proc_path, &avail); if (rc) return rc; sprintf(proc_path, "/proc/fs/lustre/osc/o%.5d/cur_grant_bytes", thread); rc = read_proc(proc_path, &grant); if (rc) return rc; if (grant == 0) { return -EINVAL; } printf("Estimate %llu clients before we run out of grant space " "(%lluK / %llu)\n", (avail << 10) / grant, avail, grant); ran++; return 0; }
/* read a string */ static amf0_data * amf0_string_read(read_proc_t read_proc, void * user_data) { uint16_t strsize; uint8_t * buffer; if (read_proc(&strsize, sizeof(uint16_t), user_data) < sizeof(uint16_t)) { return amf0_data_error(AMF0_ERROR_EOF); } strsize = swap_uint16(strsize); if (strsize == 0) { return amf0_string_new(NULL, 0); } buffer = calloc(strsize, sizeof(uint8_t)); if (buffer == NULL) { return NULL; } if (read_proc(buffer, strsize, user_data) == strsize) { amf0_data * data = amf0_string_new(buffer, strsize); free(buffer); return data; } else { free(buffer); return amf0_data_error(AMF0_ERROR_EOF); } }
/* read a date */ static amf_data * amf_date_read(amf_read_proc read_proc, void * user_data) { number64_be milliseconds; sint16_be timezone; if (read_proc(&milliseconds, sizeof(number64_be), user_data) == sizeof(number64_be) && read_proc(&timezone, sizeof(sint16_be), user_data) == sizeof(sint16_be)) { return amf_date_new(swap_number64(milliseconds), swap_sint16(timezone)); } else { return amf_data_error(AMF_ERROR_EOF); } }
/* read a date */ static amf0_data * amf0_date_read(read_proc_t read_proc, void * user_data) { number64_t milliseconds; int16_t timezone; if (read_proc(&milliseconds, sizeof(number64_t), user_data) == sizeof(number64_t) && read_proc(&timezone, sizeof(int16_t), user_data) == sizeof(int16_t)) { return amf0_date_new(swap_number64(milliseconds), swap_sint16(timezone)); } else { return NULL; } }
/* load AMF data from stream */ amf0_data * amf0_data_read(read_proc_t read_proc, void * user_data) { uint8_t type; if (read_proc(&type, sizeof(uint8_t), user_data) == sizeof(uint8_t)) { switch (type) { case AMF0_TYPE_NUMBER: return amf0_number_read(read_proc, user_data); case AMF0_TYPE_BOOLEAN: return amf0_boolean_read(read_proc, user_data); case AMF0_TYPE_STRING: return amf0_string_read(read_proc, user_data); case AMF0_TYPE_OBJECT: return amf0_object_read(read_proc, user_data); case AMF0_TYPE_NULL: return amf0_null_new(); case AMF0_TYPE_UNDEFINED: return amf0_undefined_new(); /*case AMF0_TYPE_REFERENCE:*/ case AMF0_TYPE_ECMA_ARRAY: return amf0_associative_array_read(read_proc, user_data); case AMF0_TYPE_STRICT_ARRAY: return amf0_array_read(read_proc, user_data); case AMF0_TYPE_DATE: return amf0_date_read(read_proc, user_data); /*case AMF0_TYPE_SIMPLEOBJECT:*/ case AMF0_TYPE_XML_DOCUMENT: case AMF0_TYPE_TYPED_OBJECT: case AMF0_TYPE_OBJECT_END: return NULL; /* end of composite object */ default: break; } } return NULL; }
static void read_trace(void) { FILE *fp; char *path; char *buf = NULL; size_t n; int r; if (read_proc() == '1') printf("(stack tracer running)\n"); else printf("(stack tracer not running)\n"); path = tracecmd_get_tracing_file("stack_trace"); fp = fopen(path, "r"); if (!fp) die("reading to '%s'", path); tracecmd_put_tracing_file(path); while ((r = getline(&buf, &n, fp)) >= 0) { /* * Skip any line that starts with a '#'. * Those talk about how to enable stack tracing * within the debugfs system. We don't care about that. */ if (buf[0] != '#') printf("%s", buf); free(buf); buf = NULL; } fclose(fp); }
/* read a number */ static amf0_data * amf0_number_read(read_proc_t read_proc, void * user_data) { number64_t val; if (read_proc(&val, sizeof(number64_t), user_data) == sizeof(number64_t)) { return amf0_number_new(swap_number64(val)); } return NULL; }
/* read a boolean */ static amf0_data * amf0_boolean_read(read_proc_t read_proc, void * user_data) { uint8_t val; if (read_proc(&val, sizeof(uint8_t), user_data) == sizeof(uint8_t)) { return amf0_boolean_new(val); } return NULL; }
static gboolean battery_update_os_proc(battery_priv *c) { GString *path; int len; GDir *dir; gboolean ret = FALSE; const gchar *file; ENTER; c->exist = FALSE; path = g_string_sized_new(200); g_string_append(path, PROC_ACPI); len = path->len; if (!(dir = g_dir_open(path->str, 0, NULL))) { DBG("can't open dir %s\n", path->str); goto out; } while (!ret && (file = g_dir_read_name(dir))) { g_string_append(path, file); DBG("testing %s\n", path->str); ret = g_file_test(path->str, G_FILE_TEST_IS_DIR); if (ret) ret = read_proc(c, path); g_string_truncate(path, len); } g_dir_close(dir); out: g_string_free(path, TRUE); RET(ret); }
/* read an array */ static amf0_data * amf0_array_read(read_proc_t read_proc, void * user_data) { size_t i; amf0_data * element; amf0_data * data = amf0_array_new(); if (data != NULL) { uint32_t array_size; if (read_proc(&array_size, sizeof(uint32_t), user_data) == sizeof(uint32_t)) { array_size = swap_uint32(array_size); for (i = 0; i < array_size; ++i) { element = amf0_data_read(read_proc, user_data); if (element != NULL) { if (amf0_array_push(data, element) == NULL) { amf0_data_free(element); amf0_data_free(data); return NULL; } } else { amf0_data_free(data); return NULL; } } } else { amf0_data_free(data); return NULL; } } return data; }
/* read an associative array */ static amf_data * amf_associative_array_read(amf_read_proc read_proc, void * user_data) { amf_data * name; amf_data * element; uint32_be size; byte error_code; amf_data * data; data = amf_associative_array_new(); if (data == NULL) { return NULL; } /* we ignore the 32 bits array size marker */ if (read_proc(&size, sizeof(uint32_be), user_data) < sizeof(uint32_be)) { amf_data_free(data); return amf_data_error(AMF_ERROR_EOF); } while(1) { name = amf_string_read(read_proc, user_data); error_code = amf_data_get_error_code(name); if (error_code != AMF_ERROR_OK) { /* invalid name: error */ amf_data_free(name); amf_data_free(data); return amf_data_error(error_code); } element = amf_data_read(read_proc, user_data); error_code = amf_data_get_error_code(element); if (amf_string_get_size(name) == 0 || error_code == AMF_ERROR_END_TAG || error_code == AMF_ERROR_UNKNOWN_TYPE) { /* end tag or unknown element: end of data, exit loop */ amf_data_free(name); amf_data_free(element); break; } else if (error_code != AMF_ERROR_OK) { amf_data_free(name); amf_data_free(data); amf_data_free(element); return amf_data_error(error_code); } if (amf_associative_array_add(data, (char *)amf_string_get_bytes(name), element) == NULL) { amf_data_free(name); amf_data_free(element); amf_data_free(data); return NULL; } else { amf_data_free(name); } } return data; }
/* read a boolean */ static amf_data * amf_boolean_read(amf_read_proc read_proc, void * user_data) { uint8 val; if (read_proc(&val, sizeof(uint8), user_data) == sizeof(uint8)) { return amf_boolean_new(val); } else { return amf_data_error(AMF_ERROR_EOF); } }
/* read a number */ static amf_data * amf_number_read(amf_read_proc read_proc, void * user_data) { number64_be val; if (read_proc(&val, sizeof(number64_be), user_data) == sizeof(number64_be)) { return amf_number_new(swap_number64(val)); } else { return amf_data_error(AMF_ERROR_EOF); } }
/* read a boolean */ static amf0_data * amf0_boolean_read(read_proc_t read_proc, void * user_data) { uint8_t val; if (read_proc(&val, sizeof(uint8_t), user_data) == sizeof(uint8_t)) { return amf0_boolean_new(val); } else { return amf0_data_error(AMF0_ERROR_EOF); } }
/* read a number */ static amf0_data * amf0_number_read(read_proc_t read_proc, void * user_data) { number64_t val; if (read_proc(&val, sizeof(number64_t), user_data) == sizeof(number64_t)) { return amf0_number_new(swap_number64(val)); } else { return amf0_data_error(AMF0_ERROR_EOF); } }
void* drive_test (void* arg_v) { struct drive_test_arg* dta = (struct drive_test_arg*) arg_v; int i; for (i=0; i<dta->count; i++) { if (dta->write) write_proc(); else read_proc(); } }
/* read a string */ static amf0_data * amf0_string_read(read_proc_t read_proc, void * user_data) { uint16_t strsize; uint8_t * buffer; if (read_proc(&strsize, sizeof(uint16_t), user_data) == sizeof(uint16_t)) { strsize = swap_uint16(strsize); if (strsize > 0) { buffer = (uint8_t*)calloc(strsize, sizeof(uint8_t)); if (buffer != NULL && read_proc(buffer, strsize, user_data) == strsize) { amf0_data * data = amf0_string_new(buffer, strsize); free(buffer); return data; } } else { return amf0_string_new(NULL, 0); } } return NULL; }
static void handle_open_filepath(const char *filename) { switch(file_type_with_path(filename)) { case _file_type_script: doit_proc(filename); break; case _file_type_data: read_proc(filename); break; default: break; } }
AVInputFormat* ac_probe_input_stream( void* sender, ac_read_callback read_proc, char* filename, void* *buf, int* buf_read) { //Initialize the result variables AVInputFormat* fmt = NULL; *buf_read = 0; *buf = NULL; int last_iteration = 0; int probe_size = 0; for (probe_size = PROBE_BUF_MIN; (probe_size <= PROBE_BUF_MAX) && !fmt && !last_iteration; probe_size<<=1) { int score = AVPROBE_SCORE_MAX / 4; //Allocate some memory for the current probe buffer void* tmp_buf = av_malloc(probe_size); //Unaligned memory would also be ok here memset(tmp_buf, 0, probe_size); //Copy the old data to the new buffer if (*buf) { memcpy(tmp_buf, *buf, *buf_read); //Free the old data memory av_free(*buf); } //Read the new data void* write_ptr = tmp_buf + *buf_read; int read_size = probe_size - *buf_read; int size; if (size = read_proc(sender, write_ptr, read_size) < read_size) { last_iteration = 1; probe_size = *buf_read + size; } //Probe it fmt = (AVInputFormat*)ac_probe_input_buffer(tmp_buf, probe_size, filename, &score); //Set the new buffer *buf = tmp_buf; *buf_read = probe_size; } //Return the result return fmt; }
int get_pid_info() { DIR *dir; struct dirent *ptr; int i=0; if(!(dir=opendir("/proc"))) return 0; while((ptr=readdir(dir))!=false) { if(ptr->d_name[0]>='1' && ptr->d_name[0]<='9') { read_proc(&(procInfo[i]),ptr->d_name); i++; } } closedir(dir); return i; }
static void start_stop_trace(char val) { char buf[1]; int fd; int n; buf[0] = read_proc(); if (buf[0] == val) return; fd = open(PROC_FILE, O_WRONLY); if (fd < 0) die("writing %s", PROC_FILE); buf[0] = val; n = write(fd, buf, 1); if (n < 0) die("writing into %s", PROC_FILE); close(fd); }
/* load AMF data from stream */ amf0_data * amf0_data_read(read_proc_t read_proc, void * user_data) { uint8_t type; if (read_proc(&type, sizeof(uint8_t), user_data) == sizeof(uint8_t)) { switch (type) { case AMF0_TYPE_NUMBER: return amf0_number_read(read_proc, user_data); case AMF0_TYPE_BOOLEAN: return amf0_boolean_read(read_proc, user_data); case AMF0_TYPE_STRING: return amf0_string_read(read_proc, user_data); case AMF0_TYPE_OBJECT: return amf0_object_read(read_proc, user_data); case AMF0_TYPE_MOVIECLIP: return NULL; /* not supported */ case AMF0_TYPE_NULL: return amf0_null_new(); case AMF0_TYPE_UNDEFINED: return amf0_undefined_new(); case AMF0_TYPE_REFERENCE: /* TODO */ return NULL; case AMF0_TYPE_ECMA_ARRAY: return amf0_associative_array_read(read_proc, user_data); case AMF0_TYPE_OBJECT_END: return amf0_data_error(AMF0_ERROR_END_TAG); /* end of composite object */ case AMF0_TYPE_STRICT_ARRAY: return amf0_array_read(read_proc, user_data); case AMF0_TYPE_DATE: return amf0_date_read(read_proc, user_data); case AMF0_TYPE_LONG_STRING: /* TODO */ case AMF0_TYPE_UNSUPPORTED: /* TODO */ case AMF0_TYPE_RECORDSET: /* not supported */ case AMF0_TYPE_XML_DOCUMENT: /* TODO */ case AMF0_TYPE_TYPED_OBJECT: /* TODO */ return NULL; default: break; } } return NULL; }
/* read an associative array */ static amf0_data * amf0_associative_array_read(read_proc_t read_proc, void * user_data) { amf0_data * data = amf0_associative_array_new(); if (data != NULL) { amf0_data * name; amf0_data * element; uint32_t size; if (read_proc(&size, sizeof(uint32_t), user_data) == sizeof(uint32_t)) { /* we ignore the 32 bits array size marker */ while(1) { name = amf0_string_read(read_proc, user_data); if (name != NULL) { element = amf0_data_read(read_proc, user_data); if (element != NULL) { if (amf0_associative_array_add(data, (char *)amf0_string_get_uint8_ts(name), element) == NULL) { amf0_data_free(name); amf0_data_free(element); amf0_data_free(data); return NULL; } } else { amf0_data_free(name); break; } } else { /* invalid name: error */ amf0_data_free(data); return NULL; } } } else { amf0_data_free(data); return NULL; } } return data; }
/* read an array */ static amf_data * amf_array_read(amf_read_proc read_proc, void * user_data) { size_t i; amf_data * element; byte error_code; amf_data * data; uint32 array_size; data = amf_array_new(); if (data == NULL) { return NULL; } if (read_proc(&array_size, sizeof(uint32), user_data) < sizeof(uint32)) { amf_data_free(data); return amf_data_error(AMF_ERROR_EOF); } array_size = swap_uint32(array_size); for (i = 0; i < array_size; ++i) { element = amf_data_read(read_proc, user_data); error_code = amf_data_get_error_code(element); if (error_code != AMF_ERROR_OK) { amf_data_free(element); amf_data_free(data); return amf_data_error(error_code); } if (amf_array_push(data, element) == NULL) { amf_data_free(element); amf_data_free(data); return NULL; } } return data; }
/* load AMF data from stream */ amf_data * amf_data_read(amf_read_proc read_proc, void * user_data) { byte type; if (read_proc(&type, sizeof(byte), user_data) < sizeof(byte)) { return amf_data_error(AMF_ERROR_EOF); } switch (type) { case AMF_TYPE_NUMBER: return amf_number_read(read_proc, user_data); case AMF_TYPE_BOOLEAN: return amf_boolean_read(read_proc, user_data); case AMF_TYPE_STRING: return amf_string_read(read_proc, user_data); case AMF_TYPE_OBJECT: return amf_object_read(read_proc, user_data); case AMF_TYPE_NULL: return amf_null_new(); case AMF_TYPE_UNDEFINED: return amf_undefined_new(); /*case AMF_TYPE_REFERENCE:*/ case AMF_TYPE_ASSOCIATIVE_ARRAY: return amf_associative_array_read(read_proc, user_data); case AMF_TYPE_ARRAY: return amf_array_read(read_proc, user_data); case AMF_TYPE_DATE: return amf_date_read(read_proc, user_data); /*case AMF_TYPE_SIMPLEOBJECT:*/ case AMF_TYPE_XML: case AMF_TYPE_CLASS: return amf_data_error(AMF_ERROR_UNSUPPORTED_TYPE); case AMF_TYPE_END: return amf_data_error(AMF_ERROR_END_TAG); /* end of composite object */ default: return amf_data_error(AMF_ERROR_UNKNOWN_TYPE); } }
int kernel_setup(int setup) { int rc; if(setup) { if(export_table < 0) export_table = RT_TABLE_MAIN; if(import_table < 0) import_table = RT_TABLE_MAIN; dgram_socket = socket(PF_INET, SOCK_DGRAM, 0); if(dgram_socket < 0) return -1; rc = netlink_socket(&nl_command, 0); if(rc < 0) { perror("netlink_socket(0)"); return -1; } nl_setup = 1; old_forwarding = read_proc("/proc/sys/net/ipv6/conf/all/forwarding"); if(old_forwarding < 0) { perror("Couldn't read forwarding knob."); return -1; } rc = write_proc("/proc/sys/net/ipv6/conf/all/forwarding", 1); if(rc < 0) { perror("Couldn't write forwarding knob."); return -1; } old_ipv4_forwarding = read_proc("/proc/sys/net/ipv4/conf/all/forwarding"); if(old_ipv4_forwarding < 0) { perror("Couldn't read IPv4 forwarding knob."); return -1; } rc = write_proc("/proc/sys/net/ipv4/conf/all/forwarding", 1); if(rc < 0) { perror("Couldn't write IPv4 forwarding knob."); return -1; } old_accept_redirects = read_proc("/proc/sys/net/ipv6/conf/all/accept_redirects"); if(old_accept_redirects < 0) { perror("Couldn't read accept_redirects knob."); return -1; } rc = write_proc("/proc/sys/net/ipv6/conf/all/accept_redirects", 0); if(rc < 0) { perror("Couldn't write accept_redirects knob."); return -1; } old_rp_filter = read_proc("/proc/sys/net/ipv4/conf/all/rp_filter"); if(old_rp_filter < 0) { perror("Couldn't read rp_filter knob."); return -1; } rc = write_proc("/proc/sys/net/ipv4/conf/all/rp_filter", 0); if(rc < 0) { perror("Couldn't write rp_filter knob."); return -1; } return 1; } else { close(dgram_socket); dgram_socket = -1; if(old_forwarding >= 0) { rc = write_proc("/proc/sys/net/ipv6/conf/all/forwarding", old_forwarding); if(rc < 0) { perror("Couldn't write forwarding knob.\n"); return -1; } } if(old_ipv4_forwarding >= 0) { rc = write_proc("/proc/sys/net/ipv4/conf/all/forwarding", old_ipv4_forwarding); if(rc < 0) { perror("Couldn't write IPv4 forwarding knob.\n"); return -1; } } if(old_accept_redirects >= 0) { rc = write_proc("/proc/sys/net/ipv6/conf/all/accept_redirects", old_accept_redirects); if(rc < 0) { perror("Couldn't write accept_redirects knob.\n"); return -1; } } if(old_rp_filter >= 0) { rc = write_proc("/proc/sys/net/ipv4/conf/all/rp_filter", old_rp_filter); if(rc < 0) { perror("Couldn't write rp_filter knob.\n"); return -1; } } close(nl_command.sock); nl_command.sock = -1; nl_setup = 0; return 1; } }
int main(int argc, char **argv) { int err; err = read_proc(); err = parse_proc(); return err; }
int main(int argc , char **argv ) { struct sigaction act ; sigset_t mask ; sigset_t oldmask ; struct rlimit rlim ; struct timespec timeout ; char const *output_dir ; char filename[4096] ; int sfd ; int dfd ; int ufd ; DIR *proc ; int statfd ; int diskfd ; int procfd ; char statbuf[524288] ; char diskbuf[524288] ; char procbuf[524288] ; size_t statlen ; size_t disklen ; size_t proclen ; unsigned long reltime ; int arg ; int rel ; int tmp ; unsigned long hz ; char *endptr ; int tmp___0 ; int tmp___1 ; int tmp___2 ; char uptime[80] ; size_t uptimelen ; unsigned long u ; int tmp___3 ; int tmp___4 ; int tmp___5 ; int tmp___6 ; int *tmp___7 ; int tmp___8 ; int tmp___9 ; int tmp___10 ; int tmp___11 ; int tmp___12 ; int tmp___13 ; int tmp___14 ; int tmp___15 ; int tmp___16 ; int tmp___17 ; int tmp___18 ; { #line 227 output_dir = "."; #line 233 statlen = (size_t )0; #line 233 disklen = (size_t )0; #line 233 proclen = (size_t )0; #line 234 reltime = 0UL; #line 235 arg = 1; #line 235 rel = 0; #line 237 if (argc > arg) { { #line 237 tmp = strcmp((char const *)*(argv + arg), "-r"); } #line 237 if (! tmp) { #line 238 rel = 1; #line 239 arg ++; } } #line 242 if (argc <= arg) { { #line 243 fprintf((FILE */* __restrict */)stderr, (char const */* __restrict */)"Usage: %s [-r] HZ [DIR]\n", *(argv + 0)); #line 244 exit(1); } } #line 247 if (argc > arg) { { #line 251 hz = strtoul((char const */* __restrict */)*(argv + arg), (char **/* __restrict */)(& endptr), 10); } #line 252 if (*endptr) { { #line 253 fprintf((FILE */* __restrict */)stderr, (char const */* __restrict */)"%s: HZ not an integer\n", *(argv + 0)); #line 254 exit(1); } } #line 257 if (hz > 1UL) { #line 258 timeout.tv_sec = (__time_t )0; #line 259 timeout.tv_nsec = (__syscall_slong_t )(1000000000UL / hz); } else { #line 261 timeout.tv_sec = (__time_t )1; #line 262 timeout.tv_nsec = (__syscall_slong_t )0; } #line 265 arg ++; } #line 268 if (argc > arg) { #line 269 output_dir = (char const *)*(argv + arg); #line 270 arg ++; } { #line 274 sigemptyset(& mask); #line 275 sigaddset(& mask, 15); #line 276 sigaddset(& mask, 2); #line 278 tmp___0 = sigprocmask(0, (sigset_t const */* __restrict */)(& mask), (sigset_t */* __restrict */)(& oldmask)); } #line 278 if (tmp___0 < 0) { { #line 279 perror("sigprocmask"); #line 280 exit(1); } } { #line 283 act.__sigaction_handler.sa_handler = & sig_handler; #line 284 act.sa_flags = 0; #line 285 sigemptyset(& act.sa_mask); #line 287 tmp___1 = sigaction(15, (struct sigaction const */* __restrict */)(& act), (struct sigaction */* __restrict */)((void *)0)); } #line 287 if (tmp___1 < 0) { { #line 288 perror("sigaction SIGTERM"); #line 289 exit(1); } } { #line 292 tmp___2 = sigaction(2, (struct sigaction const */* __restrict */)(& act), (struct sigaction */* __restrict */)((void *)0)); } #line 292 if (tmp___2 < 0) { { #line 293 perror("sigaction SIGINT"); #line 294 exit(1); } } { #line 298 chdir("/"); #line 301 rlim.rlim_cur = (__rlim_t )-1; #line 302 rlim.rlim_max = (__rlim_t )-1; #line 304 setrlimit(4, (struct rlimit const *)(& rlim)); #line 307 proc = opendir("/proc"); } #line 308 if (! proc) { { #line 309 perror("opendir /proc"); #line 310 exit(1); } } { #line 313 sfd = open("/proc/stat", 0); } #line 314 if (sfd < 0) { { #line 315 perror("open /proc/stat"); #line 316 exit(1); } } { #line 319 dfd = open("/proc/diskstats", 0); } #line 320 if (dfd < 0) { { #line 321 perror("open /proc/diskstats"); #line 322 exit(1); } } { #line 325 ufd = open("/proc/uptime", 0); } #line 326 if (ufd < 0) { { #line 327 perror("open /proc/uptime"); #line 328 exit(1); } } { #line 332 sprintf((char */* __restrict */)(filename), (char const */* __restrict */)"%s/proc_stat.log", output_dir); #line 333 statfd = open((char const *)(filename), 577, 420); } #line 334 if (statfd < 0) { { #line 335 perror("open proc_stat.log"); #line 336 exit(1); } } { #line 339 sprintf((char */* __restrict */)(filename), (char const */* __restrict */)"%s/proc_diskstats.log", output_dir); #line 340 diskfd = open((char const *)(filename), 577, 420); } #line 341 if (diskfd < 0) { { #line 342 perror("open proc_diskstats.log"); #line 343 exit(1); } } { #line 346 sprintf((char */* __restrict */)(filename), (char const */* __restrict */)"%s/proc_ps.log", output_dir); #line 347 procfd = open((char const *)(filename), 577, 420); } #line 348 if (procfd < 0) { { #line 349 perror("open proc_ps.log"); #line 350 exit(1); } } #line 354 if (rel) { { #line 355 reltime = get_uptime(ufd); } #line 356 if (! reltime) { { #line 357 exit(1); } } } { #line 360 while (1) { while_continue: /* CIL Label */ ; { #line 365 u = get_uptime(ufd); } #line 366 if (! u) { { #line 367 exit(1); } } { #line 369 tmp___3 = sprintf((char */* __restrict */)(uptime), (char const */* __restrict */)"%lu\n", u - reltime); #line 369 uptimelen = (size_t )tmp___3; #line 372 tmp___4 = read_file(sfd, (char const *)(uptime), uptimelen, statfd, statbuf, & statlen); } #line 372 if (tmp___4 < 0) { { #line 374 exit(1); } } { #line 376 tmp___5 = read_file(dfd, (char const *)(uptime), uptimelen, diskfd, diskbuf, & disklen); } #line 376 if (tmp___5 < 0) { { #line 378 exit(1); } } { #line 380 tmp___6 = read_proc(proc, (char const *)(uptime), uptimelen, procfd, procbuf, & proclen); } #line 380 if (tmp___6 < 0) { { #line 382 exit(1); } } { #line 384 tmp___8 = pselect(0, (fd_set */* __restrict */)((void *)0), (fd_set */* __restrict */)((void *)0), (fd_set */* __restrict */)((void *)0), (struct timespec const */* __restrict */)(& timeout), (__sigset_t const */* __restrict */)(& oldmask)); } #line 384 if (tmp___8 < 0) { { #line 385 tmp___7 = __errno_location(); } #line 385 if (*tmp___7 == 4) { #line 386 goto while_break; } else { { #line 388 perror("pselect"); #line 389 exit(1); } } } } while_break: /* CIL Label */ ; } { #line 395 tmp___9 = flush_buf(statfd, statbuf, & statlen); } #line 395 if (tmp___9 < 0) { { #line 396 exit(1); } } { #line 397 tmp___10 = close(statfd); } #line 397 if (tmp___10 < 0) { { #line 398 perror("close proc_stat.log"); #line 399 exit(1); } } { #line 402 tmp___11 = flush_buf(diskfd, diskbuf, & disklen); } #line 402 if (tmp___11 < 0) { { #line 403 exit(1); } } { #line 404 tmp___12 = close(diskfd); } #line 404 if (tmp___12 < 0) { { #line 405 perror("close proc_diskstats.log"); #line 406 exit(1); } } { #line 409 tmp___13 = flush_buf(procfd, procbuf, & proclen); } #line 409 if (tmp___13 < 0) { { #line 410 exit(1); } } { #line 411 tmp___14 = close(procfd); } #line 411 if (tmp___14 < 0) { { #line 412 perror("close proc_ps.log"); #line 413 exit(1); } } { #line 417 tmp___15 = close(ufd); } #line 417 if (tmp___15 < 0) { { #line 418 perror("close /proc/uptime"); #line 419 exit(1); } } { #line 422 tmp___16 = close(dfd); } #line 422 if (tmp___16 < 0) { { #line 423 perror("close /proc/diskstats"); #line 424 exit(1); } } { #line 427 tmp___17 = close(sfd); } #line 427 if (tmp___17 < 0) { { #line 428 perror("close /proc/stat"); #line 429 exit(1); } } { #line 432 tmp___18 = closedir(proc); } #line 432 if (tmp___18 < 0) { { #line 433 perror("close /proc"); #line 434 exit(1); } } #line 437 return (0); } }