return lines;
}
+int startDaemon() {
+ int pid;
+ int rc;
+
+ if ( (pid = fork()) == -1 ) {
+ perror("fork");
+ return -1;
+ }
+ if ( pid ) {
+ /* parent */
+ waitpid(pid,&rc,0);
+ if (WIFEXITED(rc)) {
+ DDEBUG("minilogd returned %d!\n",WEXITSTATUS(rc));
+ return WEXITSTATUS(rc);
+ }
+ else
+ return -1;
+ } else {
+ int fd;
+
+ fd=open("/dev/null",O_RDWR);
+ dup2(fd,0);
+ dup2(fd,1);
+ dup2(fd,2);
+ close(fd);
+ /* kid */
+ execlp("minilogd","minilogd",NULL);
+ perror("exec");
+ exit(-1);
+ }
+}
+
int trySocket() {
int s;
struct sockaddr_un addr;
strncpy(addr.sun_path,_PATH_LOG,sizeof(addr.sun_path)-1);
if (connect(s,(struct sockaddr *) &addr,sizeof(addr))<0) {
- if (errno == EPROTOTYPE) {
+ if (errno == EPROTOTYPE || errno == ECONNREFUSED) {
DDEBUG("connect failed (EPROTOTYPE), trying stream\n");
close(s);
s = socket(AF_LOCAL, SOCK_STREAM, 0);
if ( ((stat(_PATH_LOG,&statbuf)==-1) || trySocket())
+ && startDaemon()
) {
DDEBUG("starting daemon failed, pooling entry %d\n",logEntries);
logData=realloc(logData,(logEntries+1)*sizeof(struct logInfo));