cms-sw / cms-git-tools

CMS Git Helpers
34 stars 26 forks source link

Do not use /dev/stdout or stderr, running under sudo fails with permission errors. #71

Closed dmitrijus closed 7 years ago

dmitrijus commented 10 years ago

Hi,

The scripts should not use /dev/stderr for redirection, It's a bad practice and it causes troubles for sudo/cron/whatever users (Permission denied).

This happens because:

echo a >&2
echo a >/dev/stderr 

are different - the later will try to open a file named /dev/stderr and it will fail, because the sudo user does not have the access rights to the pts. In other words, &2 can be duplicated and written to it, but it cannot be re-openned.

The "workaround" is to run the scripts either with -q option, or create virtual stdin/stdout via redirection: git-cms-init -ssh 2>&1 | cat .

Ideally, scripts should never open /dev/stderr or /dev/stdout, but if the redirection is necessary, it should be done via exec: echo a >somefile should become exec >somefile; echo a or if some special stream is necesarry, exec 5>test; echo "hello" >&5

I can modify the scripts to remove "git-command >DEBUG_STREAM" style redirections, reimplement "-q" and similar options via "exec 1> /dev/null". That might change the output and I have no idea whether it won't break other scripts.

Dmitrijus

dmitrijus commented 10 years ago

Another easy "work-around" is to use script(1):

exec script /dev/null

"script" is a command which captures (to a file, which is /dev/null in our case) anything you type and output, but more importantly, it has to reopen the stdin/out/err in order to capture them (and they are created with correct permissions).

Dmitrijus

ktf commented 10 years ago

Thanks for reporting this. Can you please specify why you were running git cms-addpkg via sudo / cron? In principle git-cms-* are for interactive usage and you are much better off using normal git commands if you need to do things non interactively. Of course if you have a patch for this it will not be rejected though.

dmitrijus commented 10 years ago

In online dqm we run our stuff inside a special dqmdev/dqmpro user, and we usually set up cmssw inside interactively via sudo bash.

Our code is changing quite often and the git tools are quite useful. I won't make a patch (for now), running under "script" solves the problem.

As for cron - I do not use it, but I remember Antanas and several summer students complaining about this bug.

fwyzard commented 8 years ago

Partially addressed by #78 .

cmsbuild commented 8 years ago

A new Issue was created by @dmitrijus Dmitrijus.

@davidlange6, @smuzaffar, @Dr15Jones can you please review it and eventually sign/assign? Thanks.

cms-bot commands are listed here cms-sw/cmssw#13029

fwyzard commented 7 years ago

@dmitrijus is this still an issue ?

dmitrijus commented 7 years ago

I did a quick check it and it seems to work fine. Thanks.