Login
Username:

Password:

Remember me



Lost Password?

Register now!

Sections

Who's Online
48 user(s) are online (29 user(s) are browsing Forums)

Members: 0
Guests: 48

more...

Headlines






analog of execve() to resart ourself
Home away from home
Joined:
2007/9/11 12:31
From Russia
Posts: 7284
@All
Have little issue: have a game which when change settings do a restart of ourself and do it like this:

void restart (void)
{
    
char *args[] = { 0};
    
char *executable ARGV[0];

    
LOG("Run %s"executable);

    
args[0] = executable;

#ifdef _WIN32
    
execve(executable, (const char *const *) args0);
#else
    
execve(executable, (char *const *) args0);
#endif
}


So, on Win32 and on Linux that "execve()" called, the old process dies/closes, and new ones replace it automatically.

But as on amigaos4, we don't have the same functionality, I need somehow mimic the same.

Currently i have code to run it again:

#include <proto/exec.h>
#include <proto/wb.h>
#include <proto/dos.h>
    
struct Library *workbenchbase
    
struct WorkbenchIFace *iworkbench
    
BPTR path_list ZERO
    
BPTR input_file ZERO
    
BPTR output_file ZERO
    
int32 error = -1

    
sdl_fini();

    
workbenchbase IExec->OpenLibrary("workbench.library"53); 
    
iworkbench = (struct WorkbenchIFace *)IExec->GetInterface(workbenchbase"main"1NULL); 

    if (
iworkbench != NULL) { 
        
iworkbench->WorkbenchControl(NULL
            
WBCTRLA_DuplicateSearchPath, &path_list
            
TAG_END); 
    } 

    
input_file IDOS->Open("NIL:"MODE_OLDFILE); 
    
output_file IDOS->Open("NIL:"MODE_OLDFILE); 

    if (
input_file && output_file) { 
        
error IDOS->SystemTags(executable
            
NP_Name,    "Gorynlich restart"
            
NP_Path,    path_list
            
SYS_AsynchTRUE
            
SYS_Input,  input_file
            
SYS_Outputoutput_file
            
SYS_Error,  ZERO
            
TAG_END); 
    } 

    if (
error) { 
        
IDOS->Close(input_file); 
        
IDOS->Close(output_file); 
    } 

    if (
error && iworkbench != NULL) { 
        
iworkbench->WorkbenchControl(NULL
            
WBCTRLA_FreeSearchPathpath_list
            
TAG_END); 
    } 

    
IExec->DropInterface((struct Interface *)iworkbench); 
    
IExec->CloseLibrary(workbenchbase);



But then, I need to add proper "quit", but if I add proper quit (like sdl_exit() ), then I quit from the game, and the code for restarting didn't called of course.

Maybe there some analog of execve() we have without needs to worry about all this? Or the only solution there is to make a loop in the main() { }, where do check on restarting the flag and then clean resources and start them again?


In other words, do we have the functionality to restart the whole binary, just by executing it again, without additional code?

Thanks!


Edited by kas1e on 2021/4/1 20:50:36
_________________
Join us to improve dopus5!
zerohero's mirror of os4/os3 crosscompiler suites
   Report Go to top

Re: analog of execve() to resart ourself
Quite a regular
Joined:
2007/2/6 13:57
From Donostia (SPAIN)
Posts: 680
Hi, dirty way:
-Create a script like:
Wait 2 SECS
<executable>

And on restart() just before exit/quit "run script" (with SystemTags() or alike)

or add to ReadMe a warning/note to user to (re)run program when saving/changing settings

   Report Go to top

Re: analog of execve() to resart ourself
Home away from home
Joined:
2007/9/11 12:31
From Russia
Posts: 7284
@jabirulo
Yeah, that both very dirty and not user-friendly ways which I wish to avoid and implement thing properly :).

_________________
Join us to improve dopus5!
zerohero's mirror of os4/os3 crosscompiler suites
   Report Go to top

Re: analog of execve() to resart ourself
Quite a regular
Joined:
2007/2/6 13:57
From Donostia (SPAIN)
Posts: 680
Or another dirty way:
restart() quits/exit with a "special" RC (example: 99) and launch script is like this:

LABEL restart
<executable>
IF $RC EQ 99 THEN
Wait 2 SECS
SKIP restart BACK
ENDIF

and make script "main program" with icon, instead of <executable>

   Report Go to top

Re: analog of execve() to resart ourself
Home away from home
Joined:
2007/9/11 12:31
From Russia
Posts: 7284
@javier
That all no go, as I say I need that from C code itself, without additional scripts, pure C code inside of the same game's code.


_________________
Join us to improve dopus5!
zerohero's mirror of os4/os3 crosscompiler suites
   Report Go to top

Re: analog of execve() to resart ourself
Home away from home
Joined:
2006/11/20 16:26
From Norway
Posts: 3025
@kas1e

you can exit from any place in your program using exit(0);
but you most cleanup before calling exit(0);

You should not clean up:

input_file = IDOS->Open("NIL:", MODE_OLDFILE);
output_file = IDOS->Open("NIL:", MODE_OLDFILE);

this are cleaned up by the ASYNC Process.

Quote:
But then, I need to add proper "quit", but if I add proper quit (like sdl_exit() ), then I quit from the game, and the code for restarting didn't called of course.


in most of my programs, have a

bool init();

and

void shutdown();

it makes it easier to clean up, and the code looks nicer too. if you do it like that.


Edited by LiveForIt on 2021/4/2 9:52:01
_________________
(NutsAboutAmiga)

Basilisk II for AmigaOS4
AmigaInputAnywhere
Excalibur
and other tools and apps.
   Report Go to top

Re: analog of execve() to resart ourself
Home away from home
Joined:
2006/12/4 23:15
Posts: 2310
Honestly that's bad program design even in a linux environment, but given that....

Quote:

But then, I need to add proper "quit", but if I add proper quit (like sdl_exit() ), then I quit from the game, and the code for restarting didn't called of course.


Why not? Surely you already ran the new copy before exiting? You would need to run the new copy asynchronously ofcourse. (which it looks like you do) Unless there is some code that stops more than one copy from running at a time?

Depending on the program design you *might* be able to just reinitialise the program without restarting. There was case in blender where it forked of a new copy to handle the video player, when actually theer was no need, the existing copy just waited for the new one to complete and so I just called the video player code directly in the same context.

Quote:

Or the only solution there is to make a loop in the main() { }, where do check on restarting the flag and then clean resources and start them again?


If that is viable it would be more elegant, then you can send them a patch to fix their lazy code (Maybe not say that though




_________________
Blender For OS4.x : Blues : Walker Broad
   Report Go to top

Re: analog of execve() to resart ourself
Home away from home
Joined:
2006/11/20 16:26
From Norway
Posts: 3025
@broadblues

Quote:
Honestly that's bad program design even in a linux environment, but given that....


Its problem to clean up when you have many exists, and don’t know what is causing the exit, memory leeks are more likely to happen.

_________________
(NutsAboutAmiga)

Basilisk II for AmigaOS4
AmigaInputAnywhere
Excalibur
and other tools and apps.
   Report Go to top





[Advanced Search]



Powered by XOOPS 2.0 © 2001-2016 The XOOPS Project