Skip to content

Commit fb78bf2

Browse files
authored
Merge pull request #132 from garlick/logging
enable systemctl reload diod + minor logging improvements
2 parents dca6145 + 2948cc7 commit fb78bf2

File tree

8 files changed

+32
-30
lines changed

8 files changed

+32
-30
lines changed

etc/diod.service.in

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Description=9P File Server
44
[Service]
55
Type=exec
66
ExecStart=@X_SBINDIR@/diod
7+
ExecReload=kill -HUP $MAINPID
78

89
[Install]
910
WantedBy=multi-user.target

src/cmd/diod.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ main(int argc, char **argv)
121121
srvmode_t mode = SRV_NORMAL;
122122
int rfdno = -1, wfdno = -1;
123123

124-
diod_log_init (argv[0]);
124+
diod_log_init (NULL);
125125
diod_conf_init ();
126126

127127
/* config file overrides defaults */

src/libdiod/diod_log.c

+18-6
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,27 @@
2626

2727
#include "diod_log.h"
2828

29-
static char *prog = NULL;
30-
29+
static char log_prefix[32] = { 0 };
3130
static char *filename = NULL;
3231
static FILE *logf = NULL;
3332

33+
/* If 'path' is a program path, prefix is "name: ", where name is basename (path).
34+
* If 'path' ends in a space, omit the ": ", e.g. path of "# " is used verbatim.
35+
* If 'path' is NULL, there is no log prefix.
36+
*/
3437
void
35-
diod_log_init (char *p)
38+
diod_log_init (char *path)
3639
{
37-
prog = basename (p);
40+
if (path) {
41+
char *cp = strrchr (path, '/');
42+
snprintf (log_prefix,
43+
sizeof (log_prefix),
44+
"%s%s",
45+
cp ? cp + 1 : path,
46+
isspace (path[strlen (path) - 1]) ? "" : ": ");
47+
}
48+
else
49+
log_prefix[0] = '\0';
3850
logf = stderr;
3951
}
4052

@@ -93,7 +105,7 @@ _verr (int errnum, const char *fmt, va_list ap)
93105
char *s = strerror_r (errnum, errbuf, sizeof (errbuf)); /* GNU version */
94106
#endif
95107
vsnprintf (buf, sizeof (buf), fmt, ap); /* ignore overflow */
96-
fprintf (logf, "%s: %s: %s\n", prog, buf, s);
108+
fprintf (logf, "%s%s: %s\n", log_prefix, buf, s);
97109
fflush (logf);
98110
}
99111
}
@@ -105,7 +117,7 @@ diod_log_msg (const char *fmt, va_list ap)
105117

106118
if (logf) {
107119
vsnprintf (buf, sizeof (buf), fmt, ap); /* ignore overflow */
108-
fprintf (logf, "%s: %s\n", prog, buf);
120+
fprintf (logf, "%s%s\n", log_prefix, buf);
109121
fflush (logf);
110122
}
111123
}

src/libdiod/diod_rdma.c

+5
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <sys/types.h>
2424
#include <sys/socket.h>
2525
#include <netinet/in.h>
26+
#include <arpa/inet.h>
2627
#include <netdb.h>
2728
#include <sys/signal.h>
2829
#include <sys/param.h>
@@ -103,6 +104,10 @@ diod_rdma_listen (diod_rdma_t rdma)
103104
if (n)
104105
errn (n, "rdma_listen");
105106

107+
msg ("Listening on rdma %s:%d",
108+
inet_ntoa (rdma->addr.sin_addr),
109+
rdma_port);
110+
106111
return 0;
107112
}
108113

src/libdiod/diod_sock.c

+3
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,8 @@ _setup_one_inet (char *host, char *port, struct pollfd **fdsp, int *nfdsp)
177177
break;
178178
count++;
179179
}
180+
if (count > 0)
181+
msg ("Listening on %s:%s", host, port);
180182
done:
181183
if (res)
182184
freeaddrinfo (res);
@@ -211,6 +213,7 @@ _setup_one_unix (char *path, struct pollfd **fdsp, int *nfdsp)
211213
}
212214
if (_poll_add (fdsp, nfdsp, fd) < 0)
213215
goto error;
216+
msg ("Listening on %s", path);
214217
return 1;
215218
error:
216219
if (fd != -1)

src/libtest/server.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Npsrv *test_server_create (const char *testdir, int flags, int *client_fd)
2929
int s[2];
3030
Npsrv *srv;
3131

32-
diod_log_init ("#"); // add TAP compatible prefix on stderr logs
32+
diod_log_init ("# "); // add TAP compatible prefix on stderr logs
3333
diod_conf_init ();
3434
diod_conf_set_auth_required (0);
3535

tests/misc/Makefile.am

+2-20
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,6 @@ TESTS_ENVIRONMENT += "TOP_BUILDDIR=$(top_builddir)"
88

99
TESTS = t15
1010

11-
CLEANFILES = *.out *.diff
11+
CLEANFILES = *.out *.diod
1212

13-
AM_CFLAGS = @WARNING_CFLAGS@
14-
15-
AM_CPPFLAGS = \
16-
-I$(top_srcdir) \
17-
$(LUA_INCLUDE)
18-
19-
LDADD = $(top_builddir)/src/cmd/opt.o \
20-
$(top_builddir)/src/daemon/ops.o \
21-
$(top_builddir)/src/daemon/fid.o \
22-
$(top_builddir)/src/daemon/exp.o \
23-
$(top_builddir)/src/daemon/ioctx.o \
24-
$(top_builddir)/src/daemon/xattr.o \
25-
$(top_builddir)/src/libdiod/libdiod.a \
26-
$(top_builddir)/src/libnpclient/libnpclient.a \
27-
$(top_builddir)/src/libnpfs/libnpfs.a \
28-
$(top_builddir)/src/liblsd/liblsd.a \
29-
$(LIBPTHREAD) $(LUA_LIB) $(LIBMUNGE) $(LIBCAP) $(LIBTCMALLOC)
30-
31-
EXTRA_DIST = $(TESTS) $(TESTS:%=%.exp) memcheck valgrind.supp
13+
EXTRA_DIST = $(TESTS) memcheck valgrind.supp

tests/misc/t15

+1-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ bg_test ()
1212
TEST=$(basename $0 | cut -d- -f1)
1313
sockfile=$(mktemp)
1414
bg_test $sockfile &
15-
${MISC_SRCDIR}/memcheck ${TOP_BUILDDIR}/src/cmd/diod -c /dev/null -n -e ctl -l $sockfile -s >$TEST.out 2>&1
16-
diff ${MISC_SRCDIR}/$TEST.exp $TEST.out >$TEST.diff
15+
${MISC_SRCDIR}/memcheck ${TOP_BUILDDIR}/src/cmd/diod -L $TEST.diod -c /dev/null -n -e ctl -l $sockfile -s >$TEST.out 2>&1
1716
rm -f $sockfile
1817
wait %1

0 commit comments

Comments
 (0)