0

I use Vim as my editor.

I wanted to have syntax colouring when editing Crontab with crontab -e. I followed this answer. After setting variable EDITOR=vim and exporting it crontab -e now shows syntax colours like I wanted. I am editing Crontab as my own user, not using Sudo.

However this causes error when closing Crontab:

/tmp/crontab.019kNj" 4L, 278C written
E886: Can't rename viminfo file to /home/me/.viminfo!
Press ENTER or type command to continue

This happens both when saving changes and when closing without saving. Error happens only with Crontab, editing files directly with Vim works without problem. Behavior is similar when using variable VISUAL instead of EDITOR.

The file .viminfo exists in my home dir and has sensible permissions:

-rw-------.  1 me me  11K 15.10. 12:49 .viminfo

Permissions of /home/me make sense too:

drwx------. 33 me me   4,0K 15.10. 13:13 me

OS version is Red Hat Enterprise Linux Workstation release 7.9 (Maipo), Vim version is VIM - Vi IMproved 7.4 (2013 Aug 10, compiled Jan 29 2020 08:09:16) and shell is GNU bash, version 4.2.46(2)-release (x86_64-redhat-linux-gnu). Version of Crontab is crontabs-1.11-6.20121102git.el7.noarch.

What is causing this error message and how can I enable syntax colouring when editing Crontab without it?

EDIT:

If I rename .viminfo the error changes:

E138: Cannot write viminfo file /home/me/.viminfo!
6
  • 2
    Using vim as usual does not cause the same type of diagnostic message? – Kusalananda Oct 15 '20 at 10:22
  • @Kusalananda No, messages don't appear with normal Vim use. – Madoc Comadrin Oct 15 '20 at 11:44
  • 1
    @roaima Added information to original post, permissions are sensible. – Madoc Comadrin Oct 15 '20 at 11:46
  • And are /tmp permissions alright? It would be nice to see the permissions of all directories and files involved in the error message. – Quasímodo Oct 15 '20 at 13:44
  • What version does vim --version | head -n1 show you? Specifically, is it more recent than 8.0, as there was a bug that got fixed in 8.0.1024 – roaima Oct 15 '20 at 13:49
2

Turns out that this was caused by Selinux policy preventing Crontab from writing to home directories. Similar case has been reported in Red Hat bugtracker:

Runing "crontab -e" with EDITOR=vim and do some changes to the cron file. When quit from the vim, always gets a warning message: E138: Can't write viminfo file /home/hpt/.viminfo! and some avc messages in /var/log/messages:

Jun 15 13:51:24 localhost kernel: type=1400 audit(1245045084.399:17236): avc: denied { write } for pid=24910 comm="vim" name="hpt" dev=dm-6 ino=2301953 scontext=unconfined_u:unconfined_r:admin_crontab_t:s0-s0:c0.c1023 tcontext=system_u:object_r:user_home_dir_t:s0 tclass=dir Jun 15 13:51:24 localhost kernel: type=1400 audit(1245045084.400:17237): avc: denied { create } for pid=24910 comm="vim" name="v69994" scontext=unconfined_u:unconfined_r:admin_crontab_t:s0-s0:c0.c1023 tcontext=unconfined_u:object_r:tmp_t:s0 tclass=dir Jun 15 13:51:24 localhost kernel: type=1400 audit(1245045084.400:17238): avc: denied { write } for pid=24910 comm="vim" name="hpt" dev=dm-6 ino=2301953 scontext=unconfined_u:unconfined_r:admin_crontab_t:s0-s0:c0.c1023 tcontext=system_u:object_r:user_home_dir_t:s0 tclass=dir Version-Release number of selected component (if applicable):

Solution is changing the policy to allow this. I don't have details on that change as I don't have Sudo access to this machine so change was done by someone else.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.