pespin has uploaded this change for review. (
https://gerrit.osmocom.org/c/libosmocore/+/41971?usp=email )
Change subject: logging_file: Clean log_target_file_reopen()
......................................................................
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(-)
git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/71/41971/1
diff --git a/src/core/logging_file.c b/src/core/logging_file.c
index 6e01c26..078059a 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 https://gerrit.osmocom.org/c/libosmocore/+/41971?usp=email
To unsubscribe, or for help writing mail filters, visit
https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: newchange
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: Ibcb50320ad80b034115cccc3b7ab90501ac1d091
Gerrit-Change-Number: 41971
Gerrit-PatchSet: 1
Gerrit-Owner: pespin <[email protected]>