int namespace_enabled = 0;
int mount_enabled = 0;
yyin = fopen(pathname, "re");
+ int ret;
if (!yyin) {
cgroup_dbg("Failed to open file %s\n", pathname);
init_cgroup_table(config_cgroup_table, MAX_CGROUPS);
- if (yyparse() != 0) {
+ /*
+ * Parser calls longjmp() on really fatal error (like out-of-memory).
+ */
+ ret = setjmp(parser_error_env);
+ if (!ret)
+ ret = yyparse();
+ if (ret) {
+ /*
+ * Either yyparse failed or longjmp() was called.
+ */
cgroup_dbg("Failed to parse file %s\n", pathname);
fclose(yyin);
free(config_cgroup_table);
#include <libcgroup-internal.h>
#include "parse.h"
int line_no = 1;
+jmp_buf parser_error_env;
-#define YY_FATAL_ERROR(msg) fprintf(stderr, "%s\n", msg)
+#define YY_FATAL_ERROR(msg) \
+ do { \
+ fprintf(stderr, "%s\n", msg); \
+ longjmp(parser_error_env, 1); \
+ } while(0);
%}
%option nounput noinput
#include <pthread.h>
#include <sys/stat.h>
#include <sys/types.h>
+#include <setjmp.h>
/* Maximum number of mount points/controllers */
#define MAX_MNT_ELEMENTS 8
*/
extern __thread int last_errno;
+/**
+ * 'Exception handler' for lex parser.
+ */
+extern jmp_buf parser_error_env;
+
/* Internal API */
char *cg_build_path(const char *name, char *path, const char *type);
int cgroup_get_uid_gid_from_procfs(pid_t pid, uid_t *euid, gid_t *egid);