fclose(*file);
}
-static inline void close_fd(int *fd)
+static inline void close_fd(const int *fd)
{
assert(fd);
if (r < 0)
return r;
- unsigned int *data;
+ __attribute__((cleanup(free_ptr))) unsigned int *data = NULL;
int datalen;
r = recv_dlog_reply(ppd->sock_fd, DLOG_REQ_GET_CAPACITY, (void **)&data, &datalen);
if (r < 0)
- goto cleanup;
- if (!data || datalen != sizeof *data) {
- r = -EINVAL;
- goto cleanup;
- }
+ return r;
+ if (!data || datalen != sizeof *data)
+ return -EINVAL;
+
*capacity = *data;
-cleanup:
- free(data);
- return r;
+ return 0;
}
static int pipe_get_usage(struct fd_info *fdi, unsigned int *usage)
if (r < 0)
return r;
- unsigned int *data;
+ __attribute__((cleanup(free_ptr))) unsigned int *data = NULL;
int datalen;
r = recv_dlog_reply(ppd->sock_fd, DLOG_REQ_GET_USAGE, (void **)&data, &datalen);
if (r < 0)
- goto cleanup;
+ return r;
- if (!data || datalen != sizeof *data) {
- r = -EINVAL;
- goto cleanup;
- }
+ if (!data || datalen != sizeof *data)
+ return -EINVAL;
*usage = *data;
-cleanup:
- free(data);
- return r;
+ return 0;
}
/**
#include <tizen.h>
#include <logcommon.h>
+static void filter_options_destroy(dlogutil_filter_options_s **filter)
+{
+ dlogutil_filter_options_destroy(*filter);
+}
+
EXPORT_API dlogutil_config_s *dlogutil_config_create(void)
{
- dlogutil_filter_options_s *filter = NULL;
+ __attribute__((cleanup(filter_options_destroy))) dlogutil_filter_options_s *filter = dlogutil_filter_options_create();
- filter = dlogutil_filter_options_create();
if (!filter)
- goto fail;
+ return NULL;
dlogutil_config_s *ret = calloc(1, sizeof(*ret));
if (!ret)
- goto fail;
+ return NULL;
ret->mode = DLOGUTIL_MODE_NONPRINTING;
ret->logs_size = DEFAULT_SORT_BUFFER_SIZE;
ret->sort_by = DLOGUTIL_SORT_DEFAULT;
ret->filter = filter;
- return ret;
+ filter = NULL;
-fail:
- dlogutil_filter_options_destroy(filter);
-
- return NULL;
+ return ret;
}
EXPORT_API void dlogutil_config_destroy(dlogutil_config_s *config)
assert(conf);
int ret;
- struct fd_info **fdi_ptrs;
+ __attribute__((cleanup(fdi_array_free))) struct fd_info **fdi_ptrs = NULL;
unsigned int mask;
int fdi_cnt = 0;
int r;
for (int i = 0; i < LOG_ID_MAX; ++i) {
mask &= ~(1u << i);
}
- if ((mask & enabled_buffers) != 0) {
- ret = -EINVAL;
- goto failure;
- }
+ if ((mask & enabled_buffers) != 0)
+ return -EINVAL;
fdi_cnt = 0;
for (int i = 0; i < LOG_ID_MAX; ++i) {
fdi = fdi_create(is_pipe ? &ops_pipe : &ops_logger, i);
break;
}
- if (!fdi) {
- ret = -ENOMEM;
- goto failure;
- }
+ if (!fdi)
+ return -ENOMEM;
r = fdi->ops->create(fdi, conf, i, &used_paths, &aliased[i]);
if (r == 0)
fdi_ptrs[fdi_cnt++] = fdi;
}
- if (fdi_cnt == 0) {
- ret = -EINVAL; // TODO: This has literally nothing to do with EINVAL
- goto failure;
- }
+ if (fdi_cnt == 0)
+ return -EINVAL; // TODO: This has literally nothing to do with EINVAL
*fdis = fdi_ptrs;
- return fdi_cnt;
-
-failure:
+ fdi_ptrs = NULL;
- fdi_array_free(&fdi_ptrs);
- return ret;
+ return fdi_cnt;
}
struct fd_info *find_earliest_log(struct fd_info **data_fds, int fd_count, dlogutil_sorting_order_e sort_by)
printf("%s version: %s-%s\n", name, __DLOG_VERSION, __DLOG_RELEASE);
}
+static int enomem_err()
+{
+ ERR("Error: out of memory\n");
+ return -ENOMEM;
+}
+
static int parse_options(int argc, char **argv, struct log_file *l_file, int *enabled_buffers, action_e *action,
dlogutil_config_s *config, dlogutil_mode_e *mode, unsigned int *dump_size, dlogutil_sorting_order_e *sort_by)
{
if (sscanf(optarg, "%d", &tid) != 1)
err_arg_nondigit = 1;
else if (dlogutil_config_filter_tid(config, tid))
- goto enomem;
+ return enomem_err();
break;
}
case 1: { /* pid filter */
if (sscanf(optarg, "%d", &pid) != 1)
err_arg_nondigit = 1;
else if (dlogutil_config_filter_pid(config, pid))
- goto enomem;
+ return enomem_err();
break;
}
case 2: { /* version */
}
case 'f':
if (logfile_set_path(l_file, optarg) < 0)
- goto enomem;
+ return enomem_err();
break;
case 'v': {
l_file->format.format = log_format_from_string(optarg);
}
case 's':
if (dlogutil_config_filter_filterspec(config, "*:S"))
- goto enomem;
+ return enomem_err();
break;
case 'r':
if (sscanf(optarg, "%zu", &l_file->rotate_size_kbytes) != 1)
show_help(argv[0], false);
return -EINVAL;
case TIZEN_ERROR_OUT_OF_MEMORY:
- goto enomem;
+ return enomem_err();
case TIZEN_ERROR_NONE:
continue;
default:
// Again, not an error, since we can continue
return 0;
-
-enomem:
- ERR("Error: out of memory\n");
- return -ENOMEM;
}
static void config_cleanup(dlogutil_config_s *const *config) {
assert(config);
assert(dir_path);
- const int dir_fd = open(dir_path, O_DIRECTORY | O_RDONLY);
+ __attribute__((cleanup(close_fd))) const int dir_fd = open(dir_path, O_DIRECTORY | O_RDONLY);
if (dir_fd < 0)
return;
struct dirent **entries;
int entry_count = scandirat(dir_fd, ".", &entries, config_entry_filter, alphasort);
if (entry_count < 0)
- goto err_close;
+ return;
int i;
for (i = 0; i < entry_count; ++i) {
free(entries[i]);
}
free(entries);
-
-err_close:
- close(dir_fd);
}
/**
hash = ((hash << 5) + hash) + c;
- if (!s || !s[0])
- goto finish;
+ if (s)
+ while ('\0' != (c = *s++))
+ hash = ((hash << 5) + hash) + c;
- while ('\0' != (c = *s++))
- hash = ((hash << 5) + hash) + c;
-
-finish:
/* Makes the hash more diverse */
hash *= HASH_MAGIC_THINGY;
int r;
ssize_t s;
- const int fd = open(filename, flags, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP);
+ __attribute__((cleanup(close_fd))) const int fd = open(filename, flags, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP);
if (fd < 0) {
int ret = -errno;
perror("error opening dynamic conf file");
if (r < 0) {
r = -errno;
perror("snprintf error");
- goto finish;
+ return r;
}
s = write(fd, buf, r);
} else
r = 0;
-finish:
- assert(!close(fd));
return r;
}