Skip to content
Browse files

Make this compile on OmniOS

(and likely other SunOS derivatives)
  • Loading branch information...
1 parent 14a9368 commit 6bef7a096b530265a149351f644561bcc0d8d1fb @postwait postwait committed May 14, 2012
Showing with 41 additions and 26 deletions.
  1. +15 −5 Makefile
  2. +2 −1 fq.h
  3. +2 −1 fq_client.c
  4. +2 −2 fq_rcvr.c
  5. +11 −6 fq_utils.c
  6. +0 −2 fqd.c
  7. +1 −1 fqd.h
  8. +4 −3 fqd_ccs.c
  9. +1 −2 fqd_config.c
  10. +2 −1 fqd_listener.c
  11. +1 −2 fqd_routemgr.c
View
20 Makefile
@@ -1,7 +1,8 @@
CC=gcc
CKDIR=ck-0.2
+OS=$(shell uname)
-EXTRA_CFLAGS=-g -D_REENTRANT -D_DARWIN_C_SOURCE
+EXTRA_CFLAGS=-g -D_REENTRANT
EXTRA_CFLAGS+=-DDEBUG
CLIENT_OBJ=fq_client.o fq_msg.o fq_utils.o
@@ -11,6 +12,15 @@ FQD_OBJ=fqd.o fqd_listener.o fqd_ccs.o fqd_dss.o fqd_config.o \
FQC_OBJ=fqc.o $(CLIENT_OBJ)
CPPFLAGS=-I./$(CKDIR)/include
+ifeq ($(OS),SunOS)
+LIBS=-lsocket -lnsl -lxnet
+EXTRA_CFLAGS+=-D__EXTENSIONS__
+else
+ifeq ($(OS),Darwin)
+EXTRA_CFLAGS+=-D_DARWIN_C_SOURCE
+endif
+endif
+
all: libfq.a fqd fqc fq_sndr fq_rcvr
Makefile.build:
@@ -28,19 +38,19 @@ CFLAGS+=$(EXTRA_CFLAGS)
fqd: $(FQD_OBJ)
@echo " - linking $@"
- @$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(FQD_OBJ)
+ @$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(FQD_OBJ) $(LIBS)
fqc: $(FQC_OBJ)
@echo " - linking $@"
- @$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(FQC_OBJ)
+ @$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(FQC_OBJ) $(LIBS)
fq_sndr: fq_sndr.o $(CLIENT_OBJ)
@echo " - linking $@"
- @$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^
+ @$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LIBS)
fq_rcvr: fq_rcvr.o $(CLIENT_OBJ)
@echo " - linking $@"
- @$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^
+ @$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LIBS)
libfq.a: $(CLIENT_OBJ)
@echo " - creating $@"
View
3 fq.h
@@ -7,6 +7,7 @@
#include <string.h>
#include <sys/types.h>
+#include <sys/time.h>
#include <stdint.h>
#define FQ_PROTO_CMD_MODE 0xcc50cafe
@@ -194,7 +195,7 @@ void fq_debug_set_bits(uint32_t bits);
extern int
fq_debug_fl(const char *file, int line, fq_debug_bits_t, const char *fmt, ...)
- __printflike(4, 5);
+ __attribute__((format(printf, 4, 5)));
#define fq_debug(type, ...) do { \
if(0 != (type & fq_debug_bits)) { \
View
3 fq_client.c
@@ -447,7 +447,7 @@ fq_conn_worker(void *u) {
t = fq_gethrtime();
hb_us = (unsigned long long)conn_s->cmd_hb_ms * 3 * 1000000ULL;
if(conn_s->cmd_hb_last && hb_us &&
- conn_s->cmd_hb_last < (t - hb_us)) {
+ conn_s->cmd_hb_last < (unsigned int) (t - hb_us)) {
char errbuf[256];
snprintf(errbuf, sizeof(errbuf), "heartbeat failed [%llu - %llu = %llu]",
(unsigned long long)t, (unsigned long long)conn_s->cmd_hb_last,
@@ -537,6 +537,7 @@ fq_client_creds(fq_client conn, const char *host, unsigned short port,
conn_s->pass = strdup(pass);
/* determine our endpoint */
+ conn_s->remote.sin_family = AF_INET;
conn_s->remote.sin_port = htons(port);
if(inet_pton(AF_INET, host, &conn_s->remote.sin_addr) != 0) {
#ifdef HAVE_GETHOSTBYNAME_R
View
4 fq_rcvr.c
@@ -27,7 +27,7 @@ print_rate(fq_client c, hrtime_t s, hrtime_t f, uint64_t cnt, uint64_t icnt) {
}
}
int main(int argc, char **argv) {
- hrtime_t s0, s, f;
+ hrtime_t s, f;
uint64_t cnt = 0, icnt = 0, icnt_total = 0;
int rcvd = 0;
fq_client c;
@@ -59,7 +59,7 @@ int main(int argc, char **argv) {
exit(-1);
}
- s0 = s = fq_gethrtime();
+ s = fq_gethrtime();
while(1) {
f = fq_gethrtime();
while(m = fq_client_receive(c)) {
View
17 fq_utils.c
@@ -9,10 +9,7 @@
#include <errno.h>
#include <pthread.h>
#include <assert.h>
-
-#ifdef __MACH__
-#include <mach/mach.h>
-#include <mach/clock.h>
+#include <stdarg.h>
uint32_t fq_debug_bits = 0;
@@ -190,6 +187,10 @@ fq_buffered_msg_read(buffered_msg_reader *f,
return 0;
}
+#ifdef __MACH__
+#include <mach/mach.h>
+#include <mach/clock.h>
+
static int initialized = 0;
static clock_serv_t clk_system;
static mach_port_t myport;
@@ -205,6 +206,10 @@ hrtime_t fq_gethrtime() {
return ((uint64_t)now.tv_sec * 1000000000ULL) +
(uint64_t)now.tv_nsec;
}
+#else
+hrtime_t fq_gethrtime() {
+ return gethrtime();
+}
#endif
int fq_rk_to_hex(char *buf, int len, fq_rk *k) {
@@ -319,8 +324,8 @@ fq_debug_fl(const char *file, int line, fq_debug_bits_t b, const char *fmt, ...)
static hrtime_t epoch = 0;
hrtime_t now;
char fmtstring[1024];
- u_int64_t p = (u_int64_t)pthread_self();
- u_int32_t ps = p & 0xffffffff;
+ uint64_t p = (uint64_t)pthread_self();
+ uint32_t ps = p & 0xffffffff;
(void)b;
now = fq_gethrtime();
View
2 fqd.c
@@ -59,7 +59,6 @@ static uint32_t get_my_ip(void) {
}
int main(int argc, char **argv) {
pthread_t tid;
- char buff[128];
nodeid = get_my_ip();
parse_cli(argc,argv);
if(nodeid == 0) {
@@ -70,6 +69,5 @@ int main(int argc, char **argv) {
signal(SIGPIPE, SIG_IGN);
pthread_create(&tid, NULL, listener_thread, NULL);
pause();
- //fgets(buff, sizeof(buff), stdin);
return 0;
}
View
2 fqd.h
@@ -2,7 +2,7 @@
#define FQD_H
#ifndef _REENTRANT
-#error "You must compile with -D_REENTRANT
+#error "You must compile with -D_REENTRANT"
#endif
#include <stdint.h>
View
7 fqd_ccs.c
@@ -96,11 +96,11 @@ fqd_ccs_loop(remote_client *client) {
if(rv < 0) break;
t = fq_gethrtime();
hb_us = ((unsigned long long)client->heartbeat_ms) * 1000000ULL;
- if(client->heartbeat_ms && client->last_heartbeat < (t - hb_us)) {
+ if(client->heartbeat_ms && client->last_heartbeat < (unsigned int)(t - hb_us)) {
if(fqd_css_heartbeat(client)) break;
client->last_heartbeat = t;
}
- if(hb_us && client->last_activity < (t - hb_us * 3)) {
+ if(hb_us && client->last_activity < (unsigned int)(t - hb_us * 3)) {
ERRTOFD(client->fd, "heartbeat failed");
#ifdef DEBUG
fq_debug(FQ_DEBUG_CONN, "heartbeat failed from %s\n", client->pretty);
@@ -165,10 +165,11 @@ extern void
fqd_command_and_control_server(remote_client *client) {
/* auth */
int rv, registered = 0;
- u_int64_t cgen;
+ uint64_t cgen;
fq_debug(FQ_DEBUG_CONN, "--> ccs thread\n");
if((rv = fqd_ccs_auth(client)) != 0) {
fq_debug(FQ_DEBUG_CONN, "client auth failed: %d\n", rv);
+ (void)rv;
goto out;
}
if(fqd_config_register_client(client, &cgen)) {
View
3 fqd_config.c
@@ -241,7 +241,7 @@ fqd_config_deregister_client(remote_client *c, uint64_t *gen) {
extern fqd_queue *
fqd_config_register_queue(fqd_queue *c, uint64_t *gen) {
- int i, rv = 0, available_slot = -1;
+ int i, available_slot = -1;
BEGIN_CONFIG_MODIFY(config);
for(i=0; i<config->n_queues; i++) {
if(config->queues[i] && fqd_queue_cmp(c, config->queues[i]) == 0) {
@@ -268,7 +268,6 @@ fqd_config_register_queue(fqd_queue *c, uint64_t *gen) {
fqd_queue_ref(c);
if(gen) *gen = config->gen;
MARK_CONFIG(config);
- rv = 0;
oom:
END_CONFIG_MODIFY();
return c;
View
3 fqd_listener.c
@@ -87,10 +87,11 @@ int
fqd_listener(const char *host, unsigned short port) {
int fd;
remote_anon_client *client = NULL;
- unsigned long on = 1;
+ unsigned int on = 1;
struct sockaddr_in laddr;
memset(&laddr, 0, sizeof(laddr));
+ laddr.sin_family = AF_INET;
laddr.sin_addr.s_addr = INADDR_ANY;
if(host && inet_pton(AF_INET, host, &laddr.sin_addr) != 0) {
return -1;
View
3 fqd_routemgr.c
@@ -3,6 +3,7 @@
#include <string.h>
#include <ck_pr.h>
#include <assert.h>
+#include <arpa/nameser_compat.h>
#include "fqd.h"
uint32_t global_route_id = 1;
@@ -253,7 +254,6 @@ get_ruletable(struct prefix_jumptable *parent, fqd_route_rule *newrule,
}
uint32_t
fqd_routemgr_ruleset_add_rule(fqd_route_rules *set, fqd_route_rule *newrule) {
- int idx;
fqd_route_rule *r;
struct prefix_jumptable *jt;
jt = get_ruletable(&set->master, newrule, 0);
@@ -266,7 +266,6 @@ fqd_routemgr_ruleset_add_rule(fqd_route_rules *set, fqd_route_rule *newrule) {
}
}
newrule->route_id = ck_pr_faa_32(&global_route_id, 1);
- idx = newrule->route_id % RR_SET_SIZE;
newrule->next = jt->rules;
jt->rules = newrule;
return newrule->route_id;

0 comments on commit 6bef7a0

Please sign in to comment.
Something went wrong with that request. Please try again.