Loading ...
Sorry, an error occurred while loading the content.

When Vim holds files open?

Expand Messages
  • Khorev Sergey
    The reason of my question are my experiments with cscope on win32. Cscope inherits Vim handles and this may prevent deleting files from within Vim ... Now I
    Message 1 of 11 , Apr 2, 2003
    • 0 Attachment
      The reason of my question are my experiments with cscope on win32. Cscope
      inherits Vim handles and this may prevent deleting files from within Vim
      :)))

      Now I know one case - swap-files. Where can I meet similar problems?

      And one more question - will be adding flag O_NOINHERIT to the all open()
      calls something harmful?


      --
      Sergey Khorev
      http://iamphet.nm.ru
      I'm a nobody, nobody is perfect, therefore I'm perfect.
    • Bram Moolenaar
      ... I don t quite understand why cscope would inherit the Vim handles. Don t you run it as a separate program? ... That sounds like a last resort solution.
      Message 2 of 11 , Apr 2, 2003
      • 0 Attachment
        Khorev Sergey wrote:

        > The reason of my question are my experiments with cscope on win32. Cscope
        > inherits Vim handles and this may prevent deleting files from within Vim
        > :)))
        >
        > Now I know one case - swap-files. Where can I meet similar problems?

        I don't quite understand why cscope would inherit the Vim handles.
        Don't you run it as a separate program?

        > And one more question - will be adding flag O_NOINHERIT to the all open()
        > calls something harmful?

        That sounds like a "last resort" solution.

        --
        Proverb: A nightingale that forgets the lyrics is a hummingbird.

        /// Bram Moolenaar -- Bram@... -- http://www.Moolenaar.net \\\
        /// Creator of Vim - Vi IMproved -- http://www.Vim.org \\\
        \\\ Project leader for A-A-P -- http://www.A-A-P.org ///
        \\\ Help AIDS victims, buy at Amazon -- http://ICCF.nl/click1.html ///
      • Khorev Sergey
        ... Yes, as separate, but for I/O redirection to work I need: 1) create pipes in Vim 2) CreateProcess( cscope.exe... ,...) with bInheritHandles=TRUE So Cscope
        Message 3 of 11 , Apr 2, 2003
        • 0 Attachment
          > I don't quite understand why cscope would inherit the Vim
          > handles. Don't you run it as a separate program?

          Yes, as separate, but for I/O redirection to work I need:
          1) create pipes in Vim
          2) CreateProcess("cscope.exe...",...) with bInheritHandles=TRUE

          So Cscope would inherit all handles :(


          --
          Sergey Khorev
          http://iamphet.nm.ru
          If you're not confused, you're misinformed.
        • David Brown
          ... Under Unix, the fork and exec are separate steps, and you usually close all of the handles before you exec the new process. Any idea on how windows
          Message 4 of 11 , Apr 2, 2003
          • 0 Attachment
            On Thu, Apr 03, 2003 at 11:14:20AM +0400, Khorev Sergey wrote:

            > > I don't quite understand why cscope would inherit the Vim
            > > handles. Don't you run it as a separate program?
            >
            > Yes, as separate, but for I/O redirection to work I need:
            > 1) create pipes in Vim
            > 2) CreateProcess("cscope.exe...",...) with bInheritHandles=TRUE
            >
            > So Cscope would inherit all handles :(

            Under Unix, the fork and exec are separate steps, and you usually close
            all of the handles before you exec the new process. Any idea on how
            windows normally handles this. Perhaps Microsoft wasn't expecing this
            usage model.

            Do you have any non-cygwin shells with source you could look at? Cygwin
            simulates fork, so that probably won't help.

            Dave Brown
          • Bram Moolenaar
            ... I see. CreateProcess() probably duplicates all the handles. Hopefully we can solve this locally, and not change other parts of Vim to be able to run
            Message 5 of 11 , Apr 3, 2003
            • 0 Attachment
              Khorev Sergey wrote:

              > > I don't quite understand why cscope would inherit the Vim
              > > handles. Don't you run it as a separate program?
              >
              > Yes, as separate, but for I/O redirection to work I need:
              > 1) create pipes in Vim
              > 2) CreateProcess("cscope.exe...",...) with bInheritHandles=TRUE
              >
              > So Cscope would inherit all handles :(

              I see. CreateProcess() probably duplicates all the handles. Hopefully
              we can solve this locally, and not change other parts of Vim to be able
              to run cscope.

              Isn't there a way to loop over all open handles and close everything but
              the ones that are used? This would still require using an intermediate
              program that then starts cscope.exe.

              I don't know if there is some kind of trick to mark handles that should
              not be inherited.

              --
              GUARD #2: It could be carried by an African swallow!
              GUARD #1: Oh, yeah, an African swallow maybe, but not a European swallow,
              that's my point.
              GUARD #2: Oh, yeah, I agree with that...
              The Quest for the Holy Grail (Monty Python)

              /// Bram Moolenaar -- Bram@... -- http://www.Moolenaar.net \\\
              /// Creator of Vim - Vi IMproved -- http://www.Vim.org \\\
              \\\ Project leader for A-A-P -- http://www.A-A-P.org ///
              \\\ Help AIDS victims, buy at Amazon -- http://ICCF.nl/click1.html ///
            • Khorev Sergey
              ... It duplicates all _inheritable_ handles ... Problem with swap-file is solvable by changing one line in memfile.c. Are there more cases with opened files?
              Message 6 of 11 , Apr 3, 2003
              • 0 Attachment
                > I see. CreateProcess() probably duplicates all the handles.

                It duplicates all _inheritable_ handles

                > Hopefully we can solve this locally, and not change other
                > parts of Vim to be able to run cscope.

                Problem with swap-file is solvable by changing one line in memfile.c. Are
                there more cases with opened files?

                > Isn't there a way to loop over all open handles and close
                > everything but the ones that are used? This would still
                > require using an intermediate program that then starts cscope.exe.
                >
                > I don't know if there is some kind of trick to mark handles
                > that should not be inherited.

                I know three methods of making handle non-inheritable:
                1) During creation (CreateFile) pass SECURITY_ATTRIBUTES with
                bInheritHandle=FALSE [or open() with O_NOINHERIT]
                2) Duplicate existing handle to create handle without inheritance and close
                original inheritable.
                3) SetHandleInformation() that doesn't work on Win9x (hello Stephan if you
                read this).

                AFAIK there are no _official_ way to enumerate all process handles
                (non-official ones exist).

                One of the terrible walkarounds is to create helper program that will
                communicate with cscope in usual way and with Vim by means of named objects
                like events, memory-mapped files or even named pipes (so we need not
                duplicate handles for it).
                Other idea is teach Cscope (anyway it requires changes to work on Win32) to
                substitute stdin, stdout and stderr with named pipes whose names can be
                passed in command line. So there will not be need of handle inheritance.

                --
                Sergey Khorev
                http://iamphet.nm.ru
                GNU PROGRAMMERS do it for free and they don't give a damn about look & feel
              • Phillip Vandry
                ... Use fcntl( , F_SETFD, 1) here to avoid using an OS specific API in favour of a standard one? ... -Phil
                Message 7 of 11 , Apr 3, 2003
                • 0 Attachment
                  On Thu, Apr 03, 2003 at 02:07:34PM +0400, Khorev Sergey wrote:
                  > I know three methods of making handle non-inheritable:
                  > 1) During creation (CreateFile) pass SECURITY_ATTRIBUTES with
                  > bInheritHandle=FALSE [or open() with O_NOINHERIT]

                  Use fcntl(<fd>, F_SETFD, 1) here to avoid using an OS specific API in
                  favour of a standard one?

                  > 2) Duplicate existing handle to create handle without inheritance and close
                  > original inheritable.
                  > 3) SetHandleInformation() that doesn't work on Win9x (hello Stephan if you
                  > read this).

                  -Phil
                • Dorai Sitaram
                  Silly stuff, but... there should be a ftplugin for filetype = sh that at least does setl com=:# setl fo-=t
                  Message 8 of 11 , Apr 3, 2003
                  • 0 Attachment
                    Silly stuff, but... there should be a ftplugin
                    for filetype = sh that at least does

                    setl com=:#
                    setl fo-=t
                  • Benji Fisher
                    ... Dan Sharp already submitted one: ftp://ftp.vim.org/pub/vim/runtime/ftplugin/sh.vim This should be included in the distro of vim 6.2 (later this year?).
                    Message 9 of 11 , Apr 3, 2003
                    • 0 Attachment
                      Dorai Sitaram wrote:
                      > Silly stuff, but... there should be a ftplugin
                      > for filetype = sh that at least does
                      >
                      > setl com=:#
                      > setl fo-=t

                      Dan Sharp already submitted one:

                      ftp://ftp.vim.org/pub/vim/runtime/ftplugin/sh.vim

                      This should be included in the distro of vim 6.2 (later this year?). OTOH, this
                      does not (yet) set either of the options you suggest. Maybe you two can agree
                      on something.

                      If you are setting 'com', why not 'cms', too?

                      HTH --Benji Fisher
                    • Dan Sharp
                      ... I will take care of it. I had not seen the cms option until the recent thread about it and was thinking about updating my ftplugins to set it. The
                      Message 10 of 11 , Apr 3, 2003
                      • 0 Attachment
                        Benji Fisher wrote:
                        > Dorai Sitaram wrote:
                        >
                        >> Silly stuff, but... there should be a ftplugin
                        >> for filetype = sh that at least does
                        >>
                        >> setl com=:#
                        >> setl fo-=t
                        >
                        > Dan Sharp already submitted one:
                        >
                        > ftp://ftp.vim.org/pub/vim/runtime/ftplugin/sh.vim
                        >
                        > This should be included in the distro of vim 6.2 (later this year?).
                        > OTOH, this does not (yet) set either of the options you suggest. Maybe
                        > you two can agree on something.
                        >
                        > If you are setting 'com', why not 'cms', too?

                        I will take care of it. I had not seen the cms option until the recent
                        thread about it and was thinking about updating my ftplugins to set it.
                        The 'comments' option already has 'b:#' by default, so does it
                        really need :# as well?

                        Dan Sharp
                      • Khorev Sergey
                        ... There are not such function in MSVC library (fcntl) :( -- Sergey Khorev http://iamphet.nm.ru Don t attempt communication with dead people; it will only
                        Message 11 of 11 , Apr 3, 2003
                        • 0 Attachment
                          > Use fcntl(<fd>, F_SETFD, 1) here to avoid using an OS
                          > specific API in favour of a standard one?

                          There are not such function in MSVC library (fcntl) :(


                          --
                          Sergey Khorev
                          http://iamphet.nm.ru
                          Don't attempt communication with dead people; it will only lead to
                          psychological
                          problems.
                          -- Safety Tips for the Post-Nuclear Existence
                        Your message has been successfully submitted and would be delivered to recipients shortly.