need help creating install package for SIMPL open source project

Joined
Mar 15, 2011
Messages
4
Reaction score
0
Points
1
I am the facilitator for the SIMPL open source project (SIMPL). This project has been around for more than a decade. It produces a Send/Receive/Reply (QNX style) messaging toolkit primarily for Linux systems. A SIMPL application consists of two or more interacting SIMPL modules. Those SIMPL modules can be written in a wide array of programming languages (C, C++, Python, JAVA,Tcl/Tk and soon PHP) and can be mixed in a given SIMPL application. Through the use of generic surrogates those SIMPL modules can be distributed across a network, often without even a recompile.

It was recently brought to my attention that the SIMPL toolkit can be compiled and run on a Mac. There have been some issues related to the fact that the Mac OSX uses case insensitive file naming, but hopefully those are now resolved.

On Linux systems the SIMPL developer typically uses the self installing archive (SIMPL Self Installing Archive) to install the toolkit.

I'd love to have this SIMPL stuff in a more Mac friendly install package. We don't have a lot of Mac expertise in the SIMPL project, so hence this post.

Thanks in advance for any assistance you can offer.

bob
PS.
I'd also love to add Objective-C to the list of languages usable for creating SIMPL modules.
 
OP
B
Joined
Mar 15, 2011
Messages
4
Reaction score
0
Points
1
shmat problems

It would seem that I was a little premature in discussing packaging the SIMPL toolkit for the Mac. While everything appears to compile fine there is a problem with the shared memory IPC which underlies the SIMPL messaging.

In a SIMPL transaction the sender creates the shared memory segment and loads it with the outgoing message. This sender then packages up the shmid and pumps it down a fifo (used for synchronization) to the receiver. The receiver reads this shmid from the other end of the fifo and then attaches to the shared memory segment and reads the message contents.

I'm getting reports that the receiver attach is failing with the "Invalid argument" error from the shmat() call. There are only 3 args for shmat. In my case that call is set as:

*sender = shmat(fifoMsg->shmid, 0, 0);

I've verified that the shmid is the same value as was generated by the shmget() call in the sender.

Any ideas why this code which works fine on Linux would be broken on Mac OSX?

bob
PS.
The shared memory size is 1k ... which presumably rounds up to one page so we shouldn't be tripping on MacOSX default limits to shared memory.
 
OP
B
Joined
Mar 15, 2011
Messages
4
Reaction score
0
Points
1
more details on shared memory problem

Here is the code snip of the shared memory activity from the sender side of the SIMPL transaction.

======= begin code snip from sender =========
_simpl_myStuff.shmid = shmget(IPC_PRIVATE, memSize, 0777 | IPC_CREAT);
if (_simpl_myStuff.shmid == -1)
{
_simpl_setErrorCode(CANNOT_CREATE_SHMEM);
_simpl_log("%s: unable to create shmem-%s\n", fn, strerror(errno));
return(-1);
}

// attach the shmem for messages to this process
_simpl_myStuff.shmPtr = shmat(_simpl_myStuff.shmid, 0, 0);
if (_simpl_myStuff.shmPtr == (char *)-1)
{
_simpl_setErrorCode(CANNOT_ATTACH_SHMEM);
_simpl_log("%s: unable to attach shmem to process-%s\n", fn, strerror(er
rno));
return(-1);
}

// release shmem if and when owner dies by an untrappable signal
shmctl(_simpl_myStuff.shmid, IPC_RMID, 0);
======= end code snip from sender =====

All these sender side calls work without any errors. The shmid is then transmitted via a named pipe (fifo) to the receiver. The log shows that this shmid is identical on both sides of this pipe. The code inside the receiver which fails is in the snip below.

======= begin code snip from receiver ======
/*
Attach the sender's shmem to this process.
Known to fail if sender suddenly disappears.
Saving this value allows the Reply() to use the same shmem.
*/
*sender = shmat(fifoMsg->shmid, 0, 0);
if (*sender == (char *)-1)
{
_simpl_setErrorCode(CANNOT_ATTACH_SHMEM);
_simpl_log("%s: shmid=%d cannot attach to shmem-%s\n", fn, fifoMsg->shmi
d, strerror(errno));
ReplyError(*sender);
return(-1);
}

======= end code snip from receiver ========

Obviously there is lots of other code surrounding these two snips, so I went back to my "Linux Programming by Example" book and pulled some shared memory sample code together which is listed below.

========= begin sample code for sender side ========
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <sys/shm.h>

int main(void)
{
int shmid;
char *shmbuf;
char command[80];

printf("mkshm starting\n");

shmid=shmget(IPC_PRIVATE, 4096, 0777 | IPC_CREAT);
if(shmid == -1)
{
printf("shmget error %s\n",strerror(errno));
}

system("ipcs -m");

shmbuf=shmat(shmid,0,0);
if(shmbuf == (char *)-1)
{
printf("mkshm: shmat error %s\n",strerror(errno));
exit(-1);
}

sprintf(command,"./atshm %d", shmid);
system(command);

shmctl(shmid, IPC_RMID, 0);
exit(0);
}
========= end sample code for sender side =========

========= begin sample code for receiver side ========
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <sys/shm.h>

int main(int argc, char *argv[])
{
int shmid;
char *shmbuf;

printf("atshm starting\n");

shmid=atoi(argv[1]);

printf("atshm: shmid=%d\n",shmid);

shmbuf=shmat(shmid,0,0);
if(shmbuf == (char *)-1)
{
printf("atshm: shmat error %s\n",strerror(errno));
exit(-1);
}
system("ipcs -m");

shmdt(shmbuf);

system("ipcs -m");

exit(0);
}

========= end sample code for receiver side =========


Notice that it has the same sequence as the SIMPL code.

The maddening part is that the sample code WORKS !!!

Any ideas what is going on here?

bob
 
OP
B
Joined
Mar 15, 2011
Messages
4
Reaction score
0
Points
1
Bingo found the shm problem

This version of SIMPL compiles and runs on the Mac.

SIMPL Self Installing Archive

It turns out that in Linux you can attach to a shared memory segment that has been marked for destruction (once the last process detaches from it). However, on the Mac this is not permitted. This note buried in the shmctl documentation was the clue:

========= begin quote =========
Linux permits a process to attach (shmat()) a shared memory segment that has
already been marked for deletion using shmctl(IPC_RMID). This feature is not
available on other Unix implementations; portable applications should avoid
relying on it.
========= end quote ==========

At this point I still need help with my original problem which was to build an installable package for this stuff the Mac way.

Thanks.

bob
 

Shop Amazon


Shop for your Apple, Mac, iPhone and other computer products on Amazon.
We are a participant in the Amazon Services LLC Associates Program, an affiliate program designed to provide a means for us to earn fees by linking to Amazon and affiliated sites.
Top