Login
Username:

Password:

Remember me



Lost Password?

Register now!

Sections

Who's Online
128 user(s) are online (122 user(s) are browsing Forums)

Members: 0
Guests: 128

more...

Support us!

Headlines

 
  Register To Post  

analog of execve() to resart ourself
Home away from home
Home away from home


See User information
@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!
AmigaOS4 on youtube
Go to top
Re: analog of execve() to resart ourself
Just can't stay away
Just can't stay away


See User information
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

Go to top
Re: analog of execve() to resart ourself
Home away from home
Home away from home


See User information
@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!
AmigaOS4 on youtube
Go to top
Re: analog of execve() to resart ourself
Just can't stay away
Just can't stay away


See User information
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>

Go to top
Re: analog of execve() to resart ourself
Home away from home
Home away from home


See User information
@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!
AmigaOS4 on youtube
Go to top
Re: analog of execve() to resart ourself
Home away from home
Home away from home


See User information
@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.
Go to top
Re: analog of execve() to resart ourself
Home away from home
Home away from home


See User information
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




Go to top
Re: analog of execve() to resart ourself
Home away from home
Home away from home


See User information
@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.
Go to top

  Register To Post

 




Currently Active Users Viewing This Thread: 1 ( 0 members and 1 Anonymous Users )




Powered by XOOPS 2.0 © 2001-2024 The XOOPS Project