Skip to content

Commit

Permalink
Merge pull request #86 from mariux64/add-prerequisites
Browse files Browse the repository at this point in the history
Add exclusive mode and prerequisites
  • Loading branch information
donald authored Apr 19, 2020
2 parents 80541b0 + 63d6f12 commit eee840e
Show file tree
Hide file tree
Showing 18 changed files with 529 additions and 103 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ mxqd_control.o
keywordset.o
test_keywordset.o
mxqset.o
parser.tab.c
parser.tab.h
parser.tab.o
test_parser.o
test_parser


mxqsub
Expand Down
25 changes: 21 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,7 @@ mxq_daemon.h += mxq_daemon.h
### mxqd.h -------------------------------------------------------------

mxqd.h += mxqd.h
mxqd.h += keywordset.h

### mxqd_conrol.h ------------------------------------------------------

Expand Down Expand Up @@ -418,10 +419,10 @@ clean: CLEAN += mxqadmin.o

### mxqset.o ----------------------------------------------------------

mxqsset.o: $(mx_mysql.h)
mxqsset.o: $(keywordset.h)
mxqkill.o: $(mxq.h)
mxqkill.o: $(mxq_group.h)
mxqset.o: $(mx_mysql.h)
mxqset.o: $(keywordset.h)
mxqset.o: $(mxq.h)
mxqset.o: $(mxq_group.h)
mxqset.o: CFLAGS += $(CFLAGS_MYSQL)

clean: CLEAN += mxqsset.o
Expand Down Expand Up @@ -487,6 +488,7 @@ mxqd.o: $(mxq_group.h)
mxqd.o: $(mxq_job.h)
mxqd.o: $(mx_mysql.h)
mxqd.o: $(keywordset.h)
mxqd.o: parser.tab.h
mxqd.o: CFLAGS += $(CFLAGS_MYSQL)
mxqd.o: CFLAGS += $(CFLAGS_MXQ_INITIAL_PATH)
mxqd.o: CFLAGS += $(CFLAGS_MXQ_INITIAL_TMPDIR)
Expand All @@ -506,6 +508,7 @@ mxqsub.o: $(mxq_group.h)
mxqsub.o: $(mxq_job.h)
mxqsub.o: $(mx_util.h)
mxqsub.o: $(keywordset.h)
mxqsub.o: parser.tab.h
mxqsub.o: CFLAGS += $(CFLAGS_MYSQL)

clean: CLEAN += mxqsub.o
Expand Down Expand Up @@ -533,6 +536,7 @@ mxqd: mxq_job.o
mxqd: mx_mysql.o
mxqd: mxqd_control.o
mxqd: keywordset.o
mxqd: parser.tab.o
mxqd: LDLIBS += $(LDLIBS_MYSQL)

build: mxqd
Expand All @@ -549,6 +553,7 @@ mxqsub: mx_util.o
mxqsub: mx_log.o
mxqsub: mx_mysql.o
mxqsub: keywordset.o
mxqsub: parser.tab.o
mxqsub: LDLIBS += $(LDLIBS_MYSQL)

build: mxqsub
Expand Down Expand Up @@ -713,6 +718,7 @@ test_mxqd_control: mx_log.o
test_mxqd_control: mx_util.o
test_mxqd_control: mx_mysql.o
test_mxqd_control: mxq_group.o
test_mxqd_control: keywordset.o
test_mxqd_control: LDLIBS += $(LDLIBS_MYSQL)

clean: CLEAN += test_mxqd_control
Expand All @@ -724,3 +730,14 @@ test_keywordset: test_keywordset.o
test_keywordset: keywordset.o
clean: CLEAN += test_keywordset.o
test: test_keywordset

%.tab.c %.tab.h: %.y
$(call quiet-command,bison -d $<," BISON $@")

clean: CLEAN += parser.tab.c parser.tab.h
test: test_parser
clean: CLEAN += test_parser
clean: CLEAN += test_parser.o
test_parser: test_parser.o parser.tab.o keywordset.o
test_parser.o: parser.tab.h keywordset.h
clean: CLEAN += parser.tab.o
23 changes: 21 additions & 2 deletions keywordset.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,12 @@ static int find_name(struct keywordset *kws, char *name, size_t len) {
if (kws->names[i][j] != name[j])
break;
j++;
if (j==len)
return i;
if (j==len) {
if (kws->names[i][j] == 0)
return i;
else
break;
}
}
}
return -1;
Expand Down Expand Up @@ -111,6 +115,21 @@ void keywordset_update(struct keywordset *kws, char *input) {
keywordset_update_phase(kws, input, PHASE_UPDATE);
}

void keywordset_add(struct keywordset *kws, char *input) {
char *c=input;
char *name_start;
while (*c) {
while (*c && isspace(*c))
c++;
if (*c) {
name_start=c++;
while (*c && !isspace(*c))
c++;
add_name(kws, name_start, c-name_start);
}
}
}

struct keywordset *keywordset_new(char *input) {
struct keywordset *kws = xmalloc(sizeof(*kws));
kws->nr_slots = KEYWORDSET_INITIAL_SLOTS;
Expand Down
3 changes: 3 additions & 0 deletions keywordset.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@

struct keywordset *keywordset_new(char *input);
void keywordset_update(struct keywordset *kws, char *input);
void keywordset_add(struct keywordset *kws, char *input);
char *keywordset_get(struct keywordset *kws);
int keywordset_ismember(struct keywordset *kws, char *name);
void keywordset_purge(struct keywordset *kws);
void keywordset_free(struct keywordset *kws);

__attribute__ ((unused)) static void keywordset_free_byref (struct keywordset **kws) { keywordset_free(*kws); }

#endif
38 changes: 0 additions & 38 deletions mx_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
#include "mx_log.h"
#include "mx_util.h"

static inline size_t mx_strvec_length_cache(char **strvec, int32_t len);

static inline int _mx_strbeginswith(char *str, const char *start, char **endptr, short ignore_case)
{
size_t len;
Expand Down Expand Up @@ -933,40 +931,14 @@ void *mx_calloc_forever_sec(size_t nmemb, size_t size, unsigned int time)
char **mx_strvec_new(void)
{
char **strvec;
size_t len;

strvec = calloc(sizeof(*strvec), 1);
if (!strvec)
return NULL;

len = mx_strvec_length_cache(strvec, -1);
if (len != -1)
mx_strvec_length_cache(strvec, 0);

return strvec;
}

static inline size_t mx_strvec_length_cache(char **strvec, int32_t len)
{
static char ** sv = NULL;
static size_t l = 0;

if (likely(len == -1)) {
if (likely(sv == strvec)) {
return l;
}
return -1;
}

if (likely(sv == strvec)) {
l = len;
} else {
sv = strvec;
l = len;
}
return l;
}

size_t mx_strvec_length(char ** strvec)
{
char ** sv;
Expand All @@ -975,15 +947,9 @@ size_t mx_strvec_length(char ** strvec)
assert(strvec);

sv = strvec;

len = mx_strvec_length_cache(sv, -1);
if (len != -1)
return len;

for (; *sv; sv++);

len = sv-strvec;
mx_strvec_length_cache(sv, len);
return len;
}

Expand All @@ -1007,8 +973,6 @@ int mx_strvec_push_str(char *** strvecp, char * str)
sv[len++] = str;
sv[len] = NULL;

mx_strvec_length_cache(sv, len);

*strvecp = sv;

return 1;
Expand All @@ -1035,8 +999,6 @@ int mx_strvec_push_strvec(char ***strvecp, char **strvec)

memcpy(sv+len1, strvec, sizeof(*strvec) * (len2 + 1));

mx_strvec_length_cache(sv, len1+len2);

*strvecp = sv;

return 1;
Expand Down
13 changes: 11 additions & 2 deletions mxq_daemon.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@
" daemon_memory_used," \
" UNIX_TIMESTAMP(mtime) as mtime," \
" UNIX_TIMESTAMP(daemon_start) as daemon_start," \
" UNIX_TIMESTAMP(daemon_stop) as daemon_stop"
" UNIX_TIMESTAMP(daemon_stop) as daemon_stop," \
" daemon_flags," \
" prerequisites"

#undef _to_string
#undef status_str
Expand Down Expand Up @@ -75,6 +77,9 @@ static int bind_result_daemon_fields(struct mx_mysql_bind *result, struct mxq_da
res += mx_mysql_bind_var(result, idx++, int64, &(daemon->daemon_start.tv_sec));
res += mx_mysql_bind_var(result, idx++, int64, &(daemon->daemon_stop.tv_sec));

res += mx_mysql_bind_var(result, idx++, int32, &(daemon->daemon_flags));
res += mx_mysql_bind_var(result, idx++, string, &(daemon->prerequisites));

return res;
}

Expand Down Expand Up @@ -136,7 +141,9 @@ int mxq_daemon_register(struct mx_mysql *mysql, struct mxq_daemon *daemon)
" daemon_memory_used = 0,"
" mtime = NULL,"
" daemon_start = CURRENT_TIMESTAMP(),"
" daemon_stop = 0"
" daemon_stop = 0,"
" daemon_flags = ?,"
" prerequisites = ?"
);
if (!stmt) {
mx_log_err("mx_mysql_statement_prepare(): %m");
Expand All @@ -161,6 +168,8 @@ int mxq_daemon_register(struct mx_mysql *mysql, struct mxq_daemon *daemon)

res += mx_mysql_statement_param_bind(stmt, idx++, uint64, &(daemon->daemon_memory_limit_slot_soft));
res += mx_mysql_statement_param_bind(stmt, idx++, uint64, &(daemon->daemon_memory_limit_slot_hard));
res += mx_mysql_statement_param_bind(stmt, idx++, int32, &(daemon->daemon_flags));
res += mx_mysql_statement_param_bind(stmt, idx++, string, &(daemon->prerequisites));

assert(res ==0);

Expand Down
3 changes: 3 additions & 0 deletions mxq_daemon.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ struct mxq_daemon {

struct timeval daemon_start;
struct timeval daemon_stop;

int daemon_flags;
char *prerequisites;
};

void mxq_daemon_free_content(struct mxq_daemon *daemon);
Expand Down
5 changes: 4 additions & 1 deletion mxq_group.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include "mx_util.h"
#include "mx_mysql.h"

#define GROUP_FIELDS_CNT 35
#define GROUP_FIELDS_CNT 36
#define GROUP_FIELDS \
" group_id," \
" group_name," \
Expand All @@ -21,6 +21,7 @@
" group_priority," \
" group_blacklist," \
" group_whitelist," \
" prerequisites," \
" user_uid," \
" user_name," \
" user_gid," \
Expand Down Expand Up @@ -66,6 +67,7 @@ static int bind_result_group_fields(struct mx_mysql_bind *result, struct mxq_gro
res += mx_mysql_bind_var(result, idx++, uint16, &(g->group_priority));
res += mx_mysql_bind_var(result, idx++, string, &(g->group_blacklist));
res += mx_mysql_bind_var(result, idx++, string, &(g->group_whitelist));
res += mx_mysql_bind_var(result, idx++, string, &(g->prerequisites));

res += mx_mysql_bind_var(result, idx++, uint32, &(g->user_uid));
res += mx_mysql_bind_var(result, idx++, string, &(g->user_name));
Expand Down Expand Up @@ -109,6 +111,7 @@ static int bind_result_group_fields(struct mx_mysql_bind *result, struct mxq_gro

void mxq_group_free_content(struct mxq_group *g)
{
mx_free_null(g->prerequisites);
mx_free_null(g->group_whitelist);
mx_free_null(g->group_blacklist);
mx_free_null(g->group_name);
Expand Down
1 change: 1 addition & 0 deletions mxq_group.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ struct mxq_group {
uint16_t group_priority;
char * group_blacklist;
char * group_whitelist;
char * prerequisites;

uint32_t user_uid;
char * user_name;
Expand Down
Loading

0 comments on commit eee840e

Please sign in to comment.