OpenSceneGraph Forum Forum Index OpenSceneGraph Forum
Official forum which mirrors the existent OSG mailing lists. Messages posted here are forwarded to the mailing list and vice versa.
 
   FAQFAQ    SearchSearch    MemberlistMemberlist    RulesRules    UsergroupsUsergroups    RegisterRegister 
 Mail2Forum SettingsMail2Forum Settings  ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
   AlbumAlbum  OpenSceneGraph IRC ChatOpenSceneGraph IRC Chat   SmartFeedSmartFeed 

iOS 11 and OSG_SYSTEM_SUPPORTED issue

Goto page 1, 2  Next
 
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> Submission
View previous topic :: View next topic  
Author Message
a.terenzi (Alessandro Terenzi)
Appreciator


Joined: 03 Sep 2009
Posts: 250

PostPosted: Fri Jan 19, 2018 10:17 am    Post subject:
iOS 11 and OSG_SYSTEM_SUPPORTED issue
Reply with quote

Hi,
I noticed that if one tries to build for iOS 11 the build fails because, in the case one wants to deploy only for iOS 11.0 and later the 'system(.)' call is not available.

After a search I noticed that many developers suggest to use posix_spawn(.), so my suggestion is that, instead to just block the building process, we could allow to use "posix_spawn(.)" if the OSG_SYSTEM_SUPPORTED is not defined AND if we are not building for WIN32 (for which, to my understanding, "posix_spawn(.)" is not available, and anyway, I think for WIN32 'system(.)' should be always available, right?)

The affected files would be:

include/osg/osg_utils
src/osgPlugins/lua/lua-5.2.3/src/loslib.c

My idea would be to use:

Code:
pid_t pid;
posix_spawn(&pid, cmd, NULL, NULL, NULL, NULL);
int stat = waitpid(pid, NULL, 0);

instead of:

Code:
int stat = system(cmd)


What do you think?

Cheers,
Alessandro
Back to top
View user's profile Send private message
robertosfield
OSG Project Lead


Joined: 18 Mar 2009
Posts: 12132

PostPosted: Fri Jan 19, 2018 11:17 am    Post subject:
iOS 11 and OSG_SYSTEM_SUPPORTED issue
Reply with quote

HI Alessandro,

You could possible just implement osg::system() using posix_spawn().

Robert.

On 19 January 2018 at 10:18, Alessandro Terenzi <> wrote:
Quote:
Hi,
I noticed that if one tries to build for iOS 11 the build fails because, in the case one wants to deploy only for iOS 11.0 and later the 'system(.)' call is not available.

After a search I noticed that many developers suggest to use posix_spawn(.), so my suggestion is that, instead to just block the building process, we could allow to use "posix_spawn(.)" if the OSG_SYSTEM_SUPPORTED is not defined AND if we are not building for WIN32 (for which, to my understanding, "posix_spawn(.)" is not available, and anyway, I think for WIN32 'system(.)' should be always available, right?)

The affected files would be:

include/osg/osg_utils
src/osgPlugins/lua/lua-5.2.3/src/loslib.c

My idea would be to use:


Code:
pid_t pid;
posix_spawn(&pid, cmd, NULL, NULL, NULL, NULL);
int stat = waitpid(pid, NULL, 0);



instead of:


Code:
int stat = system(cmd)



What do you think?

Cheers,
Alessandro

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=72790#72790








------------------
Post generated by Mail2Forum
Back to top
View user's profile Send private message
kornerr
Appreciator


Joined: 01 Oct 2013
Posts: 280

PostPosted: Fri Jan 19, 2018 11:30 am    Post subject:
iOS 11 and OSG_SYSTEM_SUPPORTED issue
Reply with quote

Hi. You may try targeting iOS10+ if iOS11+ breaks system().

On 19 January 2018 at 14:14, Robert Osfield <> wrote:
Quote:
HI Alessandro,

You could possible just implement osg::system() using posix_spawn().

Robert.

On 19 January 2018 at 10:18, Alessandro Terenzi <> wrote:
Quote:
Hi,
I noticed that if one tries to build for iOS 11 the build fails because, in the case one wants to deploy only for iOS 11.0 and later the 'system(.)' call is not available.

After a search I noticed that many developers suggest to use posix_spawn(.), so my suggestion is that, instead to just block the building process, we could allow to use "posix_spawn(.)" if the OSG_SYSTEM_SUPPORTED is not defined AND if we are not building for WIN32 (for which, to my understanding, "posix_spawn(.)" is not available, and anyway, I think for WIN32 'system(.)' should be always available, right?)

The affected files would be:

include/osg/osg_utils
src/osgPlugins/lua/lua-5.2.3/src/loslib.c

My idea would be to use:


Code:
pid_t pid;
posix_spawn(&pid, cmd, NULL, NULL, NULL, NULL);
int stat = waitpid(pid, NULL, 0);



instead of:


Code:
int stat = system(cmd)



What do you think?

Cheers,
Alessandro

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=72790#72790









------------------
Post generated by Mail2Forum
Back to top
View user's profile Send private message
a.terenzi (Alessandro Terenzi)
Appreciator


Joined: 03 Sep 2009
Posts: 250

PostPosted: Fri Jan 19, 2018 5:22 pm    Post subject:
Reply with quote

Hi Robert,
here's a proposal about using 'posix_spawn' when 'system' is not available (see attachments).

Let me know if it's OK and feel free to merge it if everything is good.

Thanks.
Alessandro
Back to top
View user's profile Send private message
robertosfield
OSG Project Lead


Joined: 18 Mar 2009
Posts: 12132

PostPosted: Fri Jan 19, 2018 6:02 pm    Post subject:
iOS 11 and OSG_SYSTEM_SUPPORTED issue
Reply with quote

HI Alessandro,

I was thinking the place for the fallback would be in
include/osg/os_utils where the osg::system() is now defined.

Is there a reason why you are putting changes into lua?

Robert.

On 19 January 2018 at 17:22, Alessandro Terenzi <> wrote:
Quote:
Hi Robert,
here's a proposal about using 'posix_spawn' when 'system' is not available (see attachments).

Let me know if it's OK and feel free to merge it if everything is good.

Thanks.
Alessandro

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=72800#72800




Attachments:
http://forum.openscenegraph.org//files/loslib_146.c
http://forum.openscenegraph.org//files/631_1516382237._161.





------------------
Post generated by Mail2Forum
Back to top
View user's profile Send private message
a.terenzi (Alessandro Terenzi)
Appreciator


Joined: 03 Sep 2009
Posts: 250

PostPosted: Fri Jan 19, 2018 7:00 pm    Post subject:
Reply with quote

Hi Robert,
yes, I had to change also the code in the Lua's plugin because in that case the C code is calling directly the 'system' function, not the one defined in the 'osg' namespace (in include/osg/os_utils), which I think it is not visibile from that part of the Lua code (maybe, correct me if I'm wrong, the 'system' call in the Lua's plugin is the only one that is not using the 'osg::system' function).

Cheers,
Alessandro
Back to top
View user's profile Send private message
robertosfield
OSG Project Lead


Joined: 18 Mar 2009
Posts: 12132

PostPosted: Fri Jan 19, 2018 7:18 pm    Post subject:
iOS 11 and OSG_SYSTEM_SUPPORTED issue
Reply with quote

On 19 January 2018 at 19:00, Alessandro Terenzi <> wrote:
Quote:
Hi Robert,
yes, I had to change also the code in the Lua's plugin because in that case the C code is calling directly the 'system' function, not the one defined in the 'osg' namespace (in include/osg/os_utils), which I think it is not visibile from that part of the Lua code (maybe, correct me if I'm wrong, the 'system' call in the Lua's plugin is the only one that is not using the 'osg::system' function).

Ahh. I obviously didn't resolve the lua issue. I think it would be
appropriate to have the lua plugin map to the osg::system one.

Robert.


------------------
Post generated by Mail2Forum
Back to top
View user's profile Send private message
a.terenzi (Alessandro Terenzi)
Appreciator


Joined: 03 Sep 2009
Posts: 250

PostPosted: Fri Jan 19, 2018 8:34 pm    Post subject:
Reply with quote

Hi Robert,
so, if I got it right, you suggest to expose a C function/wrapper from os_utils (C++) and use it in the Lua (C) plugin? This would imply to modify the lua code anyway right?

Cheers,
Alessandro
Back to top
View user's profile Send private message
robertosfield
OSG Project Lead


Joined: 18 Mar 2009
Posts: 12132

PostPosted: Sun Jan 21, 2018 11:16 am    Post subject:
iOS 11 and OSG_SYSTEM_SUPPORTED issue
Reply with quote

Hi Alessandro,

On 19 January 2018 at 20:34, Alessandro Terenzi <> wrote:
Quote:
so, if I got it right, you suggest to expose a C function/wrapper from os_utils (C++) and use it in the Lua (C) plugin? This would imply to modify the lua code anyway right?

I don't have a clear path forward yet, the use of C in the lua plugin
is a bit different from the rest of the OSG so we'll have to find a
good way forward.

I would much rather have a unified fallback otherwise testing and
debugging can get a bit problematic as time goes on. My guess is
that we either need to compile Lua as C++ or have an extern "C" block
in the include/os_utls and have a osg_system(const char*) method that
wraps the platform specific implementation.

Robert.


------------------
Post generated by Mail2Forum
Back to top
View user's profile Send private message
robertosfield
OSG Project Lead


Joined: 18 Mar 2009
Posts: 12132

PostPosted: Sun Jan 21, 2018 12:25 pm    Post subject:
iOS 11 and OSG_SYSTEM_SUPPORTED issue
Reply with quote

I have had a bash at making a system fallback work for C and C++
compilation, it's checked in as:

https://github.com/openscenegraph/OpenSceneGraph/commit/18d5a9159f9c66336c40bf91b77dfe3ebe3af31f

In the osg/os_utils header there is now osg_system declared as a C function:

#ifdef __cplusplus
extern "C" {
#endif

/** Cross platform version of C system() function. */
extern OSG_EXPORT int osg_system(const char* str);

#ifdef __cplusplus
}
#endif

The lua plugin as well as the rest of the OSG usage of system now uses
this osg_system() function. On the implementation side I have left it
controlled by the OSG_SYSTEM_SUPPORTED cmake controlled, now
implemented in src/osg/os_utils.cpp :

extern "C" {

int osg_system(const char* command)
{
#ifdef OSG_SYSTEM_SUPPORTED
return system(command);
#else
printf("osg_system(%s) not supported.\n", command);
#endif
}

}

I'm open to the having different implementations of osg_system on
different platforms, and potentially the OSG_SYSTEM_SUPPORTED cmake +
define could be removed completely if this fallback can happen
seamlessly with the os_utils.cpp

Robert.


------------------
Post generated by Mail2Forum
Back to top
View user's profile Send private message
a.terenzi (Alessandro Terenzi)
Appreciator


Joined: 03 Sep 2009
Posts: 250

PostPosted: Mon Jan 22, 2018 10:51 am    Post subject:
Reply with quote

Hi Robert,
and thank you for the update.

One proposal for implementing 'osg_system(.)', which is working on my side (iOS), still relies on OSG_SYSTEM_SUPPORTED:

Code:
#include <osg/os_utils>

#if !defined(OSG_SYSTEM_SUPPORTED) && !defined(WIN32)
#include <spawn.h>
#endif

extern "C" {

int osg_system(const char* command)
{
#ifdef OSG_SYSTEM_SUPPORTED
    return system(command);
#elif !defined(WIN32)
    pid_t pid;
    posix_spawn(&pid, command, NULL, NULL, NULL, NULL);
    return waitpid(pid, NULL, 0);
#else
    printf("osg_system(%s) not supported.\n", command);
#endif
}

}


If we aim to remove the OSG_SYSTEM_SUPPORTED, we could use the code below instead:

Code:
#include <osg/os_utils>

#ifndef WIN32
#include <spawn.h>
#endif

extern "C" {
   
    int osg_system(const char* command)
    {
#ifdef WIN32
        return system(command);
#else
        pid_t pid;
        posix_spawn(&pid, command, NULL, NULL, NULL, NULL);
        return waitpid(pid, NULL, 0);
#endif
    }

}


I am not 100% sure but, as far as I know, 'system(.)' should be always available on Windows, so it could be safe to use it only for Windows and use 'posix_spawn(.)' on the other platforms, what do you think? posix_spawn should work on any linux, right?

Alessandro
Back to top
View user's profile Send private message
robertosfield
OSG Project Lead


Joined: 18 Mar 2009
Posts: 12132

PostPosted: Mon Jan 22, 2018 11:38 am    Post subject:
iOS 11 and OSG_SYSTEM_SUPPORTED issue
Reply with quote

Hi Alessandro,

On 22 January 2018 at 10:51, Alessandro Terenzi <> wrote:
Quote:
Code:
#include <osg/os_utils>

#ifndef WIN32
#include <spawn.h>
#endif

extern "C" {

int osg_system(const char* command)
{
#ifdef WIN32
return system(command);
#else
pid_t pid;
posix_spawn(&pid, command, NULL, NULL, NULL, NULL);
return waitpid(pid, NULL, 0);
#endif
}

}


I am not 100% sure but, as far as I know, 'system(.)' should be always available on Windows, so it could be safe to use it only for Windows and use 'posix_spawn(.)' on the other platforms, what do you think? posix_spawn should work on any linux, right?

I think it'd work, but don't know how widely it'll be supported, what
I do know that it's only iOS so far that hasn't supported system() so
I'd be inclined to just use the posix_spawn fallback for iOS for now.

Robert.


------------------
Post generated by Mail2Forum
Back to top
View user's profile Send private message
a.terenzi (Alessandro Terenzi)
Appreciator


Joined: 03 Sep 2009
Posts: 250

PostPosted: Mon Jan 22, 2018 3:47 pm    Post subject:
Reply with quote

Ok, so, as far as I understand, OSG_SYSTEM_SUPPORTED is used only for iOS related builds, right?

If this is the case we could implement os_utils.cpp just like this:

Code:
#include <osg/os_utils>

#ifndef OSG_SYSTEM_SUPPORTED
#include <spawn.h>
#endif

extern "C" {
   
    int osg_system(const char* command)
    {
#ifdef OSG_SYSTEM_SUPPORTED
        return system(command);
#else
        pid_t pid;
        posix_spawn(&pid, command, NULL, NULL, NULL, NULL);
        return waitpid(pid, NULL, 0);
#endif
    }
   
}


And, in the future, if other platforms will not support system() and the above code won't work we can use more defines to handle each case. Do you agree?

Alessandro
Back to top
View user's profile Send private message
robertosfield
OSG Project Lead


Joined: 18 Mar 2009
Posts: 12132

PostPosted: Mon Jan 22, 2018 3:50 pm    Post subject:
iOS 11 and OSG_SYSTEM_SUPPORTED issue
Reply with quote

Hi Alessandro,

OSG_SYSTEM_SUPPORTED is really just a workaround for this iOS specific
problem, I'd rather that the C++ code itself can determine whether
system() is available or not. There are C++ Apple directives that
could possibly used, if there are iOS ones then these instead.



Robert.

On 22 January 2018 at 15:47, Alessandro Terenzi <> wrote:
Quote:
Ok, so, as far as I understand, OSG_SYSTEM_SUPPORTED is used only for iOS related builds, right?

If this is the case we could implement os_utils.cpp just like this:


Code:
#include <osg/os_utils>

#ifndef OSG_SYSTEM_SUPPORTED
#include <spawn.h>
#endif

extern "C" {

int osg_system(const char* command)
{
#ifdef OSG_SYSTEM_SUPPORTED
return system(command);
#else
pid_t pid;
posix_spawn(&pid, command, NULL, NULL, NULL, NULL);
return waitpid(pid, NULL, 0);
#endif
}

}



And, in the future, if other platforms will not support system() and the above code won't work we can use more defines to handle each case. Do you agree?

Alessandro

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=72831#72831








------------------
Post generated by Mail2Forum
Back to top
View user's profile Send private message
a.terenzi (Alessandro Terenzi)
Appreciator


Joined: 03 Sep 2009
Posts: 250

PostPosted: Mon Jan 22, 2018 5:05 pm    Post subject:
Reply with quote

Hi Robert,
yes, that makes sense. So here's how we can check that we are building for iOS (device or simulator):

Code:
#include <osg/os_utils>

#if defined(__APPLE__)
    #include "TargetConditionals.h"
    #if (TARGET_OS_IPHONE)
        #define OSG_SYSTEM_NOT_SUPPORTED
    #endif
#endif

#ifdef OSG_SYSTEM_NOT_SUPPORTED
#include <spawn.h>
#endif

extern "C" {
   
    int osg_system(const char* command)
    {
#ifdef OSG_SYSTEM_NOT_SUPPORTED
        pid_t pid;
        posix_spawn(&pid, command, NULL, NULL, NULL, NULL);
        return waitpid(pid, NULL, 0);
#else
        return system(command);
#endif
    }
   
}


If this is OK I will also remove the OSG_SYSTEM_SUPPORTED option in CMake and send all the updated files here. Just let me know.

Cheers,
Alessandro
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> Submission All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum

Similar Topics
Topic Author Forum Replies Posted
No new posts osg-users Digest, Vol 136, Issue 8 jonasydy General 0 Wed Oct 10, 2018 12:40 am View latest post
No new posts osg-users Digest, Vol 135, Issue 28 jonasydy General 0 Tue Sep 25, 2018 1:45 am View latest post
No new posts [Crash issue] no error info even set ... pwang General 1 Sun Jul 29, 2018 1:20 pm View latest post
No new posts [Crash issue] How to add&remove d... pwang General 2 Thu Jul 26, 2018 10:10 am View latest post
No new posts Build error under Windows? Need feedb... robertosfield General 3 Wed Jun 27, 2018 11:11 am View latest post


Board Security Anti Bot Question MOD - phpBB MOD against Spam Bots
Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP