Skip to content

Commit

Permalink
Merge branch 'master' into issues/issue15
Browse files Browse the repository at this point in the history
* master:
  web: Fix date_end in job view
  MXQ bump version
  mxqd: Set host_id for job after loading job from database
  mxqd: Fix max job per node limit
  mxq_group/mxq_job: Cleanup old mxq_mysql fields not needed anymore
  mxq_job: Load field host_id from table mxq_job
  web: Display host_id in job view
  mysql: Add new field host_id to table mxq_job
  mxqd: Set MXQ_HOSTID to bootid-hex(starttime)-pid
  mxqd: set MXQ_HOSTNAME and MXQ_SERVERID
  mx_util: Add mx_proc_pid_stat()
  mx_util: Add mx_strscan_ull() and mx_strscan_ll()
  mx_util: Add mx_read_first_line_from_file()
  mxqd: Add options --initial-path and --initial-tmpdir
  web: Display new field job_max_per_node in group view
  mxqd: Limit maximum number of jobs when requested by user
  mxqsub: Add option --max-jobs-per-node=N
  mxq_group: Load new field job_max_per_node from mxq_group
  mysql: Add new column job_max_per_node to mxq_group table
  mxqd: Use mysql defaults from mxq.h
  mxqd: Define default for MXQ_INITIAL_PATH in mxqd.c
  mxqd: Clean up setting initial TMPDIR
  MXQ bump version
  mxqd: set TMPDIR
  web: escape user-chosen strings in html output
  web: fix typos
  web: fix usage comment of lighttpd.conf to install location
  mxqsub: fix usage information (default restart mode)
  MXQ bump version
  Makefile: Install lighttpd.conf to SYSCONFDIR/mxq
  • Loading branch information
mariux committed Sep 24, 2015
2 parents 7f513bb + f473c8c commit 335ac42
Show file tree
Hide file tree
Showing 16 changed files with 538 additions and 103 deletions.
18 changes: 13 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
MXQ_VERSION_MAJOR = 0
MXQ_VERSION_MINOR = 13
MXQ_VERSION_MINOR = 16
MXQ_VERSION_PATCH = 0
MXQ_VERSION_EXTRA = "beta"
MXQ_VERSIONDATE = 2013-2015
Expand Down Expand Up @@ -45,6 +45,11 @@ endif

########################################################################

### strip /mxq from SYSCONFDIR if set
ifeq ($(notdir ${SYSCONFDIR}),mxq)
override SYSCONFDIR := $(patsubst %/,%,$(dir ${SYSCONFDIR}))
endif

### strip /mxq from LIBEXECDIR if set
ifeq ($(notdir ${LIBEXECDIR}),mxq)
override LIBEXECDIR := $(patsubst %/,%,$(dir ${LIBEXECDIR}))
Expand All @@ -57,20 +62,22 @@ CGIDIR = ${LIBEXECDIR}/mxq/cgi
MXQ_MYSQL_DEFAULT_FILE = ${SYSCONFDIR}/mxq/mysql.cnf
MXQ_MYSQL_DEFAULT_GROUP = mxqclient

MXQ_INITIAL_PATH = /sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin
MXQ_INITIAL_PATH = /sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin
MXQ_INITIAL_TMPDIR = /tmp

CFLAGS_MXQ_MYSQL_DEFAULT_FILE = -DMXQ_MYSQL_DEFAULT_FILE=\"$(MXQ_MYSQL_DEFAULT_FILE)\"
CFLAGS_MXQ_MYSQL_DEFAULT_GROUP = -DMXQ_MYSQL_DEFAULT_GROUP=\"$(MXQ_MYSQL_DEFAULT_GROUP)\"
CFLAGS_MXQ_INITIAL_PATH = -DMXQ_INITIAL_PATH=\"$(MXQ_INITIAL_PATH)\"
CFLAGS_MXQ_INITIAL_TMPDIR = -DMXQ_INITIAL_TMPDIR=\"$(MXQ_INITIAL_TMPDIR)\"

MYSQL_CONFIG = mysql_config

OS_RELEASE = $(shell ./os-release)

# special defaults for mariux64
ifeq (${OS_RELEASE}, mariux64)
MXQ_INITIAL_PATH := ${MXQ_INITIAL_PATH}:/usr/local/package/bin

MXQ_INITIAL_PATH := ${MXQ_INITIAL_PATH}:/usr/local/package/bin
MXQ_INITIAL_TMPDIR := /scratch/local
endif

########################################################################
Expand Down Expand Up @@ -373,6 +380,7 @@ mxqd.o: $(mxq_job.h)
mxqd.o: $(mx_mysql.h)
mxqd.o: CFLAGS += $(CFLAGS_MYSQL)
mxqd.o: CFLAGS += $(CFLAGS_MXQ_INITIAL_PATH)
mxqd.o: CFLAGS += $(CFLAGS_MXQ_INITIAL_TMPDIR)
mxqd.o: CFLAGS += -Wno-unused-but-set-variable

clean: CLEAN += mxqd.o
Expand Down Expand Up @@ -506,7 +514,7 @@ install:: web/pages/mxq/mxq
$(call quiet-install,0755,$^,${DESTDIR}${CGIDIR}/mxq)

install:: web/lighttpd.conf
$(call quiet-install,0644,$^,${DESTDIR}${LIBEXECDIR}/mxq/lighttpd.conf)
$(call quiet-install,0644,$^,${DESTDIR}${SYSCONFDIR}/mxq/lighttpd.conf)

########################################################################

Expand Down
188 changes: 188 additions & 0 deletions mx_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -752,6 +752,194 @@ int mx_open_newfile(char *fname)
return fh;
}

int mx_read_first_line_from_file(char *fname, char **line)
{
_mx_cleanup_fclose_ FILE *fp;
char *buf = NULL;
size_t n = 0;
ssize_t res;

fp = fopen(fname, "r");
if (!fp)
return -errno;

res = getline(&buf, &n, fp);
if (res == -1)
return -errno;

*line = buf;

if (!res)
return res;

res--;

if (buf[res] == '\n')
buf[res] = 0;

return res;
}

int mx_strscan_ull(char **str, unsigned long long int *to)
{
unsigned long long int l;
char *s;
char *p;
char o = 0;
int res;

s = *str;

p = strchr(s, ' ');
if (p) {
o = *p;
*p = 0;
p++;
} else {
p = s + strlen(s);
}

res = mx_strtoull(s, &l);
if (o)
*(p-1) = o;

if (res == 0) {
*to = l;
*str = p;
}

return res;
}

int mx_strscan_ll(char **str, long long int *to)
{
long long int l;
char *s;
char *p;
char o = 0;
int res;

s = *str;

p = strchr(s, ' ');
if (p) {
o = *p;
*p = 0;
p++;
} else {
p = s + strlen(s);
}

res = mx_strtoll(s, &l);
if (o)
*(p-1) = o;

if (res == 0) {
*to = l;
*str = p;
}

return res;
}

int mx_strscan_proc_pid_stat(char *str, struct proc_pid_stat *pps)
{
size_t res = 0;
char *p;
char *s;

pps->comm = NULL;

s = str;

res += mx_strscan_ll(&s, &(pps->pid));

p = strrchr(s, ')');
if (!p)
return -(errno=EINVAL);

*p = 0;
s++;

pps->comm = mx_strdup_forever(s);
s = p + 2;

pps->state = *s;
res += !(*(s+1) == ' ');
s += 2;

res += mx_strscan_ll(&s, &(pps->ppid));
res += mx_strscan_ll(&s, &(pps->pgrp));
res += mx_strscan_ll(&s, &(pps->session));
res += mx_strscan_ll(&s, &(pps->tty_nr));
res += mx_strscan_ll(&s, &(pps->tpgid));
res += mx_strscan_ull(&s, &(pps->flags));
res += mx_strscan_ull(&s, &(pps->minflt));
res += mx_strscan_ull(&s, &(pps->cminflt));
res += mx_strscan_ull(&s, &(pps->majflt));
res += mx_strscan_ull(&s, &(pps->cmajflt));
res += mx_strscan_ull(&s, &(pps->utime));
res += mx_strscan_ull(&s, &(pps->stime));
res += mx_strscan_ll(&s, &(pps->cutime));
res += mx_strscan_ll(&s, &(pps->cstime));
res += mx_strscan_ll(&s, &(pps->priority));
res += mx_strscan_ll(&s, &(pps->nice));
res += mx_strscan_ll(&s, &(pps->num_threads));
res += mx_strscan_ll(&s, &(pps->itrealvalue));
res += mx_strscan_ull(&s, &(pps->starttime));
res += mx_strscan_ull(&s, &(pps->vsize));
res += mx_strscan_ll(&s, &(pps->rss));
res += mx_strscan_ull(&s, &(pps->rsslim));
res += mx_strscan_ull(&s, &(pps->startcode));
res += mx_strscan_ull(&s, &(pps->endcode));
res += mx_strscan_ull(&s, &(pps->startstack));
res += mx_strscan_ull(&s, &(pps->kstkesp));
res += mx_strscan_ull(&s, &(pps->kstkeip));
res += mx_strscan_ull(&s, &(pps->signal));
res += mx_strscan_ull(&s, &(pps->blocked));
res += mx_strscan_ull(&s, &(pps->sigignore));
res += mx_strscan_ull(&s, &(pps->sigcatch));
res += mx_strscan_ull(&s, &(pps->wchan));
res += mx_strscan_ull(&s, &(pps->nswap));
res += mx_strscan_ull(&s, &(pps->cnswap));
res += mx_strscan_ll(&s, &(pps->exit_signal));
res += mx_strscan_ll(&s, &(pps->processor));
res += mx_strscan_ull(&s, &(pps->rt_priority));
res += mx_strscan_ull(&s, &(pps->policy));
res += mx_strscan_ull(&s, &(pps->delayacct_blkio_ticks));
res += mx_strscan_ull(&s, &(pps->guest_time));
res += mx_strscan_ll(&s, &(pps->cguest_time));

if (res != 0)
return -(errno=EINVAL);

return 0;
}

int mx_proc_pid_stat(struct proc_pid_stat *pps, pid_t pid)
{
_mx_cleanup_free_ char *fname = NULL;
_mx_cleanup_free_ char *line = NULL;
int res;

mx_asprintf_forever(&fname, "/proc/%d/stat", pid);

res = mx_read_first_line_from_file(fname, &line);
if (res < 0)
return res;

res = mx_strscan_proc_pid_stat(line, pps);
if (res < 0)
return res;

return 0;
}

void mx_proc_pid_stat_free(struct proc_pid_stat *pps)
{
mx_free_null(pps->comm);
}

int mx_sleep(unsigned int seconds)
{
if (seconds)
Expand Down
65 changes: 65 additions & 0 deletions mx_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,57 @@
#include <stdint.h>
#include <stdarg.h>
#include <string.h>
#include <stdio.h>

#include "mx_log.h"

struct proc_pid_stat {
long long int pid; /* 1 */
char *comm; /* 2 (comm) */
char state; /* 3 "RSDZTW" */
long long int ppid; /* 4 */
long long int pgrp; /* 5 */
long long int session; /* 6 */
long long int tty_nr; /* 7 */
long long int tpgid; /* 8 */
unsigned long long int flags; /* 9 */
unsigned long long int minflt; /* 10 */
unsigned long long int cminflt; /* 11 */
unsigned long long int majflt; /* 12 */
unsigned long long int cmajflt; /* 13 */
unsigned long long int utime; /* 14 */
unsigned long long int stime; /* 15 */
long long int cutime; /* 16 */
long long int cstime; /* 17 */
long long int priority; /* 18 */
long long int nice; /* 19 */
long long int num_threads; /* 20 */
long long int itrealvalue; /* 21 */
unsigned long long int starttime; /* 22 */
unsigned long long int vsize; /* 23 */
long long int rss; /* 24 */
unsigned long long int rsslim; /* 25 */
unsigned long long int startcode; /* 26 */
unsigned long long int endcode; /* 27 */
unsigned long long int startstack; /* 28 */
unsigned long long int kstkesp; /* 29 */
unsigned long long int kstkeip; /* 30 */
unsigned long long int signal; /* 31 */
unsigned long long int blocked; /* 32 */
unsigned long long int sigignore; /* 33 */
unsigned long long int sigcatch; /* 34 */
unsigned long long int wchan; /* 35 */
unsigned long long int nswap; /* 36 */
unsigned long long int cnswap; /* 37 */
long long int exit_signal; /* 38 */
long long int processor; /* 39 */
unsigned long long int rt_priority; /* 40 */
unsigned long long int policy; /* 41 */
unsigned long long int delayacct_blkio_ticks; /* 42 */
unsigned long long int guest_time; /* 43 */
long long int cguest_time; /* 44 */
};

#ifdef MX_NDEBUG
# include <assert.h>
# define mx_assert_return_minus_errno(test, eno) \
Expand Down Expand Up @@ -46,9 +94,17 @@ static inline void __mx_free(void *ptr) {
free(*(void **)ptr);
}

static inline void __mx_fclose(FILE **ptr) {
if (*ptr)
fclose(*ptr);
}

#undef _mx_cleanup_free_
#define _mx_cleanup_free_ _mx_cleanup_(__mx_free)

#undef _mx_cleanup_fclose_
#define _mx_cleanup_fclose_ _mx_cleanup_(__mx_fclose)

#undef likely
#define likely(x) __builtin_expect((x),1)

Expand Down Expand Up @@ -106,6 +162,15 @@ int mx_setenvf_forever(const char *name, char *fmt, ...) __attribute__ ((format(

int mx_open_newfile(char *fname);

int mx_read_first_line_from_file(char *fname, char **line);

int mx_strscan_ull(char **str, unsigned long long int *to);
int mx_strscan_ll(char **str, long long int *to);
int mx_strscan_proc_pid_stat(char *str, struct proc_pid_stat *pps);

int mx_proc_pid_stat(struct proc_pid_stat *pps, pid_t pid);
void mx_proc_pid_stat_free(struct proc_pid_stat *pps);

int mx_sleep(unsigned int seconds);
int mx_sleep_nofail(unsigned int seconds);

Expand Down
12 changes: 4 additions & 8 deletions 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 29
#define GROUP_FIELDS_CNT 30
#define GROUP_FIELDS \
" group_id," \
" group_name," \
Expand All @@ -27,6 +27,7 @@
" job_threads," \
" job_memory," \
" job_time," \
" job_max_per_node," \
" group_jobs," \
" group_jobs_inq," \
" group_jobs_running," \
Expand Down Expand Up @@ -70,6 +71,8 @@ static int bind_result_group_fields(struct mx_mysql_bind *result, struct mxq_gro
res += mx_mysql_bind_var(result, idx++, uint64, &(g->job_memory));
res += mx_mysql_bind_var(result, idx++, uint32, &(g->job_time));

res += mx_mysql_bind_var(result, idx++, uint16, &(g->job_max_per_node));

res += mx_mysql_bind_var(result, idx++, uint64, &(g->group_jobs));
res += mx_mysql_bind_var(result, idx++, uint64, &(g->group_jobs_inq));
res += mx_mysql_bind_var(result, idx++, uint64, &(g->group_jobs_running));
Expand Down Expand Up @@ -97,16 +100,9 @@ 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->group_name);
g->_group_name_length = 0;

mx_free_null(g->user_name);
g->_user_name_length = 0;

mx_free_null(g->user_group);
g->_user_group_length = 0;

mx_free_null(g->job_command);
g->_job_command_length = 0;
}


Expand Down
Loading

0 comments on commit 335ac42

Please sign in to comment.