run through indent and manually check result
This commit is contained in:
		| @@ -69,10 +69,13 @@ static char LocalHostName[64]; | ||||
| #include <netinet/in.h> | ||||
| /* udp socket for logging to remote host */ | ||||
| static int remotefd = -1; | ||||
|  | ||||
| /* where do we log? */ | ||||
| static char *RemoteHost; | ||||
|  | ||||
| /* what port to log to? */ | ||||
| static int RemotePort = 514; | ||||
|  | ||||
| /* To remote log or not to remote log, that is the question. */ | ||||
| static int doRemoteLog = FALSE; | ||||
| static int local_logging = FALSE; | ||||
| @@ -119,40 +122,47 @@ static int circular_logging = FALSE; | ||||
|  */ | ||||
| static inline void sem_up(int semid) | ||||
| { | ||||
| 	if ( semop(semid, SMwup, 1) == -1 ) | ||||
| 	if (semop(semid, SMwup, 1) == -1) { | ||||
| 		perror_msg_and_die("semop[SMwup]"); | ||||
| 	} | ||||
| } | ||||
|  | ||||
| /* | ||||
|  * sem_down - down()'s a semaphore | ||||
|  */ | ||||
| static inline void sem_down(int semid) | ||||
| { | ||||
| 	if ( semop(semid, SMwdn, 3) == -1 ) | ||||
| 	if (semop(semid, SMwdn, 3) == -1) { | ||||
| 		perror_msg_and_die("semop[SMwdn]"); | ||||
| 	} | ||||
|  | ||||
|  | ||||
| void ipcsyslog_cleanup(void){ | ||||
| 	printf("Exiting Syslogd!\n"); | ||||
| 	if (shmid != -1) | ||||
| 		shmdt(buf); | ||||
|  | ||||
| 	if (shmid != -1) | ||||
| 		shmctl(shmid, IPC_RMID, NULL); | ||||
| 	if (s_semid != -1) | ||||
| 		semctl(s_semid, 0, IPC_RMID, 0); | ||||
| } | ||||
|  | ||||
| void ipcsyslog_init(void){ | ||||
|  | ||||
| void ipcsyslog_cleanup(void) | ||||
| { | ||||
| 	printf("Exiting Syslogd!\n"); | ||||
| 	if (shmid != -1) { | ||||
| 		shmdt(buf); | ||||
| 	} | ||||
|  | ||||
| 	if (shmid != -1) { | ||||
| 		shmctl(shmid, IPC_RMID, NULL); | ||||
| 	} | ||||
| 	if (s_semid != -1) { | ||||
| 		semctl(s_semid, 0, IPC_RMID, 0); | ||||
| 	} | ||||
| } | ||||
|  | ||||
| void ipcsyslog_init(void) | ||||
| { | ||||
| 	if (buf == NULL) { | ||||
| 	    if ((shmid = shmget(KEY_ID, shm_size, IPC_CREAT | 1023)) == -1) | ||||
| 		if ((shmid = shmget(KEY_ID, shm_size, IPC_CREAT | 1023)) == -1) { | ||||
| 			perror_msg_and_die("shmget"); | ||||
| 		} | ||||
|  | ||||
|  | ||||
| 	    if ((buf = shmat(shmid, NULL, 0)) == NULL) | ||||
| 		if ((buf = shmat(shmid, NULL, 0)) == NULL) { | ||||
| 			perror_msg_and_die("shmat"); | ||||
|  | ||||
| 		} | ||||
|  | ||||
| 		buf->size = data_size; | ||||
| 		buf->head = buf->tail = 0; | ||||
| @@ -160,18 +170,21 @@ void ipcsyslog_init(void){ | ||||
| 		// we'll trust the OS to set initial semval to 0 (let's hope) | ||||
| 		if ((s_semid = semget(KEY_ID, 2, IPC_CREAT | IPC_EXCL | 1023)) == -1) { | ||||
| 			if (errno == EEXIST) { | ||||
| 		   if ((s_semid = semget(KEY_ID, 2, 0)) == -1) | ||||
| 				if ((s_semid = semget(KEY_ID, 2, 0)) == -1) { | ||||
| 					perror_msg_and_die("semget"); | ||||
| 		}else | ||||
| 				} | ||||
| 			} else { | ||||
| 				perror_msg_and_die("semget"); | ||||
| 			} | ||||
| 		} | ||||
| 	} else { | ||||
| 		printf("Buffer already allocated just grab the semaphore?"); | ||||
| 	} | ||||
| } | ||||
|  | ||||
| /* write message to buffer */ | ||||
| void circ_message(const char *msg){ | ||||
| void circ_message(const char *msg) | ||||
| { | ||||
| 	int l = strlen(msg) + 1;	/* count the whole message w/ '\0' included */ | ||||
|  | ||||
| 	sem_down(s_semid); | ||||
| @@ -213,7 +226,9 @@ void circ_message(const char *msg){ | ||||
| 				int k = buf->tail + l - buf->head;	/* we need to know how many bytes | ||||
| 													   we are overwriting to make | ||||
| 													   enough room */ | ||||
| 			   char *c=memchr(buf->data+buf->head + k,'\0',buf->size - (buf->head + k)); | ||||
| 				char *c = | ||||
| 					memchr(buf->data + buf->head + k, '\0', | ||||
| 						   buf->size - (buf->head + k)); | ||||
| 				if (c != NULL) {	/* do a sanity check just in case! */ | ||||
| 					buf->head = c - buf->data + 1;	/* we need to convert pointer to | ||||
| 													   offset + skip the '\0' since | ||||
| @@ -226,8 +241,9 @@ void circ_message(const char *msg){ | ||||
| 					buf->head = 0; | ||||
| 				} | ||||
| 			} | ||||
| 		} /* in other cases no overflows have been done yet, so we don't care! */ | ||||
| 		} | ||||
|  | ||||
| 		/* in other cases no overflows have been done yet, so we don't care! */ | ||||
| 		/* we should be ok to append the message now */ | ||||
| 		strncpy(buf->data + buf->tail, msg, l);	/* append our message */ | ||||
| 		buf->tail += l;	/* count full message w/ '\0' terminating char */ | ||||
| @@ -241,7 +257,7 @@ void circ_message(const char *msg){ | ||||
| 		 */ | ||||
| 		c = memchr(buf->data + k, '\0', buf->size - k); | ||||
|  | ||||
| 		if (c != NULL) /* if we don't have '\0'??? weird!!! */{ | ||||
| 		if (c != NULL) {	/* if we don't have '\0'??? weird!!! */ | ||||
| 			/* move head pointer */ | ||||
| 			buf->head = c - buf->data + 1; | ||||
|  | ||||
| @@ -257,7 +273,8 @@ void circ_message(const char *msg){ | ||||
| 			/* we need to place the TAIL at the end of the message */ | ||||
| 			buf->tail = k + 1; | ||||
| 		} else { | ||||
| 			printf("Weird! Can't find the terminator token from the beginning??? \n"); | ||||
| 			printf | ||||
| 				("Weird! Can't find the terminator token from the beginning??? \n"); | ||||
| 			buf->head = buf->tail = 0;	/* reset buffer, since it's probably corrupted */ | ||||
| 		} | ||||
|  | ||||
| @@ -282,6 +299,7 @@ static void message (char *fmt, ...) | ||||
| #ifdef CONFIG_FEATURE_IPC_SYSLOG | ||||
| 	if ((circular_logging == TRUE) && (buf != NULL)) { | ||||
| 		char b[1024]; | ||||
|  | ||||
| 		va_start(arguments, fmt); | ||||
| 		vsnprintf(b, sizeof(b) - 1, fmt, arguments); | ||||
| 		va_end(arguments); | ||||
| @@ -289,7 +307,8 @@ static void message (char *fmt, ...) | ||||
|  | ||||
| 	} else | ||||
| #endif | ||||
| 	if ((fd = device_open (logFilePath, | ||||
| 	if ((fd = | ||||
| 			 device_open(logFilePath, | ||||
| 							 O_WRONLY | O_CREAT | O_NOCTTY | O_APPEND | | ||||
| 							 O_NONBLOCK)) >= 0) { | ||||
| 		fl.l_type = F_WRLCK; | ||||
| @@ -302,7 +321,8 @@ static void message (char *fmt, ...) | ||||
| 		close(fd); | ||||
| 	} else { | ||||
| 		/* Always send console messages to /dev/console so people will see them. */ | ||||
| 		if ((fd = device_open (_PATH_CONSOLE, | ||||
| 		if ((fd = | ||||
| 			 device_open(_PATH_CONSOLE, | ||||
| 						 O_WRONLY | O_NOCTTY | O_NONBLOCK)) >= 0) { | ||||
| 			va_start(arguments, fmt); | ||||
| 			vdprintf(fd, fmt, arguments); | ||||
| @@ -330,11 +350,12 @@ static void logMessage (int pri, char *msg) | ||||
| 			 c_fac->c_name && !(c_fac->c_val == LOG_FAC(pri) << 3); c_fac++); | ||||
| 		for (c_pri = prioritynames; | ||||
| 			 c_pri->c_name && !(c_pri->c_val == LOG_PRI(pri)); c_pri++); | ||||
| 		if (c_fac->c_name == NULL || c_pri->c_name == NULL) | ||||
| 		if (c_fac->c_name == NULL || c_pri->c_name == NULL) { | ||||
| 			snprintf(res, sizeof(res), "<%d>", pri); | ||||
| 		else | ||||
| 		} else { | ||||
| 			snprintf(res, sizeof(res), "%s.%s", c_fac->c_name, c_pri->c_name); | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	if (strlen(msg) < 16 || msg[3] != ' ' || msg[6] != ' ' || | ||||
| 		msg[9] != ':' || msg[12] != ':' || msg[15] != ' ') { | ||||
| @@ -366,17 +387,17 @@ static const int IOV_COUNT = 2; | ||||
| 		v->iov_len = strlen(msg); | ||||
| 	  writev_retry: | ||||
| 		if (-1 == writev(remotefd, iov, IOV_COUNT)) { | ||||
| 			if (errno == EINTR) goto writev_retry; | ||||
| 			error_msg_and_die("cannot write to remote file handle on" | ||||
| 					"%s:%d",RemoteHost,RemotePort); | ||||
| 			if (errno == EINTR) { | ||||
| 				goto writev_retry; | ||||
| 			} | ||||
| 			error_msg_and_die("cannot write to remote file handle on %s:%d", | ||||
| 							  RemoteHost, RemotePort); | ||||
| 		} | ||||
| 	} | ||||
| 	if (local_logging == TRUE) | ||||
| #endif | ||||
| 		/* now spew out the message to wherever it is supposed to go */ | ||||
| 		message("%s %s %s %s\n", timestamp, LocalHostName, res, msg); | ||||
|  | ||||
|  | ||||
| } | ||||
|  | ||||
| static void quit_signal(int sig) | ||||
| @@ -463,12 +484,12 @@ static void init_RemoteLog (void) | ||||
| 	remoteaddr.sin_addr = *(struct in_addr *) *hostinfo->h_addr_list; | ||||
| 	remoteaddr.sin_port = htons(RemotePort); | ||||
|  | ||||
|   /* | ||||
|      Since we are using UDP sockets, connect just sets the default host and port | ||||
|      for future operations | ||||
| 	/* Since we are using UDP sockets, connect just sets the default host and port | ||||
| 	 * for future operations | ||||
| 	 */ | ||||
| 	if (0 != (connect(remotefd, (struct sockaddr *) &remoteaddr, len))) { | ||||
|     error_msg_and_die("cannot connect to remote host %s:%d", RemoteHost, RemotePort); | ||||
| 		error_msg_and_die("cannot connect to remote host %s:%d", RemoteHost, | ||||
| 						  RemotePort); | ||||
| 	} | ||||
|  | ||||
| } | ||||
| @@ -496,23 +517,26 @@ static void doSyslogd (void) | ||||
| 	alarm(MarkInterval); | ||||
|  | ||||
| 	/* Create the syslog file so realpath() can work. */ | ||||
| 	if (realpath (_PATH_LOG, lfile) != NULL) | ||||
| 	if (realpath(_PATH_LOG, lfile) != NULL) { | ||||
| 		unlink(lfile); | ||||
| 	} | ||||
|  | ||||
| 	memset(&sunx, 0, sizeof(sunx)); | ||||
| 	sunx.sun_family = AF_UNIX; | ||||
| 	strncpy(sunx.sun_path, lfile, sizeof(sunx.sun_path)); | ||||
| 	if ((sock_fd = socket (AF_UNIX, SOCK_DGRAM, 0)) < 0) | ||||
| 		perror_msg_and_die ("Couldn't get file descriptor for socket " _PATH_LOG); | ||||
| 	if ((sock_fd = socket(AF_UNIX, SOCK_DGRAM, 0)) < 0) { | ||||
| 		perror_msg_and_die("Couldn't get file descriptor for socket " | ||||
| 						   _PATH_LOG); | ||||
| 	} | ||||
|  | ||||
| 	addrLength = sizeof(sunx.sun_family) + strlen(sunx.sun_path); | ||||
| 	if (bind(sock_fd, (struct sockaddr *) &sunx, addrLength) < 0) | ||||
| 	if (bind(sock_fd, (struct sockaddr *) &sunx, addrLength) < 0) { | ||||
| 		perror_msg_and_die("Could not connect to socket " _PATH_LOG); | ||||
| 	} | ||||
|  | ||||
| 	if (chmod (lfile, 0666) < 0) | ||||
| 	if (chmod(lfile, 0666) < 0) { | ||||
| 		perror_msg_and_die("Could not set permission on " _PATH_LOG); | ||||
|  | ||||
|  | ||||
| 	} | ||||
| #ifdef CONFIG_FEATURE_IPC_SYSLOG | ||||
| 	if (circular_logging == TRUE) { | ||||
| 		ipcsyslog_init(); | ||||
| @@ -542,6 +566,7 @@ static void doSyslogd (void) | ||||
|  | ||||
| 		if (FD_ISSET(sock_fd, &fds)) { | ||||
| 			int i; | ||||
|  | ||||
| 			RESERVE_CONFIG_BUFFER(tmpbuf, BUFSIZ + 1); | ||||
|  | ||||
| 			memset(tmpbuf, '\0', BUFSIZ + 1); | ||||
| @@ -558,6 +583,7 @@ static void doSyslogd (void) | ||||
| extern int syslogd_main(int argc, char **argv) | ||||
| { | ||||
| 	int opt; | ||||
|  | ||||
| #if ! defined(__uClinux__) | ||||
| 	int doFork = TRUE; | ||||
| #endif | ||||
| @@ -617,8 +643,7 @@ extern int syslogd_main(int argc, char **argv) | ||||
| 	umask(0); | ||||
|  | ||||
| #if ! defined(__uClinux__) | ||||
| 	if (doFork == TRUE) { | ||||
| 		if (daemon(0, 1) < 0) | ||||
| 	if ((doFork == TRUE) && (daemon(0, 1) < 0)) { | ||||
| 		perror_msg_and_die("daemon"); | ||||
| 	} | ||||
| #endif | ||||
|   | ||||
		Reference in New Issue
	
	Block a user