public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* 3.4.6-1 shm_open always returns -1, errno EINVAL
@ 2023-03-12  6:44 Matthew Rickard
  2023-03-12 10:35 ` Csaba Raduly
  0 siblings, 1 reply; 4+ messages in thread
From: Matthew Rickard @ 2023-03-12  6:44 UTC (permalink / raw)
  To: cygwin

Hi all,

Cygwin 3.4.6-1 shm_open seems to reject all calls, returning  the value 
-1 and setting errno to 22 EINVAL.

For example, this program:

#include <sys/mman.h>
#include <fcntl.h>
#include <errno.h>
#include <stdio.h>

int main() {
   int res = shm_open("123", O_CREAT | O_RDWR, 0666);
   int error = errno;
   printf("res=%d errno=%d\n", res, errno);
   if (error == EINVAL)
     printf("That's EINVAL\n");
   return 0;
}

Says:

$ gcc -Og -o tiny tiny.c; ./tiny
res=-1 errno=22
That's EINVAL

Not sure if relevant, but I am currently running cygserver, with a 
default config.



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

* Re: 3.4.6-1 shm_open always returns -1, errno EINVAL
  2023-03-12  6:44 3.4.6-1 shm_open always returns -1, errno EINVAL Matthew Rickard
@ 2023-03-12 10:35 ` Csaba Raduly
  2023-03-12 22:55   ` Matthew Rickard
  0 siblings, 1 reply; 4+ messages in thread
From: Csaba Raduly @ 2023-03-12 10:35 UTC (permalink / raw)
  To: Matthew Rickard, cygwin list

Hi Matthew,

On Sun, 12 Mar 2023 at 07:44, Matthew Rickard  wrote:
>
> Hi all,
>
> Cygwin 3.4.6-1 shm_open seems to reject all calls, returning  the value
> -1 and setting errno to 22 EINVAL.
>
> For example, this program:
>
> #include <sys/mman.h>
> #include <fcntl.h>
> #include <errno.h>
> #include <stdio.h>
>
> int main() {
>    int res = shm_open("123", O_CREAT | O_RDWR, 0666);
>    int error = errno;
>    printf("res=%d errno=%d\n", res, errno);
>    if (error == EINVAL)
>      printf("That's EINVAL\n");
>    return 0;
> }
>
> Says:
>
> $ gcc -Og -o tiny tiny.c; ./tiny
> res=-1 errno=22
> That's EINVAL
>

https://man7.org/linux/man-pages/man3/shm_open.3.html  says:

For portable use, a shared memory object should be 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.

Changing the shm_open call to

shm_open("/123", O_CREAT | O_RDWR, 0666);

returns 3 and sets errno to zero.

Csaba
-- 
You can get very substantial performance improvements
by not doing the right thing. - Scott Meyers, An Effective C++11/14 Sampler
So if you're looking for a completely portable, 100% standards-conformant way
to get the wrong information: this is what you want. - Scott Meyers (C++TDaWYK)

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

* Re: 3.4.6-1 shm_open always returns -1, errno EINVAL
  2023-03-12 10:35 ` Csaba Raduly
@ 2023-03-12 22:55   ` Matthew Rickard
  2023-03-13 15:07     ` [EXTERNAL] " Lavrentiev, Anton (NIH/NLM/NCBI) [C]
  0 siblings, 1 reply; 4+ messages in thread
From: Matthew Rickard @ 2023-03-12 22:55 UTC (permalink / raw)
  To: Csaba Raduly, cygwin list

That's perfect, thank you!

On 12/03/2023 9:35 pm, Csaba Raduly wrote:
> Hi Matthew,
...
> https://man7.org/linux/man-pages/man3/shm_open.3.html  says:
>
> For portable use, a shared memory object should be 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.
>
> Changing the shm_open call to
>
> shm_open("/123", O_CREAT | O_RDWR, 0666);
>
> returns 3 and sets errno to zero.
>
> Csaba

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

* RE: [EXTERNAL] Re: 3.4.6-1 shm_open always returns -1, errno EINVAL
  2023-03-12 22:55   ` Matthew Rickard
@ 2023-03-13 15:07     ` Lavrentiev, Anton (NIH/NLM/NCBI) [C]
  0 siblings, 0 replies; 4+ messages in thread
From: Lavrentiev, Anton (NIH/NLM/NCBI) [C] @ 2023-03-13 15:07 UTC (permalink / raw)
  To: Matthew Rickard, Csaba Raduly, cygwin list

> > returns 3 and sets errno to zero.

Note that "setting errno to zero" is not guaranteed in case of a successful completion of a library function or a system call.
Generally, "errno" reflects an error that occurred last when such a call failed (so in other words, in case of a successful
completion, "errno" can still carry over an error from a previously failed call).  In this particular use case, it looks like
"errno" was clear from the get go because nothing was called prior to "shm_open()", and so it remained so when the call returned (successfully).

HTH,

Anton Lavrentiev
Contractor NIH/NLM/NCBI


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

end of thread, other threads:[~2023-03-13 15:16 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-12  6:44 3.4.6-1 shm_open always returns -1, errno EINVAL Matthew Rickard
2023-03-12 10:35 ` Csaba Raduly
2023-03-12 22:55   ` Matthew Rickard
2023-03-13 15:07     ` [EXTERNAL] " Lavrentiev, Anton (NIH/NLM/NCBI) [C]

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