-
-
Notifications
You must be signed in to change notification settings - Fork 119
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enable yanking in one instance and pasting in another #280
Conversation
Hello, welcome back :-)
I wish it were true in all parts of the code base, but I think overall code quality increases over time.
There is a TODO entry for something similar, but I thought introducing tabs will solve that, not so sure anymore.
It's not possible at the moment. Proposed implementation isn't really complete, because registers are also accessed at least for
I think registers is the main thing that needs to be synchronized, but I don't know a really good way of doing it. Synchronizing state via file system might have quite an impact on performance (updating I like the approach you took of writing results of sequence of updates instead of synchronizing each update separately. Keeping that I think I'd use large chunk of shared memory (OS shouldn't actually allocate unused space) with a lock in it to implement something like These are just some thoughts I had and it's worth spending some more time on this subject, so feel free to provide your comments. So far it seems that implementation can be not intrusive (like this patch) and without extra performance penalties. |
Well, I just ``come from'' the tab-world and what I miss about tabs is the enhanced visibility of seeing multiple directories at once. Something like a quad-view would probably be OK for my needs, too, but I thought the most generic form of copying between instances probably best models how I use programs (I tend to quickly open and close most programs except E-Mail and Webbrowser very often).
Well, this is what I thought, too but I could not think of better alternatives at the time (I considered networking and similar system-wide IPC which always lead me to worry about how this behaves in a multi-user scenario. A file in the local home directory seemed to be very reliable and portable form a multi-user-security point of view...)
Are there any shared memory technologies already in use in VIFM or do you recommend one specifically? I am asking because I this seems like a clean(er) solution than what I have thought of and come up with (hopefully one does not have to do special provisions for preventing multiple users' instances from interfering :) ) and I would love to try to implement it this way.
I am sorry, but I must confess I do not understand this sentence: What is the sequence of updates which I have not synchronized separately?
Here they are, thank you very much for your feedback :) I am also interested in implementing this cleanly. If you point me into a direction for shared memory I will try to come up with a more sophisticated patch :) |
It was about granularity, I just meant that you synchronized snapshots of registers' state instead of every single update to registers (e.g., appending of a file).
None at the moment. There is POSIX shared memory ( Other two kinds are SysV shared memory and file mappings, but first one is legacy and second one provides persistence, which we don't really need (it also involves disk IO). |
OK, now I got it :)
I will try to come up with a better solution using POSIX shared memory and see how far I get :) As soon as I have anything like an improved patch, I will write again :) Thank you very much for your attention. |
Hello, after a long time I finally found time to create an implementation based on POSIX shared memory. It allows the option It is not finally complete yet: I would like to make the test use different values for constants Also, being new to Github Pull Requests, I do not know how to change my pull request without completely deleting my fork which might cause this pull request to become defective? As a workaround, I have attached my current idea (works for the most recend I am looking forward to your feedback, thanks in advance. |
Hello,
That's quite significant amount of code, thanks for your efforts!
So you can define group of vifm instances which share state between each other, I like this. Do you plan Mind that
Yes, you need to add functions. Sources used to be compiled for tests separately, but they don't any more to make sure they tests are run against the code which will actually be used by the application. See this header for a helper macro, which will make functions visible only in tests (still exported, but can't be used by accident in the application itself).
Do
I didn't check the whole set of changes in detail, but they look good to me in general. |
b0485c5
to
ecedb2a
Compare
…r synchronizing register contents across instances.
Thank you very much for your prompt reply :)
I have added the prefix to the code. I am very much with you that the details of the shared memory need not be exposed to users and have just used the
OK. For now I always call
This works well, thank you :)
This also works well and the CI pointed me to some non-GNU-C89-things (mainly Currently, the CI is still failing due to the need to link with Additionally, I remembered two questions when I revised the code for the In my tests ( The other question is concerned with the shared memory implementation: Currently, the implementation is very careful about attaching to the shared memory in the most race-condition-free manner. A similar problem arises when one considers disconnecting from shared memory. Currently, I have simplified the process by simply not deleting the shared memory file which might be left over. Is this acceptable? If not, does it make sense to have some sort of reference counter which is incremented for each instance attached to the shared memory and decremented for each instsance detached and once it reaches 0, the current instance is responsible for deleting the file (which immediately raises the race condition that some instance might just be in the process of attaching at that time causing further instances not to share memory with that instance because it refers to a deleted file...) |
This might actually be enough, because option handler is called only when value of an option actually changes, so you know that it was either cleared or changed to another non-empty value.
Adding something like this should make it pass:
This will cause
I don't think that size of memory mapping will exceed its initial size in most cases and keeping that amount of RAM busy sounds acceptable. This is something that can be addressed later if a need arises (it will be allocated only for people who enable the option anyways). |
OK.
Thank you very much, it compiles and links sucessfully*** :)
OK.
Yes. ***) Having received some test results from the CI which indicated that the OSX-build was failing because of a Linux-only function used by the test, I removed that function from non-Linux builds. Still, the CI fails in two distinct ways on Linux (GCC) and OSX (GCC and Clang behave the same from the test point of view there). On Linux, GCC outputs an error about a ``buffer overflow''. Can I do something to reproduce that issue locally as to dig into why this is happening? Obviously, on my local Debian system, this error does not occur. On OSX, the test fails indicating that sharing did not work (i.e. the output suggests that the interaction with the test _application worked correct but produced outputs as if there was no shared memory). I am thinking that this might mean that attaching to shared memory fails somehow. Still, I am not quite sure how to go further about this? Unfortunately, I do not have a local OSX system to test with, but I am probably going to add a test to check that attaching to shared memory appears to have succeeded and see if that also fails on OSX? During some additional local testing I noticed that (1) the DEBUG=... variable did not work with my test yet (fixed) and that (2) when using an invocation like Thanks again for the constructive feedback, it is very much appreciated! |
On OS X Clang pretends to be GCC, so failure should be the same.
It must be hardened build, which is compiled with something like:
In general you might try using valgrind ( diff --git a/tests/stic/stic.c b/tests/stic/stic.c
index d9a423895..a5cff30f4 100644
--- a/tests/stic/stic.c
+++ b/tests/stic/stic.c
@@ -537,7 +537,7 @@ int run_tests(stic_void_void tests)
}
if(stic_is_display_only() || stic_machine_readable) return 1;
- sprintf(version, "stic v%s%s%s", STIC_VERSION,
+ snprintf(version, sizeof(version), "stic v%s%s%s", STIC_VERSION,
(stic_suite_name[0] == '\0' ? "" : " :: "), stic_suite_name);
printf("\n");
stic_header_printer(version, stic_screen_width, '=');
There might be some difference in flags or an error which doesn't show up on Linux. It's always a problem to debug it on CI, usually with print statements or something like that. I'd make it work on Linux and dealt with OS X later. It should work since it's POSIX.
I think so. This seems to change that: tests/Makefile | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/tests/Makefile b/tests/Makefile
index ecd1a4786..80b37fd6f 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -295,11 +295,11 @@ else
$(AT)mkdir -p $$@
endif
-$1: $$($1.bin)
+$1: $$($1.bin) build
ifeq ($B,)
- @$(TEST_RUN_PREFIX) $$^ -s $(TEST_RUN_POST)
+ @$(TEST_RUN_PREFIX) $$< -s $(TEST_RUN_POST)
else
- @cd $B && $(TEST_RUN_PREFIX) $$^ -s $(TEST_RUN_POST)
+ @cd $B && $(TEST_RUN_PREFIX) $$< -s $(TEST_RUN_POST)
endif
# this runs separate fixtures, targets are of the form dir.name |
…n, apply patch for tests/stic/stic.c to fix GCC buffer overflow.
Thank you very much. Having applied the changes suggested, it succeeds on Linux GCC and Clang :) It is only sad to see that the coverage report shows all of the functionality as untested due to my use of two separate processes which cover (at least parts) of the code but do not run as part of the test framework. Can their runs somehow be included in the coverage statistics? |
Hm, I think coverage from forks should actually be collected, unless program is not terminated properly (see), but I tried removing Another thing I've found is that you can't do |
diff --git a/tests/Makefile b/tests/Makefile
index ecd1a4786..0f05355f3 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -132,6 +132,7 @@ override CFLAGS := $(CFLAGS) -MMD -pipe -Wall -Wno-char-subscripts \
override LDFLAGS := $(LDFLAGS)
ifeq (,$(findstring clang,$(CC)))
# clang is inconvenient with regard to this flag, don't do coverage with it
+ override CFLAGS += --coverage
override LDFLAGS += --coverage
endif
ifdef unix_env With this |
diff --git a/tests/registers_shared_memory_tests/registers_shared_memory.c b/tests/registers_shared_memory_tests/registers_shared_memory.c
index 33d8f1d00..ee11cab47 100644
--- a/tests/registers_shared_memory_tests/registers_shared_memory.c
+++ b/tests/registers_shared_memory_tests/registers_shared_memory.c
@@ -103,6 +103,10 @@ static void spawn_regcmd(size_t number)
dup2(outpipefd[0], STDIN_FILENO);
dup2(inpipefd[1], STDOUT_FILENO);
dup2(inpipefd[1], STDERR_FILENO);
+ close(outpipefd[0]);
+ close(outpipefd[1]);
+ close(inpipefd[0]);
+ close(inpipefd[1]);
#ifdef __linux__
prctl(PR_SET_PDEATHSIG, SIGTERM);
#endif You didn't close descriptors in the child, this is why it wouldn't finish. I think this stuff with |
Thank you very much for the assistance, it is again very much appreciated! With the suggested changes, it displays coverage correctly now as far as I can tell. |
Hello again :) I have just added another commit which enhances error display in the tests by printing error messages to the standard output (instead of trying to call a GUI function which is not available in the minimal test program). Using that, I got an error message for the failing OSX test which boils down Looking for this on the Internet, I found a promising thread at https://lists.apple.com/archives/darwin-kernel/2005/Feb/msg00077.html, but as far as I can tell, the proposed solution (which is basically that one has to |
…qual which makes a lot of the syncregs-tests irrelevant but might provide insights for mmap on OSX.
Yes, that was it https://travis-ci.org/vifm/vifm/builds/366274721 :) I am still going to revert the change. Would you think that it is a good idea to implement an equal size for |
…ters.c equal which makes a lot of the syncregs-tests irrelevant but might provide insights for mmap on OSX." Note: The proposed test was successful in that an equal size for shared_mmap_bytes and shared_initial caused the test to succeed on OSX (yet, it was only a hack, because the Build still produced a binary with different values for these variables...). This reverts commit 0e97fdc.
Hi, nice that it works on OS X too now :) It might actually be more than just a quirk of OS X, but something that other systems do too. We can probably assume that it's just OS X for now.
This is fine, most other changes aren't manually tested on Windows, *BSD, OS X, Haiku, Debian GNU/Hurd, etc. Luckily, things usually just work and those which don't can always be reported, CIs are there just to find out about issues earlier if possible. |
…orms to enhance compatibility with these operating systems (especially OSX).
I have added a commit which enables the resizing on Linux only (which I think is the safer approach given I do not know exactly what all the other OSes do :) ). Also, I have documented my intentions extensively in the comments (not sure if it might not be a bit too verbose, but at least all the related links and design thoughts should now be there....) Do you think it could be ready for inclusion into VIFM already? Anything else I could do to further improve the pull request? |
I think it's pretty much ready. I'll go over the changes and do some stylistic updates and use more of existing functions for the sake of consistency (it will probably take less time to just do these mostly mechanical things than to discuss what needs to be done, so I didn't mention them). And will at least make it compile on Windows before merging changes into Thanks for your work on this feature! |
Merged in 7625304, GitHub didn't recognize this as merging because I dropped test commit and commit that reverted it. |
Hello,
I would like to suggest an additional option be added for VIFM to be
able to synchronize register contents with other instances. Here is
why I think this would be useful:
I have been using console based file managers for a while (I started
with VIFM, then switched to ranger on Linux and kept VIFM on Windows
for a while and now I am back to VIFM on all platforms) and found it
to be difficult to adapt to a tab-based or dual-pane scheme of
managing files. What I would like to do is
have just one directory open per file manager instance and be
able to move and copy files across those multiple instances
(similar to what can be achieved
in GUI file managers using the system-wide clipboard).
As a prototype, I remapped the
yy
,dd
,p
andP
commands inmy
vifmrc
to store the argument of theyy
anddd
commands ina file which is then read whenever a
p
orP
is pressed to findout which file is to be pasted. While this works as long as one
restricts copying to
yy
, already simple derivations likey4j
forcopying the current file and four files down do not invoke the
overriden mapping for
yy
.Instead I thought it would be very nice if there was a way for
VIFM to automatically synchronize register contents with other
instances by writing and reading the
vifminfo
whenever yank,delete or paste commands are invoked in any way.
I have implemented an option called
syncregs
in the pullrequest/patch linked to this message and would like to know if
there are any obvious errors in my thoughts (like one can already
do that with VIFM or my implementation is flawed) and if there
are no obvious errors, if this has a chance of being added to
VIFM?
Thank you very much for the good work on VIFM. Compared to the
time before I started using ranger, it has improved very much
and I see the project is developed very actively -- very much
appreciated at my side! Also, I enjoy reading the source code
for its simplicity and clean style! :)