Skip to content
Snippets Groups Projects
Select Git revision
  • 3a9560fd94cd5cfb31fb3f2beaab46a4c8738d88
  • devel default
  • master
  • fo
  • jirka/typing
  • fo-base
  • mj/submit-images
  • jk/issue-96
  • jk/issue-196
  • honza/add-contestant
  • honza/mr7
  • honza/mrf
  • honza/mrd
  • honza/mra
  • honza/mr6
  • honza/submit-images
  • honza/kolo-vs-soutez
  • jh-stress-test-wip
  • shorten-schools
19 results

jinja.py

Blame
  • compctld.c 6.48 KiB
    #define _GNU_SOURCE /* struct ucred */
    #include <assert.h>
    #include <errno.h>
    #include <signal.h>
    #include <stdarg.h>
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <sys/stat.h>
    #include <sys/socket.h>
    #include <sys/un.h>
    #include <syslog.h>
    #include <unistd.h>
    
    #include "cgroup.h"
    #include "common.h"
    
    
    #define begins_with(s_, a_) (!strncmp(s_, a_, strlen(s_)))
    
    
    void
    logperror(const char *s)
    {
    	syslog(LOG_ERR, "%s: %s", s, strerror(errno));
    }
    
    void
    memory_limits(size_t *minuser, size_t *mincomp, size_t *maxcomp, size_t *total)
    {
    	FILE *f = fopen("/proc/meminfo", "r");
    	char line[1024];
    	while (fgets(line, sizeof(line), f)) {
    		if (begins_with("MemTotal:", line)) {
    			*total = 0;
    			sscanf(line, "MemTotal:%zu", total);
    			*total *= 1024;
    			break;
    		}
    	}
    	fclose(f);
    
    	*minuser = *total * split_ratio;
    	if (*minuser < static_minfree)
    		*minuser = static_minfree;
    	if (*minuser > static_maxfree)
    		*minuser = static_maxfree;
    
    	*mincomp = static_minfree;
    	ssize_t smaxcomp = *total - *minuser;
    	*maxcomp = smaxcomp > 0 ? smaxcomp : 0;
    	/* maxcomp < mincomp may happen; they are used in different
    	 * settings. */
    }
    
    size_t
    get_default_mem_limit(void)
    {
    	size_t minuser, mincomp, maxcomp, total;
    	memory_limits(&minuser, &mincomp, &maxcomp, &total);
    	return maxcomp;
    }
    
    
    void
    cgroup_init(void)
    {
    	if (cgroup_setup(chier, "memory") < 0)
    		exit(EXIT_FAILURE);
    	int ret = cgroup_create(chier, cgroup);