Check for error writing to acceptor $PIDFILE.
Accptor reports when it has exited to syslog, so we can trace if it is a
culprit in the "bind: address already in use" problem.
b=5509
b=7283
addr.sin_port = htons(port);
if (bind(m->bound,(struct sockaddr *)&addr,alen)<0){
addr.sin_port = htons(port);
if (bind(m->bound,(struct sockaddr *)&addr,alen)<0){
- perror ("tcpnal bind");
+ fprintf(stderr, "tcpnal bind: %s port %u\n", strerror(errno), port);
addr.sin_port = htons(port);
if (bind(m->bound,(struct sockaddr *)&addr,alen)<0){
addr.sin_port = htons(port);
if (bind(m->bound,(struct sockaddr *)&addr,alen)<0){
- perror ("tcpnal bind");
+ fprintf(stderr, "tcpnal bind: %s port %u\n", strerror(errno), port);
-void pidfile_create(char *name_port)
+int pidfile_create(char *name_port)
{
char *pidfile = pidfile_name(name_port);
{
char *pidfile = pidfile_name(name_port);
- FILE *fp;
-
- if ((fp = fopen(pidfile, "w"))) {
- fprintf(fp, "%d\n", getpid());
- fclose(fp);
+ int fd, rc;
+
+ if ((fd = open(pidfile, O_CREAT | O_WRONLY)) >= 0) {
+ char pid[16];
+ int size = snprintf(pid, sizeof(pid), "%u\n", getpid());
+ if (write(fd, pid, size) != size) {
+ /* hard error or short write */
+ rc = errno ? : EIO;
+ } else {
+ rc = 0;
+ }
+ close(fd);
- errlog(LOG_ERR, " error creating %s: %s\n",
- pidfile, strerror(errno));
+
+ if (rc)
+ errlog(LOG_ERR, " error creating %s: %s\n",
+ pidfile, strerror(rc));
+
+ return rc;
}
int pidfile_cleanup(char *name_port)
}
int pidfile_cleanup(char *name_port)
if (rc && errno != -ENOENT)
fprintf(stderr, "%s: error removing %s: %s\n",
progname, pidfile, strerror(errno));
if (rc && errno != -ENOENT)
fprintf(stderr, "%s: error removing %s: %s\n",
progname, pidfile, strerror(errno));
+ errlog(LOG_NOTICE, "exiting\n");
- pidfile_cleanup(name_port);
+void atexit_handler(void)
+{
+ pidfile_cleanup(name_port);
+}
+
void show_connection(int fd, __u32 net_ip)
{
static long last_time;
void show_connection(int fd, __u32 net_ip)
{
static long last_time;
signal(SIGTERM, handler);
errlog(LOG_NOTICE, "started, listening on port %d\n", port);
signal(SIGTERM, handler);
errlog(LOG_NOTICE, "started, listening on port %d\n", port);
- pidfile_create(name_port);
+ if (pidfile_create(name_port) == 0)
+ atexit(atexit_handler);
while (1) {
struct sockaddr_in clntaddr;
while (1) {
struct sockaddr_in clntaddr;
+ inet_ntop(AF_INET, &clntaddr.sin_addr, addrstr,INET_ADDRSTRLEN);
#ifdef HAVE_LIBWRAP
/* libwrap access control */
request_init(&request, RQ_DAEMON, "lustre", RQ_FILE, cfd, 0);
sock_host(&request);
if (!hosts_access(&request)) {
#ifdef HAVE_LIBWRAP
/* libwrap access control */
request_init(&request, RQ_DAEMON, "lustre", RQ_FILE, cfd, 0);
sock_host(&request);
if (!hosts_access(&request)) {
- inet_ntop(AF_INET, &clntaddr.sin_addr,
- addrstr, INET_ADDRSTRLEN);
errlog(LOG_WARNING, "unauthorized access from %s:%hd\n",
addrstr, ntohs(clntaddr.sin_port));
close (cfd);
errlog(LOG_WARNING, "unauthorized access from %s:%hd\n",
addrstr, ntohs(clntaddr.sin_port));
close (cfd);
if (require_privports &&
ntohs(clntaddr.sin_port) >= IPPORT_RESERVED) {
if (require_privports &&
ntohs(clntaddr.sin_port) >= IPPORT_RESERVED) {
- inet_ntop(AF_INET, &clntaddr.sin_addr,
- addrstr, INET_ADDRSTRLEN);
errlog(LOG_ERR,
"closing non-privileged connection from %s:%d\n",
addrstr, ntohs(clntaddr.sin_port));
errlog(LOG_ERR,
"closing non-privileged connection from %s:%d\n",
addrstr, ntohs(clntaddr.sin_port));
data.ioc_plen1 = sizeof(pcfg);
if (ioctl(pfd, IOC_PORTAL_NAL_CMD, &data) < 0) {
data.ioc_plen1 = sizeof(pcfg);
if (ioctl(pfd, IOC_PORTAL_NAL_CMD, &data) < 0) {
- errlog(LOG_ERR,
- "portals ioctl failed: %s\n", strerror(errno));
+ errlog(LOG_ERR, "portals ioctl failed for %s: %s\n",
+ addrstr, strerror(errno));
- errlog(LOG_DEBUG, "client registered\n");
+ errlog(LOG_DEBUG, "client %s registered\n", addrstr);
}
rc = close(cfd);
if (rc)
}
rc = close(cfd);
if (rc)
- perror ("close failed");
+ perror("close failed");
- pidfile_cleanup(name_port);