7

After a recent update, kate seems to exec a copy of itself, presumably with some parameter which prevents an endless recursion, and then exits. Presumably this was intended to help users who run kate with a command in a command window and don't want the command window blocked until the kate window is closed.

However this breaks things like git commit and sudoedit, since these wait for kate to exit and then check to see if the file was changed. Now that the original kate process exits immediately, the file hasn't changed. How can I stop kate from exec'ing itself?

The only way that I can think of is to move the real /usr/bin/kate to something like /usr/bin/realkate, and create a tiny shell script at /usr/bin/kate which does something like /usr/bin/realkate -b $*, but this will get overwritten on the next upgrade.

I tried alias kate='kate -b' in my .bashrc, but this only works if I run kate from the command line, not when git commit or sudoedit runs it.

Possibly this could be fixed in katerc, but there doesn't seem to be any documentation for that.

2
  • /usr/bin/realkate -b $* will not be overwritten by any upgrades, but as a matter of principle, you should create it in /usr/local/bin instead (see unix.stackexchange.com/questions/8656/…). Commented yesterday
  • 1
    Nitpick: the term you want here is not ‘execing’, it’s ‘forking’. If it were just calling exec(), there wouldn’t be a new process. Commented 20 hours ago

1 Answer 1

12

From the Kate manual (which you evidently are already aware of):

kate -b --block
If using an already running Kate instance, block until it exits, if URLs given to open.

You can use Kate with this option as editor for typing in commit messages for version control systems like Git or Subversion. These systems expect to block the editor till you have entered your message, because they then open the temporary file, which would be empty if Kate immediately returned to the caller.

This option is also needed with KIO (KDE Input/Output), if you open a remote file (which has been downloaded to a temporary) and should be reuploaded, after you saved it.

So, use kate -b or kate --block as your Git commit message editor. You would do this by setting the VISUAL or EDITOR environment variable to the editor command, possibly in your ~/.bashrc (or equivalent) file:

export VISUAL='kate -b'

Both git commit and visudo use these environment variables (with VISUAL having precedence over EDITOR), as do a large number of other utilities that have text-editing capabilities (mutt, mailx, and bash, to name only three), but for git and sudoedit, you can also define the editors for each separately:

export SUDO_EDITOR='kate -b'
export GIT_EDITOR='kate -b'

(Both these have higher precedence than the more general VISUAL variable.)

See, e.g., the visudo(8), git-commit(1), and git-var(1) manuals. The manuals will also let you know that you can set the editor in the system-wide configuration of sudo and in your personal git configuration, as an alternative to using environment variables.

Other utilities often mention in their manuals what specific environment variables (often EDITOR or VISUAL) or other configurable settings are used to specify a specific editor.

6
  • Yes, export EDITOR='kate -b' works for both git commit and sudoedit. Thanks to @Kusalananda for that. I expected sudoedit to use root's environment rather than the user's one since there might be a security weakness there, for example if someone had managed to hack my .bashrc and put their own directory in the PATH.... In fact it does use my environment, at least for EDITOR. Commented 21 hours ago
  • SUDO does use my PATH. So if someone manages to hack my .bashrc, the next time I use sudoedit, they can run their own version of kate, which could do anything since it's running as root. I don't let anyone else touch my machine, but for a multi-user system I think this is a potential security weakness. An attacker only has to persuade me to run a program which modifies my PATH as well as doing what it is supposed to do. The fake version of kate can exec the real kate unless it is being run as root. How often do people check their PATH variable or their .bashrc? Commented 21 hours ago
  • 1
    @RichardParkins What luck, then, that the editor that is invoked by sudoedit, is only ever executed as the sudo-invoking user, on a copy of the file that is being edited. See the manual (the description of the -e option of sudo). Also, if someone "hacks your .bashrc", you've already lost and whatever command you run is compromised, even your login shell. You can always bypass the PATH lookup by specifying the full path to the editor in the environment variable's value, if that makes you feel safer.
    – Kusalananda
    Commented 19 hours ago
  • SUDO, however, as I noted, can execute any command I specify, with my PATH. I appreciate that is someone hacks my .bashrc I'm already compromised, but in principle I can't mess with things that require root privilege unless I sudo. What I'm concerned about here is escalation of privilege, which is a classic attack strategy. It is, and should be, quite hard to attack root directly. It isn't necessarily as hard to attack individual users, who probably aren't as careful in their own sandbox as they are when using sudo. However sudo using the user's path escalates privilege. Commented 17 hours ago
  • @RichardParkins If you want to know how to set up a particular value for the PATH variable when using sudo, you should ask a question about that (or look for existing questions relating to this). It seems tangential to the issue at hand, though, which is about using the Kate editor with git commit and sudoedit. The sudoedit command does not run the editor as any other user than the invoking user.
    – Kusalananda
    Commented 9 hours ago

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.