~schuster/mysql-proxy/PR-255-connection-timeout

« back to all changes in this revision

Viewing changes to src/chassis-limits.c

  • Committer: jan at mysql
  • Date: 2010-03-24 15:24:51 UTC
  • Revision ID: jan@mysql.com-20100324152451-vxeoq9bomrxx3lud
try to raise the hard-limit to at least the soft-limit (fixes #48120) and made the log-messages 'unlimited' aware

Show diffs side-by-side

added added

removed removed

Lines of Context:
52
52
#endif
53
53
#endif
54
54
 
 
55
#ifndef _WIN32
 
56
/**
 
57
 * log the limit at debug level
 
58
 */
 
59
static void chassis_fdlimit_log(struct rlimit *limit, const char *msg) {
 
60
        if (RLIM_INFINITY == limit->rlim_max && RLIM_INFINITY == limit->rlim_cur) {
 
61
                g_debug("%s: %s = unlimited (hard: unlimited)",
 
62
                                G_STRLOC,
 
63
                                msg);
 
64
        } else if (RLIM_INFINITY == limit->rlim_max) {
 
65
                g_debug("%s: %s = %"G_RLIM_T_FORMAT" (hard: unlimited)",
 
66
                                G_STRLOC,
 
67
                                msg,
 
68
                                limit->rlim_cur);
 
69
        } else if (RLIM_INFINITY == limit->rlim_cur) {
 
70
                g_debug("%s: %s = unlimited (hard: %"G_RLIM_T_FORMAT")",
 
71
                                G_STRLOC,
 
72
                                msg,
 
73
                                limit->rlim_max);
 
74
        } else {
 
75
                g_debug("%s: %s = %"G_RLIM_T_FORMAT" (hard: %"G_RLIM_T_FORMAT")",
 
76
                                G_STRLOC,
 
77
                                msg,
 
78
                                limit->rlim_cur,
 
79
                                limit->rlim_max);
 
80
        }
 
81
}
 
82
#endif
 
83
 
55
84
int chassis_set_fdlimit(int max_files_number) {
56
85
#ifdef _WIN32
57
86
        g_debug("%s: current maximum number of open stdio file descriptors: %d", G_STRLOC, _getmaxstdio());
72
101
                                  G_STRLOC, g_strerror(errno), errno);
73
102
        } else {
74
103
                rlim_t soft_limit = max_files_rlimit.rlim_cur;
75
 
                g_debug("%s: current RLIMIT_NOFILE = %"G_RLIM_T_FORMAT" (hard: %"G_RLIM_T_FORMAT")", G_STRLOC, max_files_rlimit.rlim_cur, max_files_rlimit.rlim_max);
 
104
                rlim_t hard_limit = max_files_rlimit.rlim_max;
 
105
 
 
106
                chassis_fdlimit_log(&max_files_rlimit, "current RLIMIT_NOFILE");
76
107
 
77
108
                max_files_rlimit.rlim_cur = max_files_number;
 
109
                if (hard_limit < max_files_number) { /* raise the hard-limit too in case it is smaller than the soft-limit, otherwise we get a EINVAL */
 
110
                        max_files_rlimit.rlim_max = max_files_number;
 
111
                }
78
112
 
79
 
                g_debug("%s: trying to set new RLIMIT_NOFILE = %"G_RLIM_T_FORMAT" (hard: %"G_RLIM_T_FORMAT")", G_STRLOC, max_files_rlimit.rlim_cur, max_files_rlimit.rlim_max);
 
113
                chassis_fdlimit_log(&max_files_rlimit, "setting RLIMIT_NOFILE");
80
114
                if (-1 == setrlimit(RLIMIT_NOFILE, &max_files_rlimit)) {
81
 
                        g_critical("%s: could not raise RLIMIT_NOFILE to %u, %s (%d). Current limit still %"G_RLIM_T_FORMAT".", G_STRLOC, max_files_number, g_strerror(errno), errno, soft_limit);
 
115
                        g_critical("%s: could not raise RLIMIT_NOFILE to %u, %s (%d). Current limit still %"G_RLIM_T_FORMAT".",
 
116
                                        G_STRLOC,
 
117
                                        max_files_number,
 
118
                                        g_strerror(errno), errno,
 
119
                                        soft_limit);
82
120
                } else {
83
121
                        if (-1 == getrlimit(RLIMIT_NOFILE, &max_files_rlimit)) {
84
122
                                g_warning("%s: cannot get limit of open files for this process. %s (%d)",
85
123
                                                  G_STRLOC, g_strerror(errno), errno);
86
124
                        } else {
87
 
                                g_debug("%s: set new RLIMIT_NOFILE = %"G_RLIM_T_FORMAT" (hard: %"G_RLIM_T_FORMAT")", G_STRLOC, max_files_rlimit.rlim_cur, max_files_rlimit.rlim_max);
 
125
                                chassis_fdlimit_log(&max_files_rlimit, "successfully set RLIMIT_NOFILE");
88
126
                        }
89
127
                }
90
128
        }