From 1f819d7adc66aa4d6b7f286b0d653c41fed665dd Mon Sep 17 00:00:00 2001 From: Kalev Lember Date: Fri, 18 Sep 2015 13:54:34 +0200 Subject: [PATCH] offline update: Use glib api for for reading symlinks readlink() man page says that applications must not rely on it returning null-terminated links. This commit switches it to use g_file_read_link() instead that has much nicer API and shields us from readlink() oddities. --- src/fu-util.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/fu-util.c b/src/fu-util.c index 25709a0ea..71c3cbb91 100644 --- a/src/fu-util.c +++ b/src/fu-util.c @@ -686,22 +686,21 @@ fu_util_offline_update_reboot (void) static gboolean fu_util_install_prepared (FuUtilPrivate *priv, gchar **values, GError **error) { - gchar buf[1024]; gint vercmp; - gssize len; guint cnt = 0; guint i; const gchar *tmp; + g_autofree gchar *link = NULL; g_autoptr(GPtrArray) devices = NULL; g_autoptr(FuPending) pending = NULL; /* verify this is pointing to our cache */ - len = readlink (FU_OFFLINE_TRIGGER_FILENAME, buf, sizeof(buf) - 1); - if (len == -1) { + link = g_file_read_link (FU_OFFLINE_TRIGGER_FILENAME, NULL); + if (link == NULL) { g_debug ("No %s, exiting", FU_OFFLINE_TRIGGER_FILENAME); return TRUE; } - if (g_strcmp0 (buf, "/var/lib/fwupd") != 0) { + if (g_strcmp0 (link, "/var/lib/fwupd") != 0) { g_debug ("Another framework set up the trigger, exiting"); return TRUE; }