pespin submitted this change.

View Change

Approvals: Jenkins Builder: Verified pespin: Looks good to me, approved osmith: Looks good to me, but someone else must approve fixeria: Looks good to me, but someone else must approve
logging_file: Clean log_target_file_reopen()

Move specific assert for wq further below.
Do early return to get rid of extra indentation.

Change-Id: Ibcb50320ad80b034115cccc3b7ab90501ac1d091
---
M src/core/logging_file.c
1 file changed, 19 insertions(+), 18 deletions(-)

diff --git a/src/core/logging_file.c b/src/core/logging_file.c
index 99a797c..413a0a7 100644
--- a/src/core/logging_file.c
+++ b/src/core/logging_file.c
@@ -52,34 +52,35 @@
struct osmo_wqueue *wq;
int rc;

- OSMO_ASSERT(target->type == LOG_TGT_TYPE_FILE || target->type == LOG_TGT_TYPE_STDERR);
- OSMO_ASSERT(target->tgt_file.out || target->tgt_file.wqueue);
+ OSMO_ASSERT(target->type == LOG_TGT_TYPE_FILE ||
+ target->type == LOG_TGT_TYPE_STDERR);

if (target->type == LOG_TGT_TYPE_STDERR)
return -ENOTSUP;

- if (target->tgt_file.out) {
+ if (target->tgt_file.out) { /* stream mode */
fclose(target->tgt_file.out);
target->tgt_file.out = fopen(target->tgt_file.fname, "a");
if (!target->tgt_file.out)
return -errno;
- } else {
- wq = target->tgt_file.wqueue;
- if (wq->bfd.fd >= 0) {
- osmo_fd_unregister(&wq->bfd);
- close(wq->bfd.fd);
- wq->bfd.fd = -1;
- }
-
- rc = open(target->tgt_file.fname, O_WRONLY|O_APPEND|O_CREAT|O_NONBLOCK, 0660);
- if (rc < 0)
- return -errno;
- wq->bfd.fd = rc;
- rc = osmo_fd_register(&wq->bfd);
- if (rc < 0)
- return rc;
+ return 0;
}

+ OSMO_ASSERT(target->tgt_file.wqueue);
+ wq = target->tgt_file.wqueue;
+ if (wq->bfd.fd >= 0) {
+ osmo_fd_unregister(&wq->bfd);
+ close(wq->bfd.fd);
+ wq->bfd.fd = -1;
+ }
+
+ rc = open(target->tgt_file.fname, O_WRONLY|O_APPEND|O_CREAT|O_NONBLOCK, 0660);
+ if (rc < 0)
+ return -errno;
+ wq->bfd.fd = rc;
+ rc = osmo_fd_register(&wq->bfd);
+ if (rc < 0)
+ return rc;
return 0;
}


To view, visit change 41971. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-MessageType: merged
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: Ibcb50320ad80b034115cccc3b7ab90501ac1d091
Gerrit-Change-Number: 41971
Gerrit-PatchSet: 7
Gerrit-Owner: pespin <pespin@sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: fixeria <vyanitskiy@sysmocom.de>
Gerrit-Reviewer: osmith <osmith@sysmocom.de>
Gerrit-Reviewer: pespin <pespin@sysmocom.de>
Gerrit-CC: laforge <laforge@osmocom.org>