lib: Release big lock before popen.
mosys and flashrom shares same lock, and will hang if we try to execute
flashrom from mosys. lib/flashrom/flashrom.c solves this by releasing
and re-acquire biglock before and after spawning flashrom.
Chassis identifier in probe.c also calls vpd_get_value, which may invoke
'vpd' -> 'flashrom' if cache is not available, so we have to handle
locks in same way.
BRANCH=None
BUG=chromium:687149
TEST=VPD_IGNORE_CACHE=1 mosys platform chassis
Change-Id: I2189444f75726f99a39b466377dcdba8000dcd72
Reviewed-on: https://chromium-review.googlesource.com/440750
Commit-Ready: Hung-Te Lin <hungte@chromium.org>
Tested-by: Hung-Te Lin <hungte@chromium.org>
Reviewed-by: Hung-Te Lin <hungte@chromium.org>
diff --git a/lib/misc/probe.c b/lib/misc/probe.c
index 24ef2ff..3cb96b5 100644
--- a/lib/misc/probe.c
+++ b/lib/misc/probe.c
@@ -38,6 +38,7 @@
#include <unistd.h>
#include "mosys/alloc.h"
+#include "mosys/big_lock.h"
#include "mosys/callbacks.h"
#include "mosys/globals.h"
#include "mosys/log.h"
@@ -294,6 +295,27 @@
return (const char *)model_name;
}
+static int _release_lock(void)
+{
+#if defined(CONFIG_USE_IPC_LOCK)
+ return mosys_release_big_lock() >= 0;
+#endif
+ return 0;
+}
+
+static int _acquire_lock()
+{
+#if defined(CONFIG_USE_IPC_LOCK)
+ /* Timeout copied from lib/flashrom/flashrom.c */
+ if (mosys_acquire_big_lock(50000) < 0) {
+ lprintf(LOG_DEBUG, "%s: could not re-acquire lock\n",
+ __func__);
+ return -1;
+ }
+#endif
+ return 0;
+}
+
/*
* extract_customization_id_series_part - Gets SERIES from VPD customization_id.
*
@@ -303,10 +325,17 @@
{
char *series = NULL, *dash;
char buffer[256];
- FILE *fp = popen("vpd_get_value customization_id", "r");
+ FILE *fp = NULL;
+ int relock = 0;
- if (!fp)
+ relock = _release_lock();
+ fp = popen("vpd_get_value customization_id", "r");
+
+ if (!fp) {
+ if (relock)
+ _acquire_lock();
return NULL;
+ }
if (!fgets(buffer, sizeof(buffer), fp))
buffer[0] = '\0';
@@ -322,6 +351,8 @@
}
fclose(fp);
+ if (relock)
+ _acquire_lock();
return series;
}