ts-7000
[Top] [All Lists]

[ts-7000] Re: looking for another solution.

To:
Subject: [ts-7000] Re: looking for another solution.
From: "Brad Nelson" <>
Date: Wed, 27 Aug 2008 17:42:21 -0000
Hi Peter,

Originally we used a shell script.  I went to find it and found a
binary instead.  Ahh, teamwork...  I believe the reason it was changed
was that it seemed better as a binary because the shell script was
creating new processes constantly, and after a couple of days the PID
numbers were exorbitantly large.  Whether or not that could become an
issue or not, we don't know, but it just seemed like this was a
cleaner solution.

Here is the source for our bat3chk binary:

/* bat3chk.c -- Doug Brown

Responsible for making sure the battery daemon is running. It will
update the console if the battery daemon is unable to load. Otherwise,
it just restarts bat3 whenever an error occurs.
        
*/

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/wait.h>

#define BAT3_CMD "/usr/bin/nice", "/usr/bin/nice", "-n", "-5", "bat3",
"--shutdown", "10", "--on", "200", "--off", "20", "--charge", "400"

int main(int argc, char *argv[])
{
        pid_t bat3PID, returnPID;
        int status;

        while (1)
        {
                bat3PID = fork();

                if (bat3PID == 0) // child process
                {
                        if (execlp(BAT3_CMD, 0) == -1)
                        {
                                // if it's just normal operation
                                printf("Battery unable to charge");
                                sleep(1);
                        }
                }
                else if (bat3PID != -1) // parent process, no error
                {
                        status = 0;
                        returnPID = wait(&status); // wait for bat3 to exit
                }
                else // fork() failed
                {
                        printf("Battery unable to charge");
                        sleep(1);
                }
        }
}

Modify it to match your needs, compile, put it in the /etc/init.d/
folder, and use update-rc.d to make the program run on startup.

Best regards,
Brad Nelson

--- In  "PeterElliot" <> wrote:
>
> Brad,
> 
> Thank you for all the interesting insight into what you've done to get
> the BAT3 working as well as it can.
> 
> Can you outline what this shell script was, and what function it
> performed. (You could post it to the files section if possible).
> 
> Thanks,
> 
> PJE
> 



------------------------------------

Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/ts-7000/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/ts-7000/join
    (Yahoo! ID required)

<*> To change settings via email:
     
    

<*> To unsubscribe from this group, send an email to:
    

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/

<Prev in Thread] Current Thread [Next in Thread>
Admin

Disclaimer: Neither Andrew Taylor nor the University of NSW School of Computer and Engineering take any responsibility for the contents of this archive. It is purely a compilation of material sent by many people to the birding-aus mailing list. It has not been checked for accuracy nor its content verified in any way. If you wish to get material removed from the archive or have other queries about the archive e-mail Andrew Taylor at this address: andrewt@cse.unsw.EDU.AU