aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/initlog.187
-rw-r--r--src/initlog.c453
-rw-r--r--src/initlog.conf23
-rw-r--r--src/initlog.h20
-rw-r--r--src/process.c330
-rw-r--r--src/process.h9
6 files changed, 0 insertions, 922 deletions
diff --git a/src/initlog.1 b/src/initlog.1
deleted file mode 100644
index b508b295..00000000
--- a/src/initlog.1
+++ /dev/null
@@ -1,87 +0,0 @@
-.TH initlog 8 "Sun Jan 24 1999"
-.SH NAME
-initlog \- log messages and events to the system logger
-.SH SYNOPSIS
-.B initlog
-[\-cefnpqrs] [\-\-cmd=ARG] [\-\-event=ARG] [\-\-facility=ARG]
-[\-\-name=ARG] [\-\-priority=ARG] [\-\-run=ARG] [\-\-string=ARG]
-.SH DESCRIPTION
-\fBinitlog\fR logs messages and events to the system logger.
-It is mainly designed for use in init scripts. initlog
-reads a configuration file
-.I /etc/initlog.conf
-by default, to determine its settings. Any line preceded with a
-.I #
-is a comment, and the following configuration directives
-are recognized:
-.TP
-.I facility <logging facility>
-Sets the default logging facility
-.TP
-.I priority <logging priority>
-Sets the default logging priority
-.TP
-.I ignore <regexp>
-Messages that match the regular expression will not be logged.
-.TP
-initlog behavior can also be configured by command-line options.
-
-\fBNote that initlog is deprecated and will be removed in a future
-release.\fR
-
-.SS OPTIONS
-.TP
-.I "\-c, \-\-cmd=[program]"
-Execute the specified program, logging anything output to
-stdout or stderr.
-.TP
-.I "\-e, \-\-event=[number]"
-Logs that the specified event happened. Used in conjuction
-with \fB\-\-name\fR. Currently specified events are:
-.PD 0
-.RS 8n
-.TP 3n
-.B 1
-the action completed successfully
-.TP
-.B 2
-the action failed
-.TP
-.B 3
-the action was cancelled at user request
-.TP
-.B 4
-the action failed due to the failure of a dependent action
-.RE
-.PD
-.TP
-.I "\-f, \-\-facility=[facility]"
-Log at the specified syslog facility. The default
-is \fBdaemon\fR (see syslog(3)).
-.TP
-.I "\-n, \-\-name=[string]"
-Log the event under the specified string, such as
-"inetd".
-.TP
-.I "\-p, \-\-priority=[priority]"
-Log at the specified syslog priority. The default
-is \fBnotice\fR (see syslog(3)).
-.TP
-.I "\-q"
-Do not print the program's output, unless it exits
-with a non-zero exit code.
-.TP
-.I "\-r, \-\-run=[program]"
-Execute the specified program, with an open file
-descriptor so that the program can pass back
-commands to initlog.
-.TP
-.I "\-s, \-\-string=[string]"
-Log the specified string to the logger.
-.TP
-.I "\-\-conf=[file]"
-Specifies an alternate configuration file.
-.SH FILES
-.I /etc/initlog.conf
-.SH "SEE ALSO"
-syslog(3), logger(1)
diff --git a/src/initlog.c b/src/initlog.c
deleted file mode 100644
index e42960a8..00000000
--- a/src/initlog.c
+++ /dev/null
@@ -1,453 +0,0 @@
-/*
- * Copyright (c) 1999-2003 Red Hat, Inc. All rights reserved.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License, version 2,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
- *
- */
-
-#include <ctype.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <libintl.h>
-#include <locale.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-
-#define SYSLOG_NAMES
-#include <syslog.h>
-
-#include <sys/socket.h>
-#include <sys/stat.h>
-#include <sys/un.h>
-#include <sys/wait.h>
-
-#define _(String) gettext((String))
-
-#include <popt.h>
-
-#include <regex.h>
-
-#include "initlog.h"
-#include "process.h"
-
-static int logfacility=LOG_DAEMON;
-static int logpriority=LOG_NOTICE;
-static int reexec=0;
-static int quiet=0;
-int debug=0;
-
-regex_t **regList = NULL;
-
-static int logEntries = 0;
-struct logInfo *logData = NULL;
-
-void readConfiguration(char *fname) {
- int fd,num=0;
- struct stat sbuf;
- char *data,*line, *d;
- regex_t *regexp;
- int lfac=-1,lpri=-1;
-
- if ((fd=open(fname,O_RDONLY))==-1) return;
- if (fstat(fd,&sbuf)) {
- close(fd);
- return;
- }
- d = data=malloc(sbuf.st_size+1);
- if (read(fd,data,sbuf.st_size)!=sbuf.st_size) {
- close(fd);
- free(data);
- return;
- }
- close(fd);
- data[sbuf.st_size] = '\0';
- while ((line=getLine(&data))) {
- if (line[0]=='#') continue;
- if (!strncmp(line,"ignore ",7)) {
- regexp = malloc(sizeof(regex_t));
- if (!regcomp(regexp,line+7,REG_EXTENDED|REG_NOSUB|REG_NEWLINE)) {
- regList = realloc(regList,(num+2) * sizeof(regex_t *));
- regList[num] = regexp;
- regList[num+1] = NULL;
- num++;
- }
- }
- if (!strncmp(line,"facility ",9)) {
- lfac=atoi(line+9);
- if ((lfac == 0) && strcmp(line+9,"0")) {
- int x =0;
-
- lfac = LOG_DAEMON;
- for (x=0;facilitynames[x].c_name;x++) {
- if (!strcmp(line+9,facilitynames[x].c_name)) {
- lfac = facilitynames[x].c_val;
- break;
- }
- }
- }
- }
- if (!strncmp(line,"priority ",9)) {
- lpri = atoi(line+9);
- if ((lpri == 0) && strcmp(line+9,"0")) {
- int x=0;
-
- lpri = LOG_NOTICE;
- for (x=0;prioritynames[x].c_name;x++) {
- if (!strcmp(line+9,prioritynames[x].c_name)) {
- lpri = prioritynames[x].c_val;
- break;
- }
- }
- }
- }
- }
- if (lfac!=-1) logfacility=lfac;
- if (lpri!=-1) logpriority=lpri;
- free(d);
-}
-
-char *getLine(char **data) {
- /* Get one line from data */
- /* Anything up to a carraige return (\r) or a backspace (\b) is discarded. */
- /* If this really bothers you, mail me and I might make it configurable. */
- /* It's here to avoid confilcts with fsck's progress bar. */
- char *x, *y;
-
- if (!*data) return NULL;
- x=*data;
- while (*x && (*x != '\n')) {
- while (*x && (*x != '\n') && (*x != '\r') && (*x != '\b')) x++;
- if (*x && (*x=='\r' || *x =='\b')) {
- *data = x+1;
- x++;
- }
- }
- if (*x) {
- x++;
- } else {
- if (x-*data) {
- y=malloc(x-*data+1);
- y[x-*data] = 0;
- y[x-*data-1] = '\n';
- memcpy(y,*data,x-*data);
- } else {
- y=NULL;
- }
- *data = NULL;
- return y;
- }
- y = malloc(x-*data);
- y[x-*data-1] = 0;
- memcpy(y,*data,x-*data-1);
- *data = x;
- return y;
-}
-
-char **toArray(char *line, int *num) {
- /* Converts a long string into an array of lines. */
- char **lines;
- char *tmpline;
-
- *num = 0;
- lines = NULL;
-
- while ((tmpline=getLine(&line))) {
- if (!*num)
- lines = (char **) malloc(sizeof(char *));
- else
- lines = (char **) realloc(lines, (*num+1)*sizeof(char *));
- lines[*num] = tmpline;
- (*num)++;
- }
- return lines;
-}
-
-int trySocket() {
- int s;
- struct sockaddr_un addr;
-
- s = socket(AF_LOCAL, SOCK_DGRAM, 0);
- if (s<0)
- return 1;
-
- bzero(&addr,sizeof(addr));
- addr.sun_family = AF_LOCAL;
- strncpy(addr.sun_path,_PATH_LOG,sizeof(addr.sun_path)-1);
-
- if (connect(s,(struct sockaddr *) &addr,sizeof(addr))<0) {
- if (errno == EPROTOTYPE || errno == ECONNREFUSED) {
- DDEBUG("connect failed (EPROTOTYPE), trying stream\n");
- close(s);
- s = socket(AF_LOCAL, SOCK_STREAM, 0);
- if (connect(s,(struct sockaddr *) &addr, sizeof(addr)) < 0) {
- DDEBUG("connect failed: %s\n",strerror(errno));
- close(s);
- return 1;
- }
- close(s);
- return 0;
- }
- close(s);
- DDEBUG("connect failed: %s\n",strerror(errno));
- return 1;
- } else {
- close(s);
- return 0;
- }
-}
-
-int logLine(struct logInfo *logEnt) {
- /* Logs a line... somewhere. */
- int x;
- struct stat statbuf;
-
- /* Don't log empty or null lines */
- if (!logEnt->line || !strcmp(logEnt->line,"\n")) return 0;
-
-
- if ((stat(_PATH_LOG,&statbuf)==-1) || trySocket()) {
- DDEBUG("starting daemon failed, pooling entry %d\n",logEntries);
- logData=realloc(logData,(logEntries+1)*sizeof(struct logInfo));
- logData[logEntries].fac = logEnt->fac;
- logData[logEntries].pri = logEnt->pri;
- logData[logEntries].cmd = strdup(logEnt->cmd);
- logData[logEntries].line = strdup(logEnt->line);
- logEntries++;
- } else {
- if (logEntries>0) {
- for (x=0;x<logEntries;x++) {
- DDEBUG("flushing log entry %d =%s=\n",x,logData[x].line);
- openlog(logData[x].cmd,0,logData[x].fac);
- syslog(logData[x].pri,"%s",logData[x].line);
- closelog();
- }
- free(logData);
- logEntries = 0;
- }
- DDEBUG("logging =%s= via syslog\n",logEnt->line);
- openlog(logEnt->cmd,0,logEnt->fac);
- syslog(logEnt->pri,"%s",logEnt->line);
- closelog();
- }
- return 0;
-}
-
-int logEvent(char *cmd, int eventtype,char *string) {
- char *eventtable [] = {
- _("%s babbles incoherently"),
- _("%s succeeded"),
- _("%s failed"),
- _("%s cancelled at user request"),
- _("%s failed due to a failed dependency"),
- /* insert more here */
- NULL
- };
- int x=0,len, rc;
- struct logInfo logentry;
-
- if (cmd) {
- logentry.cmd = basename(cmd);
- if ((logentry.cmd[0] =='K' || logentry.cmd[0] == 'S') &&
- ( logentry.cmd[1] >= '0' && logentry.cmd[1] <= '9' ) &&
- ( logentry.cmd[2] >= '0' && logentry.cmd[2] <= '9' ) )
- logentry.cmd+=3;
- logentry.cmd = strdup(logentry.cmd);
- } else
- logentry.cmd = strdup(_("(none)"));
- if (!string) {
- string = alloca(strlen(cmd)+1);
- strcpy(string,cmd);
- }
-
- while (eventtable[x] && x<eventtype) x++;
- if (!(eventtable[x])) x=0;
-
- len=strlen(eventtable[x])+strlen(string);
- logentry.line=malloc(len);
- snprintf(logentry.line,len,eventtable[x],string);
-
- logentry.pri = logpriority;
- logentry.fac = logfacility;
-
- rc = logLine(&logentry);
- free(logentry.line);
- free(logentry.cmd);
- return rc;
-}
-
-int logString(char *cmd, char *string) {
- struct logInfo logentry;
- int rc;
-
- if (cmd) {
- logentry.cmd = basename(cmd);
- if ((logentry.cmd[0] =='K' || logentry.cmd[0] == 'S') &&
- ( logentry.cmd[1] >= '0' && logentry.cmd[1] <= 0x39 ) &&
- ( logentry.cmd[2] >= '0' && logentry.cmd[2] <= 0x39 ) )
- logentry.cmd+=3;
- logentry.cmd = strdup(logentry.cmd);
- } else
- logentry.cmd = strdup(_(""));
- logentry.line = strdup(string);
- logentry.pri = logpriority;
- logentry.fac = logfacility;
-
- rc = logLine(&logentry);
- free(logentry.line);
- free(logentry.cmd);
- return rc;
-}
-
-int processArgs(int argc, char **argv, int silent) {
- char *cmdname=NULL;
- char *conffile=NULL;
- int cmdevent=0;
- char *cmd=NULL;
- char *logstring=NULL;
- char *fac=NULL,*pri=NULL;
- int lfac=-1, lpri=-1;
- poptContext context;
- int rc;
- struct poptOption optTable[] = {
- POPT_AUTOHELP
- { "conf", 0, POPT_ARG_STRING, &conffile, 0,
- "configuration file (default: /etc/initlog.conf)", NULL
- },
- { "name", 'n', POPT_ARG_STRING, &cmdname, 0,
- "name of service being logged", NULL
- },
- { "event", 'e', POPT_ARG_INT, &cmdevent, 0,
- "event being logged (see man page)", NULL
- },
- { "cmd", 'c', POPT_ARG_STRING, &cmd, 0,
- "command to run, logging output", NULL
- },
- { "debug", 'd', POPT_ARG_NONE, &debug, 0,
- "print lots of verbose debugging info", NULL
- },
- { "run", 'r', POPT_ARG_STRING, &cmd, 3,
- "command to run, accepting input on open fd", NULL
- },
- { "string", 's', POPT_ARG_STRING, &logstring, 0,
- "string to log", NULL
- },
- { "facility", 'f', POPT_ARG_STRING, &fac, 1,
- "facility to log at (default: 'local7')", NULL
- },
- { "priority", 'p', POPT_ARG_STRING, &pri, 2,
- "priority to log at (default: 'notice')", NULL
- },
- { "quiet", 'q', POPT_ARG_NONE, &quiet, 0,
- "suppress stdout/stderr", NULL
- },
- { 0, 0, 0, 0, 0, 0 }
- };
-
- context = poptGetContext("initlog", argc, argv, optTable, 0);
-
- while ((rc = poptGetNextOpt(context)) > 0) {
- switch (rc) {
- case 1:
- lfac=atoi(fac);
- if ((lfac == 0) && strcmp(fac,"0")) {
- int x =0;
-
- lfac = LOG_DAEMON;
- for (x=0;facilitynames[x].c_name;x++) {
- if (!strcmp(fac,facilitynames[x].c_name)) {
- lfac = facilitynames[x].c_val;
- break;
- }
- }
- }
- break;
- case 2:
- lpri = atoi(pri);
- if ((lpri == 0) && strcmp(pri,"0")) {
- int x=0;
-
- lpri = LOG_NOTICE;
- for (x=0;prioritynames[x].c_name;x++) {
- if (!strcmp(pri,prioritynames[x].c_name)) {
- lpri = prioritynames[x].c_val;
- break;
- }
- }
- }
- break;
- case 3:
- reexec = 1;
- break;
- default:
- break;
- }
- }
-
- if ((rc < -1)) {
- if (!silent)
- fprintf(stderr, "%s: %s\n",
- poptBadOption(context, POPT_BADOPTION_NOALIAS),
- poptStrerror(rc));
-
- return -1;
- }
- if ( (cmd && logstring) || (cmd && cmdname) ) {
- if (!silent)
- fprintf(stderr, _("--cmd and --run are incompatible with --string or --name\n"));
- return -1;
- }
- if ( cmdname && (!logstring && !cmdevent)) {
- if (!silent)
- fprintf(stderr, _("--name requires one of --event or --string\n"));
- return -1;
- }
- if (cmdevent && cmd) {
- if (!silent)
- fprintf(stderr, _("--cmd and --run are incompatible with --event\n"));
- return -1;
- }
- if (conffile) {
- readConfiguration(conffile);
- } else {
- readConfiguration("/etc/initlog.conf");
- }
- if (cmd) {
- while (isspace(*cmd)) cmd++;
- }
- if (lpri!=-1) logpriority=lpri;
- if (lfac!=-1) logfacility=lfac;
- if (cmdevent) {
- logEvent(cmdname,cmdevent,logstring);
- } else if (logstring) {
- logString(cmdname,logstring);
- } else if ( cmd && *cmd) {
- return(runCommand(cmd,reexec,quiet,debug));
- } else {
- if (!silent)
- fprintf(stderr,"nothing to do!\n");
- return -1;
- }
- return 0;
-}
-
-int main(int argc, char **argv) {
-
- setlocale(LC_ALL,"");
- bindtextdomain("initlog","/etc/locale");
- textdomain("initlog");
- fprintf(stderr, _("WARNING: initlog is deprecated and will be removed in a future release\n"));
- exit(processArgs(argc,argv,0));
-}
diff --git a/src/initlog.conf b/src/initlog.conf
deleted file mode 100644
index 4505c7d6..00000000
--- a/src/initlog.conf
+++ /dev/null
@@ -1,23 +0,0 @@
-# /etc/initlog.conf
-#
-# initlog configuration file
-#
-# lines preceded by a '#' are comments
-#
-# anything not recognized is ignored. :)
-
-# This sets the default logging facility. (can override with command line arguments)
-facility local7
-
-# This sets the default logging priority. (can override with command line arguments)
-priority notice
-
-# ignore foo
-# means to discard any output lines that match the regular expression foo
-
-# This regexp is useful if you use fsck's -C option.
-ignore [^:]+: \|[=]+
-# This regexp is useful for fsck's feature of setting file types
-ignore [^:]+: Setting filetype
-# This regexp is useful for quotacheck
-ignore ^[-\\\|\/]$
diff --git a/src/initlog.h b/src/initlog.h
deleted file mode 100644
index 94f467bf..00000000
--- a/src/initlog.h
+++ /dev/null
@@ -1,20 +0,0 @@
-
-#define _GNU_SOURCE 1
-
-#ifndef INITLOG_H
-#define INITLOG_H
-
-struct logInfo {
- char *cmd;
- char *line;
- int fac;
- int pri;
-};
-
-char *getLine(char **data);
-int logString(char *cmd, char *string);
-int processArgs(int argc, char **argv, int silent);
-
-#define DDEBUG if (debug) printf
-
-#endif
diff --git a/src/process.c b/src/process.c
deleted file mode 100644
index ef70bf96..00000000
--- a/src/process.c
+++ /dev/null
@@ -1,330 +0,0 @@
-/*
- * Copyright (c) 1999-2003 Red Hat, Inc. All rights reserved.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License, version 2,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
- *
- */
-
-#include <errno.h>
-#include <fcntl.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-
-#include <sys/signal.h>
-#include <sys/poll.h>
-#include <sys/stat.h>
-#include <sys/wait.h>
-
-#include <popt.h>
-
-#include <regex.h>
-
-#include "initlog.h"
-#include "process.h"
-
-extern regex_t **regList;
-
-int forkCommand(char **args, int *outfd, int *errfd, int *cmdfd, int quiet) {
- /* Fork command 'cmd', returning pid, and optionally pointer
- * to open file descriptor fd */
- int fdout=-1, fderr=-1, fdcmd=-1, pid;
- int outpipe[2], errpipe[2], fdpipe[2];
- int ourpid;
-
- if ( (pipe(outpipe)==-1) || (pipe(errpipe)==-1) || (pipe(fdpipe)==-1) ) {
- perror("pipe");
- return -1;
- }
-
- if (outfd) {
- fdout = outpipe[1];
- *outfd = outpipe[0];
- } else {
- if (!quiet)
- fdout=dup(1);
- }
- if (errfd) {
- fderr = errpipe[1];
- *errfd = errpipe[0];
- } else {
- if (!quiet)
- fderr=dup(2);
- }
-
- if (cmdfd) {
- *cmdfd = fdpipe[0];
- fdcmd = fdpipe[1];
- } else {
- fdcmd = open("/dev/null",O_WRONLY);
- }
- if (fdout==-1 || fderr==-1 || fdcmd==-1)
- return -1;
- ourpid = getpid();
- if ((pid = fork())==-1) {
- perror("fork");
- return -1;
- }
- /* We exec the command normally as the child. However, if we're getting passed
- * back arguments via an fd, we'll exec it as the parent. Therefore, if Bill
- * fucks up and we segfault or something, we don't kill rc.sysinit. */
- if ( (cmdfd&&!pid) || (pid &&!cmdfd)) {
- /* parent */
- close(fdout);
- close(fderr);
- close(fdcmd);
- if (!pid)
- return ourpid;
- else
- return pid;
- } else {
- /* kid */
- int sc_open_max;
-
- if (outfd) {
- if ( (dup2(fdout,1)==-1) ) {
- perror("dup2");
- exit(-1);
- }
- } else if (quiet)
- if ((dup2(open("/dev/null",O_WRONLY),1))==-1) {
- perror("dup2");
- exit(-1);
- }
-
- if (errfd) {
- if ((dup2(fderr,2)==-1)) {
- perror("dup2");
- exit(-1);
- }
- } else if (quiet)
- if ((dup2(open("/dev/null",O_WRONLY),2))==-1) {
- perror("dup2");
- exit(-1);
- }
-
-
- if ((dup2(fdcmd,CMD_FD)==-1)) {
- perror("dup2");
- exit(-1);
- }
- close(fdout);
- close(fderr);
- close(fdcmd);
- if (outfd)
- close(*outfd);
- if (errfd)
- close(*errfd);
- if (cmdfd)
- close(*cmdfd);
-
- /* close up extra fds, and hope this doesn't break anything */
- sc_open_max = sysconf(_SC_OPEN_MAX);
- if(sc_open_max > 1) {
- int fd;
- for(fd = 3; fd < sc_open_max; fd++) {
- if (!(cmdfd && fd == CMD_FD))
- close(fd);
- }
- }
-
- execvp(args[0],args);
- perror("execvp");
- exit(-1);
- }
-}
-
-int monitor(char *cmdname, int pid, int numfds, int *fds, int reexec, int quiet, int debug) {
- struct pollfd *pfds;
- char *outbuf=NULL;
- char *tmpstr=NULL;
- int x,y,rc=-1;
- int done=0;
- int output=0;
- char **cmdargs=NULL;
- char **tmpargs=NULL;
- int cmdargc;
- char *procpath = NULL;
-
- if (reexec) {
- procpath=malloc(20*sizeof(char));
- snprintf(procpath,20,"/proc/%d",pid);
- }
-
- pfds = malloc(numfds*sizeof(struct pollfd));
- for (x=0;x<numfds;x++) {
- pfds[x].fd = fds[x];
- pfds[x].events = POLLIN | POLLPRI;
- }
-
- while (!done) {
- usleep(500);
- if (((x=poll(pfds,numfds,500))==-1)&&errno!=EINTR) {
- perror("poll");
- free(pfds);
- if (procpath)
- free(procpath);
- return -1;
- }
- if (!reexec) {
- if (waitpid(pid,&rc,WNOHANG))
- done=1;
- } else {
- struct stat sbuf;
- /* if /proc/pid ain't there and /proc is, it's dead... */
- if (stat(procpath,&sbuf)&&!stat("/proc/cpuinfo",&sbuf))
- done=1;
- }
- if (x<0)
- continue;
- y=0;
- while (y<numfds) {
- if ( x && ((pfds[y].revents & (POLLIN | POLLPRI)) )) {
- int bytesread = 0;
-
- do {
- char *b, *buf=calloc(8193,sizeof(char));
- b = buf;
- bytesread = read(pfds[y].fd,buf,8192);
- if (bytesread==-1) {
- perror("read");
- free(pfds);
- if (procpath)
- free(procpath);
- free(buf);
- return -1;
- }
- if (bytesread) {
- if (!quiet && !reexec)
- write(1,buf,bytesread);
- if (quiet) {
- outbuf=realloc(outbuf,(outbuf ? strlen(outbuf)+bytesread+1 : bytesread+1));
- if (!output) outbuf[0]='\0';
- strcat(outbuf,buf);
- output = 1;
- }
- while ((tmpstr=getLine(&buf))) {
- int ignore=0;
-
- if (regList) {
- int count=0;
-
- while (regList[count]) {
- if (!regexec(regList[count],tmpstr,0,NULL,0)) {
- ignore=1;
- break;
- }
- count++;
- }
- }
- if (!ignore) {
- if (!reexec) {
- if (getenv("IN_INITLOG")) {
- char *buffer=calloc(8192,sizeof(char));
- DDEBUG("sending =%s= to initlog parent\n",tmpstr);
- snprintf(buffer,8192,"-n %s -s \"%s\"\n",
- cmdname,tmpstr);
- /* don't blow up if parent isn't there */
- signal(SIGPIPE,SIG_IGN);
- write(CMD_FD,buffer,strlen(buffer));
- signal(SIGPIPE,SIG_DFL);
- free(buffer);
- } else {
- logString(cmdname,tmpstr);
- }
- } else {
- int z;
-
- cmdargs=NULL;
- tmpargs=NULL;
- cmdargc=0;
-
- poptParseArgvString(tmpstr,&cmdargc,&tmpargs);
- cmdargs=malloc( (cmdargc+2) * sizeof(char *) );
- cmdargs[0]=strdup("initlog");
- for (z=0;z<(cmdargc);z++) {
- cmdargs[z+1]=tmpargs[z];
- }
- cmdargs[cmdargc+1]=NULL;
- processArgs(cmdargc+1,cmdargs,1);
- free(cmdargs[0]);
- free(tmpargs);
- free(cmdargs);
- }
- }
- if (tmpstr) free(tmpstr);
- }
- }
- free(b);
- } while ( bytesread==8192 );
- }
- y++;
- }
- }
- if ((!WIFEXITED(rc)) || (rc=WEXITSTATUS(rc))) {
- /* If there was an error and we're quiet, be loud */
-
- if (quiet && output) {
- write(1,outbuf,strlen(outbuf));
- }
- free(pfds);
- if (procpath)
- free(procpath);
- if(outbuf)
- free(outbuf);
- return (rc);
- }
- free(pfds);
- if (procpath)
- free(procpath);
- if(outbuf)
- free(outbuf);
- return 0;
-}
-
-int runCommand(char *cmd, int reexec, int quiet, int debug) {
- int fds[2];
- int pid,x;
- char **args, **tmpargs;
- char *cmdname;
-
- poptParseArgvString(cmd,&x,&tmpargs);
- args = malloc((x+1)*sizeof(char *));
- for ( pid = 0; pid < x ; pid++) {
- args[pid] = strdup(tmpargs[pid]);
- }
- args[pid] = NULL;
- if (strcmp(args[0],"sh") && strcmp(args[0],"/bin/sh"))
- cmdname = basename(args[0]);
- else
- cmdname = basename(args[1]);
- if ((cmdname[0] =='K' || cmdname[0] == 'S') &&
- ( cmdname[1] >= '0' && cmdname[1] <= '9' ) &&
- ( cmdname[2] >= '0' && cmdname[2] <= '9' ) )
- cmdname+=3;
- if (!reexec) {
- pid=forkCommand(args,&fds[0],&fds[1],NULL,quiet);
- if (pid == -1)
- return -1;
- x=monitor(cmdname,pid,2,fds,reexec,quiet,debug);
- } else {
- setenv("IN_INITLOG","yes",1);
- pid=forkCommand(args,NULL,NULL,&fds[0],quiet);
- if (pid == -1)
- return -1;
- unsetenv("IN_INITLOG");
- x=monitor(cmdname,pid,1,&fds[0],reexec,quiet,debug);
- }
- return x;
-}
diff --git a/src/process.h b/src/process.h
deleted file mode 100644
index ef98f787..00000000
--- a/src/process.h
+++ /dev/null
@@ -1,9 +0,0 @@
-#ifndef PROCESS_H
-#define PROCESS_H
-
-
-#define CMD_FD 21
-
-int runCommand(char *cmd, int reexec, int quiet, int debug);
-
-#endif