Changed all error return codes
This commit is contained in:
14
lib/Makefile
14
lib/Makefile
@@ -33,7 +33,7 @@ DIESEL_OBJS = diesel.o mbdiesel.o
|
||||
MEMWATCH_SRCS = memwatch.c
|
||||
MEMWATCH_OBJS = memwatch.o
|
||||
MEMWATCH_HDRS = memwatch.h
|
||||
OTHER_HDRS = ansi.h bluewave.h libs.h mbse.h records.h structs.h users.h
|
||||
OTHER_HDRS = ansi.h bluewave.h libs.h mbse.h records.h structs.h users.h mberrors.h
|
||||
SRCS = ${CLCOMM_SRCS} ${COMMON_SRCS} ${DBASE_SRCS} ${MSGBASE_SRCS} ${MBINET_SRCS} \
|
||||
${DIESEL_SRCS} ${MEMWATCH_SRCS}
|
||||
OBJS = ${CLCOMM_OBJS} ${COMMON_OBJS} ${DBASE_OBJS} ${MSGBASE_OBJS} ${MBINET_OBJS} \
|
||||
@@ -115,7 +115,7 @@ depend: ftscprod.c
|
||||
|
||||
# DO NOT DELETE THIS LINE - MAKE DEPEND RELIES ON IT
|
||||
# Dependencies generated by make depend
|
||||
clcomm.o: ../config.h libs.h memwatch.h clcomm.h
|
||||
clcomm.o: ../config.h libs.h memwatch.h mberrors.h clcomm.h
|
||||
client.o: ../config.h libs.h memwatch.h clcomm.h
|
||||
crc.o: ../config.h libs.h memwatch.h clcomm.h
|
||||
semafore.o: ../config.h libs.h memwatch.h structs.h clcomm.h common.h
|
||||
@@ -139,11 +139,11 @@ dostran.o: ../config.h libs.h memwatch.h structs.h users.h records.h common.h
|
||||
ftnmsg.o: ../config.h libs.h memwatch.h structs.h common.h clcomm.h
|
||||
mbfile.o: ../config.h libs.h memwatch.h structs.h clcomm.h common.h
|
||||
nodelock.o: ../config.h libs.h memwatch.h structs.h clcomm.h common.h
|
||||
rawio.o: ../config.h libs.h memwatch.h structs.h common.h
|
||||
rawio.o: ../config.h libs.h memwatch.h structs.h common.h mberrors.h
|
||||
strcasestr.o: ../config.h libs.h memwatch.h
|
||||
charconv_hz.o: ../config.h libs.h memwatch.h structs.h common.h clcomm.h
|
||||
execute.o: ../config.h libs.h memwatch.h structs.h clcomm.h common.h
|
||||
expipe.o: ../config.h libs.h memwatch.h structs.h clcomm.h common.h
|
||||
execute.o: ../config.h libs.h memwatch.h structs.h clcomm.h mberrors.h common.h
|
||||
expipe.o: ../config.h libs.h memwatch.h structs.h clcomm.h mberrors.h common.h
|
||||
getheader.o: ../config.h libs.h memwatch.h structs.h users.h records.h clcomm.h common.h
|
||||
mime.o: ../config.h libs.h memwatch.h structs.h clcomm.h common.h
|
||||
noderecord.o: ../config.h libs.h memwatch.h structs.h common.h users.h records.h dbnode.h common.h
|
||||
@@ -155,8 +155,8 @@ gmtoffset.o: ../config.h libs.h memwatch.h structs.h common.h
|
||||
packet.o: ../config.h libs.h memwatch.h structs.h users.h records.h clcomm.h common.h dbnode.h
|
||||
rfcdate.o: ../config.h libs.h memwatch.h structs.h common.h clcomm.h
|
||||
term.o: ../config.h libs.h memwatch.h structs.h users.h ansi.h records.h common.h
|
||||
dbcfg.o: ../config.h libs.h memwatch.h mbse.h structs.h users.h records.h dbcfg.h
|
||||
dbdupe.o: ../config.h libs.h memwatch.h structs.h clcomm.h dbdupe.h
|
||||
dbcfg.o: ../config.h libs.h memwatch.h mbse.h structs.h users.h records.h mberrors.h dbcfg.h
|
||||
dbdupe.o: ../config.h libs.h memwatch.h structs.h clcomm.h mberrors.h dbdupe.h
|
||||
dbftn.o: ../config.h libs.h memwatch.h structs.h users.h records.h dbcfg.h dbftn.h
|
||||
dbmsgs.o: ../config.h libs.h memwatch.h structs.h users.h records.h clcomm.h dbcfg.h dbmsgs.h
|
||||
dbnode.o: ../config.h libs.h memwatch.h structs.h common.h users.h records.h clcomm.h dbcfg.h dbnode.h
|
||||
|
@@ -31,6 +31,7 @@
|
||||
#include "../config.h"
|
||||
#include "libs.h"
|
||||
#include "memwatch.h"
|
||||
#include "mberrors.h"
|
||||
#include "clcomm.h"
|
||||
|
||||
|
||||
@@ -106,7 +107,7 @@ void InitClient(char *user, char *myname, char *where, char *log, long loggr, ch
|
||||
printf("Could not get the MBSE_ROOT environment variable\n");
|
||||
printf("Please set the environment variable ie:\n");
|
||||
printf("\"MBSE_ROOT=/opt/mbse; export MBSE_ROOT\"\n\n");
|
||||
exit(1);
|
||||
exit(MBERR_INIT_ERROR);
|
||||
}
|
||||
|
||||
sprintf(progname, "%s", myname);
|
||||
@@ -125,7 +126,7 @@ void InitClient(char *user, char *myname, char *where, char *log, long loggr, ch
|
||||
mypid = getpid();
|
||||
if (socket_connect(user, myname, where) == -1) {
|
||||
printf("PANIC: cannot access socket\n");
|
||||
exit(1);
|
||||
exit(MBERR_INIT_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -35,6 +35,7 @@
|
||||
#include "structs.h"
|
||||
#include "users.h"
|
||||
#include "records.h"
|
||||
#include "mberrors.h"
|
||||
#include "dbcfg.h"
|
||||
|
||||
|
||||
@@ -46,7 +47,7 @@ void InitConfig(void)
|
||||
printf("Could not get MBSE_ROOT environment variable\n");
|
||||
printf("Please set the environment variable ie:\n");
|
||||
printf("\"MBSE_ROOT=/opt/mbse;export MBSE_ROOT\"\n\n");
|
||||
exit(1);
|
||||
exit(MBERR_INIT_ERROR);
|
||||
}
|
||||
LoadConfig();
|
||||
}
|
||||
@@ -69,7 +70,7 @@ void LoadConfig(void)
|
||||
#ifdef MEMWATCH
|
||||
mwTerm();
|
||||
#endif
|
||||
exit(1);
|
||||
exit(MBERR_CONFIG_ERROR);
|
||||
}
|
||||
|
||||
free(FileName);
|
||||
|
@@ -33,9 +33,11 @@
|
||||
#include "memwatch.h"
|
||||
#include "structs.h"
|
||||
#include "clcomm.h"
|
||||
#include "mberrors.h"
|
||||
#include "dbdupe.h"
|
||||
|
||||
|
||||
|
||||
typedef struct _dupesrec {
|
||||
unsigned long *crcs;
|
||||
int loaded;
|
||||
@@ -85,7 +87,7 @@ int CheckDupe(unsigned long crc, int idx, int max)
|
||||
if ((fil = fopen(dfile, "w")) == NULL) {
|
||||
WriteError("$PANIC: dbdupe.c, can't create %s", dfile);
|
||||
free(dfile);
|
||||
exit(1);
|
||||
exit(MBERR_INIT_ERROR);
|
||||
}
|
||||
fclose(fil);
|
||||
fil = fopen(dfile, "r+");
|
||||
|
231
lib/execute.c
231
lib/execute.c
@@ -1,11 +1,10 @@
|
||||
/*****************************************************************************
|
||||
*
|
||||
* File ..................: execute.c
|
||||
* $Id$
|
||||
* Purpose ...............: Execute subprogram
|
||||
* Last modification date : 16-Feb-2001
|
||||
*
|
||||
*****************************************************************************
|
||||
* Copyright (C) 1997-2001
|
||||
* Copyright (C) 1997-2002
|
||||
*
|
||||
* Michiel Broek FIDO: 2:280/2802
|
||||
* Beekmansbos 10
|
||||
@@ -34,6 +33,7 @@
|
||||
#include "memwatch.h"
|
||||
#include "structs.h"
|
||||
#include "clcomm.h"
|
||||
#include "mberrors.h"
|
||||
#include "common.h"
|
||||
|
||||
|
||||
@@ -43,91 +43,90 @@ int e_pid = 0; /* Execute child pid */
|
||||
|
||||
int execute(char *cmd, char *file, char *pkt, char *in, char *out, char *err)
|
||||
{
|
||||
char buf[512];
|
||||
char *vector[16];
|
||||
int i;
|
||||
int pid, status, rc;
|
||||
char buf[512];
|
||||
char *vector[16];
|
||||
int i, pid, status, rc;
|
||||
|
||||
if (pkt == NULL)
|
||||
sprintf(buf, "%s %s", cmd, file);
|
||||
else
|
||||
sprintf(buf, "%s %s %s", cmd, file, pkt);
|
||||
Syslog('+', "Execute: %s",buf);
|
||||
if (pkt == NULL)
|
||||
sprintf(buf, "%s %s", cmd, file);
|
||||
else
|
||||
sprintf(buf, "%s %s %s", cmd, file, pkt);
|
||||
Syslog('+', "Execute: %s",buf);
|
||||
|
||||
i = 0;
|
||||
vector[i++] = strtok(buf," \t\n");
|
||||
while ((vector[i++] = strtok(NULL," \t\n")) && (i<16));
|
||||
vector[15] = NULL;
|
||||
fflush(stdout);
|
||||
fflush(stderr);
|
||||
i = 0;
|
||||
vector[i++] = strtok(buf," \t\n");
|
||||
while ((vector[i++] = strtok(NULL," \t\n")) && (i<16));
|
||||
vector[15] = NULL;
|
||||
fflush(stdout);
|
||||
fflush(stderr);
|
||||
|
||||
if ((pid = fork()) == 0) {
|
||||
if (in) {
|
||||
close(0);
|
||||
if (open(in,O_RDONLY) != 0) {
|
||||
WriteError("$Reopen of stdin to %s failed", MBSE_SS(in));
|
||||
exit(-1);
|
||||
}
|
||||
}
|
||||
if (out) {
|
||||
close(1);
|
||||
if (open(out,O_WRONLY | O_APPEND | O_CREAT,0600) != 1) {
|
||||
WriteError("$Reopen of stdout to %s failed", MBSE_SS(out));
|
||||
exit(-1);
|
||||
}
|
||||
}
|
||||
if (err) {
|
||||
close(2);
|
||||
if (open(err,O_WRONLY | O_APPEND | O_CREAT,0600) != 2) {
|
||||
WriteError("$Reopen of stderr to %s failed", MBSE_SS(err));
|
||||
exit(-1);
|
||||
}
|
||||
}
|
||||
errno = 0;
|
||||
rc = getpriority(PRIO_PROCESS, 0);
|
||||
if (errno == 0) {
|
||||
rc = setpriority(PRIO_PROCESS, 0, 15);
|
||||
if (rc)
|
||||
WriteError("$execv can't set priority to 15");
|
||||
}
|
||||
rc = execv(vector[0],vector);
|
||||
WriteError("$execv \"%s\" returned %d", MBSE_SS(vector[0]), rc);
|
||||
setpriority(PRIO_PROCESS, 0, 0);
|
||||
exit(-1);
|
||||
if ((pid = fork()) == 0) {
|
||||
if (in) {
|
||||
close(0);
|
||||
if (open(in,O_RDONLY) != 0) {
|
||||
WriteError("$Reopen of stdin to %s failed", MBSE_SS(in));
|
||||
exit(MBERR_EXEC_FAILED);
|
||||
}
|
||||
}
|
||||
|
||||
e_pid = pid;
|
||||
|
||||
do {
|
||||
rc = wait(&status);
|
||||
e_pid = 0;
|
||||
} while (((rc > 0) && (rc != pid)) || ((rc == -1) && (errno == EINTR)));
|
||||
|
||||
if (out) {
|
||||
close(1);
|
||||
if (open(out,O_WRONLY | O_APPEND | O_CREAT,0600) != 1) {
|
||||
WriteError("$Reopen of stdout to %s failed", MBSE_SS(out));
|
||||
exit(MBERR_EXEC_FAILED);
|
||||
}
|
||||
}
|
||||
if (err) {
|
||||
close(2);
|
||||
if (open(err,O_WRONLY | O_APPEND | O_CREAT,0600) != 2) {
|
||||
WriteError("$Reopen of stderr to %s failed", MBSE_SS(err));
|
||||
exit(MBERR_EXEC_FAILED);
|
||||
}
|
||||
}
|
||||
errno = 0;
|
||||
rc = getpriority(PRIO_PROCESS, 0);
|
||||
if (errno == 0) {
|
||||
rc = setpriority(PRIO_PROCESS, 0, 15);
|
||||
if (rc)
|
||||
WriteError("$execv can't set priority to 15");
|
||||
}
|
||||
rc = execv(vector[0],vector);
|
||||
WriteError("$execv \"%s\" returned %d", MBSE_SS(vector[0]), rc);
|
||||
setpriority(PRIO_PROCESS, 0, 0);
|
||||
switch (rc) {
|
||||
exit(MBERR_EXEC_FAILED);
|
||||
}
|
||||
|
||||
e_pid = pid;
|
||||
|
||||
do {
|
||||
rc = wait(&status);
|
||||
e_pid = 0;
|
||||
} while (((rc > 0) && (rc != pid)) || ((rc == -1) && (errno == EINTR)));
|
||||
|
||||
setpriority(PRIO_PROCESS, 0, 0);
|
||||
switch (rc) {
|
||||
case -1:
|
||||
WriteError("$Wait returned %d, status %d,%d", rc,status>>8,status&0xff);
|
||||
return -1;
|
||||
return MBERR_EXEC_FAILED;
|
||||
case 0:
|
||||
return 0;
|
||||
default:
|
||||
if (WIFEXITED(status)) {
|
||||
rc = WEXITSTATUS(status);
|
||||
if (rc) {
|
||||
WriteError("Execute: returned error %d", rc);
|
||||
return rc;
|
||||
}
|
||||
rc = WEXITSTATUS(status);
|
||||
if (rc) {
|
||||
WriteError("Execute: returned error %d", rc);
|
||||
return (rc + MBERR_EXTERNAL);
|
||||
}
|
||||
}
|
||||
if (WIFSIGNALED(status)) {
|
||||
rc = WTERMSIG(status);
|
||||
WriteError("Wait stopped on signal %d", rc);
|
||||
return rc;
|
||||
rc = WTERMSIG(status);
|
||||
WriteError("Wait stopped on signal %d", rc);
|
||||
return rc;
|
||||
}
|
||||
if (rc)
|
||||
WriteError("Wait stopped unknown, rc=%d", rc);
|
||||
WriteError("Wait stopped unknown, rc=%d", rc);
|
||||
return rc;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -136,57 +135,57 @@ int execute(char *cmd, char *file, char *pkt, char *in, char *out, char *err)
|
||||
|
||||
int execsh(char *cmd, char *in, char *out, char *err)
|
||||
{
|
||||
int pid, status, rc, sverr;
|
||||
int pid, status, rc, sverr;
|
||||
|
||||
Syslog('+', "Execute shell: %s", MBSE_SS(cmd));
|
||||
fflush(stdout);
|
||||
fflush(stderr);
|
||||
Syslog('+', "Execute shell: %s", MBSE_SS(cmd));
|
||||
fflush(stdout);
|
||||
fflush(stderr);
|
||||
|
||||
if ((pid = fork()) == 0) {
|
||||
if (in) {
|
||||
close(0);
|
||||
if (open(in, O_RDONLY) != 0) {
|
||||
WriteError("$Reopen of stdin to %s failed",MBSE_SS(in));
|
||||
exit(-1);
|
||||
}
|
||||
}
|
||||
if (out) {
|
||||
close(1);
|
||||
if (open(out, O_WRONLY | O_APPEND | O_CREAT,0600) != 1) {
|
||||
WriteError("$Reopen of stdout to %s failed",MBSE_SS(out));
|
||||
exit(-1);
|
||||
}
|
||||
}
|
||||
if (err) {
|
||||
close(2);
|
||||
if (open(err, O_WRONLY | O_APPEND | O_CREAT,0600) != 2) {
|
||||
WriteError("$Reopen of stderr to %s failed",MBSE_SS(err));
|
||||
exit(-1);
|
||||
}
|
||||
}
|
||||
|
||||
rc = execl(SHELL, "sh", "-c", cmd, NULL);
|
||||
WriteError("$execl \"%s\" returned %d", MBSE_SS(cmd), rc);
|
||||
exit(-1);
|
||||
if ((pid = fork()) == 0) {
|
||||
if (in) {
|
||||
close(0);
|
||||
if (open(in, O_RDONLY) != 0) {
|
||||
WriteError("$Reopen of stdin to %s failed",MBSE_SS(in));
|
||||
exit(MBERR_EXEC_FAILED);
|
||||
}
|
||||
}
|
||||
if (out) {
|
||||
close(1);
|
||||
if (open(out, O_WRONLY | O_APPEND | O_CREAT,0600) != 1) {
|
||||
WriteError("$Reopen of stdout to %s failed",MBSE_SS(out));
|
||||
exit(MBERR_EXEC_FAILED);
|
||||
}
|
||||
}
|
||||
if (err) {
|
||||
close(2);
|
||||
if (open(err, O_WRONLY | O_APPEND | O_CREAT,0600) != 2) {
|
||||
WriteError("$Reopen of stderr to %s failed",MBSE_SS(err));
|
||||
exit(MBERR_EXEC_FAILED);
|
||||
}
|
||||
}
|
||||
|
||||
e_pid = pid;
|
||||
rc = execl(SHELL, "sh", "-c", cmd, NULL);
|
||||
WriteError("$execl \"%s\" returned %d", MBSE_SS(cmd), rc);
|
||||
exit(MBERR_EXEC_FAILED);
|
||||
}
|
||||
|
||||
do {
|
||||
rc = wait(&status);
|
||||
e_pid = 0;
|
||||
sverr = errno;
|
||||
if (status)
|
||||
WriteError("$Wait returned %d, status %d,%d", rc, status >> 8, status & 0xff);
|
||||
}
|
||||
e_pid = pid;
|
||||
|
||||
while (((rc > 0) && (rc != pid)) || ((rc == -1) && (sverr == EINTR)));
|
||||
if (rc == -1) {
|
||||
WriteError("$Wait returned %d, status %d,%d", rc, status >> 8, status & 0xff);
|
||||
return -1;
|
||||
}
|
||||
do {
|
||||
rc = wait(&status);
|
||||
e_pid = 0;
|
||||
sverr = errno;
|
||||
if (status)
|
||||
WriteError("$Wait returned %d, status %d,%d", rc, status >> 8, status & 0xff);
|
||||
}
|
||||
|
||||
return status;
|
||||
while (((rc > 0) && (rc != pid)) || ((rc == -1) && (sverr == EINTR)));
|
||||
if (rc == -1) {
|
||||
WriteError("$Wait returned %d, status %d,%d", rc, status >> 8, status & 0xff);
|
||||
return MBERR_EXEC_FAILED;
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
|
234
lib/expipe.c
234
lib/expipe.c
@@ -33,15 +33,16 @@
|
||||
#include "memwatch.h"
|
||||
#include "structs.h"
|
||||
#include "clcomm.h"
|
||||
#include "mberrors.h"
|
||||
#include "common.h"
|
||||
|
||||
|
||||
|
||||
static struct _fppid {
|
||||
FILE *fp;
|
||||
int pid;
|
||||
FILE *fp;
|
||||
int pid;
|
||||
} fppid[] = {
|
||||
{NULL, 0}, {NULL, 0}, {NULL, 0}
|
||||
{NULL, 0}, {NULL, 0}, {NULL, 0}
|
||||
};
|
||||
|
||||
#define maxfppid 2
|
||||
@@ -50,147 +51,142 @@ static struct _fppid {
|
||||
|
||||
FILE *expipe(char *cmd, char *from, char *to)
|
||||
{
|
||||
char buf[256], *buflimit;
|
||||
char *vector[16];
|
||||
int i, rc;
|
||||
char *p, *q, *f=from, *t=to;
|
||||
int pipedes[2];
|
||||
FILE *fp;
|
||||
int pid, slot;
|
||||
char buf[256], *buflimit, *vector[16], *p, *q, *f=from, *t=to;
|
||||
FILE *fp;
|
||||
int i, rc, pid, slot, pipedes[2];
|
||||
|
||||
buflimit = buf + sizeof(buf) -1 - (f&&t&&(strlen(f)>strlen(t))?strlen(f):t?strlen(t):0);
|
||||
buflimit = buf + sizeof(buf) -1 - (f&&t&&(strlen(f)>strlen(t))?strlen(f):t?strlen(t):0);
|
||||
|
||||
for (slot = 0; slot <= maxfppid; slot++) {
|
||||
if (fppid[slot].fp == NULL)
|
||||
for (slot = 0; slot <= maxfppid; slot++) {
|
||||
if (fppid[slot].fp == NULL)
|
||||
break;
|
||||
}
|
||||
if (slot > maxfppid) {
|
||||
WriteError("Attempt to pipe more than %d processes", maxfppid + 1);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
for (p = cmd, q = buf; (*p); p++) {
|
||||
if (q > buflimit) {
|
||||
WriteError("Attempt to pipe too long command");
|
||||
return NULL;
|
||||
}
|
||||
switch (*p) {
|
||||
case '$': switch (*(++p)) {
|
||||
case 'f':
|
||||
case 'F': if ((f))
|
||||
while (*f)
|
||||
*(q++) = *(f++);
|
||||
f=from;
|
||||
break;
|
||||
case 't':
|
||||
case 'T': if ((t))
|
||||
while (*t)
|
||||
*(q++) = *(t++);
|
||||
t=to;
|
||||
break;
|
||||
default: *(q++)='$';
|
||||
*(q++)=*p;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case '\\': *(q++) = *(++p);
|
||||
break;
|
||||
default: *(q++) = *p;
|
||||
break;
|
||||
}
|
||||
if (slot > maxfppid) {
|
||||
WriteError("Attempt to pipe more than %d processes", maxfppid + 1);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
*q = '\0';
|
||||
Syslog('+', "Expipe: %s",buf);
|
||||
i = 0;
|
||||
vector[i++] = strtok(buf," \t\n");
|
||||
while ((vector[i++] = strtok(NULL," \t\n")) && (i<16));
|
||||
vector[15] = NULL;
|
||||
fflush(stdout);
|
||||
fflush(stderr);
|
||||
if (pipe(pipedes) != 0) {
|
||||
WriteError("$Pipe failed for command \"%s\"", MBSE_SS(vector[0]));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Syslog('e', "pipe() returned read=%d, write=%d", pipedes[0], pipedes[1]);
|
||||
if ((pid = fork()) == 0) {
|
||||
close(pipedes[1]);
|
||||
close(0);
|
||||
if (dup(pipedes[0]) != 0) {
|
||||
WriteError("$Reopen of stdin for command %s failed", MBSE_SS(vector[0]));
|
||||
exit(MBERR_EXEC_FAILED);
|
||||
}
|
||||
rc = execv(vector[0],vector);
|
||||
WriteError("$Exec \"%s\" returned %d", MBSE_SS(vector[0]), rc);
|
||||
exit(MBERR_EXEC_FAILED);
|
||||
}
|
||||
|
||||
for (p = cmd, q = buf; (*p); p++) {
|
||||
if (q > buflimit) {
|
||||
WriteError("Attempt to pipe too long command");
|
||||
return NULL;
|
||||
}
|
||||
switch (*p) {
|
||||
case '$': switch (*(++p)) {
|
||||
case 'f':
|
||||
case 'F': if ((f))
|
||||
while (*f)
|
||||
*(q++) = *(f++);
|
||||
f=from;
|
||||
break;
|
||||
case 't':
|
||||
case 'T': if ((t))
|
||||
while (*t)
|
||||
*(q++) = *(t++);
|
||||
t=to;
|
||||
break;
|
||||
default: *(q++)='$';
|
||||
*(q++)=*p;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case '\\': *(q++) = *(++p);
|
||||
break;
|
||||
default: *(q++) = *p;
|
||||
break;
|
||||
}
|
||||
}
|
||||
close(pipedes[0]);
|
||||
|
||||
*q = '\0';
|
||||
Syslog('+', "Expipe: %s",buf);
|
||||
i = 0;
|
||||
vector[i++] = strtok(buf," \t\n");
|
||||
while ((vector[i++] = strtok(NULL," \t\n")) && (i<16));
|
||||
vector[15] = NULL;
|
||||
fflush(stdout);
|
||||
fflush(stderr);
|
||||
if (pipe(pipedes) != 0) {
|
||||
WriteError("$Pipe failed for command \"%s\"", MBSE_SS(vector[0]));
|
||||
return NULL;
|
||||
}
|
||||
if ((fp = fdopen(pipedes[1],"w")) == NULL) {
|
||||
WriteError("$fdopen failed for pipe to command \"%s\"", MBSE_SS(vector[0]));
|
||||
}
|
||||
|
||||
Syslog('e', "pipe() returned read=%d, write=%d", pipedes[0], pipedes[1]);
|
||||
if ((pid = fork()) == 0) {
|
||||
close(pipedes[1]);
|
||||
close(0);
|
||||
if (dup(pipedes[0]) != 0) {
|
||||
WriteError("$Reopen of stdin for command %s failed", MBSE_SS(vector[0]));
|
||||
exit(-1);
|
||||
}
|
||||
rc = execv(vector[0],vector);
|
||||
WriteError("$Exec \"%s\" returned %d", MBSE_SS(vector[0]), rc);
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
close(pipedes[0]);
|
||||
|
||||
if ((fp = fdopen(pipedes[1],"w")) == NULL) {
|
||||
WriteError("$fdopen failed for pipe to command \"%s\"", MBSE_SS(vector[0]));
|
||||
}
|
||||
|
||||
fppid[slot].fp = fp;
|
||||
fppid[slot].pid = pid;
|
||||
return fp;
|
||||
fppid[slot].fp = fp;
|
||||
fppid[slot].pid = pid;
|
||||
return fp;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int exclose(FILE *fp)
|
||||
{
|
||||
int status, rc;
|
||||
int pid, slot, sverr;
|
||||
int status, rc, pid, slot, sverr;
|
||||
|
||||
for (slot = 0; slot <= maxfppid; slot++) {
|
||||
if (fppid[slot].fp == fp)
|
||||
break;
|
||||
}
|
||||
if (slot > maxfppid) {
|
||||
WriteError("Attempt to close unopened pipe");
|
||||
return -1;
|
||||
}
|
||||
pid = fppid[slot].pid;
|
||||
fppid[slot].fp = NULL;
|
||||
fppid[slot].pid = 0;
|
||||
for (slot = 0; slot <= maxfppid; slot++) {
|
||||
if (fppid[slot].fp == fp)
|
||||
break;
|
||||
}
|
||||
if (slot > maxfppid) {
|
||||
WriteError("Attempt to close unopened pipe");
|
||||
return -1;
|
||||
}
|
||||
pid = fppid[slot].pid;
|
||||
fppid[slot].fp = NULL;
|
||||
fppid[slot].pid = 0;
|
||||
|
||||
Syslog('e', "Closing pipe to the child process %d",pid);
|
||||
if ((rc = fclose(fp)) != 0) {
|
||||
WriteError("$Error closing pipe to transport (rc=%d)", rc);
|
||||
if ((rc = kill(pid,SIGKILL)) != 0)
|
||||
WriteError("$kill for pid %d returned %d",pid,rc);
|
||||
}
|
||||
Syslog('e', "Waiting for process %d to finish",pid);
|
||||
do {
|
||||
rc = wait(&status);
|
||||
sverr = errno;
|
||||
if (status)
|
||||
Syslog('e', "$Wait returned %d, status %d,%d", rc, status >> 8, status & 0xff);
|
||||
} while (((rc > 0) && (rc != pid)) || ((rc == -1) && (sverr == EINTR)));
|
||||
Syslog('e', "Closing pipe to the child process %d",pid);
|
||||
if ((rc = fclose(fp)) != 0) {
|
||||
WriteError("$Error closing pipe to transport (rc=%d)", rc);
|
||||
if ((rc = kill(pid,SIGKILL)) != 0)
|
||||
WriteError("$kill for pid %d returned %d",pid,rc);
|
||||
}
|
||||
Syslog('e', "Waiting for process %d to finish",pid);
|
||||
do {
|
||||
rc = wait(&status);
|
||||
sverr = errno;
|
||||
if (status)
|
||||
Syslog('e', "$Wait returned %d, status %d,%d", rc, status >> 8, status & 0xff);
|
||||
} while (((rc > 0) && (rc != pid)) || ((rc == -1) && (sverr == EINTR)));
|
||||
|
||||
switch (rc) {
|
||||
switch (rc) {
|
||||
case -1:WriteError("$Wait returned %d, status %d,%d", rc, status >> 8, status & 0xff);
|
||||
return -1;
|
||||
return MBERR_EXEC_FAILED;
|
||||
case 0: return 0;
|
||||
default:
|
||||
if (WIFEXITED(status)) {
|
||||
rc = WEXITSTATUS(status);
|
||||
if (rc) {
|
||||
WriteError("Expipe: returned error %d", rc);
|
||||
return rc;
|
||||
}
|
||||
rc = WEXITSTATUS(status);
|
||||
if (rc) {
|
||||
WriteError("Expipe: returned error %d", rc);
|
||||
return (rc + MBERR_EXTERNAL);
|
||||
}
|
||||
}
|
||||
if (WIFSIGNALED(status)) {
|
||||
rc = WTERMSIG(status);
|
||||
WriteError("Wait stopped on signal %d", rc);
|
||||
return rc;
|
||||
rc = WTERMSIG(status);
|
||||
WriteError("Wait stopped on signal %d", rc);
|
||||
return rc;
|
||||
}
|
||||
if (rc)
|
||||
WriteError("Wait stopped unknown, rc=%d", rc);
|
||||
WriteError("Wait stopped unknown, rc=%d", rc);
|
||||
return rc;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
47
lib/mberrors.h
Normal file
47
lib/mberrors.h
Normal file
@@ -0,0 +1,47 @@
|
||||
#ifndef _MBERRORS_H
|
||||
#define _MBERRORS_H
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
/*
|
||||
* Exit status values
|
||||
*/
|
||||
#define MBERR_OK 0 /* No errors */
|
||||
#define MBERR_COMMANDLINE 100 /* Commandline error */
|
||||
#define MBERR_CONFIG_ERROR 101 /* Configuration error */
|
||||
#define MBERR_INIT_ERROR 102 /* Initialisation error */
|
||||
#define MBERR_DISK_FULL 103 /* Some disk partition full */
|
||||
#define MBERR_UPS_ALARM 104 /* UPS alarm detected */
|
||||
#define MBERR_NO_RECIPIENTS 105 /* No valid recipients */
|
||||
#define MBERR_EXEC_FAILED 106 /* Execute external prog failed */
|
||||
#define MBERR_TTYIO_ERROR 107 /* Set tty failed */
|
||||
#define MBERR_FTRANSFER 108 /* File transfer error */
|
||||
#define MBERR_ATTACH_FAILED 109 /* File attach failed */
|
||||
#define MBERR_NO_PROGLOCK 110 /* Cannot lock program, retry later */
|
||||
#define MBERR_NODE_NOT_IN_LIST 111 /* Node not in nodelist */
|
||||
#define MBERR_NODE_MAY_NOT_CALL 112 /* Node may not be called */
|
||||
#define MBERR_NO_CONNECTION 113 /* Cannot make connection */
|
||||
#define MBERR_PORTERROR 114 /* Cannot open tty port */
|
||||
#define MBERR_NODE_LOCKED 115 /* Node is locked */
|
||||
#define MBERR_NO_IP_ADDRESS 116 /* Node IP address not found */
|
||||
#define MBERR_UNKNOWN_SESSION 117 /* Unknown session */
|
||||
#define MBERR_NOT_ZMH 118 /* Not Zone Mail Hour */
|
||||
#define MBERR_MODEM_ERROR 119 /* Modem error */
|
||||
#define MBERR_NO_PORT_AVAILABLE 120 /* No modemport available */
|
||||
#define MBERR_SESSION_ERROR 121 /* Session error (password) */
|
||||
#define MBERR_EMSI 122 /* EMSI session error */
|
||||
#define MBERR_FTSC 123 /* FTSC session error */
|
||||
#define MBERR_WAZOO 124 /* WAZOO session error */
|
||||
#define MBERR_YOOHOO 125 /* YOOHOO session error */
|
||||
#define MBERR_OUTBOUND_SCAN 126 /* Outbound scan error */
|
||||
#define MBERR_CANNOT_MAKE_POLL 127 /* Cannot make poll */
|
||||
#define MBERR_REQUEST 128 /* File request error */
|
||||
#define MBERR_DIFF_ERROR 129 /* Error processing nodediff */
|
||||
#define MBERR_VIRUS_FOUND 130 /* Virus found */
|
||||
#define MBERR_GENERAL 131 /* General error */
|
||||
#define MBERR_TIMEOUT 132 /* Timeout error */
|
||||
#define MBERR_TTYIO 200 /* Base for ttyio errors */
|
||||
#define MBERR_MEMWATCH 255 /* Memwatch error */
|
||||
#define MBERR_EXTERNAL 256 /* Status external prog + 256 */
|
||||
|
||||
#endif
|
67
lib/rawio.c
67
lib/rawio.c
@@ -33,6 +33,7 @@
|
||||
#include "memwatch.h"
|
||||
#include "structs.h"
|
||||
#include "common.h"
|
||||
#include "mberrors.h"
|
||||
|
||||
|
||||
int rawset = FALSE;
|
||||
@@ -43,31 +44,31 @@ int rawset = FALSE;
|
||||
*/
|
||||
void Setraw()
|
||||
{
|
||||
int rc;
|
||||
int rc;
|
||||
|
||||
if ((rc = tcgetattr(ttyfd, &tbufs))) {
|
||||
perror("");
|
||||
printf("$tcgetattr(0, save) return %d\n", rc);
|
||||
exit(1);
|
||||
}
|
||||
if ((rc = tcgetattr(ttyfd, &tbufs))) {
|
||||
perror("");
|
||||
printf("$tcgetattr(0, save) return %d\n", rc);
|
||||
exit(MBERR_TTYIO_ERROR);
|
||||
}
|
||||
|
||||
tbufsavs = tbufs;
|
||||
tbufs.c_iflag &= ~(INLCR | ICRNL | ISTRIP | IXON ); /* IUCLC removed for FreeBSD */
|
||||
/*
|
||||
* Map CRNL modes strip control characters and flow control
|
||||
*/
|
||||
tbufs.c_oflag &= ~OPOST; /* Don't do ouput character translation */
|
||||
tbufs.c_lflag &= ~(ICANON | ECHO); /* No canonical input and no echo */
|
||||
tbufs.c_cc[VMIN] = 1; /* Receive 1 character at a time */
|
||||
tbufs.c_cc[VTIME] = 0; /* No time limit per character */
|
||||
tbufsavs = tbufs;
|
||||
tbufs.c_iflag &= ~(INLCR | ICRNL | ISTRIP | IXON ); /* IUCLC removed for FreeBSD */
|
||||
/*
|
||||
* Map CRNL modes strip control characters and flow control
|
||||
*/
|
||||
tbufs.c_oflag &= ~OPOST; /* Don't do ouput character translation */
|
||||
tbufs.c_lflag &= ~(ICANON | ECHO); /* No canonical input and no echo */
|
||||
tbufs.c_cc[VMIN] = 1; /* Receive 1 character at a time */
|
||||
tbufs.c_cc[VTIME] = 0; /* No time limit per character */
|
||||
|
||||
if ((rc = tcsetattr(ttyfd, TCSADRAIN, &tbufs))) {
|
||||
perror("");
|
||||
printf("$tcsetattr(%d, TCSADRAIN, raw) return %d\n", ttyfd, rc);
|
||||
exit(1);
|
||||
}
|
||||
if ((rc = tcsetattr(ttyfd, TCSADRAIN, &tbufs))) {
|
||||
perror("");
|
||||
printf("$tcsetattr(%d, TCSADRAIN, raw) return %d\n", ttyfd, rc);
|
||||
exit(MBERR_TTYIO_ERROR);
|
||||
}
|
||||
|
||||
rawset = TRUE;
|
||||
rawset = TRUE;
|
||||
}
|
||||
|
||||
|
||||
@@ -77,19 +78,19 @@ void Setraw()
|
||||
*/
|
||||
void Unsetraw()
|
||||
{
|
||||
int rc;
|
||||
int rc;
|
||||
|
||||
/*
|
||||
* Only unset the mode if it is set to raw mode
|
||||
*/
|
||||
if (rawset == TRUE) {
|
||||
if ((rc = tcsetattr(ttyfd, TCSAFLUSH, &tbufsavs))) {
|
||||
perror("");
|
||||
printf("$tcsetattr(%d, TCSAFLUSH, save) return %d\n", ttyfd, rc);
|
||||
exit(1);
|
||||
}
|
||||
/*
|
||||
* Only unset the mode if it is set to raw mode
|
||||
*/
|
||||
if (rawset == TRUE) {
|
||||
if ((rc = tcsetattr(ttyfd, TCSAFLUSH, &tbufsavs))) {
|
||||
perror("");
|
||||
printf("$tcsetattr(%d, TCSAFLUSH, save) return %d\n", ttyfd, rc);
|
||||
exit(MBERR_TTYIO_ERROR);
|
||||
}
|
||||
rawset = FALSE;
|
||||
}
|
||||
rawset = FALSE;
|
||||
}
|
||||
|
||||
|
||||
@@ -104,7 +105,7 @@ unsigned char Getone()
|
||||
|
||||
if ((ttyfd = open ("/dev/tty", O_RDWR|O_NONBLOCK)) < 0) {
|
||||
perror("open 8");
|
||||
exit(1);
|
||||
exit(MBERR_TTYIO_ERROR);
|
||||
}
|
||||
Setraw();
|
||||
|
||||
|
Reference in New Issue
Block a user