From 70852a24b6a17727e79cf627aa918a4664e50e38 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Fri, 28 Nov 2014 17:09:25 -0500 Subject: closer to building --- common/Makefile.am | 2 ++ common/inotify_helpers.c | 28 ++++++++++++++++------------ common/nslcd-prot.c | 38 -------------------------------------- common/nslcd-prot.h | 38 -------------------------------------- 4 files changed, 18 insertions(+), 88 deletions(-) diff --git a/common/Makefile.am b/common/Makefile.am index 87863f4..cee985a 100644 --- a/common/Makefile.am +++ b/common/Makefile.am @@ -32,3 +32,5 @@ libdict_a_SOURCES = dict.c dict.h \ libexpr_a_SOURCES = expr.c expr.h libinotify_helpers_a_SOURCES = inotify_helpers.c inotify_helpers.h +libinotify_helpers_a_CFLAGS = -std=c99 +libinotify_helpers_a_CPPFLAGS = -D_POSIX_SOURCE diff --git a/common/inotify_helpers.c b/common/inotify_helpers.c index 781843e..1b4b930 100644 --- a/common/inotify_helpers.c +++ b/common/inotify_helpers.c @@ -1,5 +1,6 @@ +#include /* for strlen(3), memcpy(3) */ #include /* for printf(3) */ -#include /* for realloc(3), memcpy(3) */ +#include /* for realloc(3) */ #include /* for read(2) */ #include "inotify_helpers.h" @@ -75,7 +76,7 @@ inotify_mask2str(uint32_t mask) { if (mask & (1 << i)) { if (out.len > 0) strbufcat(&out, " | "); - strbufcat(&out, in_bits[i]); + strbufcat(&out, in_mask_bits[i]); } } return out.str; @@ -85,16 +86,19 @@ inotify_mask2str(uint32_t mask) { int inotify_print_event(struct inotify_event *event) { - return printf("wd:%d\n" - "\tmask:[%s]\n" - "\tcookie:%u\n" - "\tlen:%u\n" - "\tname:%s\n", - event->wd, - mask2str(event->mask), - event->cookie, - event->len, - event->len > 0 ? event->name : ""); + char *mask = inotify_mask2str(event->mask); + int ret = printf("wd:%d\n" + "\tmask:[%s]\n" + "\tcookie:%u\n" + "\tlen:%u\n" + "\tname:%s\n", + event->wd, + mask, + event->cookie, + event->len, + event->len > 0 ? event->name : ""); + free(mask); + return ret; } diff --git a/common/nslcd-prot.c b/common/nslcd-prot.c index 87c0066..e4d5a3c 100644 --- a/common/nslcd-prot.c +++ b/common/nslcd-prot.c @@ -55,41 +55,3 @@ to be able to tio_reset() the stream to re-read the current entity. Since group entities can grow arbitrarily large, this setting limits the number of users that can be put in a group. */ - -/* returns a socket to the server or NULL on error (see errno), - socket should be closed with fclose() */ -TFILE *nslcd_client_open() -{ - int sock; - struct sockaddr_un addr; - TFILE *fp; - int flags; - /* create a socket */ - if ((sock = socket(PF_UNIX, SOCK_STREAM, 0)) < 0) - return NULL; - /* create socket address structure */ - memset(&addr, 0, sizeof(struct sockaddr_un)); - addr.sun_family = AF_UNIX; - strncpy(addr.sun_path, NSLCD_SOCKET, sizeof(addr.sun_path)); - addr.sun_path[sizeof(addr.sun_path) - 1] = '\0'; - /* close the file descriptor on exec (ignore errors) */ - flags = fcntl(sock, F_GETFL); - if (flags >= 0) - (void)fcntl(sock, F_SETFD, flags | FD_CLOEXEC); - /* connect to the socket */ - if (connect(sock, (struct sockaddr *)&addr, SUN_LEN(&addr)) < 0) - { - (void)close(sock); - return NULL; - } - /* create a stream object */ - if ((fp = tio_fdopen(sock, READ_TIMEOUT, WRITE_TIMEOUT, - READBUFFER_MINSIZE, READBUFFER_MAXSIZE, - WRITEBUFFER_MINSIZE, WRITEBUFFER_MAXSIZE)) == NULL) - { - (void)close(sock); - return NULL; - } - /* return the stream */ - return fp; -} diff --git a/common/nslcd-prot.h b/common/nslcd-prot.h index 649be89..acc42f6 100644 --- a/common/nslcd-prot.h +++ b/common/nslcd-prot.h @@ -330,44 +330,6 @@ static void debug_dump(const void *ptr, size_t size) /* These are functions and macors for performing common operations in the nslcd request/response protocol. */ -/* returns a socket to the server or NULL on error (see errno), - socket should be closed with tio_close() */ -TFILE *nslcd_client_open(void) - MUST_USE; - -/* generic request code */ -#define NSLCD_REQUEST(fp, action, writefn) \ - /* open a client socket */ \ - if ((fp = nslcd_client_open()) == NULL) \ - { \ - ERROR_OUT_OPENERROR; \ - } \ - /* write a request header with a request code */ \ - WRITE_INT32(fp, (int32_t)NSLCD_VERSION) \ - WRITE_INT32(fp, (int32_t)action) \ - /* write the request parameters (if any) */ \ - writefn; \ - /* flush the stream */ \ - if (tio_flush(fp) < 0) \ - { \ - DEBUG_PRINT("WRITE_FLUSH : error: %s", strerror(errno)); \ - ERROR_OUT_WRITEERROR(fp); \ - } \ - /* read and check response version number */ \ - READ(fp, &tmpint32, sizeof(int32_t)); \ - tmpint32 = ntohl(tmpint32); \ - if (tmpint32 != (int32_t)NSLCD_VERSION) \ - { \ - ERROR_OUT_READERROR(fp); \ - } \ - /* read and check response request number */ \ - READ(fp, &tmpint32, sizeof(int32_t)); \ - tmpint32 = ntohl(tmpint32); \ - if (tmpint32 != (int32_t)(action)) \ - { \ - ERROR_OUT_READERROR(fp); \ - } - /* Read the response code (the result code of the query) from the stream. */ #define READ_RESPONSE_CODE(fp) \ -- cgit v1.2.3