summaryrefslogtreecommitdiff
path: root/src/readahead/readahead-common.c
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2013-10-12 20:28:21 -0400
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2013-10-13 17:56:55 -0400
commit1ca208fb4f93e5869704af1812cbff7130a2fc03 (patch)
tree689343b99c76e4d34c625197762de97e8435571d /src/readahead/readahead-common.c
parentb506291ff195e03ce793ac925cc2d158f0b452b5 (diff)
Introduce udev object cleanup functions
Diffstat (limited to 'src/readahead/readahead-common.c')
-rw-r--r--src/readahead/readahead-common.c66
1 files changed, 25 insertions, 41 deletions
diff --git a/src/readahead/readahead-common.c b/src/readahead/readahead-common.c
index a234a89954..aea1fbeea4 100644
--- a/src/readahead/readahead-common.c
+++ b/src/readahead/readahead-common.c
@@ -27,13 +27,14 @@
#include <fcntl.h>
#include <sys/mman.h>
#include <unistd.h>
-#include <libudev.h>
#include "log.h"
#include "readahead-common.h"
#include "util.h"
#include "missing.h"
#include "fileio.h"
+#include "libudev.h"
+#include "udev-util.h"
int file_verify(int fd, const char *fn, off_t file_size_max, struct stat *st) {
assert(fd >= 0);
@@ -60,9 +61,9 @@ int file_verify(int fd, const char *fn, off_t file_size_max, struct stat *st) {
int fs_on_ssd(const char *p) {
struct stat st;
- struct udev *udev = NULL;
- struct udev_device *udev_device = NULL, *look_at = NULL;
- bool b = false;
+ _cleanup_udev_unref_ struct udev *udev = NULL;
+ _cleanup_udev_device_unref_ struct udev_device *udev_device = NULL;
+ struct udev_device *look_at = NULL;
const char *devtype, *rotational, *model, *id;
int r;
@@ -128,7 +129,7 @@ int fs_on_ssd(const char *p) {
udev_device = udev_device_new_from_devnum(udev, 'b', st.st_dev);
if (!udev_device)
- goto finish;
+ return false;
devtype = udev_device_get_property_value(udev_device, "DEVTYPE");
if (devtype && streq(devtype, "partition"))
@@ -137,46 +138,34 @@ int fs_on_ssd(const char *p) {
look_at = udev_device;
if (!look_at)
- goto finish;
+ return false;
/* First, try high-level property */
id = udev_device_get_property_value(look_at, "ID_SSD");
- if (id) {
- b = streq(id, "1");
- goto finish;
- }
+ if (id)
+ return streq(id, "1");
/* Second, try kernel attribute */
rotational = udev_device_get_sysattr_value(look_at, "queue/rotational");
- if (rotational) {
- b = streq(rotational, "0");
- goto finish;
- }
+ if (rotational)
+ return streq(rotational, "0");
/* Finally, fallback to heuristics */
look_at = udev_device_get_parent(look_at);
if (!look_at)
- goto finish;
+ return false;
model = udev_device_get_sysattr_value(look_at, "model");
if (model)
- b = !!strstr(model, "SSD");
-
-finish:
- if (udev_device)
- udev_device_unref(udev_device);
-
- if (udev)
- udev_unref(udev);
+ return !!strstr(model, "SSD");
- return b;
+ return false;
}
int fs_on_read_only(const char *p) {
struct stat st;
- struct udev *udev = NULL;
- struct udev_device *udev_device = NULL;
- bool b = false;
+ _cleanup_udev_unref_ struct udev *udev = NULL;
+ _cleanup_udev_device_unref_ struct udev_device *udev_device = NULL;
const char *read_only;
assert(p);
@@ -187,24 +176,19 @@ int fs_on_read_only(const char *p) {
if (major(st.st_dev) == 0)
return false;
- if (!(udev = udev_new()))
+ udev = udev_new();
+ if (!udev)
return -ENOMEM;
- if (!(udev_device = udev_device_new_from_devnum(udev, 'b', st.st_dev)))
- goto finish;
-
- if ((read_only = udev_device_get_sysattr_value(udev_device, "ro")))
- if ((b = streq(read_only, "1")))
- goto finish;
-
-finish:
- if (udev_device)
- udev_device_unref(udev_device);
+ udev_device = udev_device_new_from_devnum(udev, 'b', st.st_dev);
+ if (!udev_device)
+ return false;
- if (udev)
- udev_unref(udev);
+ read_only = udev_device_get_sysattr_value(udev_device, "ro");
+ if (read_only)
+ return streq(read_only, "1");
- return b;
+ return false;
}
bool enough_ram(void) {