Logging to debug file descriptor max out
parent
f5c5add46d
commit
85b77e2ce9
|
@ -18,13 +18,13 @@
|
||||||
#if defined(IS_PLAT_LAYER)
|
#if defined(IS_PLAT_LAYER)
|
||||||
|
|
||||||
# if defined(USE_LOG)
|
# if defined(USE_LOG)
|
||||||
# define LOG(m) GEN_LOG(sysfunc.log, FNLN m)
|
# define LOG(m) GEN_LOG(sysfunc.log, FNLN "\n" m)
|
||||||
# else
|
# else
|
||||||
# define LOG(m)
|
# define LOG(m)
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
# if defined(USE_LOGF)
|
# if defined(USE_LOGF)
|
||||||
# define LOGF(...) GEN_LOGF(sysfunc.log, FNLN __VA_ARGS__)
|
# define LOGF(...) GEN_LOGF(sysfunc.log, FNLN "\n" __VA_ARGS__)
|
||||||
# else
|
# else
|
||||||
# define LOGF(...)
|
# define LOGF(...)
|
||||||
# endif
|
# endif
|
||||||
|
@ -32,13 +32,13 @@
|
||||||
#else /* Not platform layer */
|
#else /* Not platform layer */
|
||||||
|
|
||||||
# if defined(USE_LOG)
|
# if defined(USE_LOG)
|
||||||
# define LOG(s,m) GEN_LOG((s)->log, FNLN m)
|
# define LOG(s,m) GEN_LOG((s)->log, FNLN "\n" m)
|
||||||
# else
|
# else
|
||||||
# define LOG(s,m)
|
# define LOG(s,m)
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
# if defined(USE_LOGF)
|
# if defined(USE_LOGF)
|
||||||
# define LOGF(s,...) GEN_LOGF((s)->log, FNLN __VA_ARGS__)
|
# define LOGF(s,...) GEN_LOGF((s)->log, FNLN "\n" __VA_ARGS__)
|
||||||
# else
|
# else
|
||||||
# define LOGF(s,...)
|
# define LOGF(s,...)
|
||||||
# endif
|
# endif
|
||||||
|
|
|
@ -155,7 +155,7 @@ Sys_Set_File_List_Sig(system_set_file_list){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
LOGF("set_file_list: %s\n", directory);
|
LOGF("%s\n", directory);
|
||||||
|
|
||||||
DIR *d = opendir(directory);
|
DIR *d = opendir(directory);
|
||||||
if (d != 0){
|
if (d != 0){
|
||||||
|
@ -261,19 +261,23 @@ Sys_Get_Canonical_Sig(system_get_canonical){
|
||||||
if (read_p == filename || read_p[0] == '/'){
|
if (read_p == filename || read_p[0] == '/'){
|
||||||
if (read_p[1] == '/'){
|
if (read_p[1] == '/'){
|
||||||
++read_p;
|
++read_p;
|
||||||
} else if(read_p[1] == '.'){
|
}
|
||||||
|
else if(read_p[1] == '.'){
|
||||||
if (read_p[2] == '/' || !read_p[2]){
|
if (read_p[2] == '/' || !read_p[2]){
|
||||||
read_p += 2;
|
read_p += 2;
|
||||||
} else if(read_p[2] == '.' && (read_p[3] == '/' || !read_p[3])){
|
} else if(read_p[2] == '.' && (read_p[3] == '/' || !read_p[3])){
|
||||||
while(write_p > path && *--write_p != '/');
|
while(write_p > path && *--write_p != '/');
|
||||||
read_p += 3;
|
read_p += 3;
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
*write_p++ = *read_p++;
|
*write_p++ = *read_p++;
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else{
|
||||||
*write_p++ = *read_p++;
|
*write_p++ = *read_p++;
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else{
|
||||||
*write_p++ = *read_p++;
|
*write_p++ = *read_p++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -281,7 +285,8 @@ Sys_Get_Canonical_Sig(system_get_canonical){
|
||||||
|
|
||||||
if (max >= (write_p - path)){
|
if (max >= (write_p - path)){
|
||||||
memcpy(buffer, path, write_p - path);
|
memcpy(buffer, path, write_p - path);
|
||||||
} else {
|
}
|
||||||
|
else{
|
||||||
write_p = path;
|
write_p = path;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -301,11 +306,12 @@ Sys_Load_Handle_Sig(system_load_handle){
|
||||||
b32 result = false;
|
b32 result = false;
|
||||||
|
|
||||||
i32 fd = open(filename, O_RDONLY);
|
i32 fd = open(filename, O_RDONLY);
|
||||||
if (fd == -1){
|
if (fd == -1 || fd == 0){
|
||||||
LOG("error: open\n");
|
LOGF("upable to open file descriptor for %s\n", filename);
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
*(int*)handle_out = fd;
|
LOGF("file descriptor (%d) == file %s\n", fd, filename);
|
||||||
|
*(i32*)handle_out = fd;
|
||||||
result = true;
|
result = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -316,28 +322,29 @@ internal
|
||||||
Sys_Load_Size_Sig(system_load_size){
|
Sys_Load_Size_Sig(system_load_size){
|
||||||
u32 result = 0;
|
u32 result = 0;
|
||||||
|
|
||||||
int fd = *(int*)&handle;
|
i32 fd = *(i32*)&handle;
|
||||||
struct stat st;
|
struct stat st = {0};
|
||||||
|
|
||||||
if (fstat(fd, &st) == -1){
|
if (fstat(fd, &st) == -1){
|
||||||
LOG("error: fstat\n");
|
LOGF("unable to stat a file\n");
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
|
LOGF("file descriptor (%d) has size %d\n", fd, (i32)st.st_size);
|
||||||
result = st.st_size;
|
result = st.st_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
internal
|
internal
|
||||||
Sys_Load_File_Sig(system_load_file){
|
Sys_Load_File_Sig(system_load_file){
|
||||||
int fd = *(int*)&handle;
|
i32 fd = *(i32*)&handle;
|
||||||
|
|
||||||
do{
|
do{
|
||||||
ssize_t n = read(fd, buffer, size);
|
ssize_t n = read(fd, buffer, size);
|
||||||
if (n == -1){
|
if (n == -1){
|
||||||
if (errno != EINTR){
|
if (errno != EINTR){
|
||||||
LOG("error: read\n");
|
LOGF("error reading from file descriptor (%d)\n", fd);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -347,25 +354,29 @@ Sys_Load_File_Sig(system_load_file){
|
||||||
}
|
}
|
||||||
} while(size);
|
} while(size);
|
||||||
|
|
||||||
return size == 0;
|
return(size == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
internal
|
internal
|
||||||
Sys_Load_Close_Sig(system_load_close){
|
Sys_Load_Close_Sig(system_load_close){
|
||||||
b32 result = 1;
|
b32 result = true;
|
||||||
|
|
||||||
int fd = *(int*)&handle;
|
i32 fd = *(i32*)&handle;
|
||||||
if (close(fd) == -1){
|
if (close(fd) == -1){
|
||||||
LOG("error: close\n");
|
LOGF("error closing file descriptor (%d)\n", fd);
|
||||||
result = 0;
|
result = false;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
LOGF("file descriptor (%d) closed\n", fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
internal
|
internal
|
||||||
Sys_Save_File_Sig(system_save_file){
|
Sys_Save_File_Sig(system_save_file){
|
||||||
int fd = open(filename, O_WRONLY | O_TRUNC | O_CREAT, 00640);
|
i32 fd = open(filename, O_WRONLY|O_TRUNC|O_CREAT, 00640);
|
||||||
|
|
||||||
LOGF("%s %d\n", filename, size);
|
LOGF("%s %d\n", filename, size);
|
||||||
if (fd < 0){
|
if (fd < 0){
|
||||||
LOGF("error: open '%s': %s\n", filename, strerror(errno));
|
LOGF("error: open '%s': %s\n", filename, strerror(errno));
|
||||||
|
@ -378,7 +389,8 @@ Sys_Save_File_Sig(system_save_file){
|
||||||
LOG("error: write\n");
|
LOG("error: write\n");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else{
|
||||||
size -= written;
|
size -= written;
|
||||||
buffer += written;
|
buffer += written;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue