Skip to content

Commit

Permalink
Merge branch 'donald/rewrite/fixes'
Browse files Browse the repository at this point in the history
* donald/rewrite/fixes:
  mxqd: fix irrelevant memory leak
  test_mx_util: add test for mx_strvec
  mx_util: free the right pointer in mx_strvec_free
  mxqd: cleanup
  mxqd: abort with USAGE on unknown option
  mx_flock: increase loglevel
  mx_getopt: fix typo in comment
  mxqd: fail with diagnostic if unable to write to log directory
  mxqd: return failure when fork fails in setup_cronolog
  sql: fix syntax
  • Loading branch information
mariux committed Oct 16, 2015
2 parents 951865c + f83e67a commit 4c35885
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 15 deletions.
12 changes: 6 additions & 6 deletions mx_flock.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ static inline int _flock_open(struct mx_flock *lock, mode_t mode)

fd = open(lock->fname, O_RDONLY|O_CREAT|O_NOCTTY|O_CLOEXEC, mode);
if (fd < 0) {
mx_log_debug("open(): %m");
mx_log_err("%s: %m",lock->fname);
return -1;
}

Expand Down Expand Up @@ -80,7 +80,7 @@ struct mx_flock *mx_flock(int operation, char *fmt, ...)

lock = malloc(sizeof(*lock));
if (!lock) {
mx_log_debug("malloc(): %m");
mx_log_err("malloc(): %m");
return NULL;
}

Expand All @@ -93,7 +93,7 @@ struct mx_flock *mx_flock(int operation, char *fmt, ...)
va_end(ap);

if (res == -1) {
mx_log_debug("vasprintf(): %m");
mx_log_err("vasprintf(): %m");
_flock_free(lock);
return NULL;
}
Expand All @@ -111,7 +111,7 @@ struct mx_flock *mx_flock(int operation, char *fmt, ...)
if (res < 0) {
if (errno == EWOULDBLOCK)
return lock;
mx_log_debug("flock(): %m");
mx_log_err("flock(): %m");
_flock_free(lock);
return NULL;
}
Expand Down Expand Up @@ -144,11 +144,11 @@ int mx_funlock(struct mx_flock *lock)

res = unlink(lock->fname);
if (res < 0)
mx_log_debug("unlink(): %m");
mx_log_warning("unlink(): %m");

res = flock(lock->fd, LOCK_UN);
if (res < 0)
mx_log_debug("flock(): %m");
mx_log_warning("flock(): %m");

_flock_close(lock);
_flock_free(lock);
Expand Down
2 changes: 1 addition & 1 deletion mx_getopt.c
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ static int _mx_getopt_long(struct mx_getopt_ctl *optctl, int *optindex)

*optindex = -1;

/* not an option: pop arguement */
/* not an option: pop argument */

if(!maybe_option) {
mx_getopt_pop_current_argument(optctl);
Expand Down
2 changes: 1 addition & 1 deletion mx_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -1126,7 +1126,7 @@ void mx_strvec_free(char **strvec)
return;

for (sv = strvec; *sv; sv++) {
free(sv);
free(*sv);
}
free(strvec);
}
Expand Down
10 changes: 7 additions & 3 deletions mxqd.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ int setup_cronolog(char *cronolog, char *link, char *format)
pid = fork();
if (pid < 0) {
mx_log_err("cronolog fork failed: %m");
return 1;
return 0;
} else if(pid == 0) {
res = dup2(pipe_fd[0], STDIN_FILENO);
if (res == -1) {
Expand Down Expand Up @@ -247,8 +247,7 @@ int server_init(struct mxq_server *server, int argc, char *argv[])

mx_getopt_init(&optctl, argc-1, &argv[1], opts);

optctl.flags = MX_FLAG_STOPONUNKNOWN|MX_FLAG_STOPONNOOPT;
// optctl.flags = MX_FLAG_STOPONUNKNOWN;
// optctl.flags = MX_FLAG_STOPONUNKNOWN|MX_FLAG_STOPONNOOPT;

while ((opt=mx_getopt(&optctl, &i)) != MX_GETOPT_END) {
if (opt == MX_GETOPT_ERROR) {
Expand Down Expand Up @@ -404,6 +403,10 @@ int server_init(struct mxq_server *server, int argc, char *argv[])
setup_stdin("/dev/null");

if (!arg_nolog) {
if (access("/var/log",R_OK|W_OK|X_OK)) {
mx_log_err("MAIN: cant write to /var/log: %m");
exit(EX_IOERR);
}
res = setup_cronolog("/usr/sbin/cronolog", "/var/log/mxqd_log", "/var/log/%Y/mxqd_log-%Y-%m");
if (!res) {
mx_log_err("MAIN: cronolog setup failed. exiting.");
Expand Down Expand Up @@ -1369,6 +1372,7 @@ void server_close(struct mxq_server *server)
mx_funlock(server->flock);

mx_free_null(server->boot_id);
mx_free_null(server->host_id);
}

int killall(struct mxq_server *server, int sig, unsigned int pgrp)
Expand Down
3 changes: 0 additions & 3 deletions mxqd.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,11 @@ struct mxq_server {
char *host_id;
char *hostname;
char *server_id;
char *lockfilename;
char *pidfilename;
struct mx_flock *flock;

char *initial_path;
char *initial_tmpdir;

int is_running;
};


Expand Down
2 changes: 1 addition & 1 deletion mysql/create_tables.sql
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ CREATE TABLE IF NOT EXISTS mxq_server (
host_mtime TIMESTAMP DEFAULT CURRENT_TIMESTAMP,

server_start TIMESTAMP DEFAULT 0,
server_stop TIMESTAMP DEFAULT 0,
server_stop TIMESTAMP DEFAULT 0
);


Expand Down
10 changes: 10 additions & 0 deletions test_mx_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,15 @@ static void test_mx_strscan(void)
mx_proc_pid_stat_free(&pps2);
}

static void test_mx_strvec() {
char **strvec;

strvec=mx_strvec_new();
mx_strvec_push_str(&strvec,strdup("Hallo"));
mx_strvec_push_str(&strvec,strdup("Bla"));
mx_strvec_push_str(&strvec,strdup("lall"));
mx_strvec_free(strvec);
}

int main(int argc, char *argv[])
{
Expand All @@ -372,5 +381,6 @@ int main(int argc, char *argv[])
test_mx_strtobytes();
test_mx_read_first_line_from_file();
test_mx_strscan();
test_mx_strvec();
return 0;
}

0 comments on commit 4c35885

Please sign in to comment.