Skip to content

Commit

Permalink
tree: Replace perror() with mx_log_err("... %m")
Browse files Browse the repository at this point in the history
  • Loading branch information
donald committed Feb 19, 2022
1 parent 29a1606 commit 1870a2f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
4 changes: 2 additions & 2 deletions mx_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -1310,7 +1310,7 @@ time_t mx_clock_boottime() {
struct timespec ts;
int res = clock_gettime(CLOCK_BOOTTIME, &ts);
if (res != 0) {
perror("clock_gettime");
mx_log_err("clock_gettime: %m");
}
return (ts.tv_sec);
}
Expand Down Expand Up @@ -1350,7 +1350,7 @@ static char *mx_call_external_v(char *helper, char **argv) {
close(pipefd[0]);
dup2(pipefd[1], 1);
execv(helper, argv);
perror(helper);
mx_log_err("%s: %m", helper);
exit(1);
}
close(pipefd[1]);
Expand Down
14 changes: 7 additions & 7 deletions mxqd.c
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ static int cpuset_init(struct mxq_server *server)
static void read_hostconfig_retry(struct keywordset *kws) {
char *line = mx_call_external("/usr/sbin/hostconfig", NULL);
if (!line) {
perror("hostconfig");
mx_log_err("hostconfig: %m");
exit(1);
}
keywordset_add(kws, line);
Expand All @@ -339,7 +339,7 @@ static char gpu_setup_script[] = LIBEXECDIR "/mxq/gpu-setup";
static int get_gpus() {
char *line = mx_call_external(gpu_setup_script, "init", NULL);
if (!line) {
perror("gpu-setup init");
mx_log_err("gpu-setuo init: %m");
exit(1);
}
int gpus = atoi(line);
Expand All @@ -356,13 +356,13 @@ static void read_cpufeatures(struct keywordset *kws) {
size_t linebuflen = 0;
FILE *proc_cpuinfo = fopen("/proc/cpuinfo","r");
if (proc_cpuinfo == NULL) {
perror("/proc/cpuinfo");
mx_log_err("/proc/cpuinfo: %m");
exit(1);
}
while (1) {
ssize_t len = getline(&line, &linebuflen, proc_cpuinfo);
if (len<0) {
perror("/proc/cpuinfo");
mx_log_err("/proc/cpuinfo: %m");
exit(1);
}
if(line[len-1] == '\n')
Expand All @@ -371,7 +371,7 @@ static void read_cpufeatures(struct keywordset *kws) {
int i=sscanf(line,"flags : %n", &keywords);
if (i==EOF) {
if (ferror(proc_cpuinfo)) {
perror("/proc/cpuinfo");
mx_log_err("/proc/cpuinfo: %m");
exit(1);
}
fprintf(stderr,"%s: unexpected EOF during read\n","proc/cpuinfo");
Expand Down Expand Up @@ -910,7 +910,7 @@ static int init_child_process(struct mxq_group_list *glist, struct mxq_job *job)
mx_asprintf_forever(&uid, "%u", group->user_uid);
char *gpu_uuid = mx_call_external(gpu_setup_script, "job-init", pid, uid, NULL);
if (!gpu_uuid) {
perror("gpu-setup job-init");
mx_log_err("gpu-setup job-init: %m");
exit(1);
}
mx_setenv_forever("CUDA_VISIBLE_DEVICES", gpu_uuid);
Expand Down Expand Up @@ -2040,7 +2040,7 @@ static void release_gpu(struct mxq_server *server, struct mxq_group *group, stru
char *gpu_uuid = mx_call_external(gpu_setup_script, "job-release", pid, NULL);
free(pid);
if (!gpu_uuid) {
perror("gpu-setup job-release");
mx_log_err("gpu-setup job-release: %m");
exit(1);
}
free(gpu_uuid);
Expand Down
5 changes: 3 additions & 2 deletions ppidcache.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "mx_util.h"
#include "ppidcache.h"
#include "mx_proc.h"
#include "mx_log.h"

struct entry {
pid_t pid;
Expand Down Expand Up @@ -79,15 +80,15 @@ void ppidcache_scan(struct ppidcache *ppidcache) {
ppidcache->count = 0;
dir = opendir("/proc");
if (dir == NULL) {
perror("/proc");
mx_log_err("/proc: %m");
return;
}
while (1) {
errno = 0;
dirent = readdir(dir);
if (dirent == NULL) {
if (errno)
perror("/proc");
mx_log_err("/proc: %m");
return;
}
if (strspn(dirent->d_name, "0123456789") != strlen(dirent->d_name))
Expand Down

0 comments on commit 1870a2f

Please sign in to comment.