Bugzilla – Attachment 1387 Details for
Bug 1397
sftp-server can only handle 100 open file handles
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Allocate file handles dynamically
sftp-server-dynamic-handle.patch (text/plain), 2.61 KB, created by
Miklos Szeredi
on 2007-12-07 23:12:50 AEDT
(
hide
)
Description:
Allocate file handles dynamically
Filename:
MIME Type:
Creator:
Miklos Szeredi
Created:
2007-12-07 23:12:50 AEDT
Size:
2.61 KB
patch
obsolete
>Index: ssh/sftp-server.c >=================================================================== >--- ssh.orig/sftp-server.c 2007-09-13 06:39:04.000000000 +0200 >+++ ssh/sftp-server.c 2007-12-07 09:31:17.000000000 +0100 >@@ -164,6 +164,7 @@ struct Handle { > int fd; > char *name; > u_int64_t bytes_read, bytes_write; >+ int next_unused; > }; > > enum { >@@ -172,40 +173,44 @@ enum { > HANDLE_FILE > }; > >-Handle handles[100]; >- >-static void >-handle_init(void) >-{ >- u_int i; >- >- for (i = 0; i < sizeof(handles)/sizeof(Handle); i++) >- handles[i].use = HANDLE_UNUSED; >+Handle *handles = NULL; >+u_int num_handles = 0; >+int first_unused = -1; >+ >+static void handle_unused(int i) >+{ >+ handles[i].use = HANDLE_UNUSED; >+ handles[i].next_unused = first_unused; >+ first_unused = i; > } > > static int > handle_new(int use, const char *name, int fd, DIR *dirp) > { >- u_int i; >+ int i; > >- for (i = 0; i < sizeof(handles)/sizeof(Handle); i++) { >- if (handles[i].use == HANDLE_UNUSED) { >- handles[i].use = use; >- handles[i].dirp = dirp; >- handles[i].fd = fd; >- handles[i].name = xstrdup(name); >- handles[i].bytes_read = handles[i].bytes_write = 0; >- return i; >- } >- } >- return -1; >+ if (first_unused == -1) { >+ num_handles++; >+ handles = xrealloc(handles, num_handles, sizeof(Handle)); >+ handle_unused(num_handles - 1); >+ } >+ >+ i = first_unused; >+ first_unused = handles[i].next_unused; >+ >+ handles[i].use = use; >+ handles[i].dirp = dirp; >+ handles[i].fd = fd; >+ handles[i].name = xstrdup(name); >+ handles[i].bytes_read = handles[i].bytes_write = 0; >+ >+ return i; > } > > static int > handle_is_ok(int i, int type) > { >- return i >= 0 && (u_int)i < sizeof(handles)/sizeof(Handle) && >- handles[i].use == type; >+ return i >= 0 && (u_int)i < num_handles && handles[i].use == type; > } > > static int >@@ -295,12 +300,12 @@ handle_close(int handle) > > if (handle_is_ok(handle, HANDLE_FILE)) { > ret = close(handles[handle].fd); >- handles[handle].use = HANDLE_UNUSED; > xfree(handles[handle].name); >+ handle_unused(handle); > } else if (handle_is_ok(handle, HANDLE_DIR)) { > ret = closedir(handles[handle].dirp); >- handles[handle].use = HANDLE_UNUSED; > xfree(handles[handle].name); >+ handle_unused(handle); > } else { > errno = ENOENT; > } >@@ -328,7 +333,7 @@ handle_log_exit(void) > { > u_int i; > >- for (i = 0; i < sizeof(handles)/sizeof(Handle); i++) >+ for (i = 0; i < num_handles; i++) > if (handles[i].use != HANDLE_UNUSED) > handle_log_close(i, "forced"); > } >@@ -1249,8 +1254,6 @@ main(int argc, char **argv) > logit("session opened for local user %s from [%s]", > pw->pw_name, client_addr); > >- handle_init(); >- > in = dup(STDIN_FILENO); > out = dup(STDOUT_FILENO); >
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 1397
: 1387