iwd.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/3] storage: provide storage_is_file
@ 2021-08-09  5:27 Matt Oberle
  2021-08-09  5:27 ` [PATCH 2/3] knownnetworks: stat fallback for unknown d_type Matt Oberle
  2021-08-09  5:27 ` [PATCH 3/3] hotspot: " Matt Oberle
  0 siblings, 2 replies; 4+ messages in thread
From: Matt Oberle @ 2021-08-09  5:27 UTC (permalink / raw)
  To: iwd

[-- Attachment #1: Type: text/plain, Size: 1794 bytes --]

Add a function 'storage_is_file' which will use stat to verify a
file's existence given a path relative to the storage directory.

Not all filesystems provide a file type via readdir's d_type.
XFS is a notable system with optional d_type support.
When d_type is not supported stat must be used as a fallback.
If a stat fallback is not provided iwd will fail to load state files.

---
 src/storage.c | 18 ++++++++++++++++++
 src/storage.h |  1 +
 2 files changed, 19 insertions(+)

diff --git a/src/storage.c b/src/storage.c
index 00d93933..4b89c615 100644
--- a/src/storage.c
+++ b/src/storage.c
@@ -29,11 +29,13 @@
 #include <errno.h>
 #include <ctype.h>
 #include <fcntl.h>
+#include <stdbool.h>
 #include <string.h>
 #include <stdarg.h>
 #include <stdlib.h>
 #include <unistd.h>
 #include <time.h>
+#include <sys/stat.h>
 #include <sys/time.h>
 #include <sys/types.h>
 #include <sys/stat.h>
@@ -445,3 +447,19 @@ void storage_known_frequencies_sync(struct l_settings *known_freqs)
 
 	l_free(known_freq_file_path);
 }
+
+bool storage_is_file(const char *filename)
+{
+	char *path;
+	struct stat st;
+	int err;
+
+	path = storage_get_path("%s", filename);
+	err = stat(path, &st);
+	l_free(path);
+
+	if (!err && S_ISREG(st.st_mode) != 0)
+		return true;
+
+	return false;
+}
diff --git a/src/storage.h b/src/storage.h
index 80b63c53..e1ec2cd4 100644
--- a/src/storage.h
+++ b/src/storage.h
@@ -32,6 +32,7 @@ ssize_t write_file(const void *buffer, size_t len, bool preserve_times,
 			const char *path_fmt, ...)
 	__attribute__((format(printf, 4, 5)));
 
+bool storage_is_file(const char *filename);
 bool storage_create_dirs(void);
 void storage_cleanup_dirs(void);
 char *storage_get_path(const char *format, ...);
-- 
2.32.0

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/3] knownnetworks: stat fallback for unknown d_type
  2021-08-09  5:27 [PATCH 1/3] storage: provide storage_is_file Matt Oberle
@ 2021-08-09  5:27 ` Matt Oberle
  2021-08-12 15:02   ` Denis Kenzior
  2021-08-09  5:27 ` [PATCH 3/3] hotspot: " Matt Oberle
  1 sibling, 1 reply; 4+ messages in thread
From: Matt Oberle @ 2021-08-09  5:27 UTC (permalink / raw)
  To: iwd

[-- Attachment #1: Type: text/plain, Size: 879 bytes --]

Utilize 'storage_is_file' when readdir returns DT_UNKNOWN to ensure
features like autoconnect work on filesystems that don't return a d_type
(eg. XFS).
---
 src/knownnetworks.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/src/knownnetworks.c b/src/knownnetworks.c
index 85648ead..5c3f432a 100644
--- a/src/knownnetworks.c
+++ b/src/knownnetworks.c
@@ -1071,8 +1071,12 @@ static int known_networks_init(void)
 		struct l_settings *settings;
 		L_AUTO_FREE_VAR(char *, full_path) = NULL;
 
-		if (dirent->d_type != DT_REG && dirent->d_type != DT_LNK)
+		if (dirent->d_type == DT_UNKNOWN) {
+			if (!storage_is_file(dirent->d_name))
+				continue;
+		} else if (dirent->d_type != DT_REG && dirent->d_type != DT_LNK) {
 			continue;
+		}
 
 		ssid = storage_network_ssid_from_path(dirent->d_name,
 							&security);
-- 
2.32.0

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 3/3] hotspot: stat fallback for unknown d_type
  2021-08-09  5:27 [PATCH 1/3] storage: provide storage_is_file Matt Oberle
  2021-08-09  5:27 ` [PATCH 2/3] knownnetworks: stat fallback for unknown d_type Matt Oberle
@ 2021-08-09  5:27 ` Matt Oberle
  1 sibling, 0 replies; 4+ messages in thread
From: Matt Oberle @ 2021-08-09  5:27 UTC (permalink / raw)
  To: iwd

[-- Attachment #1: Type: text/plain, Size: 920 bytes --]

Utilize 'storage_is_file' when readdir returns DT_UNKNOWN to ensure
features like autoconnect work on filesystems that don't return a d_type
(eg. XFS).
---
 src/hotspot.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/src/hotspot.c b/src/hotspot.c
index e99b2a38..17e8577e 100644
--- a/src/hotspot.c
+++ b/src/hotspot.c
@@ -495,12 +495,16 @@ static int hotspot_init(void)
 		char *filename;
 		struct network_config config;
 
-		if (dirent->d_type != DT_REG && dirent->d_type != DT_LNK)
-			continue;
-
 		filename = l_strdup_printf("%s/%s", hs20_dir, dirent->d_name);
 		s = l_settings_new();
 
+		if (dirent->d_type == DT_UNKNOWN) {
+			if (!storage_is_file(filename))
+				goto next;
+		} else if (dirent->d_type != DT_REG && dirent->d_type != DT_LNK) {
+			goto next;
+		}
+
 		if (!l_settings_load_from_file(s, filename))
 			goto next;
 
-- 
2.32.0

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 2/3] knownnetworks: stat fallback for unknown d_type
  2021-08-09  5:27 ` [PATCH 2/3] knownnetworks: stat fallback for unknown d_type Matt Oberle
@ 2021-08-12 15:02   ` Denis Kenzior
  0 siblings, 0 replies; 4+ messages in thread
From: Denis Kenzior @ 2021-08-12 15:02 UTC (permalink / raw)
  To: iwd

[-- Attachment #1: Type: text/plain, Size: 1166 bytes --]

Hi Matt,

On 8/9/21 12:27 AM, Matt Oberle wrote:
> Utilize 'storage_is_file' when readdir returns DT_UNKNOWN to ensure
> features like autoconnect work on filesystems that don't return a d_type
> (eg. XFS).
> ---
>   src/knownnetworks.c | 6 +++++-
>   1 file changed, 5 insertions(+), 1 deletion(-)
> 

All applied.  I did make a minor amend for style reasons:

> diff --git a/src/knownnetworks.c b/src/knownnetworks.c
> index 85648ead..5c3f432a 100644
> --- a/src/knownnetworks.c
> +++ b/src/knownnetworks.c
> @@ -1071,8 +1071,12 @@ static int known_networks_init(void)
>   		struct l_settings *settings;
>   		L_AUTO_FREE_VAR(char *, full_path) = NULL;
>   
> -		if (dirent->d_type != DT_REG && dirent->d_type != DT_LNK)
> +		if (dirent->d_type == DT_UNKNOWN) {
> +			if (!storage_is_file(dirent->d_name))
> +				continue;
> +		} else if (dirent->d_type != DT_REG && dirent->d_type != DT_LNK) {

Broke up this line into two so it fits on 80 char columns.  Similar amend in 
patch 3.

>   			continue;
> +		}
>   
>   		ssid = storage_network_ssid_from_path(dirent->d_name,
>   							&security);
> 

Thanks!

Regards,
-Denis

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-08-12 15:02 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-09  5:27 [PATCH 1/3] storage: provide storage_is_file Matt Oberle
2021-08-09  5:27 ` [PATCH 2/3] knownnetworks: stat fallback for unknown d_type Matt Oberle
2021-08-12 15:02   ` Denis Kenzior
2021-08-09  5:27 ` [PATCH 3/3] hotspot: " Matt Oberle

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).