ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:82821] [Ruby trunk Bug#13907] Operation not permitted (Errno::EPERM) when adjusting .irbrc_history file permissions
       [not found] <redmine.issue-13907.20170915164941@ruby-lang.org>
@ 2017-09-15 16:49 ` aheaven87
  2017-09-15 20:13 ` [ruby-core:82824] " shevegen
  2019-06-24 18:19 ` [ruby-core:93338] " merch-redmine
  2 siblings, 0 replies; 3+ messages in thread
From: aheaven87 @ 2017-09-15 16:49 UTC (permalink / raw
  To: ruby-core

Issue #13907 has been reported by heaven (Alexander S.).

----------------------------------------
Bug #13907: Operation not permitted (Errno::EPERM) when adjusting .irbrc_history file permissions
https://bugs.ruby-lang.org/issues/13907

* Author: heaven (Alexander S.)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: ruby 2.3.3p222 (2016-11-21 revision 56859) [x86_64-linux]
* Backport: 2.2: UNKNOWN, 2.3: UNKNOWN, 2.4: UNKNOWN
----------------------------------------
This is happening every time I close irb on the server:
```
$ bin/rails console
Loading staging environment (Rails 5.1.3)
2.3.0 :001 > IRB.conf[:SAVE_HISTORY]
 => 100
2.3.0 :002 > IRB.conf[:HISTORY_FILE]
 => nil
2.3.0 :003 > IRB.rc_file("_history")
 => "/usr/local/rvm/rubies/ruby-2.3.3/.irbrc_history"
2.3.0 :004 > exit
/usr/local/rvm/rubies/ruby-2.3.3/lib/ruby/2.3.0/irb/ext/save-history.rb:91:in `chmod': Operation not permitted @ chmod_internal - /usr/local/rvm/rubies/ruby-2.3.3/.irbrc_history (Errno::EPERM)
	from /usr/local/rvm/rubies/ruby-2.3.3/lib/ruby/2.3.0/irb/ext/save-history.rb:91:in `save_history'
	from /usr/local/rvm/rubies/ruby-2.3.3/lib/ruby/2.3.0/irb/ext/save-history.rb:64:in `block in extended'
	from /usr/local/rvm/rubies/ruby-2.3.3/lib/ruby/2.3.0/irb.rb:404:in `block in irb_at_exit'
	from /usr/local/rvm/rubies/ruby-2.3.3/lib/ruby/2.3.0/irb.rb:404:in `each'
	from /usr/local/rvm/rubies/ruby-2.3.3/lib/ruby/2.3.0/irb.rb:404:in `irb_at_exit'
	from /usr/local/rvm/rubies/ruby-2.3.3/lib/ruby/2.3.0/irb.rb:398:in `start'
	from /var/www/crm.wegohealth.com/shared/bundle/ruby/2.3.0/gems/railties-5.1.3/lib/rails/commands/console/console_command.rb:62:in `start'
	from /var/www/crm.wegohealth.com/shared/bundle/ruby/2.3.0/gems/railties-5.1.3/lib/rails/commands/console/console_command.rb:17:in `start'
	from /var/www/crm.wegohealth.com/shared/bundle/ruby/2.3.0/gems/railties-5.1.3/lib/rails/commands/console/console_command.rb:85:in `perform'
	from /var/www/crm.wegohealth.com/shared/bundle/ruby/2.3.0/gems/thor-0.20.0/lib/thor/command.rb:27:in `run'
	from /var/www/crm.wegohealth.com/shared/bundle/ruby/2.3.0/gems/thor-0.20.0/lib/thor/invocation.rb:126:in `invoke_command'
	from /var/www/crm.wegohealth.com/shared/bundle/ruby/2.3.0/gems/thor-0.20.0/lib/thor.rb:387:in `dispatch'
	from /var/www/crm.wegohealth.com/shared/bundle/ruby/2.3.0/gems/railties-5.1.3/lib/rails/command/base.rb:63:in `perform'
	from /var/www/crm.wegohealth.com/shared/bundle/ruby/2.3.0/gems/railties-5.1.3/lib/rails/command.rb:44:in `invoke'
	from /var/www/crm.wegohealth.com/shared/bundle/ruby/2.3.0/gems/railties-5.1.3/lib/rails/commands.rb:16:in `<top (required)>'
	from bin/rails:10:in `require'
	from bin/rails:10:in `<main>'
```

IRB is trying to adjust file permissions `File.chmod(0600, history_file)` which isn't possible because the file owner is root:rvm. I am not sure if this is really an IRB bug or not, but perhaps it should check the owner first.

```
$ ls -la /usr/local/rvm/rubies/ruby-2.3.3/
total 36
drwxrwsr-x 6 root rvm 4096 Sep 15 11:46 .
drwxrwsr-x 4 root rvm 4096 Aug 14 12:05 ..
drwxrwsr-x 2 root rvm 4096 Aug 14 12:05 bin
-rw-rw-r-- 1 root rvm 7954 Aug 14 12:05 config
drwxrwsr-x 3 root rvm 4096 Aug 14 12:05 include
-rwxrwxr-x 1 root rvm  406 Aug 14 12:05 .irbrc
-rw-rw-r-- 1 root rvm    0 Sep 15 12:28 .irbrc_history
drwxrwsr-x 4 root rvm 4096 Aug 14 12:05 lib
drwxrwsr-x 3 root rvm 4096 Aug 14 12:05 share
```



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [ruby-core:82824] [Ruby trunk Bug#13907] Operation not permitted (Errno::EPERM) when adjusting .irbrc_history file permissions
       [not found] <redmine.issue-13907.20170915164941@ruby-lang.org>
  2017-09-15 16:49 ` [ruby-core:82821] [Ruby trunk Bug#13907] Operation not permitted (Errno::EPERM) when adjusting .irbrc_history file permissions aheaven87
@ 2017-09-15 20:13 ` shevegen
  2019-06-24 18:19 ` [ruby-core:93338] " merch-redmine
  2 siblings, 0 replies; 3+ messages in thread
From: shevegen @ 2017-09-15 20:13 UTC (permalink / raw
  To: ruby-core

Issue #13907 has been updated by shevegen (Robert A. Heiler).


I am pretty sure that this is a small bug in IRB. It is a method in IRB itself,
so it should be the responsibility of IRB to handle cases like the above
properly.

The method looks like this:

    def save_history
      if num = IRB.conf[:SAVE_HISTORY] and (num = num.to_i) > 0
        if history_file = IRB.conf[:HISTORY_FILE]
          history_file = File.expand_path(history_file)
        end
        history_file = IRB.rc_file("_history") unless history_file

        # Change the permission of a file that already exists[BUG #7694]
        begin
          if File.stat(history_file).mode & 066 != 0
            File.chmod(0600, history_file)
          end
        rescue Errno::ENOENT
        rescue
          raise
        end

        open(history_file, 'w', 0600 ) do |f|
          hist = HISTORY.to_a
          f.puts(hist[-num..-1] || hist)
        end
      end
    end


The problem should be at:

    if File.stat(history_file).mode & 066 != 0
        File.chmod(0600, history_file)

I don't have 2.3.3. so I can not check if this still exists in
more recent versions of IRB. But I think that in general, 
there should either be a check BEFORE File.chmod, to see whether
we can modify the file in question - this may be more elegant.

Or alternatively, Errno::EPERM should also be rescued. (In the
above check, with proper permissions, one can probably change it
within ruby + irb; whereas, without proper permissions, I do
not think that ruby can do something if you lack permissions to
the filesystem.)

But anyway, I agree with you - IRB should check for the proper 
permission.

PS: The old bug referenced here was from 4 years ago at:

https://bugs.ruby-lang.org/issues/7694

----------------------------------------
Bug #13907: Operation not permitted (Errno::EPERM) when adjusting .irbrc_history file permissions
https://bugs.ruby-lang.org/issues/13907#change-66704

* Author: heaven (Alexander S.)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: ruby 2.3.3p222 (2016-11-21 revision 56859) [x86_64-linux]
* Backport: 2.2: UNKNOWN, 2.3: UNKNOWN, 2.4: UNKNOWN
----------------------------------------
This is happening every time I close irb on the server:
```
$ bin/rails console
Loading staging environment (Rails 5.1.3)
2.3.0 :001 > IRB.conf[:SAVE_HISTORY]
 => 100
2.3.0 :002 > IRB.conf[:HISTORY_FILE]
 => nil
2.3.0 :003 > IRB.rc_file("_history")
 => "/usr/local/rvm/rubies/ruby-2.3.3/.irbrc_history"
2.3.0 :004 > exit
/usr/local/rvm/rubies/ruby-2.3.3/lib/ruby/2.3.0/irb/ext/save-history.rb:91:in `chmod': Operation not permitted @ chmod_internal - /usr/local/rvm/rubies/ruby-2.3.3/.irbrc_history (Errno::EPERM)
	from /usr/local/rvm/rubies/ruby-2.3.3/lib/ruby/2.3.0/irb/ext/save-history.rb:91:in `save_history'
	from /usr/local/rvm/rubies/ruby-2.3.3/lib/ruby/2.3.0/irb/ext/save-history.rb:64:in `block in extended'
	from /usr/local/rvm/rubies/ruby-2.3.3/lib/ruby/2.3.0/irb.rb:404:in `block in irb_at_exit'
	from /usr/local/rvm/rubies/ruby-2.3.3/lib/ruby/2.3.0/irb.rb:404:in `each'
	from /usr/local/rvm/rubies/ruby-2.3.3/lib/ruby/2.3.0/irb.rb:404:in `irb_at_exit'
	from /usr/local/rvm/rubies/ruby-2.3.3/lib/ruby/2.3.0/irb.rb:398:in `start'
	from /var/www/crm.wegohealth.com/shared/bundle/ruby/2.3.0/gems/railties-5.1.3/lib/rails/commands/console/console_command.rb:62:in `start'
	from /var/www/crm.wegohealth.com/shared/bundle/ruby/2.3.0/gems/railties-5.1.3/lib/rails/commands/console/console_command.rb:17:in `start'
	from /var/www/crm.wegohealth.com/shared/bundle/ruby/2.3.0/gems/railties-5.1.3/lib/rails/commands/console/console_command.rb:85:in `perform'
	from /var/www/crm.wegohealth.com/shared/bundle/ruby/2.3.0/gems/thor-0.20.0/lib/thor/command.rb:27:in `run'
	from /var/www/crm.wegohealth.com/shared/bundle/ruby/2.3.0/gems/thor-0.20.0/lib/thor/invocation.rb:126:in `invoke_command'
	from /var/www/crm.wegohealth.com/shared/bundle/ruby/2.3.0/gems/thor-0.20.0/lib/thor.rb:387:in `dispatch'
	from /var/www/crm.wegohealth.com/shared/bundle/ruby/2.3.0/gems/railties-5.1.3/lib/rails/command/base.rb:63:in `perform'
	from /var/www/crm.wegohealth.com/shared/bundle/ruby/2.3.0/gems/railties-5.1.3/lib/rails/command.rb:44:in `invoke'
	from /var/www/crm.wegohealth.com/shared/bundle/ruby/2.3.0/gems/railties-5.1.3/lib/rails/commands.rb:16:in `<top (required)>'
	from bin/rails:10:in `require'
	from bin/rails:10:in `<main>'
```

IRB is trying to adjust file permissions `File.chmod(0600, history_file)` which isn't possible because the file owner is root:rvm. I am not sure if this is really an IRB bug or not, but perhaps it should check the owner first.

```
$ ls -la /usr/local/rvm/rubies/ruby-2.3.3/
total 36
drwxrwsr-x 6 root rvm 4096 Sep 15 11:46 .
drwxrwsr-x 4 root rvm 4096 Aug 14 12:05 ..
drwxrwsr-x 2 root rvm 4096 Aug 14 12:05 bin
-rw-rw-r-- 1 root rvm 7954 Aug 14 12:05 config
drwxrwsr-x 3 root rvm 4096 Aug 14 12:05 include
-rwxrwxr-x 1 root rvm  406 Aug 14 12:05 .irbrc
-rw-rw-r-- 1 root rvm    0 Sep 15 12:28 .irbrc_history
drwxrwsr-x 4 root rvm 4096 Aug 14 12:05 lib
drwxrwsr-x 3 root rvm 4096 Aug 14 12:05 share
```



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [ruby-core:93338] [Ruby trunk Bug#13907] Operation not permitted (Errno::EPERM) when adjusting .irbrc_history file permissions
       [not found] <redmine.issue-13907.20170915164941@ruby-lang.org>
  2017-09-15 16:49 ` [ruby-core:82821] [Ruby trunk Bug#13907] Operation not permitted (Errno::EPERM) when adjusting .irbrc_history file permissions aheaven87
  2017-09-15 20:13 ` [ruby-core:82824] " shevegen
@ 2019-06-24 18:19 ` merch-redmine
  2 siblings, 0 replies; 3+ messages in thread
From: merch-redmine @ 2019-06-24 18:19 UTC (permalink / raw
  To: ruby-core

Issue #13907 has been updated by jeremyevans0 (Jeremy Evans).

Assignee set to keiju (Keiju Ishitsuka)
Status changed from Open to Assigned

I'm not sure if this is a bug or not.  However, considering that irb ignores permission issues on `.irbrc` (not intentionally I think), I suppose it makes sense to also ignore permission issues on the history file.  I added a pull request in case the IRB maintainers want to make this change: https://github.com/ruby/irb/pull/19.

----------------------------------------
Bug #13907: Operation not permitted (Errno::EPERM) when adjusting .irbrc_history file permissions
https://bugs.ruby-lang.org/issues/13907#change-78823

* Author: heaven (Alexander S.)
* Status: Assigned
* Priority: Normal
* Assignee: keiju (Keiju Ishitsuka)
* Target version: 
* ruby -v: ruby 2.3.3p222 (2016-11-21 revision 56859) [x86_64-linux]
* Backport: 2.2: UNKNOWN, 2.3: UNKNOWN, 2.4: UNKNOWN
----------------------------------------
This is happening every time I close irb on the server:
```
$ bin/rails console
Loading staging environment (Rails 5.1.3)
2.3.0 :001 > IRB.conf[:SAVE_HISTORY]
 => 100
2.3.0 :002 > IRB.conf[:HISTORY_FILE]
 => nil
2.3.0 :003 > IRB.rc_file("_history")
 => "/usr/local/rvm/rubies/ruby-2.3.3/.irbrc_history"
2.3.0 :004 > exit
/usr/local/rvm/rubies/ruby-2.3.3/lib/ruby/2.3.0/irb/ext/save-history.rb:91:in `chmod': Operation not permitted @ chmod_internal - /usr/local/rvm/rubies/ruby-2.3.3/.irbrc_history (Errno::EPERM)
	from /usr/local/rvm/rubies/ruby-2.3.3/lib/ruby/2.3.0/irb/ext/save-history.rb:91:in `save_history'
	from /usr/local/rvm/rubies/ruby-2.3.3/lib/ruby/2.3.0/irb/ext/save-history.rb:64:in `block in extended'
	from /usr/local/rvm/rubies/ruby-2.3.3/lib/ruby/2.3.0/irb.rb:404:in `block in irb_at_exit'
	from /usr/local/rvm/rubies/ruby-2.3.3/lib/ruby/2.3.0/irb.rb:404:in `each'
	from /usr/local/rvm/rubies/ruby-2.3.3/lib/ruby/2.3.0/irb.rb:404:in `irb_at_exit'
	from /usr/local/rvm/rubies/ruby-2.3.3/lib/ruby/2.3.0/irb.rb:398:in `start'
	from /var/www/crm.wegohealth.com/shared/bundle/ruby/2.3.0/gems/railties-5.1.3/lib/rails/commands/console/console_command.rb:62:in `start'
	from /var/www/crm.wegohealth.com/shared/bundle/ruby/2.3.0/gems/railties-5.1.3/lib/rails/commands/console/console_command.rb:17:in `start'
	from /var/www/crm.wegohealth.com/shared/bundle/ruby/2.3.0/gems/railties-5.1.3/lib/rails/commands/console/console_command.rb:85:in `perform'
	from /var/www/crm.wegohealth.com/shared/bundle/ruby/2.3.0/gems/thor-0.20.0/lib/thor/command.rb:27:in `run'
	from /var/www/crm.wegohealth.com/shared/bundle/ruby/2.3.0/gems/thor-0.20.0/lib/thor/invocation.rb:126:in `invoke_command'
	from /var/www/crm.wegohealth.com/shared/bundle/ruby/2.3.0/gems/thor-0.20.0/lib/thor.rb:387:in `dispatch'
	from /var/www/crm.wegohealth.com/shared/bundle/ruby/2.3.0/gems/railties-5.1.3/lib/rails/command/base.rb:63:in `perform'
	from /var/www/crm.wegohealth.com/shared/bundle/ruby/2.3.0/gems/railties-5.1.3/lib/rails/command.rb:44:in `invoke'
	from /var/www/crm.wegohealth.com/shared/bundle/ruby/2.3.0/gems/railties-5.1.3/lib/rails/commands.rb:16:in `<top (required)>'
	from bin/rails:10:in `require'
	from bin/rails:10:in `<main>'
```

IRB is trying to adjust file permissions `File.chmod(0600, history_file)` which isn't possible because the file owner is root:rvm. I am not sure if this is really an IRB bug or not, but perhaps it should check the owner first.

```
$ ls -la /usr/local/rvm/rubies/ruby-2.3.3/
total 36
drwxrwsr-x 6 root rvm 4096 Sep 15 11:46 .
drwxrwsr-x 4 root rvm 4096 Aug 14 12:05 ..
drwxrwsr-x 2 root rvm 4096 Aug 14 12:05 bin
-rw-rw-r-- 1 root rvm 7954 Aug 14 12:05 config
drwxrwsr-x 3 root rvm 4096 Aug 14 12:05 include
-rwxrwxr-x 1 root rvm  406 Aug 14 12:05 .irbrc
-rw-rw-r-- 1 root rvm    0 Sep 15 12:28 .irbrc_history
drwxrwsr-x 4 root rvm 4096 Aug 14 12:05 lib
drwxrwsr-x 3 root rvm 4096 Aug 14 12:05 share
```



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-06-24 18:19 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <redmine.issue-13907.20170915164941@ruby-lang.org>
2017-09-15 16:49 ` [ruby-core:82821] [Ruby trunk Bug#13907] Operation not permitted (Errno::EPERM) when adjusting .irbrc_history file permissions aheaven87
2017-09-15 20:13 ` [ruby-core:82824] " shevegen
2019-06-24 18:19 ` [ruby-core:93338] " merch-redmine

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).