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!
Madoc Comadrin
  • 218
  • 3
  • 11

1 Answers1

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.

Madoc Comadrin
  • 218
  • 3
  • 11