Browse Source

MT#56374 move resources() to lib

Useful helper function for other components

Change-Id: Idb8ab38e3ac27461b71e28029e7abc0bfc0529c2
pull/1694/head
Richard Fuchs 2 years ago
parent
commit
ee0fa947ce
4 changed files with 32 additions and 28 deletions
  1. +0
    -17
      daemon/main.c
  2. +0
    -10
      include/helpers.h
  3. +18
    -0
      lib/auxlib.c
  4. +14
    -1
      lib/auxlib.h

+ 0
- 17
daemon/main.c View File

@ -3,7 +3,6 @@
#include <stdio.h>
#include <unistd.h>
#include <signal.h>
#include <sys/resource.h>
#include <glib.h>
#include <glib/gstdio.h>
#include <sys/types.h>
@ -165,22 +164,6 @@ static void signals(void) {
pthread_sigmask(SIG_SETMASK, &ss, NULL);
}
static void resources(void) {
struct rlimit rl;
int tryv;
rlim(RLIMIT_CORE, RLIM_INFINITY);
if (getrlimit(RLIMIT_NOFILE, &rl))
rl.rlim_cur = 0;
for (tryv = ((1<<20) - 1); tryv && tryv > rl.rlim_cur && rlim(RLIMIT_NOFILE, tryv) == -1; tryv >>= 1)
;
rlim(RLIMIT_DATA, RLIM_INFINITY);
rlim(RLIMIT_RSS, RLIM_INFINITY);
rlim(RLIMIT_AS, RLIM_INFINITY);
}
static void __find_if_name(char *s, struct ifaddrs *ifas, GQueue *addrs) {


+ 0
- 10
include/helpers.h View File

@ -13,7 +13,6 @@
#include <stdarg.h>
#include <arpa/inet.h>
#include <pthread.h>
#include <sys/resource.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
@ -251,15 +250,6 @@ INLINE void swap_ptrs(void *a, void *b) {
*bb = t;
}
INLINE int rlim(int res, rlim_t val) {
struct rlimit rlim;
ZERO(rlim);
rlim.rlim_cur = rlim.rlim_max = val;
return setrlimit(res, &rlim);
}
/*** INET ADDRESS HELPERS ***/


+ 18
- 0
lib/auxlib.c View File

@ -12,6 +12,7 @@
#endif
#include <sys/socket.h>
#include <netinet/in.h>
#include <sys/resource.h>
#include "log.h"
#include "loglib.h"
@ -69,6 +70,23 @@ void service_notify(const char *message) {
}
void resources(void) {
struct rlimit rl;
int tryv;
rlim(RLIMIT_CORE, RLIM_INFINITY);
if (getrlimit(RLIMIT_NOFILE, &rl))
rl.rlim_cur = 0;
for (tryv = ((1<<20) - 1); tryv && tryv > rl.rlim_cur && rlim(RLIMIT_NOFILE, tryv) == -1; tryv >>= 1)
;
rlim(RLIMIT_DATA, RLIM_INFINITY);
rlim(RLIMIT_RSS, RLIM_INFINITY);
rlim(RLIMIT_AS, RLIM_INFINITY);
}
static unsigned int options_length(const GOptionEntry *arr) {
unsigned int len = 0;
for (const GOptionEntry *p = arr; p->long_name; p++)


+ 14
- 1
lib/auxlib.h View File

@ -8,6 +8,7 @@
#include <pthread.h>
#include <stdint.h>
#include <stdbool.h>
#include <sys/resource.h>
#define THREAD_BUF_SIZE 64
@ -412,6 +413,19 @@ INLINE long unsigned int ssl_random(void) {
}
INLINE int rlim(int res, rlim_t val) {
struct rlimit rlim;
ZERO(rlim);
rlim.rlim_cur = rlim.rlim_max = val;
return setrlimit(res, &rlim);
}
void resources(void);
/*** TAINT FUNCTIONS ***/
#if __has_attribute(__error__)
@ -431,5 +445,4 @@ taint_func(random, "use ssl_random() instead");
taint_func(srandom, "use rtpe_ssl_init() instead");
#endif

Loading…
Cancel
Save