diff options
author | Stefano Brivio <sbrivio@redhat.com> | 2024-06-15 00:37:11 +0200 |
---|---|---|
committer | Stefano Brivio <sbrivio@redhat.com> | 2024-06-21 15:32:43 +0200 |
commit | 92a22fef93a528030669e357a32c19f143a2d3b5 (patch) | |
tree | 37d5ff28d073c0c68601a45e8f540f9da3d7d8b3 /log.c | |
parent | c1140df889aeb90f944c1caabdf6f73522dbb250 (diff) | |
download | passt-92a22fef93a528030669e357a32c19f143a2d3b5.tar passt-92a22fef93a528030669e357a32c19f143a2d3b5.tar.gz passt-92a22fef93a528030669e357a32c19f143a2d3b5.tar.bz2 passt-92a22fef93a528030669e357a32c19f143a2d3b5.tar.lz passt-92a22fef93a528030669e357a32c19f143a2d3b5.tar.xz passt-92a22fef93a528030669e357a32c19f143a2d3b5.tar.zst passt-92a22fef93a528030669e357a32c19f143a2d3b5.zip |
treewide: Replace perror() calls with calls to logging functions
perror() prints directly to standard error, but in many cases standard
error might be already closed, or we might want to skip logging, based
on configuration. Our logging functions provide all that.
While at it, make errors more descriptive, replacing some of the
existing basic perror-style messages.
Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
Diffstat (limited to 'log.c')
-rw-r--r-- | log.c | 12 |
1 files changed, 4 insertions, 8 deletions
@@ -206,10 +206,8 @@ void logfile_init(const char *name, const char *path, size_t size) char nl = '\n', exe[PATH_MAX] = { 0 }; int n; - if (readlink("/proc/self/exe", exe, PATH_MAX - 1) < 0) { - perror("readlink /proc/self/exe"); - exit(EXIT_FAILURE); - } + if (readlink("/proc/self/exe", exe, PATH_MAX - 1) < 0) + die_perror("Failed to read own /proc/self/exe link"); log_file = open(path, O_CREAT | O_TRUNC | O_APPEND | O_RDWR | O_CLOEXEC, S_IRUSR | S_IWUSR); @@ -222,10 +220,8 @@ void logfile_init(const char *name, const char *path, size_t size) name, exe, getpid()); if (write(log_file, log_header, n) <= 0 || - write(log_file, &nl, 1) <= 0) { - perror("Couldn't write to log file\n"); - exit(EXIT_FAILURE); - } + write(log_file, &nl, 1) <= 0) + die_perror("Couldn't write to log file"); /* For FALLOC_FL_COLLAPSE_RANGE: VFS block size can be up to one page */ log_cut_size = ROUND_UP(log_size * LOGFILE_CUT_RATIO / 100, PAGE_SIZE); |