f



Got "permission denied" when creating a posix message queue.

Below code is the excise from Unix network programming: IPC.

But after building the code using : g++ thisfile.cpp -lrt
running: a.out /tmp/mq.1234 will cause the code print "errno=13
Permission denied".
How to solve this issue? Thank you!

#include <mqueue.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys/stat.h>

#define FILE_MODE S_IRUSR|S_IWUSR
int main(int argc, char** argv){
    int c, flags;
    mqd_t mqd;
    flags = O_RDWR|O_CREAT;

    while( ( c = getopt(argc, argv, "e" ) ) != -1 ){
        switch (c){
        case 'e':
            flags |= O_EXCL;
            break;
        }
    }
    if( optind != argc - 1 ){
        printf("usage: mqcreate [ -e ] <name>");
        return  -1;
    }


    printf("FILE_MOED=%d\n", FILE_MODE);
    mqd = mq_open( argv[optind], flags, FILE_MODE, NULL);
    printf("The message queue d: %d \n", mqd);
    printf("%d :%s \n", errno, strerror(errno));
    mq_close(mqd);
    exit(0);
}
0
zhubicen (17)
9/2/2009 6:42:50 AM
comp.unix.programmer 10848 articles. 0 followers. kokososo56 (349) is leader. Post Follow

2 Replies
1388 Views

Similar Articles

[PageSpeed] 36

Hill wrote:
> Below code is the excise from Unix network programming: IPC.
> 
> But after building the code using : g++ thisfile.cpp -lrt
> running: a.out /tmp/mq.1234 will cause the code print "errno=13

Hello!

Try this:

../a.out -e /mq.1234

and use the following commands to see your new MQ:

olimpico_work ~ # mkdir /dev/mqueue
olimpico_work ~ # mount -t mqueue none /dev/mqueue
olimpico_work ~ # ls -l /dev/mqueue/
total 0
-rw------- 1 krivenok krivenok 80 Sep  2 10:56 mq.1234
olimpico_work ~ #

 From man 7 mq_overview:

Each message queue is identified by a name of the form /somename; that 
is, a null-terminated string of up to NAME_MAX (i.e.,
        255) characters consisting of an initial slash, followed by one 
or more characters, none of which are slashes.

And from man 2 mq_open:

EACCES name contained more than one slash.


> Permission denied".
> How to solve this issue? Thank you!
> 
> #include <mqueue.h>
> #include <errno.h>
> #include <stdio.h>
> #include <stdlib.h>
> #include <unistd.h>
> #include <string.h>
> #include <sys/stat.h>
> 
> #define FILE_MODE S_IRUSR|S_IWUSR
> int main(int argc, char** argv){
>     int c, flags;
>     mqd_t mqd;
>     flags = O_RDWR|O_CREAT;
> 
>     while( ( c = getopt(argc, argv, "e" ) ) != -1 ){
>         switch (c){
>         case 'e':
>             flags |= O_EXCL;
>             break;
>         }
>     }
>     if( optind != argc - 1 ){
>         printf("usage: mqcreate [ -e ] <name>");
>         return  -1;
>     }
> 
> 
>     printf("FILE_MOED=%d\n", FILE_MODE);
>     mqd = mq_open( argv[optind], flags, FILE_MODE, NULL);
>     printf("The message queue d: %d \n", mqd);
>     printf("%d :%s \n", errno, strerror(errno));
>     mq_close(mqd);
>     exit(0);
> }
0
krivenok (5)
9/2/2009 7:02:44 AM
On 9=D4=C22=C8=D5, =CF=C2=CE=E73=CA=B102=B7=D6, "Dmitry V. Krivenok" <krive=
....@orangesystem.ru>
wrote:
> Hill wrote:
> > Below code is the excise from Unix network programming: IPC.
>
> > But after building the code using : g++ thisfile.cpp -lrt
> > running: a.out /tmp/mq.1234 will cause the code print "errno=3D13
>
> Hello!
>
> Try this:
>
> ./a.out -e /mq.1234
>
> and use the following commands to see your new MQ:
>
> olimpico_work ~ # mkdir /dev/mqueue
> olimpico_work ~ # mount -t mqueue none /dev/mqueue
> olimpico_work ~ # ls -l /dev/mqueue/
> total 0
> -rw------- 1 krivenok krivenok 80 Sep  2 10:56 mq.1234
> olimpico_work ~ #
>
>  From man 7 mq_overview:
>
> Each message queue is identified by a name of the form /somename; that
> is, a null-terminated string of up to NAME_MAX (i.e.,
>         255) characters consisting of an initial slash, followed by one
> or more characters, none of which are slashes.
>
> And from man 2 mq_open:
>
> EACCES name contained more than one slash.
>
>
>
> > Permission denied".
> > How to solve this issue? Thank you!
>
> > #include <mqueue.h>
> > #include <errno.h>
> > #include <stdio.h>
> > #include <stdlib.h>
> > #include <unistd.h>
> > #include <string.h>
> > #include <sys/stat.h>
>
> > #define FILE_MODE S_IRUSR|S_IWUSR
> > int main(int argc, char** argv){
> >     int c, flags;
> >     mqd_t mqd;
> >     flags =3D O_RDWR|O_CREAT;
>
> >     while( ( c =3D getopt(argc, argv, "e" ) ) !=3D -1 ){
> >         switch (c){
> >         case 'e':
> >             flags |=3D O_EXCL;
> >             break;
> >         }
> >     }
> >     if( optind !=3D argc - 1 ){
> >         printf("usage: mqcreate [ -e ] <name>");
> >         return  -1;
> >     }
>
> >     printf("FILE_MOED=3D%d\n", FILE_MODE);
> >     mqd =3D mq_open( argv[optind], flags, FILE_MODE, NULL);
> >     printf("The message queue d: %d \n", mqd);
> >     printf("%d :%s \n", errno, strerror(errno));
> >     mq_close(mqd);
> >     exit(0);
> > }

Thank you!

This issue is caused by the argument:/tmp/mq.1234.
The name of posix msgqueue must have only one slash on some system. I
test using debian5.

from man 7 mq_overview:
Message queues are created and opened using mq_open(3); this function
returns a message queue descriptor
       (mqd_t), which is used to refer to the open message queue in
later calls.  Each message queue is identi=A9\
       fied  by  a name of the form /somename.  Two processes can
operate on the same queue by passing the same
       name to mq_open(3).
0
zhubicen (17)
9/3/2009 7:15:19 AM
Reply:

Similar Artilces:

Method of suppressing "Permission denied" messages during "find" command ?
I can start a find command similar to find / -name "dummy" -print and it will find all files. However a lot of files were listed with the remark "Permission denied" and similar other warnings. How can I suppress these messages? George -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 George Dainis wrote: > I can start a find command similar to > > find / -name "dummy" -print > > and it will find all files. However a lot of files were listed with the remark > "Permission denied" and similar other warnings. > > How can I suppr...

"Permission denied to create file" message from untar
I'm using Matlab's untar and I keep getting the message: "Warning: Permission denied to create file "foo.bar". The error comes from line 106 in extractArchive.m, and according to the comments in that m-file, this means that "the file is trying to be written into a directory with insufficient privileges." Anyone know how to fix this in Windows XP and Matlab 7.4? I'm the administrator with full permissions, so I'm not sure why Matlab is unable to create a directory that it can write to. It might have something to do with the fact that files and direct...

"""""""""ADD ME""""""""""
Hi , Hope you are doing great. Please let me take this opportunity to introduce myself, Iam Karthik working with BhanInfoi Inc, a NY based company. We have consultants on our bench on various technologies, my request is to add me to your distribution list and kindly do send me the requirements. i have the below list available 1. Mainframe 2. Java 3.. Financial Analyst 4. Data Architect If there is any vendor ship agreement which has to be signed then I would like to take an opportunity to represent my company and expect your cooperation... ...

Urgent Requirement in """""""""""""NEW YORK""""""""""""""""
Hello Partners, Please find the requirement below. Please send the updated resume along with rate and contact no. REQ#1: Title : Java Developer ( Rating Project) Duration : 6 months Rate : open Location : NY strong java, WebLogic 9.2, Web Services, Oracle REQ#2: Title : Java Developer Duration : 4 months Rate : open Location : NY Strong java, SQL REQ#3: Title : VB.Net Consultant Location : NY Duration : 4 months Rate : open Primarily looking at someone who has Excel, VB.net and Oracle (good to have). Req #4: Title : Java Developer (MSA Project) Duration : 6+ months Rate : open Location : NY Note : Please send your updated resume along with contact no karthik@bhaninfo.com : No phone calls please. Thanks & Regards Karthik BhanInfo karthik@bhaninfo.com ...

Changing case "message" to "MESSAGE"
Working my way through Koenig & Moo "Accelerated C++" and using Borlang Builder 5 (but that is probably not relevant) I reached exercise 1-1 and typed in #include <vcl.h> #pragma hdrstop #include <iostream> #include <string> int main(int argc, char*argv[]} { const std::string hello = "Hello" // This by itself compiled const std::string message = "Hello" // and other stuff which I have //left out here. system("PAUSE"); return 0; } But I left caps lock on, and by mistake typed MESSAGE, an...

"If then; if then;" and "If then; if;"
I have a raw data set which is a hierarchical file: H 321 s. main st P Mary E 21 F P william m 23 M P Susan K 3 F H 324 S. Main St I use the folowing code to read the data to creat one observation per detail(P) record including hearder record(H): data test; infile 'C:\Documents and Settings\retain.txt'; retain Address; input type $1. @; if type='H' then input @3 Address $12.; if type='P' then input @3 Name $10. @13 Age 3. @16 Gender $1.; run; but the output is not what I want: 1 321 s. main H 2 321 s. main P Mary E 21 F 3 321 s...

"my" and "our"
Hi, while testing a program, I erroneously declared the same variable twice within a block, the first time with "my", the second time with "our": { my $fz = 'VTX_Link'; .... ( around 200 lines of code, all in the same block) our $fz = 'VTX_Linkset'; ... } So the initial contents of the $fz declared with "my" is lost, because "our" creates a lexical alias for the global $fz, thus overwriting the previous "my" declaration. It was my error, no question. But I wonder why Perl doesn't mention this - even with "use s...

"/a" is not "/a" ?
Hi everybody, while testing a module today I stumbled on something that I can work around but I don't quite understand. >>> a = "a" >>> b = "a" >>> a == b True >>> a is b True >>> c = "/a" >>> d = "/a" >>> c == d True # all good so far >>> c is d False # eeeeek! Why c and d point to two different objects with an identical string content rather than the same object? Manu Emanuele D'Arrigo wrote: >>>> c = "/a" >>>&...

"or" and "and"
Hi, I'm just getting to discover ruby, but I find it very nice programming language. I just still don't understand how the "or" and "and" in ruby... I was playing with ruby and for example made a def to print Stem and Leaf plot (for those who didn't have a statistics course or slept on it, e.g. http://cnx.org/content/m10157/latest/) Here is the Beta version of it: class Array def n ; self.size ; end def stem_and_leaf(st = 1) # if st != (2 or 5 or 10) then ; st = 1 ; end k = Hash.new(0) self.each {|x| k[x.to_f] += 1 } k = k.sort{|a, b| a[0].to_f <=&g...

"out" and "in out"
Hi i found the following explaination: In Ada, "in" parameters are similar to C++ const parameters. They are effectively read-only within the scope of the called subprogram. Ada "in out" parameters have a reliable initial value (that passed in from the calling subprogram) and may be modified within the scope of the called procedure. Ada "out" parameters have no reliable initial value, but are expected to be assigned a value within the called procedure. What does "have no reliable initial value" mean when considering the "out" parameter? By c...

"C" programm in "Matlab" Programm
Hi, i habe a matlab code which is looking like that " in C: unsigned char i, Checksum; unsigned char Command[9]; //Set the “Command” array to the desired command Checksum = Command[0]; for(i=1; i<8; i++) Checksum+=Command[i]; Command[8]=Checksum; //insert checksum as last byte of the command //Now, send it to the module how can i convert it to matlab? thanks for you answer melano "Miland " <miland17@yahoo.de> wrote in message <j0mb4f$48u$1@newscl01ah.mathworks.com>... > Hi, > i habe a matlab code which is looking like that "...

about "++" and "--"
why this program snippet display "8,7,7,8,-7,-8" the program is: main() { int i=8; printf("%d\n%d\n%d\n%d\n%d\n%d\n",++i,--i,i++,i--,-i++,-i--); } > why this program snippet display "8,7,7,8,-7,-8" Ask your compiler-vendor because this result is IMHO implementation-defined. Check this out: http://www.parashift.com/c++-faq-lite/misc-technical-issues.html#faq-39.15 http://www.parashift.com/c++-faq-lite/misc-technical-issues.html#faq-39.16 Regards, Irina Marudina fxc123@gmail.com wrote: > why this program snippet display "8,7,7,8,-7,-8&q...

why "::", not "."
Why does the method of modules use a dot, and the constants a double colon? e.g. Math::PI and Math.cos -- Posted via http://www.ruby-forum.com/. On Oct 26, 2010, at 01:48 , Oleg Igor wrote: > Why does the method of modules use a dot, and the constants a double > colon? > e.g. > Math::PI and Math.cos For the same reason why inner-classes/modules use double colon, because = they're constants and that's how you look up via constant namespace. Math::PI and ActiveRecord::Base are the same type of lookup... it is = just that Base is a module and PI is a float....

"mailutil transfer" spews "Permission denied" errors
I'm intending to use `mailutil' from the IMAP Toolkit to copy several thousand IMAP mailboxes from one Cyrus server to another. In my tests, `mailutil transfer' works, but it generates a stream of `Permission denied' errors. I assume these occur because the source folders are opened read-only, but the server is attempting to set flags there. Is there a way to prevent the attempt, or at least to suppress the errors? -- -Gary Mills- -Unix Support- -U of M Academic Computing and Networking- On Wed, 27 Jan 2005, Gary Mills wrote: > I'm intending to use `mailutil&...

Create "to" and "from" attributes
Hi, In an existing centerline road shapefile, I need to create "to" and "from" attributes - NOT with addresses, but road names. for example Main street will have FROM: First St. TO: Second St. There is probably a script or something out there, but I have not been able to find yet. Thanks for any ideas, Lee. ...

Does it need a ";" at the very after of "if" and "for"
write code like: int main(void) { int a=10; if(a<20) {} } Compiler ok on dev-cpp . don't we have to add a ";" after if statement? marsarden said: > write code like: > > int main(void) > { > int a=10; > if(a<20) > {} > } > > Compiler ok on dev-cpp . don't we have to add a ";" after if > statement? The syntax for 'if' is: if(expression) statement There is no semicolon after the ) but before the statement. The statement is either a normal statement (which can be empty), ending in a semicolon:- if(expr) ...

A problem about "[ ]" "( )" "="
I want to read several images saved in a director,and give them to I1,I2 ,I3....,using the following codes: filelist=dir(['c:\MATLAB701\work\...\*.jpg']); for i=1 :length(filelist) I=imread(fullfile('c:\MATLAB701\work\...',filelist(i).name)); end; but failed. Then I used I(i)=imread... ,still failed. How could I do? "John" <mailofww@126.com> wrote in message news:ef19e12.-1@webx.raydaftYaTP... >I want to read several images saved in a director,and give them to > I1,I2 ,I3....,using the following codes: > filelist=dir(['c:\MATLAB701\work\.....

"In" "Out" and "Trash"
I just bought a new computer and I re-installed Eudora Light on my new computer. But when I open Eudora, the "In", "Out" and "Trash" links are not on the left side of the screen the way they were on my old computer. How can I get these links back on the left side of the screen? Thank you. On 25 Mar 2007 09:49:22 -0700, "abx" <abfunex@yahoo.com> wrote: >I just bought a new computer and I re-installed Eudora Light on my new >computer. But when I open Eudora, the "In", "Out" and "Trash" links >are ...

Total confusing "Permission denied" message
I need to set up a service account that will be used by some DBAs after my contract is done. I built and tested everything in my personal account and now I'm moving everything to the service account. Unfortunately, commands that were working perfectly are now failing. I've even tried copying all of my .ssh files to the service account, and that also fails. I've run both client commands with three '-v' options and included the 'diff' below. Can anyone thing of anything I'm missing, or even a good "next step"? Thanks. example|global$ uname -a SunOS example 5.10 Generic_127111-06 sun4v sparc SUNW,Sun-Fire-T200 example|global$ ssh -l samwyse -o PreferredAuthentications=publickey localhost echo hi hi example|global$ ssh -l symcli -o PreferredAuthentications=publickey localhost echo hi Permission denied (gssapi-keyex,gssapi-with- mic,publickey,password,keyboard-interactive). example|global$ ls -al ~symcli/.ssh total 292 drwxr-xr-x 2 symcli unix 512 Oct 30 20:39 . drwxrwxr-x 5 symcli root 512 Nov 2 20:36 .. -rw-r--r-- 1 symcli unix 61060 Aug 21 20:03 authorized_keys -rw------- 1 symcli unix 668 May 27 18:59 id_dsa -rw-r--r-- 1 symcli unix 608 May 27 18:59 id_dsa.pub -rw------- 1 symcli unix 883 May 27 18:59 id_rsa -rw-r--r-- 1 symcli unix 228 May 27 18:59 id_rsa.pub -rw-r--r-- 1 symcli unix 71926 Sep 23 20:37 k...

FAILURE: Permission Denied "last error" message
I am running Windows XP and Kermit 95 2.1.2 and have a script which accesses an Alpha system running VMS via modem and / or tcpip. The script runs fine as long as it is run from the Administrator's account of the Windows XP computer. As soon as I switch to another account the script issues "FAILURE: Permission Denied" on the "last error" line of the file transfer screen. The script connects to the Alpha fine it just won't "get" the file i ask it to. The next mystery is if I am in the other account I can manually issue all the commands in the sc...

How to create a file named "\a" and "-a"
Hi !How to create a file named "\a" and "-a"? dolphin wrote: > Hi !How to create a file named "\a" and "-a"? > "touch \\a" nets you "\a" making "-a" filename is harder.. You may have to resort to C code.. Its pretty hard to get the standard tools to ignore what they interpret as switches. On 16 Mar 2007 at 14:36, dolphin wrote: > Hi !How to create a file named "\a" touch '\a' > and "-a"? touch -- -a (assuming GNU touch) -- email: echo t.adllkhsl@iypzavs.hj.br | tr a-gh-pq...

Hit "send"
Using Eudora 6.1 on Mac OSX. Everything has been working fine for the past couple months until this past Friday. Now, I address a mail, compile a message and hit send. I can see the window where Eudora is talking to the server. I don't get any error message or anything, but all the mail I'm trying to send ends up as "queued" status rather than actually being sent. I try to send them again and the same thing happens. Yes, I do have the personality setting at "send messages when sending" (not using more than one personality nor address). Any suggestions...

"unix" and "system" functions
Hi, "Unix" and "system" seem to perform identical tasks, aside from the fact that one can be forced to echo command output to the command window. Aside from that, is there any reason for choosing one over the other? Fred -- Fred Ma Dept. of Electronics, Carleton University 1125 Colonel By Drive, Ottawa, Ontario Canada, K1S 5B6 On 3 Feb 2004 11:03:14 GMT, Fred Ma <fma@doe.carleton.ca> wrote: >Hi, > >"Unix" and "system" seem to perform identical tasks, >aside from the fact that one can be forced to >echo command out...

Urgent JAVA Requirement in """"""NEW YORK"""""""""
Hello Partners, How are you ? Please find the requirement below. Location : NY Duration : 8 mnths Rate :Open Job description: Java/J2EE Web Service Developer =B7 (4+ years of application development experience in Java/J2EE and Web service technologies. =B7 Experience with spring & Hibernate. =B7 Experience with J2EE Application Server (preferably Web logic). =B7 Preferable Aqua logic DSP Experience =B7 Preferable Sonic ESB Composite Service experience Experience w...

Web resources about - Got "permission denied" when creating a posix message queue. - comp.unix.programmer

Resources last updated: 3/11/2016 3:23:40 AM