summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/bootchart/bootchart.c10
-rw-r--r--src/bootchart/store.c24
-rw-r--r--src/libudev/libudev-device.c2
-rw-r--r--src/libudev/libudev-enumerate.c2
-rw-r--r--src/libudev/libudev-list.c2
-rw-r--r--src/libudev/libudev-monitor.c2
-rw-r--r--src/libudev/libudev-queue-private.c4
-rw-r--r--src/libudev/libudev-queue.c2
-rw-r--r--src/libudev/libudev-util.c7
-rw-r--r--src/libudev/libudev.c2
-rw-r--r--src/shared/time-dst.c2
-rw-r--r--src/udev/udev-ctrl.c2
-rw-r--r--src/udev/udev-event.c2
-rw-r--r--src/udev/udev-rules.c2
-rw-r--r--src/udev/udevadm-hwdb.c8
-rw-r--r--src/udev/udevd.c4
16 files changed, 38 insertions, 39 deletions
diff --git a/src/bootchart/bootchart.c b/src/bootchart/bootchart.c
index 27fd505929..630f9c5d15 100644
--- a/src/bootchart/bootchart.c
+++ b/src/bootchart/bootchart.c
@@ -318,10 +318,10 @@ int main(int argc, char *argv[]) {
(void) setrlimit(RLIMIT_NOFILE, &rlim);
/* start with empty ps LL */
- ps_first = calloc(1, sizeof(struct ps_struct));
+ ps_first = new0(struct ps_struct, 1);
if (!ps_first) {
- perror("calloc(ps_struct)");
- exit(EXIT_FAILURE);
+ log_oom();
+ return EXIT_FAILURE;
}
/* handle TERM/INT nicely */
@@ -397,8 +397,8 @@ int main(int argc, char *argv[]) {
/* caught signal, probably HUP! */
break;
}
- perror("nanosleep()");
- exit (EXIT_FAILURE);
+ log_error("nanosleep() failed: %m");
+ exit(EXIT_FAILURE);
}
} else {
overrun++;
diff --git a/src/bootchart/store.c b/src/bootchart/store.c
index b6ba113561..3e0052d212 100644
--- a/src/bootchart/store.c
+++ b/src/bootchart/store.c
@@ -132,8 +132,6 @@ void log_sample(int sample, struct list_sample_data **ptr) {
struct list_sample_data *sampledata;
struct ps_sched_struct *ps_prev = NULL;
-
-
sampledata = *ptr;
/* all the per-process stuff goes here */
@@ -151,8 +149,8 @@ void log_sample(int sample, struct list_sample_data **ptr) {
/* block stuff */
vmstat = openat(procfd, "vmstat", O_RDONLY);
if (vmstat == -1) {
- perror("open /proc/vmstat");
- exit (EXIT_FAILURE);
+ log_error("Failed to open /proc/vmstat: %m");
+ exit(EXIT_FAILURE);
}
}
@@ -183,8 +181,8 @@ vmstat_next:
/* overall CPU utilization */
schedstat = openat(procfd, "schedstat", O_RDONLY);
if (schedstat == -1) {
- perror("open /proc/schedstat");
- exit (EXIT_FAILURE);
+ log_error("Failed to open /proc/schedstat: %m");
+ exit(EXIT_FAILURE);
}
}
@@ -257,17 +255,17 @@ schedstat_next:
char t[32];
struct ps_struct *parent;
- ps->next_ps = calloc(1, sizeof(struct ps_struct));
+ ps->next_ps = new0(struct ps_struct, 1);
if (!ps->next_ps) {
- perror("calloc(ps_struct)");
+ log_oom();
exit (EXIT_FAILURE);
}
ps = ps->next_ps;
ps->pid = pid;
- ps->sample = calloc(1, sizeof(struct ps_sched_struct));
+ ps->sample = new0(struct ps_sched_struct, 1);
if (!ps->sample) {
- perror("calloc(ps_struct)");
+ log_oom();
exit (EXIT_FAILURE);
}
ps->sample->sampledata = sampledata;
@@ -393,10 +391,10 @@ schedstat_next:
if (!sscanf(buf, "%s %s %*s", rt, wt))
continue;
- ps->sample->next = calloc(1, sizeof(struct ps_sched_struct));
+ ps->sample->next = new0(struct ps_sched_struct, 1);
if (!ps->sample) {
- perror("calloc(ps_struct)");
- exit (EXIT_FAILURE);
+ log_oom();
+ exit(EXIT_FAILURE);
}
ps->sample->next->prev = ps->sample;
ps->sample = ps->sample->next;
diff --git a/src/libudev/libudev-device.c b/src/libudev/libudev-device.c
index 38144e3fbe..9f80f56d42 100644
--- a/src/libudev/libudev-device.c
+++ b/src/libudev/libudev-device.c
@@ -647,7 +647,7 @@ struct udev_device *udev_device_new(struct udev *udev)
if (udev == NULL)
return NULL;
- udev_device = calloc(1, sizeof(struct udev_device));
+ udev_device = new0(struct udev_device, 1);
if (udev_device == NULL)
return NULL;
udev_device->refcount = 1;
diff --git a/src/libudev/libudev-enumerate.c b/src/libudev/libudev-enumerate.c
index 48ffe83d36..1a880c2a34 100644
--- a/src/libudev/libudev-enumerate.c
+++ b/src/libudev/libudev-enumerate.c
@@ -83,7 +83,7 @@ _public_ struct udev_enumerate *udev_enumerate_new(struct udev *udev)
if (udev == NULL)
return NULL;
- udev_enumerate = calloc(1, sizeof(struct udev_enumerate));
+ udev_enumerate = new0(struct udev_enumerate, 1);
if (udev_enumerate == NULL)
return NULL;
udev_enumerate->refcount = 1;
diff --git a/src/libudev/libudev-list.c b/src/libudev/libudev-list.c
index c6e5a61fe9..42fcb853c7 100644
--- a/src/libudev/libudev-list.c
+++ b/src/libudev/libudev-list.c
@@ -165,7 +165,7 @@ struct udev_list_entry *udev_list_entry_add(struct udev_list *list, const char *
}
/* add new name */
- entry = calloc(1, sizeof(struct udev_list_entry));
+ entry = new0(struct udev_list_entry, 1);
if (entry == NULL)
return NULL;
entry->name = strdup(name);
diff --git a/src/libudev/libudev-monitor.c b/src/libudev/libudev-monitor.c
index f976da0b8a..ba1b04d479 100644
--- a/src/libudev/libudev-monitor.c
+++ b/src/libudev/libudev-monitor.c
@@ -96,7 +96,7 @@ static struct udev_monitor *udev_monitor_new(struct udev *udev)
{
struct udev_monitor *udev_monitor;
- udev_monitor = calloc(1, sizeof(struct udev_monitor));
+ udev_monitor = new0(struct udev_monitor, 1);
if (udev_monitor == NULL)
return NULL;
udev_monitor->refcount = 1;
diff --git a/src/libudev/libudev-queue-private.c b/src/libudev/libudev-queue-private.c
index 80d7ceef2b..d5a2b503dd 100644
--- a/src/libudev/libudev-queue-private.c
+++ b/src/libudev/libudev-queue-private.c
@@ -79,7 +79,7 @@ struct udev_queue_export *udev_queue_export_new(struct udev *udev)
if (udev == NULL)
return NULL;
- udev_queue_export = calloc(1, sizeof(struct udev_queue_export));
+ udev_queue_export = new0(struct udev_queue_export, 1);
if (udev_queue_export == NULL)
return NULL;
udev_queue_export->udev = udev;
@@ -162,7 +162,7 @@ static struct queue_devpaths *build_index(struct udev_queue_export *udev_queue_e
udev_err(udev_queue_export->udev, "queue file overflow\n");
return NULL;
}
- devpaths = calloc(1, sizeof(struct queue_devpaths) + (range + 1) * sizeof(long));
+ devpaths = malloc0(sizeof(struct queue_devpaths) + (range + 1) * sizeof(long));
if (devpaths == NULL)
return NULL;
devpaths->devpaths_size = range + 1;
diff --git a/src/libudev/libudev-queue.c b/src/libudev/libudev-queue.c
index f67dba9958..2cb4d67121 100644
--- a/src/libudev/libudev-queue.c
+++ b/src/libudev/libudev-queue.c
@@ -69,7 +69,7 @@ _public_ struct udev_queue *udev_queue_new(struct udev *udev)
if (udev == NULL)
return NULL;
- udev_queue = calloc(1, sizeof(struct udev_queue));
+ udev_queue = new0(struct udev_queue, 1);
if (udev_queue == NULL)
return NULL;
udev_queue->refcount = 1;
diff --git a/src/libudev/libudev-util.c b/src/libudev/libudev-util.c
index c940e06f71..d9cdde1751 100644
--- a/src/libudev/libudev-util.c
+++ b/src/libudev/libudev-util.c
@@ -203,6 +203,7 @@ int util_resolve_subsys_kernel(struct udev *udev, const char *string,
udev_device_unref(dev);
return 0;
}
+
ssize_t util_get_sys_core_link_value(struct udev *udev, const char *slink, const char *syspath, char *value, size_t size)
{
char path[UTIL_PATH_SIZE];
@@ -417,7 +418,7 @@ uint64_t util_string_bloom64(const char *str)
ssize_t print_kmsg(const char *fmt, ...)
{
- int fd;
+ _cleanup_close_ int fd = -1;
va_list ap;
char text[1024];
ssize_t len;
@@ -435,7 +436,7 @@ ssize_t print_kmsg(const char *fmt, ...)
ret = write(fd, text, len);
if (ret < 0)
- ret = -errno;
- close(fd);
+ return -errno;
+
return ret;
}
diff --git a/src/libudev/libudev.c b/src/libudev/libudev.c
index e1ba82febf..e2ab960d55 100644
--- a/src/libudev/libudev.c
+++ b/src/libudev/libudev.c
@@ -121,7 +121,7 @@ _public_ struct udev *udev_new(void)
const char *env;
FILE *f;
- udev = calloc(1, sizeof(struct udev));
+ udev = new0(struct udev, 1);
if (udev == NULL)
return NULL;
udev->refcount = 1;
diff --git a/src/shared/time-dst.c b/src/shared/time-dst.c
index 3950a882bf..65e2998c98 100644
--- a/src/shared/time-dst.c
+++ b/src/shared/time-dst.c
@@ -183,7 +183,7 @@ read_again:
return -EINVAL;
}
- transitions = (time_t *)calloc(total_size + tzspec_len, 1);
+ transitions = malloc0(total_size + tzspec_len);
if (transitions == NULL)
return -EINVAL;
diff --git a/src/udev/udev-ctrl.c b/src/udev/udev-ctrl.c
index a65603b3cf..2633423352 100644
--- a/src/udev/udev-ctrl.c
+++ b/src/udev/udev-ctrl.c
@@ -75,7 +75,7 @@ struct udev_ctrl *udev_ctrl_new_from_fd(struct udev *udev, int fd)
struct udev_ctrl *uctrl;
const int on = 1;
- uctrl = calloc(1, sizeof(struct udev_ctrl));
+ uctrl = new0(struct udev_ctrl, 1);
if (uctrl == NULL)
return NULL;
uctrl->refcount = 1;
diff --git a/src/udev/udev-event.c b/src/udev/udev-event.c
index c8e216c341..8eb1e2b7ec 100644
--- a/src/udev/udev-event.c
+++ b/src/udev/udev-event.c
@@ -39,7 +39,7 @@ struct udev_event *udev_event_new(struct udev_device *dev)
struct udev *udev = udev_device_get_udev(dev);
struct udev_event *event;
- event = calloc(1, sizeof(struct udev_event));
+ event = new0(struct udev_event, 1);
if (event == NULL)
return NULL;
event->dev = dev;
diff --git a/src/udev/udev-rules.c b/src/udev/udev-rules.c
index e90829811b..0a32604412 100644
--- a/src/udev/udev-rules.c
+++ b/src/udev/udev-rules.c
@@ -1615,7 +1615,7 @@ struct udev_rules *udev_rules_new(struct udev *udev, int resolve_names)
char **files, **f;
int r;
- rules = calloc(1, sizeof(struct udev_rules));
+ rules = new0(struct udev_rules, 1);
if (rules == NULL)
return NULL;
rules->udev = udev;
diff --git a/src/udev/udevadm-hwdb.c b/src/udev/udevadm-hwdb.c
index a22de1da4d..16abbe8d2f 100644
--- a/src/udev/udevadm-hwdb.c
+++ b/src/udev/udevadm-hwdb.c
@@ -190,7 +190,7 @@ static int trie_insert(struct trie *trie, struct trie_node *node, const char *se
continue;
/* split node */
- new_child = calloc(sizeof(struct trie_node), 1);
+ new_child = new0(struct trie_node, 1);
if (!new_child)
return -ENOMEM;
@@ -233,7 +233,7 @@ static int trie_insert(struct trie *trie, struct trie_node *node, const char *se
ssize_t off;
/* new child */
- child = calloc(sizeof(struct trie_node), 1);
+ child = new0(struct trie_node, 1);
if (!child)
return -ENOMEM;
@@ -576,7 +576,7 @@ static int adm_hwdb(struct udev *udev, int argc, char *argv[]) {
char **files, **f;
_cleanup_free_ char *hwdb_bin = NULL;
- trie = calloc(sizeof(struct trie), 1);
+ trie = new0(struct trie, 1);
if (!trie) {
rc = EXIT_FAILURE;
goto out;
@@ -590,7 +590,7 @@ static int adm_hwdb(struct udev *udev, int argc, char *argv[]) {
}
/* index */
- trie->root = calloc(sizeof(struct trie_node), 1);
+ trie->root = new0(struct trie_node, 1);
if (!trie->root) {
rc = EXIT_FAILURE;
goto out;
diff --git a/src/udev/udevd.c b/src/udev/udevd.c
index dca62f2429..9d7fa033b6 100644
--- a/src/udev/udevd.c
+++ b/src/udev/udevd.c
@@ -200,7 +200,7 @@ static void worker_new(struct event *event)
udev_monitor_allow_unicast_sender(worker_monitor, monitor);
udev_monitor_enable_receiving(worker_monitor);
- worker = calloc(1, sizeof(struct worker));
+ worker = new0(struct worker, 1);
if (worker == NULL) {
udev_monitor_unref(worker_monitor);
return;
@@ -431,7 +431,7 @@ static int event_queue_insert(struct udev_device *dev)
{
struct event *event;
- event = calloc(1, sizeof(struct event));
+ event = new0(struct event, 1);
if (event == NULL)
return -1;