Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
mx_util: Add mx_hostname() from mxq_util
  • Loading branch information
mariux committed Jul 27, 2015
1 parent 917ad20 commit f9538ed
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 24 deletions.
18 changes: 18 additions & 0 deletions mx_util.c
Expand Up @@ -441,6 +441,24 @@ int mx_asprintf_forever(char **strp, const char *fmt, ...)
return len;
}

char *mx_hostname(void)
{
static char hostname[1024] = "";
int res;

if (*hostname)
return hostname;

res = gethostname(hostname, 1024);
if (res == -1) {
if (errno != ENAMETOOLONG)
assert_perror(errno);
hostname[1024-1] = 0;
}

return hostname;
}

char *mx_dirname(char *path)
{
char *tmp;
Expand Down
1 change: 1 addition & 0 deletions mx_util.h
Expand Up @@ -88,6 +88,7 @@ char *mx_strdup_forever(char *str);
int mx_vasprintf_forever(char **strp, const char *fmt, va_list ap);
int mx_asprintf_forever(char **strp, const char *fmt, ...) __attribute__ ((format(printf, 2, 3)));

char *mx_hostname(void);
char *mx_dirname(char *path);
char *mx_dirname_forever(char *path);

Expand Down
19 changes: 0 additions & 19 deletions mxq_util.c
Expand Up @@ -19,25 +19,6 @@

#include "mxq_util.h"


char *mxq_hostname(void)
{
static char hostname[1024] = "";
int res;

if (*hostname)
return hostname;

res = gethostname(hostname, 1024);
if (res == -1) {
if (errno != ENAMETOOLONG)
assert_perror(errno);
hostname[1024-1] = 0;
}

return hostname;
}

char **strvec_new(void)
{
char **strvec;
Expand Down
2 changes: 0 additions & 2 deletions mxq_util.h
Expand Up @@ -6,8 +6,6 @@
#include <string.h>
#include <mysql.h>

char *mxq_hostname(void);

char** strvec_new(void);
size_t strvec_length(char **strvec);
int strvec_push_str(char ***strvecp, char *str);
Expand Down
4 changes: 2 additions & 2 deletions mxqd.c
Expand Up @@ -332,7 +332,7 @@ int server_init(struct mxq_server *server, int argc, char *argv[])
mx_mysql_option_set_default_group(server->mysql, arg_mysql_default_group);
mx_mysql_option_set_reconnect(server->mysql, 1);

server->hostname = mxq_hostname();
server->hostname = mx_hostname();
server->server_id = arg_server_id;

server->flock = mx_flock(LOCK_EX, "/dev/shm/mxqd.%s.%s.lck", server->hostname, server->server_id);
Expand Down Expand Up @@ -768,7 +768,7 @@ static int init_child_process(struct mxq_group_list *group, struct mxq_job *j)
mx_setenv_forever("PWD", j->job_workdir);
mx_setenv_forever("HOME", passwd->pw_dir);
mx_setenv_forever("SHELL", passwd->pw_shell);
mx_setenv_forever("HOSTNAME", mxq_hostname());
mx_setenv_forever("HOSTNAME", mx_hostname());
mx_setenvf_forever("JOB_ID", "%lu", j->job_id);
mx_setenvf_forever("MXQ_JOBID", "%lu", j->job_id);
mx_setenvf_forever("MXQ_THREADS", "%d", g->job_threads);
Expand Down
2 changes: 1 addition & 1 deletion mxqsub.c
Expand Up @@ -736,7 +736,7 @@ int main(int argc, char *argv[])
/******************************************************************/

group.job_command = arg_program_name;
job.host_submit = mxq_hostname();
job.host_submit = mx_hostname();

/******************************************************************/

Expand Down

0 comments on commit f9538ed

Please sign in to comment.