ftpd: tweak timeout code
This commit is contained in:
@ -87,9 +87,8 @@ struct globals {
|
|||||||
int pasv_listen_fd;
|
int pasv_listen_fd;
|
||||||
int proc_self_fd;
|
int proc_self_fd;
|
||||||
int local_file_fd;
|
int local_file_fd;
|
||||||
int start_time;
|
unsigned end_time;
|
||||||
int abs_timeout;
|
unsigned timeout;
|
||||||
int timeout;
|
|
||||||
off_t local_file_pos;
|
off_t local_file_pos;
|
||||||
off_t restart_pos;
|
off_t restart_pos;
|
||||||
len_and_sockaddr *local_addr;
|
len_and_sockaddr *local_addr;
|
||||||
@ -105,8 +104,9 @@ struct globals {
|
|||||||
};
|
};
|
||||||
#define G (*(struct globals*)&bb_common_bufsiz1)
|
#define G (*(struct globals*)&bb_common_bufsiz1)
|
||||||
#define INIT_G() do { \
|
#define INIT_G() do { \
|
||||||
strcpy(G.msg_ok + 4, MSG_OK ); \
|
/* Moved to main */ \
|
||||||
strcpy(G.msg_err + 4, MSG_ERR); \
|
/*strcpy(G.msg_ok + 4, MSG_OK );*/ \
|
||||||
|
/*strcpy(G.msg_err + 4, MSG_ERR);*/ \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
|
|
||||||
@ -206,7 +206,7 @@ timeout_handler(int sig UNUSED_PARAM)
|
|||||||
off_t pos;
|
off_t pos;
|
||||||
int sv_errno = errno;
|
int sv_errno = errno;
|
||||||
|
|
||||||
if (monotonic_sec() - G.start_time > G.abs_timeout)
|
if ((int)(monotonic_sec() - G.end_time) >= 0)
|
||||||
goto timed_out;
|
goto timed_out;
|
||||||
|
|
||||||
if (!G.local_file_fd)
|
if (!G.local_file_fd)
|
||||||
@ -946,25 +946,29 @@ enum {
|
|||||||
int ftpd_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
int ftpd_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||||
int ftpd_main(int argc, char **argv)
|
int ftpd_main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
|
unsigned abs_timeout;
|
||||||
smallint opts;
|
smallint opts;
|
||||||
|
|
||||||
INIT_G();
|
INIT_G();
|
||||||
|
|
||||||
G.start_time = monotonic_sec();
|
abs_timeout = 1 * 60 * 60;
|
||||||
G.abs_timeout = 1 * 60 * 60;
|
|
||||||
G.timeout = 2 * 60;
|
G.timeout = 2 * 60;
|
||||||
opt_complementary = "t+:T+";
|
opt_complementary = "t+:T+";
|
||||||
opts = getopt32(argv, "l1vS" USE_FEATURE_FTP_WRITE("w") "t:T:", &G.timeout, &G.abs_timeout);
|
opts = getopt32(argv, "l1vS" USE_FEATURE_FTP_WRITE("w") "t:T:", &G.timeout, &abs_timeout);
|
||||||
|
|
||||||
if (opts & (OPT_l|OPT_1)) {
|
if (opts & (OPT_l|OPT_1)) {
|
||||||
/* Our secret backdoor to ls */
|
/* Our secret backdoor to ls */
|
||||||
memset(&G, 0, sizeof(G));
|
memset(&G, 0, sizeof(G));
|
||||||
/* TODO: pass -n too? */
|
/* TODO: pass -n too? */
|
||||||
|
/* --group-directories-first would be nice, but ls don't do that yet */
|
||||||
xchdir(argv[2]);
|
xchdir(argv[2]);
|
||||||
argv[2] = (char*)"--";
|
argv[2] = (char*)"--";
|
||||||
return ls_main(argc, argv);
|
return ls_main(argc, argv);
|
||||||
}
|
}
|
||||||
|
G.end_time = monotonic_sec() + abs_timeout;
|
||||||
|
if (G.timeout > abs_timeout)
|
||||||
|
G.timeout = abs_timeout + 1;
|
||||||
|
strcpy(G.msg_ok + 4, MSG_OK );
|
||||||
|
strcpy(G.msg_err + 4, MSG_ERR);
|
||||||
|
|
||||||
G.local_addr = get_sock_lsa(STDIN_FILENO);
|
G.local_addr = get_sock_lsa(STDIN_FILENO);
|
||||||
if (!G.local_addr) {
|
if (!G.local_addr) {
|
||||||
|
Reference in New Issue
Block a user