etc 1.1.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +0 -2
- data/ext/etc/etc.c +48 -12
- data/ext/etc/extconf.rb +5 -0
- data/test/etc/test_etc.rb +25 -2
- metadata +7 -7
- data/stub/etc.rb +0 -1
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 5f5196e40206894d4fc74d486106863f351e131e89fa6017807542361a09c617
         | 
| 4 | 
            +
              data.tar.gz: 131ade148fb05d021a9956ee282722012abbc0607f87bfa15bd06a0374264a4a
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 210712686ace4800e20dbc1c4f97ead9a352f6d65dc794bb0033f55da286ec730bef1269f5b9479b4f600a87a55a31470f7596b83ddc705aeb5f194618646e37
         | 
| 7 | 
            +
              data.tar.gz: aa0cba8840eb405a1b80339d82c44b2c582e97b2cab1db8d7ad05f315ac1a78325c421698b94a53283302702f5ea2a669221bfbf84f0be88bf880fc863ade405
         | 
    
        data/README.md
    CHANGED
    
    | @@ -1,7 +1,5 @@ | |
| 1 1 | 
             
            # Etc
         | 
| 2 2 |  | 
| 3 | 
            -
            [](https://travis-ci.org/ruby/etc)
         | 
| 4 | 
            -
             | 
| 5 3 | 
             
            The Etc module provides access to information typically stored in files in the /etc directory on Unix systems.
         | 
| 6 4 |  | 
| 7 5 | 
             
            The information accessible consists of the information found in the `/etc/passwd` and `/etc/group` files, plus information about he system's temporary directory (/tmp) and configuration directory (/etc).
         | 
    
        data/ext/etc/etc.c
    CHANGED
    
    | @@ -52,10 +52,34 @@ char *getenv(); | |
| 52 52 | 
             
            #endif
         | 
| 53 53 | 
             
            char *getlogin();
         | 
| 54 54 |  | 
| 55 | 
            -
            #define RUBY_ETC_VERSION "1. | 
| 55 | 
            +
            #define RUBY_ETC_VERSION "1.2.0"
         | 
| 56 | 
            +
             | 
| 57 | 
            +
            #ifdef HAVE_RB_DEPRECATE_CONSTANT
         | 
| 58 | 
            +
            void rb_deprecate_constant(VALUE mod, const char *name);
         | 
| 59 | 
            +
            #else
         | 
| 60 | 
            +
            # define rb_deprecate_constant(mod,name) ((void)(mod),(void)(name))
         | 
| 61 | 
            +
            #endif
         | 
| 56 62 |  | 
| 57 63 | 
             
            #include "constdefs.h"
         | 
| 58 64 |  | 
| 65 | 
            +
            #ifdef HAVE_RB_EXT_RACTOR_SAFE
         | 
| 66 | 
            +
            #include "ruby/thread_native.h"
         | 
| 67 | 
            +
            #else
         | 
| 68 | 
            +
            /* Implement rb_native_mutex_x using an int */
         | 
| 69 | 
            +
            typedef int rb_nativethread_lock_t;
         | 
| 70 | 
            +
            static int rb_native_mutex_trylock(int *mutex) {
         | 
| 71 | 
            +
                if (*mutex) {
         | 
| 72 | 
            +
                	return 1;
         | 
| 73 | 
            +
                }
         | 
| 74 | 
            +
                *mutex = 1;
         | 
| 75 | 
            +
                return 0;
         | 
| 76 | 
            +
            }
         | 
| 77 | 
            +
            static void rb_native_mutex_unlock(int *mutex) {
         | 
| 78 | 
            +
                *mutex = 0;
         | 
| 79 | 
            +
            }
         | 
| 80 | 
            +
            #define rb_native_mutex_initialize rb_native_mutex_unlock
         | 
| 81 | 
            +
            #endif
         | 
| 82 | 
            +
             | 
| 59 83 | 
             
            /* call-seq:
         | 
| 60 84 | 
             
             *	getlogin	->  String
         | 
| 61 85 | 
             
             *
         | 
| @@ -119,6 +143,12 @@ safe_setup_filesystem_str(const char *str) | |
| 119 143 | 
             
            #endif
         | 
| 120 144 |  | 
| 121 145 | 
             
            #ifdef HAVE_GETPWENT
         | 
| 146 | 
            +
            # ifdef __APPLE__
         | 
| 147 | 
            +
            #   define PW_TIME2VAL(t) INT2NUM((int)(t))
         | 
| 148 | 
            +
            # else
         | 
| 149 | 
            +
            #   define PW_TIME2VAL(t) TIMET2NUM(t)
         | 
| 150 | 
            +
            # endif
         | 
| 151 | 
            +
             | 
| 122 152 | 
             
            static VALUE
         | 
| 123 153 | 
             
            setup_passwd(struct passwd *pwd)
         | 
| 124 154 | 
             
            {
         | 
| @@ -136,7 +166,7 @@ setup_passwd(struct passwd *pwd) | |
| 136 166 | 
             
            			 safe_setup_filesystem_str(pwd->pw_dir),
         | 
| 137 167 | 
             
            			 safe_setup_filesystem_str(pwd->pw_shell),
         | 
| 138 168 | 
             
            #ifdef HAVE_STRUCT_PASSWD_PW_CHANGE
         | 
| 139 | 
            -
            			  | 
| 169 | 
            +
            			 PW_TIME2VAL(pwd->pw_change),
         | 
| 140 170 | 
             
            #endif
         | 
| 141 171 | 
             
            #ifdef HAVE_STRUCT_PASSWD_PW_QUOTA
         | 
| 142 172 | 
             
            			 INT2NUM(pwd->pw_quota),
         | 
| @@ -151,7 +181,7 @@ setup_passwd(struct passwd *pwd) | |
| 151 181 | 
             
            			 safe_setup_locale_str(pwd->pw_comment),
         | 
| 152 182 | 
             
            #endif
         | 
| 153 183 | 
             
            #ifdef HAVE_STRUCT_PASSWD_PW_EXPIRE
         | 
| 154 | 
            -
            			  | 
| 184 | 
            +
            			 PW_TIME2VAL(pwd->pw_expire),
         | 
| 155 185 | 
             
            #endif
         | 
| 156 186 | 
             
            			 0		/*dummy*/
         | 
| 157 187 | 
             
            	);
         | 
| @@ -228,12 +258,12 @@ etc_getpwnam(VALUE obj, VALUE nam) | |
| 228 258 | 
             
            }
         | 
| 229 259 |  | 
| 230 260 | 
             
            #ifdef HAVE_GETPWENT
         | 
| 231 | 
            -
            static  | 
| 261 | 
            +
            static rb_nativethread_lock_t passwd_blocking;
         | 
| 232 262 | 
             
            static VALUE
         | 
| 233 263 | 
             
            passwd_ensure(VALUE _)
         | 
| 234 264 | 
             
            {
         | 
| 235 265 | 
             
                endpwent();
         | 
| 236 | 
            -
                passwd_blocking | 
| 266 | 
            +
                rb_native_mutex_unlock(&passwd_blocking);
         | 
| 237 267 | 
             
                return Qnil;
         | 
| 238 268 | 
             
            }
         | 
| 239 269 |  | 
| @@ -252,10 +282,9 @@ passwd_iterate(VALUE _) | |
| 252 282 | 
             
            static void
         | 
| 253 283 | 
             
            each_passwd(void)
         | 
| 254 284 | 
             
            {
         | 
| 255 | 
            -
                if (passwd_blocking) {
         | 
| 285 | 
            +
                if (rb_native_mutex_trylock(&passwd_blocking)) {
         | 
| 256 286 | 
             
            	rb_raise(rb_eRuntimeError, "parallel passwd iteration");
         | 
| 257 287 | 
             
                }
         | 
| 258 | 
            -
                passwd_blocking = (int)Qtrue;
         | 
| 259 288 | 
             
                rb_ensure(passwd_iterate, 0, passwd_ensure, 0);
         | 
| 260 289 | 
             
            }
         | 
| 261 290 | 
             
            #endif
         | 
| @@ -471,12 +500,12 @@ etc_getgrnam(VALUE obj, VALUE nam) | |
| 471 500 | 
             
            }
         | 
| 472 501 |  | 
| 473 502 | 
             
            #ifdef HAVE_GETGRENT
         | 
| 474 | 
            -
            static  | 
| 503 | 
            +
            static rb_nativethread_lock_t group_blocking;
         | 
| 475 504 | 
             
            static VALUE
         | 
| 476 505 | 
             
            group_ensure(VALUE _)
         | 
| 477 506 | 
             
            {
         | 
| 478 507 | 
             
                endgrent();
         | 
| 479 | 
            -
                group_blocking | 
| 508 | 
            +
                rb_native_mutex_unlock(&group_blocking);
         | 
| 480 509 | 
             
                return Qnil;
         | 
| 481 510 | 
             
            }
         | 
| 482 511 |  | 
| @@ -496,10 +525,9 @@ group_iterate(VALUE _) | |
| 496 525 | 
             
            static void
         | 
| 497 526 | 
             
            each_group(void)
         | 
| 498 527 | 
             
            {
         | 
| 499 | 
            -
                if (group_blocking) {
         | 
| 528 | 
            +
                if (rb_native_mutex_trylock(&group_blocking)) {
         | 
| 500 529 | 
             
            	rb_raise(rb_eRuntimeError, "parallel group iteration");
         | 
| 501 530 | 
             
                }
         | 
| 502 | 
            -
                group_blocking = (int)Qtrue;
         | 
| 503 531 | 
             
                rb_ensure(group_iterate, 0, group_ensure, 0);
         | 
| 504 532 | 
             
            }
         | 
| 505 533 | 
             
            #endif
         | 
| @@ -1064,6 +1092,9 @@ Init_etc(void) | |
| 1064 1092 | 
             
            {
         | 
| 1065 1093 | 
             
                VALUE mEtc;
         | 
| 1066 1094 |  | 
| 1095 | 
            +
                #ifdef HAVE_RB_EXT_RACTOR_SAFE
         | 
| 1096 | 
            +
            	RB_EXT_RACTOR_SAFE(true);
         | 
| 1097 | 
            +
                #endif
         | 
| 1067 1098 | 
             
                mEtc = rb_define_module("Etc");
         | 
| 1068 1099 | 
             
                rb_define_const(mEtc, "VERSION", rb_str_new_cstr(RUBY_ETC_VERSION));
         | 
| 1069 1100 | 
             
                init_constants(mEtc);
         | 
| @@ -1165,10 +1196,14 @@ Init_etc(void) | |
| 1165 1196 | 
             
                rb_define_const(mEtc, "Passwd", sPasswd);
         | 
| 1166 1197 | 
             
            #endif
         | 
| 1167 1198 | 
             
                rb_define_const(rb_cStruct, "Passwd", sPasswd); /* deprecated name */
         | 
| 1199 | 
            +
                rb_deprecate_constant(rb_cStruct, "Passwd");
         | 
| 1168 1200 | 
             
                rb_extend_object(sPasswd, rb_mEnumerable);
         | 
| 1169 1201 | 
             
                rb_define_singleton_method(sPasswd, "each", etc_each_passwd, 0);
         | 
| 1170 | 
            -
             | 
| 1202 | 
            +
            #ifdef HAVE_GETPWENT
         | 
| 1203 | 
            +
                rb_native_mutex_initialize(&passwd_blocking);
         | 
| 1204 | 
            +
            #endif
         | 
| 1171 1205 | 
             
            #ifdef HAVE_GETGRENT
         | 
| 1206 | 
            +
                rb_native_mutex_initialize(&group_blocking);
         | 
| 1172 1207 | 
             
                sGroup = rb_struct_define_under(mEtc, "Group", "name",
         | 
| 1173 1208 | 
             
            #ifdef HAVE_STRUCT_GROUP_GR_PASSWD
         | 
| 1174 1209 | 
             
            				    "passwd",
         | 
| @@ -1200,6 +1235,7 @@ Init_etc(void) | |
| 1200 1235 | 
             
                rb_define_const(mEtc, "Group", sGroup);
         | 
| 1201 1236 | 
             
            #endif
         | 
| 1202 1237 | 
             
                rb_define_const(rb_cStruct, "Group", sGroup); /* deprecated name */
         | 
| 1238 | 
            +
                rb_deprecate_constant(rb_cStruct, "Group");
         | 
| 1203 1239 | 
             
                rb_extend_object(sGroup, rb_mEnumerable);
         | 
| 1204 1240 | 
             
                rb_define_singleton_method(sGroup, "each", etc_each_group, 0);
         | 
| 1205 1241 | 
             
            #endif
         | 
    
        data/ext/etc/extconf.rb
    CHANGED
    
    | @@ -47,6 +47,11 @@ if !File.exist?("#{srcdir}/depend") | |
| 47 47 | 
             
              %x[#{RbConfig.ruby} #{srcdir}/mkconstants.rb -o #{srcdir}/constdefs.h]
         | 
| 48 48 | 
             
            end
         | 
| 49 49 |  | 
| 50 | 
            +
            decl = [
         | 
| 51 | 
            +
              "void rb_deprecate_constant(VALUE, const char *);",
         | 
| 52 | 
            +
            ]
         | 
| 53 | 
            +
            have_func('rb_deprecate_constant(Qnil, "None")', [decl])
         | 
| 54 | 
            +
             | 
| 50 55 | 
             
            $distcleanfiles << "constdefs.h"
         | 
| 51 56 |  | 
| 52 57 | 
             
            create_makefile("etc")
         | 
    
        data/test/etc/test_etc.rb
    CHANGED
    
    | @@ -44,7 +44,7 @@ class TestEtc < Test::Unit::TestCase | |
| 44 44 | 
             
                unless s.empty?
         | 
| 45 45 | 
             
                  assert_include(s, Etc.getpwuid)
         | 
| 46 46 | 
             
                end
         | 
| 47 | 
            -
              end
         | 
| 47 | 
            +
              end unless RUBY_PLATFORM.include?("android")
         | 
| 48 48 |  | 
| 49 49 | 
             
              def test_getpwnam
         | 
| 50 50 | 
             
                passwd = {}
         | 
| @@ -54,7 +54,7 @@ class TestEtc < Test::Unit::TestCase | |
| 54 54 | 
             
                passwd.each_value do |s|
         | 
| 55 55 | 
             
                  assert_equal(s, Etc.getpwnam(s.name))
         | 
| 56 56 | 
             
                end
         | 
| 57 | 
            -
              end
         | 
| 57 | 
            +
              end unless RUBY_PLATFORM.include?("android")
         | 
| 58 58 |  | 
| 59 59 | 
             
              def test_passwd_with_low_level_api
         | 
| 60 60 | 
             
                a = []
         | 
| @@ -169,4 +169,27 @@ class TestEtc < Test::Unit::TestCase | |
| 169 169 | 
             
                assert_operator(1, :<=, n)
         | 
| 170 170 | 
             
              end
         | 
| 171 171 |  | 
| 172 | 
            +
              def test_ractor
         | 
| 173 | 
            +
                return unless Etc.passwd # => skip test if no platform support
         | 
| 174 | 
            +
             | 
| 175 | 
            +
                assert_ractor(<<~RUBY, require: 'etc')
         | 
| 176 | 
            +
                  ractor = Ractor.new do
         | 
| 177 | 
            +
                    Etc.passwd do |s|
         | 
| 178 | 
            +
                      Ractor.yield :sync
         | 
| 179 | 
            +
                      Ractor.yield s.name
         | 
| 180 | 
            +
                      break :done
         | 
| 181 | 
            +
                    end
         | 
| 182 | 
            +
                  end
         | 
| 183 | 
            +
                  ractor.take # => :sync
         | 
| 184 | 
            +
                  assert_raise RuntimeError, /parallel/ do
         | 
| 185 | 
            +
                    Etc.passwd {}
         | 
| 186 | 
            +
                  end
         | 
| 187 | 
            +
                  name = ractor.take # => first name
         | 
| 188 | 
            +
                  ractor.take # => :done
         | 
| 189 | 
            +
                  name2 = Etc.passwd do |s|
         | 
| 190 | 
            +
                    break s.name
         | 
| 191 | 
            +
                  end
         | 
| 192 | 
            +
                  assert_equal(name2, name)
         | 
| 193 | 
            +
                RUBY
         | 
| 194 | 
            +
              end
         | 
| 172 195 | 
             
            end
         | 
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: etc
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 1. | 
| 4 | 
            +
              version: 1.2.0
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Yukihiro Matsumoto
         | 
| 8 | 
            -
            autorequire: | 
| 8 | 
            +
            autorequire:
         | 
| 9 9 | 
             
            bindir: exe
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date:  | 
| 11 | 
            +
            date: 2020-12-23 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: bundler
         | 
| @@ -80,13 +80,13 @@ files: | |
| 80 80 | 
             
            - ext/etc/etc.c
         | 
| 81 81 | 
             
            - ext/etc/extconf.rb
         | 
| 82 82 | 
             
            - ext/etc/mkconstants.rb
         | 
| 83 | 
            -
            - stub/etc.rb
         | 
| 84 83 | 
             
            - test/etc/test_etc.rb
         | 
| 85 84 | 
             
            homepage: https://github.com/ruby/etc
         | 
| 86 85 | 
             
            licenses:
         | 
| 86 | 
            +
            - Ruby
         | 
| 87 87 | 
             
            - BSD-2-Clause
         | 
| 88 88 | 
             
            metadata: {}
         | 
| 89 | 
            -
            post_install_message: | 
| 89 | 
            +
            post_install_message:
         | 
| 90 90 | 
             
            rdoc_options: []
         | 
| 91 91 | 
             
            require_paths:
         | 
| 92 92 | 
             
            - lib
         | 
| @@ -101,8 +101,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement | |
| 101 101 | 
             
                - !ruby/object:Gem::Version
         | 
| 102 102 | 
             
                  version: '0'
         | 
| 103 103 | 
             
            requirements: []
         | 
| 104 | 
            -
            rubygems_version: 3. | 
| 105 | 
            -
            signing_key: | 
| 104 | 
            +
            rubygems_version: 3.2.2
         | 
| 105 | 
            +
            signing_key:
         | 
| 106 106 | 
             
            specification_version: 4
         | 
| 107 107 | 
             
            summary: Provides access to information typically stored in UNIX /etc directory.
         | 
| 108 108 | 
             
            test_files: []
         | 
    
        data/stub/etc.rb
    DELETED
    
    | @@ -1 +0,0 @@ | |
| 1 | 
            -
            require "#{RUBY_VERSION[/\d+\.\d+/]}/etc.so"
         |