@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, 0 };
char *executable = ARGV[0];
LOG("Run %s", executable);
args[0] = executable;
#ifdef _WIN32
execve(executable, (const char *const *) args, 0);
#else
execve(executable, (char *const *) args, 0);
#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", 1, NULL);
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_Asynch, TRUE,
SYS_Input, input_file,
SYS_Output, output_file,
SYS_Error, ZERO,
TAG_END);
}
if (error) {
IDOS->Close(input_file);
IDOS->Close(output_file);
}
if (error && iworkbench != NULL) {
iworkbench->WorkbenchControl(NULL,
WBCTRLA_FreeSearchPath, path_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