Re: lug-bg: AutoSlack 1.7 KeepAlive script
- Subject: Re: lug-bg: AutoSlack 1.7 KeepAlive script
- From: vd@xxxxxxxxx (Vladimir Dzhuvinov)
- Date: Fri, 25 May 2001 14:47:58 +0000 (GMT)
Zdravei,
On Fri, 25 May 2001, George Danchev wrote:
>neuspeshno , prosto tazi funkciq vse oste ne raboti) i sled kato izte4e
>TIMEOUT parametura koito mu se zadava (opitvah na nqkolko ftp servera s
>mnogo golemi timeout stoinosti - ne resume-va ) autoslack prekratqwa rabota
>. Trqbwa ru4no da se startira otnovo i zlopolu4niq package ste bude izteglen
>otna4alo , za ve4e izteglinite nqma problemi - spool-nati sa v edin
>dir . Ta pri men taka 3 puti dropwashe na polovinata na glibc-2.2.2 (27MB)
>... dialer-a (v moq slu4ai) reconnect-va , no autoslack ne iska da resume-ne
>:(((.
Predpolagam, che tova e bilo mnogo nepriatno :-(
>Ta pitaneto mi e slednoto :
...
>Ta moje li nqkoi da nahvurlq suvsem grubo nqkolko red4eta na takuv keepalive
>bash script koito da sledi i restartira : autoslack -opt1 -opt2 -optX
>( moje i na drug script ezik ) , a az posle ste si go "doumorq".
Prastam ti edna cqla C programa, kompilira se s
gcc -o keepalive keepalive.c
Sled tova pishesh
./keepalive command [arguments]
led koeto keepalive instalira SIGCHLD handler, fork-va command child,
i usleep(). Ako child command terminira, keepalive poluchava SIGCHLD,
sybuwda se, fork-va nov command child i pak zaspiva...
Edinstveniq nachin da prekratish tozi cikyl e da kill-nesh keepalive.
Predpolagam, che autoslack e konzolna programa, a pyk keepalive sym q
pisal s mnogo verbose prints, koito mogat da sa nepodhodiasti za teb,
zatova mojesh spokoino da iztriesh vsicko sto e printf() v keepalive.c
Razbira se, ne poemam nikakva garanciq za tazi programa.
Use at your own risk ;-))
Pozdravi,
Vladimir Dzhuvinov
--
PGP 1024D/959FC3BC 2001-02-12 Vladimir Dzhuvinov <vd@xxxxxxxxx>
Key fingerprint = CB20 FC83 775C C34E 49D5 0F71 BAE5 7C38 959F C3BC
Download public PGP key from http://www.valan.net/vdzhuvinov.asc
/* Vladimir Djouvinov, 12-2-1999
* Forks out a child process and goes into sleep-wakeup cycle
* If a SIGCHILD is received (child process died),
* a new instance of it is forked
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>
#include <signal.h>
#include <unistd.h>
#include <sys/wait.h>
char* full_program_invocation_name;
char* command;
char** arguments;
pid_t child_pid;
int
start_process ()
{
/* --- check for NULL function arguments --- */
if (command == NULL)
{
fprintf(stderr, "%s: no process to start\n",
full_program_invocation_name);
return (1);
}
/* --- fork scan process --- */
child_pid = fork();
if(child_pid == -1)
{
/* fork() failed */
fprintf(stderr, "%s: forking failed: %s\n",
full_program_invocation_name,
strerror(errno));
return (1);
}
else if(child_pid == 0)
{
/* child */
if ((execvp (command, arguments) )==-1)
{
fprintf(stderr, "%s: couldn't execute %s: %s\n",
full_program_invocation_name,
command,
strerror(errno));
return (1);
}
/* exit child. note the use of _exit() instead of exit() */
_exit(-1);
}
else
/* parent */
{
printf ("%s: forked child process with pid %d\n",
full_program_invocation_name,
child_pid);
}
return (0);
}
void
child_exit (int sig)
{
int exit_status;
puts("received SIGCHLD");
if (waitpid(child_pid, &exit_status, WNOHANG | WUNTRACED) == -1)
fprintf(stderr, "%s: couldn't get status of child process(pid=%d): %s\n",
full_program_invocation_name,
child_pid,
strerror(errno));
printf ("%s: child process(pid=%d) terminated with status %d, starting new process...\n",
full_program_invocation_name,
child_pid,
WEXITSTATUS(exit_status));
start_process();
}
int
main (int argc, char *argv[])
{
int i;
/* --- set the program invocation name for error reporting--- */
full_program_invocation_name = argv[0];
/* --- check input --- */
if (argc == 1){
printf ("%s: usage %s command [options...]\n",
full_program_invocation_name,
full_program_invocation_name);
return (1);
}
/* --- install a signal handler for the child exit signal --- */
if (signal (SIGCHLD, child_exit)==SIG_ERR) {
printf ("%s: signal CHLD cannot be handled\n",
full_program_invocation_name);
return (1);
}
/* --- set the command of the process to be started --- */
command = argv[1];
printf ("command is %s\n", command);
/* --- set the process arguments pointer --- */
arguments = (char**)malloc(argc * sizeof(char*));
for (i=0; i < argc; ++i) {
arguments[i] = argv[i+1];
printf ("ref. %d = %s\n", i, arguments[i]);
}
arguments[++i] == NULL;
/* --- call fork wrapper --- */
start_process();
while (1)
sleep(60);
return (0);
}
===========================================================================
A mail-list of Linux Users Group - Bulgaria (bulgarian linuxers)
http://www.linux-bulgaria.org/ Hosted by Internet Group Ltd. - Stara Zagora
|