Skip to content

Commit

Permalink
mxqd: Introduce new macro RUNNING_AS_ROOT
Browse files Browse the repository at this point in the history
  • Loading branch information
mariux committed Oct 24, 2015
1 parent 9bc10dc commit af5dde3
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions mxqd.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@
# define MXQ_INITIAL_TMPDIR "/tmp"
#endif

#define RUNNING_AS_ROOT (getuid() == 0)

volatile sig_atomic_t global_sigint_cnt=0;
volatile sig_atomic_t global_sigterm_cnt=0;

Expand Down Expand Up @@ -493,7 +495,7 @@ int server_init(struct mxq_server *server, int argc, char *argv[])
}
}

if (getuid()) {
if (!RUNNING_AS_ROOT) {
#if defined(MXQ_DEVELOPMENT) || defined(RUNASNORMALUSER)
mx_log_notice("Running mxqd as non-root user.");
#else
Expand Down Expand Up @@ -526,7 +528,7 @@ int server_init(struct mxq_server *server, int argc, char *argv[])
server->memory_max_per_slot = arg_memory_max;

/* if run as non-root use full memory by default for every job */
if (!arg_memory_max && getuid() != 0)
if (!arg_memory_max && !RUNNING_AS_ROOT)
server->memory_max_per_slot = arg_memory_total;

server->memory_avg_per_slot = (long double)server->memory_total / (long double)server->slots;
Expand Down Expand Up @@ -976,7 +978,7 @@ static int init_child_process(struct mxq_group_list *group, struct mxq_job *j)
g->user_name, g->user_uid, g->group_id, j->job_id);
}

if(getuid()==0) {
if(RUNNING_AS_ROOT) {

res = initgroups(passwd->pw_name, g->user_gid);
if (res == -1) {
Expand Down Expand Up @@ -1738,7 +1740,7 @@ int load_groups(struct mxq_server *server) {
int total;
int i;

if (getuid() == 0)
if (RUNNING_AS_ROOT)
group_cnt = mxq_load_running_groups(server->mysql, &mxqgroups);
else
group_cnt = mxq_load_running_groups_for_user(server->mysql, &mxqgroups, getuid());
Expand Down

0 comments on commit af5dde3

Please sign in to comment.