posix_mq RubyGem user+dev discussion/patches/pulls/bugs/help
 help / color / mirror / code / Atom feed
From: "Iñaki Baz Castillo" <ibc@aliax.net>
To: ruby.posix.mq@librelist.com
Subject: Re: "mode" and varios processes sharing the same queue for writting [SOLVED]
Date: Fri, 8 Jan 2010 14:25:54 +0100	[thread overview]
Message-ID: <201001081425.54411.ibc@aliax.net> (raw)
In-Reply-To: 201001081212.16254.ibc@aliax.net

El Viernes, 8 de Enero de 2010, Iñaki Baz Castillo escribió:
> Hi, I'll have an external process (running as root) which creates a
>  posix_mq queue just for read-only. As it runs as root I can set a longer
>  "maxmsg" value.
> 
> Then I've other processes (Unicor workers) running as non privileged users
>  and must write in that queue.
> 
> So in the external process I do:
> 
>   File.umask(0000)
>   MQ = POSIX_MQ.new "/mq", IO::RDONLY | IO::CREAT, 00002
> 
> "mode" = 00002 which means "others have write permission" (in combination
>  with the modified umask, of course, if not it doesn't work).
> 
> Is it the correct approach?

The already working solution:

----------------------------------
group_name   = ARGV[0]

# Change the effective group (just if we are root).
if Process.euid == 0 and group_name
  gid = Etc.getgrnam(group_name).gid
  puts "setting effective group to '#{group_name}' (gid #{gid})..."
  Process::GID.change_privilege(gid)
end

# Change umask to 0047 so the group has write permissions for the posix_mq.
File.umask(0047)  # => When creating a file permissions are:  -rw--w----

MQ = POSIX_MQ.new "/my_mq", IO::RDONLY | IO::CREAT, 00620
--------------------------------

In this way a user whose primary group is "group_name" will have write access 
(but no read access) to the mqueue. :)



> And the other question: Being posix_mq process/thread safe, does it mean
>  that I could open the queue writter in the master process so it could be
>  safely shared by all the workers? or shall I open the queue writter for
>  each worker?

After some testing I would say that it's totally safe (it works for me by 
creating the mqueue writter in the master process).



Best regards.


-- 
Iñaki Baz Castillo <ibc@aliax.net>

  parent reply	other threads:[~2010-01-08 13:26 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-01-08 11:12 "mode" and varios processes sharing the same queue for writting Iñaki Baz Castillo
2010-01-08 11:27 ` Iñaki Baz Castillo
2010-01-08 13:25 ` Iñaki Baz Castillo [this message]
2010-01-08 19:52 ` Eric Wong
2010-01-09 17:24   ` Iñaki Baz Castillo
2010-01-09 19:48     ` Eric Wong
2010-01-09 22:55       ` Iñaki Baz Castillo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://yhbt.net/ruby_posix_mq/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=201001081425.54411.ibc@aliax.net \
    --to=ibc@aliax.net \
    --cc=ruby.posix.mq@librelist.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://yhbt.net/ruby_posix_mq.git/

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).