Skip to content

Commit

Permalink
Remove unnecessary stack traces
Browse files Browse the repository at this point in the history
  • Loading branch information
ydahhrk committed Feb 4, 2023
1 parent fcd7cf5 commit b027fb4
Show file tree
Hide file tree
Showing 11 changed files with 48 additions and 39 deletions.
16 changes: 8 additions & 8 deletions src/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ rwlock_read_lock(pthread_rwlock_t *lock)
case 0:
return error;
case EAGAIN:
pr_op_err("There are too many threads; I can't modify the database.");
pr_op_err_st("There are too many threads; I can't modify the database.");
return error;
}

Expand Down Expand Up @@ -140,7 +140,7 @@ process_dir_files(char const *location, char const *file_ext, bool empty_err,
dir_loc = opendir(location);
if (dir_loc == NULL) {
error = -errno;
pr_op_err("Couldn't open directory '%s': %s", location,
pr_op_err_st("Couldn't open directory '%s': %s", location,
strerror(-error));
goto end;
}
Expand All @@ -157,7 +157,7 @@ process_dir_files(char const *location, char const *file_ext, bool empty_err,
errno = 0;
}
if (errno) {
pr_op_err("Error reading dir %s", location);
pr_op_err_st("Error reading dir %s", location);
error = -errno;
}
if (!error && found == 0)
Expand All @@ -183,7 +183,7 @@ process_file_or_dir(char const *location, char const *file_ext, bool empty_err,
error = stat(location, &attr);
if (error) {
error = errno;
pr_op_err("Error reading path '%s': %s", location,
pr_op_err_st("Error reading path '%s': %s", location,
strerror(error));
return error;
}
Expand Down Expand Up @@ -247,15 +247,15 @@ dir_exists(char const *path, bool *result)

if (stat(path, &_stat) == 0) {
if (!S_ISDIR(_stat.st_mode)) {
return pr_op_err("Path '%s' exists and is not a directory.",
return pr_op_err_st("Path '%s' exists and is not a directory.",
path);
}
*result = true;
} else if (errno == ENOENT) {
*result = false;
} else {
error = errno;
pr_op_err("stat() failed: %s", strerror(error));
pr_op_err_st("stat() failed: %s", strerror(error));
return error;
}

Expand All @@ -271,7 +271,7 @@ create_dir(char *path)
if (mkdir(path, 0777) != 0) {
error = errno;
if (error != EEXIST) {
pr_op_err("Error while making directory '%s': %s",
pr_op_err_st("Error while making directory '%s': %s",
path, strerror(error));
return error;
}
Expand Down Expand Up @@ -395,7 +395,7 @@ delete_dir_recursive_bottom_up(char const *path)
if (error == ENOTEMPTY || error == EEXIST)
break;

pr_op_err("Couldn't delete directory '%s': %s", work_loc,
pr_op_err_st("Couldn't delete directory '%s': %s", work_loc,
strerror(error));
goto release_str;
} while (true);
Expand Down
7 changes: 3 additions & 4 deletions src/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ file_get(char const *file_name, FILE **result, struct stat *stat,
goto fail;
}
if (!S_ISREG(stat->st_mode)) {
error = pr_op_err("%s does not seem to be a file", file_name);
error = pr_val_err("%s does not seem to be a file", file_name);
goto fail;
}

Expand Down Expand Up @@ -96,9 +96,8 @@ file_load(char const *file_name, struct file_contents *fc)
* less bytes than requested like read() does. It's either
* "consumed everything", "EOF reached" or error.
*/
pr_op_err("Likely programming error: fread() < file size");
pr_op_err("fr:%zu bs:%zu EOF:%d", fread_result, fc->buffer_size,
feof(file));
pr_op_err_st("Likely programming error: fread() < file size (fr:%zu bs:%zu EOF:%d)",
fread_result, fc->buffer_size, feof(file));
free(fc->buffer);
error = -EINVAL;
goto end;
Expand Down
2 changes: 1 addition & 1 deletion src/http/http.c
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ get_http_response_code(struct http_handler *handler, long *http_code,
res = curl_easy_getinfo(handler->curl, CURLINFO_RESPONSE_CODE,
http_code);
if (res != CURLE_OK) {
return pr_op_err("curl_easy_getinfo(CURLINFO_RESPONSE_CODE) returned %d (%s). "
return pr_op_err_st("curl_easy_getinfo(CURLINFO_RESPONSE_CODE) returned %d (%s). "
"I think this is supposed to be illegal, so I'll have to drop URI '%s'.",
res, curl_err_string(handler, res), uri);
}
Expand Down
7 changes: 7 additions & 0 deletions src/log.c
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,13 @@ pr_op_warn(const char *format, ...)

int
pr_op_err(const char *format, ...)
{
PR_SIMPLE(LOG_ERR, op_config);
return -EINVAL;
}

int
pr_op_err_st(const char *format, ...)
{
PR_SIMPLE(LOG_ERR, op_config);
lock_mutex();
Expand Down
2 changes: 2 additions & 0 deletions src/log.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ void pr_op_info(const char *, ...) CHECK_FORMAT(1, 2);
int pr_op_warn(const char *, ...) CHECK_FORMAT(1, 2);
/* Problematic situations that prevent Fort from doing its job. */
int pr_op_err(const char *, ...) CHECK_FORMAT(1, 2);
/* Like pr_op_err(), but it also prints a stack trace */
int pr_op_err_st(const char *format, ...) CHECK_FORMAT(1, 2);
/* Like pr_op_err(), except it prints libcrypto's error stack as well. */
int op_crypto_err(const char *, ...) CHECK_FORMAT(1, 2);

Expand Down
20 changes: 10 additions & 10 deletions src/rsync/rsync.c
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ create_pipes(int fds[2][2])

if (pipe(fds[0]) == -1) {
error = errno;
pr_op_err("Piping rsync stderr: %s", strerror(error));
pr_op_err_st("Piping rsync stderr: %s", strerror(error));
return -error;
}

Expand All @@ -281,7 +281,7 @@ create_pipes(int fds[2][2])
close(fds[0][0]);
close(fds[0][1]);

pr_op_err("Piping rsync stdout: %s", strerror(error));
pr_op_err_st("Piping rsync stdout: %s", strerror(error));
return -error;
}

Expand Down Expand Up @@ -311,7 +311,7 @@ log_buffer(char const *buffer, ssize_t read, int type, bool log_operation)
}
if (type == 0) {
if (log_operation)
pr_op_err(PRE_RSYNC "%s", cur);
pr_op_err_st(PRE_RSYNC "%s", cur);
pr_val_err(PRE_RSYNC "%s", cur);
} else {
pr_val_info(PRE_RSYNC "%s", cur);
Expand Down Expand Up @@ -438,7 +438,7 @@ do_rsync(struct rpki_uri *uri, bool is_ta, bool log_operation)
}
if (child_pid < 0) {
error = errno;
pr_op_err("Couldn't fork to execute rsync: %s",
pr_op_err_st("Couldn't fork to execute rsync: %s",
strerror(error));
/* Close all ends from the created pipes */
close(fork_fds[0][0]);
Expand All @@ -457,7 +457,7 @@ do_rsync(struct rpki_uri *uri, bool is_ta, bool log_operation)
do {
if (error == -1) {
error = errno;
pr_op_err("The rsync sub-process returned error %d (%s)",
pr_op_err_st("The rsync sub-process returned error %d (%s)",
error, strerror(error));
if (child_status > 0)
break;
Expand Down Expand Up @@ -496,23 +496,23 @@ do_rsync(struct rpki_uri *uri, bool is_ta, bool log_operation)
if (WIFSIGNALED(child_status)) {
switch (WTERMSIG(child_status)) {
case SIGINT:
pr_op_err("RSYNC was user-interrupted. Guess I'll interrupt myself too.");
pr_op_err_st("RSYNC was user-interrupted. Guess I'll interrupt myself too.");
break;
case SIGQUIT:
pr_op_err("RSYNC received a quit signal. Guess I'll quit as well.");
pr_op_err_st("RSYNC received a quit signal. Guess I'll quit as well.");
break;
case SIGKILL:
pr_op_err("Killed.");
pr_op_err_st("Killed.");
break;
default:
pr_op_err("The RSYNC was terminated by a signal [%d] I don't have a handler for. Dunno; guess I'll just die.",
pr_op_err_st("The RSYNC was terminated by a signal [%d] I don't have a handler for. Dunno; guess I'll just die.",
WTERMSIG(child_status));
break;
}
return -EINTR; /* Meh? */
}

pr_op_err("The RSYNC command died in a way I don't have a handler for. Dunno; guess I'll die as well.");
pr_op_err_st("The RSYNC command died in a way I don't have a handler for. Dunno; guess I'll die as well.");
return -EINVAL;
release_args:
/* The happy path also falls here */
Expand Down
8 changes: 4 additions & 4 deletions src/rtr/pdu_sender.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,16 @@ send_response(int fd, uint8_t pdu_type, unsigned char *data, size_t data_len)
pfd.revents = 0;
error = poll(&pfd, 1, -1);
if (error < 0)
return pr_op_err("poll() error: %d", error);
return pr_op_err_st("poll() error: %d", error);
if (error == 0)
return pr_op_err("poll() returned 0, even though there's no timeout.");
return pr_op_err_st("poll() returned 0, even though there's no timeout.");
if (pfd.revents & (POLLHUP | POLLERR | POLLNVAL))
return pr_op_err("poll() returned revents %u.", pfd.revents);
return pr_op_err_st("poll() returned revents %u.", pfd.revents);
} while (!(pfd.revents & POLLOUT));

if (write(fd, data, data_len) < 0) {
error = errno;
pr_op_err("Error sending %s to client: %s",
pr_op_err_st("Error sending %s to client: %s",
pdutype2str(pdu_type), strerror(error));
return error;
}
Expand Down
4 changes: 2 additions & 2 deletions src/rtr/rtr.c
Original file line number Diff line number Diff line change
Expand Up @@ -195,15 +195,15 @@ set_nonblock(int fd)
flags = fcntl(fd, F_GETFL);
if (flags == -1) {
error = errno;
pr_op_err("fcntl() to get flags failed: %s", strerror(error));
pr_op_err_st("fcntl() to get flags failed: %s", strerror(error));
return error;
}

flags |= O_NONBLOCK;

if (fcntl(fd, F_SETFL, flags) == -1) {
error = errno;
pr_op_err("fcntl() to set flags failed: %s", strerror(error));
pr_op_err_st("fcntl() to set flags failed: %s", strerror(error));
return error;
}

Expand Down
6 changes: 3 additions & 3 deletions src/slurm/slurm_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ set_max_prefix_length(json_t *object, bool is_assertion, uint8_t addr_fam,
/* An underflow or overflow will be considered here */
if (int_tmp <= 0 || (addr_fam == AF_INET ? 32 : 128) < int_tmp)
return pr_op_err("Max prefix length (%lld) is out of range [1 - %d].",
int_tmp, (addr_fam == AF_INET ? 32 : 128));
int_tmp, (addr_fam == AF_INET) ? 32 : 128);

*flag = *flag | SLURM_PFX_FLAG_MAX_LENGTH;
*result = (uint8_t) int_tmp;
Expand All @@ -216,7 +216,7 @@ validate_base64url_encoded(const char *encoded)
* without trailing '=' (Section 5 of [RFC4648])"
*/
if (strrchr(encoded, '=') != NULL)
return pr_op_err("The base64 encoded value has trailing '='");
return pr_op_err_st("The base64 encoded value has trailing '='");

/*
* IMHO there's an error at RFC 8416 regarding the use of base64
Expand Down Expand Up @@ -589,7 +589,7 @@ load_version(json_t *root)
version = -1;
error = json_get_int(root, SLURM_VERSION, &version);
if (error)
return error == -ENOENT ?
return (error == -ENOENT) ?
pr_op_err("SLURM member '"SLURM_VERSION"' is required.") :
error;

Expand Down
13 changes: 7 additions & 6 deletions src/thread/thread_pool.c
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ thread_pool_attr_create(pthread_attr_t *attr)

error = pthread_attr_init(attr);
if (error) {
pr_op_err("pthread_attr_init() returned error %d: %s",
pr_op_err_st("pthread_attr_init() returned error %d: %s",
error, strerror(error));
return error;
}
Expand All @@ -239,7 +239,8 @@ thread_pool_attr_create(pthread_attr_t *attr)
error = pthread_attr_setstacksize(attr, 1024 * 1024 * 2);
if (error) {
pthread_attr_destroy(attr);
pr_op_err("pthread_attr_setstacksize() returned error %d: %s",
pr_op_err_st(
"pthread_attr_setstacksize() returned error %d: %s",
error, strerror(error));
return error;
}
Expand Down Expand Up @@ -278,7 +279,7 @@ spawn_threads(struct thread_pool *pool)
error = pthread_create(&pool->thread_ids[i], &attr, tasks_poll,
pool);
if (error) {
pr_op_err("pthread_create() returned error %d: %s",
pr_op_err_st("pthread_create() returned error %d: %s",
error, strerror(error));
goto end;
}
Expand All @@ -305,23 +306,23 @@ thread_pool_create(char const *name, unsigned int threads,
/* Init locking */
error = pthread_mutex_init(&result->lock, NULL);
if (error) {
pr_op_err("pthread_mutex_init() returned error %d: %s",
pr_op_err_st("pthread_mutex_init() returned error %d: %s",
error, strerror(error));
goto free_tmp;
}

/* Init conditional to signal pending work */
error = pthread_cond_init(&result->parent2worker, NULL);
if (error) {
pr_op_err("pthread_cond_init(p2w) returned error %d: %s",
pr_op_err_st("pthread_cond_init(p2w) returned error %d: %s",
error, strerror(error));
goto free_mutex;
}

/* Init conditional to signal no pending work */
error = pthread_cond_init(&result->worker2parent, NULL);
if (error) {
pr_op_err("pthread_cond_init(w2p) returned error %d: %s",
pr_op_err_st("pthread_cond_init(w2p) returned error %d: %s",
error, strerror(error));
goto free_working_cond;
}
Expand Down
2 changes: 1 addition & 1 deletion src/thread_var.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ state_retrieve(void)

state = pthread_getspecific(state_key);
if (state == NULL)
pr_op_err("Programming error: This thread lacks a validation state.");
pr_crit("Programming error: This thread lacks a validation state.");

return state;
}
Expand Down

0 comments on commit b027fb4

Please sign in to comment.