- Fix build on linux

This commit is contained in:
root 2015-10-27 10:42:05 +03:30
parent 56bc05a259
commit e153639fef
4 changed files with 24 additions and 5 deletions

View File

@ -23,7 +23,7 @@ get-deps:
$(SUBDIRS): $(SUBDIRS):
$(MAKE) -C $@ all $(MAKE) -C $@ all
test: logfile.c logfile_test.c test: logfile.h logfile.c logfile_test.c
$(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) logfile.c logfile_test.c -o logfile_test $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) logfile.c logfile_test.c -o logfile_test
clean: clean:

View File

@ -55,6 +55,10 @@
#define PORT 5060 #define PORT 5060
#define BACKLOG 1024 #define BACKLOG 1024
#ifndef IPV6_BINDV6ONLY /* Linux does not have IPV6_BINDV6ONLY */
#define IPV6_BINDV6ONLY IPV6_V6ONLY
#endif /*IPV6_BINDV6ONLY */
/* /*
* Globals * Globals
@ -75,7 +79,7 @@ int t6_sockfd, u6_sockfd;
* trim string from whitespace characters * trim string from whitespace characters
*/ */
size_t size_t
chomp(char *restrict s) chomp(char *s)
{ {
int i; int i;
@ -130,7 +134,7 @@ signal_handler(int sig)
} }
void void
process_request(int af, struct sockaddr *restrict src, int proto, char *str) process_request(int af, struct sockaddr *src, int proto, char *str)
{ {
char *p_names[] = {"TCP", "UDP", "RAW", "UNKNOWN"}; char *p_names[] = {"TCP", "UDP", "RAW", "UNKNOWN"};
char *pname; char *pname;

View File

@ -26,6 +26,12 @@
#include "logfile.h" #include "logfile.h"
#ifdef __linux__
#define _PROGNAME program_invocation_short_name
#else
#define _PROGNAME getprogname()
#endif /* __linux__ */
log_t * log_t *
log_open(const char *path, mode_t mode) log_open(const char *path, mode_t mode)
{ {
@ -35,7 +41,7 @@ log_open(const char *path, mode_t mode)
int fd; int fd;
if (path == NULL) { if (path == NULL) {
asprintf(&filename, "%s/%s.log", LOGPATH, getprogname()); asprintf(&filename, "%s/%s.log", LOGPATH, _PROGNAME);
} else { } else {
filename = (char *)path; filename = (char *)path;
} }
@ -44,8 +50,12 @@ log_open(const char *path, mode_t mode)
* try to create / append the file and make sure it is correctly * try to create / append the file and make sure it is correctly
* created * created
*/ */
if ((fd = open(filename, O_WRONLY | O_APPEND | O_CREAT | O_EXLOCK | O_SYNC, mode)) == -1) if ((fd = open(filename, O_WRONLY | O_APPEND | O_CREAT | O_SYNC, mode)) == -1)
return (NULL); return (NULL);
if (flock(fd, LOCK_EX) == -1 ) {
close(fd);
return (NULL);
}
if (stat(filename, &sb) == -1) { if (stat(filename, &sb) == -1) {
close(fd); close(fd);
return (NULL); return (NULL);

View File

@ -27,6 +27,10 @@
#ifndef _LOGFILE_H #ifndef _LOGFILE_H
#define _LOGFILE_H #define _LOGFILE_H
#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#endif
#include <sys/file.h> #include <sys/file.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
@ -41,6 +45,7 @@
#include <fcntl.h> #include <fcntl.h>
#include <string.h> #include <string.h>
#include <time.h> #include <time.h>
#include <libgen.h>
#define LOGPATH "/var/log" #define LOGPATH "/var/log"
#define MAX_MSG_SIZE 65536 #define MAX_MSG_SIZE 65536