From 83785b5bb42978b583144326bfe852376df5dd4d Mon Sep 17 00:00:00 2001 From: Marius Tolzmann Date: Sat, 24 Oct 2015 00:25:45 +0200 Subject: [PATCH] mxqd: When run as non-root only load groups for current user --- mxq_group.c | 33 --------------------------------- mxq_group.h | 1 - mxqd.c | 7 +++++-- 3 files changed, 5 insertions(+), 36 deletions(-) diff --git a/mxq_group.c b/mxq_group.c index 65f7757a..2887411d 100644 --- a/mxq_group.c +++ b/mxq_group.c @@ -292,39 +292,6 @@ int mxq_load_active_groups_for_user(struct mx_mysql *mysql, struct mxq_group **m return res; } -int mxq_load_active_groups(struct mx_mysql *mysql, struct mxq_group **mxq_groups) -{ - int res; - struct mxq_group *groups = NULL; - struct mxq_group g = {0}; - struct mx_mysql_bind result = {0}; - - assert(mysql); - assert(mxq_groups); - - *mxq_groups = NULL; - - char *query = - "SELECT" - GROUP_FIELDS - " FROM mxq_group" - " WHERE (group_jobs_inq > 0 OR group_jobs_running > 0)" - " ORDER BY user_name, group_mtime" - " LIMIT 1000"; - - res = bind_result_group_fields(&result, &g); - assert(res == 0); - - res = mx_mysql_do_statement_retry_on_fail(mysql, query, NULL, &result, &g, (void **)&groups, sizeof(*groups)); - if (res < 0) { - mx_log_err("mx_mysql_do_statement_retry_on_fail(): %m"); - return res; - } - - *mxq_groups = groups; - return res; -} - int mxq_load_running_groups(struct mx_mysql *mysql, struct mxq_group **mxq_groups) { int res; diff --git a/mxq_group.h b/mxq_group.h index e678cb31..46a352b2 100644 --- a/mxq_group.h +++ b/mxq_group.h @@ -68,7 +68,6 @@ inline uint64_t mxq_group_jobs_inq(struct mxq_group *g); int mxq_load_group(struct mx_mysql *mysql, struct mxq_group **mxq_groups, uint64_t group_id); int mxq_load_all_groups(struct mx_mysql *mysql, struct mxq_group **mxq_groups); -int mxq_load_active_groups(struct mx_mysql *mysql, struct mxq_group **mxq_groups); int mxq_load_all_groups_for_user(struct mx_mysql *mysql, struct mxq_group **mxq_groups, uint64_t user_uid); int mxq_load_active_groups_for_user(struct mx_mysql *mysql, struct mxq_group **mxq_groups, uint64_t user_uid); int mxq_load_running_groups(struct mx_mysql *mysql, struct mxq_group **mxq_groups); diff --git a/mxqd.c b/mxqd.c index eaf6eed4..6b8a206a 100644 --- a/mxqd.c +++ b/mxqd.c @@ -1626,13 +1626,16 @@ int catchall(struct mxq_server *server) { } int load_groups(struct mxq_server *server) { - struct mxq_group *mxqgroups; + struct mxq_group *mxqgroups = NULL; struct mxq_group_list *group; int group_cnt; int total; int i; - group_cnt = mxq_load_active_groups(server->mysql, &mxqgroups); + if (getuid() == 0) + group_cnt = mxq_load_running_groups(server->mysql, &mxqgroups); + else + group_cnt = mxq_load_running_groups_for_user(server->mysql, &mxqgroups, getuid()); for (i=0, total=0; i