libprefs-1.2.5.patchset revision b8162aa8
1From f8807bd4979b9ddd718100bf5af2e18228c84a8c Mon Sep 17 00:00:00 2001
2From: Adrien Destugues <pulkomandy@pulkomandy.tk>
3Date: Sun, 10 Mar 2019 16:47:58 +0100
4Subject: applying patch libprefs-1.2.5.patch
5
6
7diff --git a/src/libprefs.cpp b/src/libprefs.cpp
8index da58013..90d0aa4 100644
9--- a/src/libprefs.cpp
10+++ b/src/libprefs.cpp
11@@ -71,6 +71,7 @@
12 #include <image.h>
13 #endif
14 
15+#include <Entry.h>
16 
17 /*	identifier for this implementation of the prefs library	*/
18 #define	PREF_VERSION_STRING		"simple libprefs.so version 1.2.4"
19@@ -435,7 +436,7 @@ _PREFMakePath(
20 {
21 	status_t err = B_OK;
22 	BPath bpath;
23-	err = find_directory(user_level ? B_USER_SETTINGS_DIRECTORY : B_COMMON_SETTINGS_DIRECTORY, &bpath, true, NULL);
24+	err = find_directory(B_USER_SETTINGS_DIRECTORY, &bpath, true, NULL);
25 	if (err < B_OK) return err;
26 	strncpy(path, bpath.Path(), path_max);
27 	path[path_max-1] = 0;
28@@ -894,9 +895,9 @@ PREFReloadSet(PREFData data)
29 #if DEBUG
30 	printf("reload read %d\n", rd);
31 #endif
32+	char * buffer = (char *)malloc(size);
33 	if (rd < 0) { err = rd; goto cleanup; }
34 	if (rd != sizeof(size)) { err = B_ERROR; goto cleanup; }
35-	char * buffer = (char *)malloc(size);
36 	if (buffer == NULL) { err = B_NO_MEMORY; goto cleanup; }
37 	rd = read(data->transaction->fd, buffer, size);
38 #if DEBUG
39@@ -1156,7 +1157,7 @@ typedef struct _PREFAppIterator {
40 			curItem = 0;
41 			item = new char*[block];
42 			BPath bpath;
43-			if (!find_directory(user_level ? B_USER_SETTINGS_DIRECTORY : B_COMMON_SETTINGS_DIRECTORY, &bpath, true, NULL))
44+			if (!find_directory(B_USER_SETTINGS_DIRECTORY, &bpath, true, NULL))
45 			{
46 				BDirectory dir(bpath.Path());
47 				BEntry entry;
48@@ -1278,7 +1279,7 @@ typedef struct _PREFSetIterator
49 			curItem = 0;
50 			item = new char*[block];
51 			BPath bpath;
52-			if (!find_directory(user_level ? B_USER_SETTINGS_DIRECTORY : B_COMMON_SETTINGS_DIRECTORY, &bpath, true, NULL))
53+			if (!find_directory(B_USER_SETTINGS_DIRECTORY, &bpath, true, NULL))
54 			{
55 				char str[B_FILE_NAME_LENGTH+20];
56 				strcpy(str, LP_MAGIC);
57-- 
582.19.1
59
60
61From 3337f96a5487660f97dc1a51f17dbfd2b067e3e1 Mon Sep 17 00:00:00 2001
62From: Adrien Destugues <pulkomandy@pulkomandy.tk>
63Date: Sun, 10 Mar 2019 18:26:34 +0100
64Subject: Remove non-existant syscall.
65
66
67diff --git a/src/libprefs.cpp b/src/libprefs.cpp
68index 90d0aa4..50cd31d 100644
69--- a/src/libprefs.cpp
70+++ b/src/libprefs.cpp
71@@ -83,11 +83,6 @@ long long	POLL_INTERVAL = 9000000;	/*	nine seconds	*/
72 /*	COMMON_DIRNAME is used to disambigue the case where user folder == common folder	*/
73 #define COMMON_DIRNAME	"(libprefs common)"
74 
75-/*	some magic system calls	*/
76-extern "C" int _klock_node_(int fd);
77-extern "C" int _kunlock_node_(int fd);
78-
79-
80 /*	changes allowing hierarchical sets	*/
81 #define PRE_121 0
82 
83@@ -1525,7 +1520,7 @@ PREFBeginTransaction(
84 	release_sem(fTransSem);
85 	/*	open and lock file	*/
86 open_again:
87-	int fd = open(data->prefs, O_RDWR | O_CREAT, 0666);
88+	int fd = open(data->prefs, O_RDWR | O_CREAT | O_EXCL, 0666);
89 #if DEBUG
90 	printf("open %s returns %d\n", data->prefs, fd);
91 #endif
92@@ -1534,16 +1529,6 @@ open_again:
93 	if (fd < 0) printf("errno = %08x\n", errno);
94 #endif
95 	if ((fd < 0) && (errno != EBUSY)) return fd;
96-	if ((fd < 0) || (_klock_node_(fd) < B_OK))
97-	{	/*	it is unfortunate that there is no atomic/blocking way to wait	*/
98-		/*	for exclusive access to a file - now we are forces to busy-wait	*/
99-		if (fd >= 0) close(fd);
100-#if DEBUG
101-		printf("can't lock - snoozing\n", fd);
102-#endif
103-		snooze((rand()&0x7fff)+(find_thread(NULL)&0x7fff)+10000);	//	random snooze time to break ties
104-		goto open_again;
105-	}
106 	/*	acquire transaction semaphore - this will always work,							*/
107 	/*	because the transaction semaphore is never held across blocking system calls	*/
108 	acquire_sem(fTransSem);
109-- 
1102.19.1
111
112