chiark / gitweb /
libsystemd: add sd-hwdb library
[elogind.git] / src / shared / path-util.c
index 5bc5012fe89ed61900f038dd260d348593ec58fd..be03695cf866e06fcc3c33d59e524a233e81f33b 100644 (file)
@@ -533,7 +533,16 @@ int path_is_read_only_fs(const char *path) {
         if (statvfs(path, &st) < 0)
                 return -errno;
 
-        return !!(st.f_flag & ST_RDONLY);
+        if (st.f_flag & ST_RDONLY)
+                return true;
+
+        /* On NFS, statvfs() might not reflect whether we can actually
+         * write to the remote share. Let's try again with
+         * access(W_OK) which is more reliable, at least sometimes. */
+        if (access(path, W_OK) < 0 && errno == EROFS)
+                return true;
+
+        return false;
 }
 
 int path_is_os_tree(const char *path) {
@@ -554,11 +563,11 @@ int path_is_os_tree(const char *path) {
         return r >= 0;
 }
 
-int find_binary(const char *name, char **filename) {
+int find_binary(const char *name, bool local, char **filename) {
         assert(name);
 
         if (is_path(name)) {
-                if (access(name, X_OK) < 0)
+                if (local && access(name, X_OK) < 0)
                         return -errno;
 
                 if (filename) {
@@ -574,7 +583,7 @@ int find_binary(const char *name, char **filename) {
                 return 0;
         } else {
                 const char *path;
-                char *state, *w;
+                const char *word, *state;
                 size_t l;
 
                 /**
@@ -585,10 +594,10 @@ int find_binary(const char *name, char **filename) {
                 if (!path)
                         path = DEFAULT_PATH;
 
-                FOREACH_WORD_SEPARATOR(w, l, path, ":", state) {
+                FOREACH_WORD_SEPARATOR(word, l, path, ":", state) {
                         _cleanup_free_ char *p = NULL;
 
-                        if (asprintf(&p, "%.*s/%s", (int) l, w, name) < 0)
+                        if (asprintf(&p, "%.*s/%s", (int) l, word, name) < 0)
                                 return -ENOMEM;
 
                         if (access(p, X_OK) < 0)
@@ -648,7 +657,7 @@ int fsck_exists(const char *fstype) {
 
         checker = strappenda("fsck.", fstype);
 
-        r = find_binary(checker, &p);
+        r = find_binary(checker, true, &p);
         if (r < 0)
                 return r;