English Amiga Board


Go Back   English Amiga Board > Coders > Coders. Language > Coders. C/C++

 
 
Thread Tools
Old 28 September 2018, 22:05   #1
BSzili
Registered User

BSzili's Avatar
 
Join Date: Nov 2011
Location: Hungary
Posts: 274
Creating a removable patch in C

I'm working on a patch for a lowlevel.library function that is almost finished, and all I need is a small program that can install and remove it. I already made a remove function that checks if there was another patch installed after mine for this purpose.

What I'm trying to do is very similar to a DOS TSR program. On the first launch it would install the patch and stay resident. Upon subsequent runs it would detect the resident version, and would try to remove the patch if requested. Is this possible? Are there any examples out there I could look at?

I'm using VBCC, but my code is fairly portable and it compiles with GCC as well (at least for now ).
BSzili is offline  
Old 28 September 2018, 22:47   #2
Samurai_Crow
Total Chaos forever!

Samurai_Crow's Avatar
 
Join Date: Aug 2007
Location: Ft. Collins, CO USA
Age: 44
Posts: 1,134
Send a message via Yahoo to Samurai_Crow
PowerPacker Patcher would install and remove itself. I don't know if there's source for it though.
Samurai_Crow is offline  
Old 29 September 2018, 10:48   #3
BSzili
Registered User

BSzili's Avatar
 
Join Date: Nov 2011
Location: Hungary
Posts: 274
I also remember seeing a few that could do this, but none of them were open source, so I don't know where to start.
BSzili is offline  
Old 29 September 2018, 12:04   #4
meynaf
son of 68k
meynaf's Avatar
 
Join Date: Nov 2007
Location: Lyon / France
Age: 45
Posts: 3,338
This is perfectly doable. In fact it's the way IPrefs work...
In unix world this is called a daemon.

Normally you should make your program self-detaching.
To know if it has already been run, create a public message port.
meynaf is offline  
Old 29 September 2018, 13:36   #5
alkis
Registered User

 
Join Date: Dec 2010
Location: Athens/Greece
Age: 47
Posts: 456
Excluding the self-detaching bit, this might be of help

http://amigadev.elowar.com/read/ADCD.../node0082.html
alkis is offline  
Old 29 September 2018, 13:58   #6
BSzili
Registered User

BSzili's Avatar
 
Join Date: Nov 2011
Location: Hungary
Posts: 274
Quote:
Originally Posted by meynaf View Post
This is perfectly doable. In fact it's the way IPrefs work...
In unix world this is called a daemon.

Normally you should make your program self-detaching.
To know if it has already been run, create a public message port.
What would be a system-friendly way of detaching from the CLI? The trivial method would be to use SystemTagList to restart the program with some argument, but then I might as well just use Run and be done with it.

Quote:
Originally Posted by alkis View Post
Excluding the self-detaching bit, this might be of help

http://amigadev.elowar.com/read/ADCD.../node0082.html
This is exactly how my program looks like now.
BSzili is offline  
Old 29 September 2018, 14:15   #7
meynaf
son of 68k
meynaf's Avatar
 
Join Date: Nov 2007
Location: Lyon / France
Age: 45
Posts: 3,338
Quote:
Originally Posted by BSzili View Post
What would be a system-friendly way of detaching from the CLI? The trivial method would be to use SystemTagList to restart the program with some argument, but then I might as well just use Run and be done with it.
Normally you should use your own seglist to create a process, then alter your seglist so your program remains in memory after exit, then exit.
I've seen that somewhere but i don't remember the details.

In a simpler way you could AllocMem and move some code there before exiting, but it's not exactly trivial in C.

Using Run is also a solution, of course. However you have to put your task to sleep otherwise it'll end up eating too much cpu
meynaf is offline  
Old 29 September 2018, 14:28   #8
BSzili
Registered User

BSzili's Avatar
 
Join Date: Nov 2011
Location: Hungary
Posts: 274
Thanks, that put me on the right path. You have to set cli_Module to NULL so it won't get freed, the detacher startup code in AROS does just this.
BSzili is offline  
Old 29 September 2018, 15:09   #9
alkis
Registered User

 
Join Date: Dec 2010
Location: Athens/Greece
Age: 47
Posts: 456
Also this https://github.com/cahirwpz/libnix/b.../misc/detach.c
alkis is offline  
Old 29 September 2018, 15:32   #10
BSzili
Registered User

BSzili's Avatar
 
Join Date: Nov 2011
Location: Hungary
Posts: 274
Thanks. It looks like libnix does the same thing (clearing cli_Module) with some gymnastics with the stack pointer. These should be more than enough to make my own version.
BSzili is offline  
 


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

Similar Threads
Thread Thread Starter Forum Replies Last Post
CF removable or fixed type irrelevant fgh support.Hardware 23 20 May 2015 10:18
removable drive removal error NewDeli support.WinUAE 5 24 September 2009 22:15
Problem With Removable Media Drives Ed Cruse support.WinUAE 5 29 June 2009 15:17
three in one? (SCSI Patch,Mac Patch,MapRom) RogerWilco09 support.Apps 0 05 May 2009 17:56
Removable Drive Problem With 1540b2 And On. Ed Cruse support.WinUAE 0 30 November 2008 19:12

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 05:06.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2018, vBulletin Solutions Inc.
Page generated in 0.07247 seconds with 13 queries