Professional Web Applications Themes

mkfifo in Ruby 1.8? - Ruby

Why is (the library call) mkfifo missing in Ruby 1.8? Is there a way to do it simply (without coding the trivial C stub) in Ruby, other than system("mkfifo #{path}") -- Basile STARYNKEVITCH http://starynkevitch.net/Basile/ email: basile<at>starynkevitch<dot>net aliases: basile<at>tunes<dot>org = bstarynk<at>nerim<dot>net 8, rue de la Fa´encerie, 92340 Bourg La Reine, France...

  1. #1

    Default mkfifo in Ruby 1.8?

    Why is (the library call) mkfifo missing in Ruby 1.8? Is there a way
    to do it simply (without coding the trivial C stub) in Ruby, other
    than system("mkfifo #{path}")



    --
    Basile STARYNKEVITCH http://starynkevitch.net/Basile/
    email: basile<at>starynkevitch<dot>net
    aliases: basile<at>tunes<dot>org = bstarynk<at>nerim<dot>net
    8, rue de la Fa´encerie, 92340 Bourg La Reine, France
    Basile Guest

  2. #2

    Default Re: mkfifo in Ruby 1.8?

    In article <lesours>,
    Basile Starynkevitch [news] <net> wrote: 

    You could use syscall :-) No I'm not advocating this seriously.

    # Linux 2.4

    SYS_mknod = 14
    S_IFIFO = 4096
    name = 'my_fifo'

    puts "result is #{syscall(SYS_mknod, name, 0666 | S_IFIFO)}"

    Mike
    --
    co.uk | The "`Stok' disclaimers" apply.
    http://www.stok.co.uk/~mike/ | GPG PGP Key 1024D/059913DA
    com | Fingerprint 0570 71CD 6790 7C28 3D60
    http://www.exegenix.com/ | 75D2 9EC4 C1C0 0599 13DA
    Mike Guest

  3. #3

    Default Re: mkfifo in Ruby 1.8?

    In article <lesours>, Basile Starynkevitch
    [news] wrote: 

    You could use the 'dl' library:

    require 'dl/import'

    module LIBC
    extend DL::Importable

    dlload 'libc.so.6'

    extern 'int mkfifo(char*, uint)'
    extern 'void perror(char*)'
    end

    if -1 == LIBC.mkfifo('foo', 007)
    LIBC.perror("mkfifo")
    end
    Tim Guest

  4. #4

    Default Re: mkfifo in Ruby 1.8?

    Hi,

    At Fri, 6 Feb 2004 16:45:01 +0900,
    Basile Starynkevitch [news] wrote in [ruby-talk:91680]: 

    Because just nobody has wanted it yet, perhaps.


    Index: configure.in
    ================================================== =================
    RCS file: /cvs/ruby/src/ruby/configure.in,v
    retrieving revision 1.223
    diff -u -2 -p -d -r1.223 configure.in
    --- configure.in 30 Jan 2004 17:39:04 -0000 1.223
    +++ configure.in 7 Feb 2004 02:17:56 -0000
    -397,5 +397,5 AC_CHECK_FUNCS(fmod killpg wait4 waitpid
    getpriority getrlimit dlopen sigprocmask sigaction _setjmp\
    setsid telldir seekdir fchmod mktime timegm cosh sinh tanh\
    - setuid setgid)
    + setuid setgid mkfifo mknod)
    AC_ARG_ENABLE(setreuid,
    [ --enable-setreuid use setreuid()/setregid() according to need even if obsolete.],
    Index: file.c
    ================================================== =================
    RCS file: /cvs/ruby/src/ruby/file.c,v
    retrieving revision 1.178
    diff -u -2 -p -d -r1.178 file.c
    --- file.c 4 Feb 2004 13:39:49 -0000 1.178
    +++ file.c 7 Feb 2004 03:07:22 -0000
    -3207,4 +3207,101 rb_f_test(argc, argv)
    }

    +/*
    + * call-seq:
    + * File.mknod(file_name, [type, [mode, [dev]]]) => 0
    + *
    + * Create a filesystem node (file, device special file or named pipe)
    + * named _file_name_, specified by _mode_ and _dev_.
    + *
    + * _type_ and _mode_ specifies the type and the permissions of node to
    + * be created respectively.
    + *
    + * The permissions are modified by the process's umask in the usual
    + * way: the permissions of the created node are (mode & ~umask).
    + *
    + * _type_ should be one of +?f+, +?c+, +?b+ and +?p+ to specify a
    + * normal file (which will be created empty), character special file,
    + * block special file or FIFO (named pipe), respectively, or +nil+,
    + * which will create a normal file.
    + */
    +
    +static VALUE
    +rb_file_s_mknod(argc, argv)
    + int argc;
    + VALUE *argv;
    +{
    +#ifdef HAVE_MKNOD
    + VALUE path, type, vmode, vdev;
    + int mode = 0666, dev = 0, t;
    +
    + rb_secure(4);
    + switch (rb_scan_args(argc, argv, "13", &path, &type, &vmode, &vdev)) {
    + case 4:
    + dev = NUM2INT(vdev);
    + case 3:
    + mode = NUM2INT(vmode) & ~S_IFMT;
    + }
    + SafeStringValue(path);
    + if (!NIL_P(type)) {
    + rb_check_safe_obj(type);
    + switch (t = NUM2CHR(type)) {
    + case 'f': mode |= S_IFREG; break;
    + case 'c': mode |= S_IFCHR; break;
    +#ifdef S_IFBLK
    + case 'b': mode |= S_IFBLK; break;
    +#endif
    +#ifdef S_IFIFO
    + case 'p': mode |= S_IFIFO; break;
    +#endif
    + default:
    + rb_raise(rb_eArgError, "unknown node type - %c", t);
    + }
    + }
    + if (mknod(RSTRING(path)->ptr, mode, dev)) {
    + rb_sys_fail(0);
    + }
    +#else
    + rb_notimplement();
    +#endif
    + return INT2FIX(0);
    +}
    +
    +/*
    + * call-seq:
    + * File.mkfifo(file_name, mode) => 0
    + *
    + * Creates a FIFO special file with name _file_name_. _mode_
    + * specifies the FIFO's permissions. It is modified by the process's
    + * umask in the usual way: the permissions of the created file are
    + * (mode & ~umask).
    + */
    +
    +static VALUE
    +rb_file_s_mkfifo(argc, argv)
    + int argc;
    + VALUE *argv;
    +{
    +#if !defined HAVE_MKFIFO && defined HAVE_MKNOD && defined S_IFIFO
    +#define mkfifo(path, mode) mknod(path, (mode)&~S_IFMT|S_IFIFO, 0)
    +#define HAVE_MKFIFO
    +#endif
    +#ifdef HAVE_MKFIFO
    + VALUE path, vmode;
    + int mode = 0666;
    +
    + rb_secure(4);
    + if (rb_scan_args(argc, argv, "11", &path, &vmode) > 1) {
    + mode = NUM2INT(vmode);
    + }
    + SafeStringValue(path);
    + if (mkfifo(RSTRING(path)->ptr, mode)) {
    + rb_sys_fail(0);
    + }
    +#else
    + rb_notimplement();
    +#endif
    + return INT2FIX(0);
    +}
    +


    -4209,4 +4306,6 Init_File()
    rb_define_singleton_method(rb_cFile, "umask", rb_file_s_umask, -1);
    rb_define_singleton_method(rb_cFile, "truncate", rb_file_s_truncate, 2);
    + rb_define_singleton_method(rb_cFile, "mknod", rb_file_s_mknod, -1);
    + rb_define_singleton_method(rb_cFile, "mkfifo", rb_file_s_mkfifo, -1);
    rb_define_singleton_method(rb_cFile, "expand_path", rb_file_s_expand_path, -1);
    rb_define_singleton_method(rb_cFile, "basename", rb_file_s_basename, -1);


    --
    Nobu Nakada


    nobu.nokada@softhome.net Guest

  5. #5

    Default pty.so: [BUG] Segmentation fault

    I just installed ruby-1.8.1 and found this problem.

    make test -- worked fine during the installation of ruby


    -----

    The program below will work on the same machine using ruby-1.6.8

    What can I do to smoke this bug out?

    Bob Gustafson

    ------

    bash-2.03# ruby bugtest.rb
    /usr/local/lib/ruby/1.8/sparc-solaris2.7/pty.so: [BUG] Segmentation fault
    ruby 1.8.1 (2003-12-25) [sparc-solaris2.7]

    Abort (core dumped)

    bash-2.03# cat bugtest.rb
    require 'pty'
    puts "This is a test"
    bash-2.03#


    Bob Guest

  6. #6

    Default Re: pty.so: [BUG] Segmentation fault

    Hi,

    In message "pty.so: [BUG] Segmentation fault"
    on 04/02/07, Bob Gustafson <com> writes:

    |The program below will work on the same machine using ruby-1.6.8
    |What can I do to smoke this bug out?

    Hmm, is there somebody to confirm this on Solaris 2.7?

    matz.


    Yukihiro Guest

  7. #7

    Default Re: pty.so: [BUG] Segmentation fault

    Yukihiro Matsumoto wrote: 

    No segfault here.

    $ ruby -v bugtest.rb
    ruby 1.8.1 (2003-12-25) [sparc-solaris2.7]
    This is a test
    $ cat bugtest.rb
    require 'pty'
    puts "This is a test"

    However, I did have some strange behavior while updating from 2003-12-22
    to 2003-12-25. After building and installing the latter, ruby -v told me
    I still had the earlier version. So I blew away my entire
    $PREFIX/lib/ruby, and rebuilt, and that fixed the version discrepancy.

    Is it possible that the include path found version.h in
    $PREFIX/lib/ruby/1.8/sparc-solaris2.7/ before the one in the build dir?
    I've never seen this problem on linux, and I don't recall seeing it
    before on solaris.

    A typical compiler invocation looks like:

    gcc -I/usr/path/include -I. -I. -I/usr/path/include -c class.c

    So it does look like my install dir is being searched first. My
    configure command is simply

    /configure --prefix=/usr/path

    Anyway, the OP might want to try manually deleting lib/ruby and rebuilding.


    Joel Guest

  8. #8

    Default Re: pty.so: [BUG] Segmentation fault

    Hi,

    At Sun, 8 Feb 2004 07:11:47 +0900,
    Joel VanderWerf wrote in [ruby-talk:91760]: 

    No.
     

    It is strange. Don't you set CFLAGS env? Otherwise, '-g -O2'
    should appear instead.

    --
    Nobu Nakada


    nobu.nokada@softhome.net Guest

  9. #9

    Default Re: pty.so: [BUG] Segmentation fault

    net wrote: 
    >
    >
    > No.
    >

    >
    >
    > It is strange. Don't you set CFLAGS env? Otherwise, '-g -O2'
    > should appear instead.[/ref]

    Oops. That's exactly what it was. I have:

    declare -x CFLAGS="-I/usr/path/include"

    That was for some other software. Good to know that can interfere with
    ruby builds. Thanks.


    Joel Guest

Similar Threads

  1. Ruby/Ruby on Rails Syntax Highlight/Code completion
    By Cannikinn in forum Macromedia Exchange Dreamweaver Extensions
    Replies: 1
    Last Post: September 22nd, 01:05 AM
  2. Replies: 0
    Last Post: November 1st, 05:21 PM
  3. Replies: 1
    Last Post: October 29th, 07:52 PM
  4. RubyConf, Ruby Central, Ruby Garden temporary outage
    By dblack@superlink.net in forum Ruby
    Replies: 1
    Last Post: September 10th, 03:46 PM
  5. [ANN] ruby-freedb, ruby-serialport, ruby-mp3info moved to Rubyforge
    By guillaume.pierronnet@ratp.fr in forum Ruby
    Replies: 0
    Last Post: August 31st, 11:57 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139