#include <stdarg.h>
#include <getopt.h>
#include <fcntl.h>
+#include <signal.h>
#include <scif.h>
#include <arpa/inet.h>
#include <infiniband/verbs.h>
mlog(0, "mcm msg completion signal rate %d\n", mcm_signal);
}
+static int lock_fd;
static int mpxy_open_lock_file(void)
{
- int lock_fd, rc;
+ int rc;
char pid[16];
lock_fd = open(lock_file, O_RDWR | O_CREAT | O_EXCL, 0640);
return 0;
}
+static void mpxyd_release_lock_file( void )
+{
+ lockf(lock_fd, F_ULOCK, 0);
+ close(lock_fd);
+ unlink(lock_file);
+}
+
static void daemonize(void)
{
id_t pid, sid;
}
+static volatile int finished = 0;
+void sig_handler( int signum )
+{
+ mlog(0, "Killed by signal %d.\n", signum);
+ finished = 1;
+}
+
/*
* MPXY server will listen on both a IB UD QP for fabric CM messages
* and a SCIF port for inter-bus MCM operation messages to/from MIC MCM clients.
struct mcm_cq *m_cq;
struct mcm_qp *m_qp;
int time_ms, ret, data = 0, real_data;
+ struct sigaction act, oldact;
+
+ act.sa_handler = sig_handler;
+ sigemptyset(&act.sa_mask);
+ act.sa_flags = 0;
+ if (sigaction(SIGINT, &act, &oldact))
+ mlog(0, "sigaction: %s\n", strerror(errno));
+ if (sigaction(SIGTERM, &act, &oldact))
+ mlog(0, "sigaction: %s\n", strerror(errno));
/* FD array */
set = mcm_alloc_fd_set();
mlog(0, "server started\n");
- while (1) {
+ while (!finished) {
if (data)
time_ms = 0; /* no time to sleep */
else
mlog(0, "shutdown complete\n");
fclose(logfile);
+
+ mpxyd_release_lock_file();
return 0;
}