/*
- * $Id$
- *
- * DEBUG: section -- External DISKD process implementation.
- * AUTHOR: Harvest Derived
- *
- * SQUID Web Proxy Cache http://www.squid-cache.org/
- * ----------------------------------------------------------
- *
- * Squid is the result of efforts by numerous individuals from
- * the Internet community; see the CONTRIBUTORS file for full
- * details. Many organizations have provided support for Squid's
- * development; see the SPONSORS file for full details. Squid is
- * Copyrighted (C) 2001 by the Regents of the University of
- * California; see the COPYRIGHT file for full details. Squid
- * incorporates software developed and/or copyrighted by other
- * sources; see the CREDITS file for full details.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
+ * Copyright (C) 1996-2021 The Squid Software Foundation and contributors
*
+ * Squid software is distributed under GPLv2+ license and includes
+ * contributions from numerous individuals and organizations.
+ * Please see the COPYING and CONTRIBUTORS files for details.
*/
-#include "config.h"
+/* DEBUG: section -- External DISKD process implementation. */
+
#include "squid.h"
+#include "DiskIO/DiskDaemon/diomsg.h"
+#include "hash.h"
+#include <cerrno>
+#include <iostream>
+#if HAVE_SYS_IPC_H
#include <sys/ipc.h>
+#endif
+#if HAVE_SYS_MSG_H
#include <sys/msg.h>
+#endif
+#if HAVE_SYS_SHM_H
#include <sys/shm.h>
-
-#include "DiskIO/DiskDaemon/diomsg.h"
+#endif
void
xassert(const char *msg, const char *file, int line)
static int DebugLevel = 0;
static int
-do_open(diomsg * r, int len, const char *buf)
+do_open(diomsg * r, int, const char *buf)
{
int fd;
file_state *fs;
fs = (file_state *)xcalloc(1, sizeof(*fs));
fs->id = r->id;
- fs->key = &fs->id; /* gack */
+ fs->key = &fs->id; /* gack */
fs->fd = fd;
hash_join(hash, (hash_link *) fs);
- DEBUG(2)
- fprintf(stderr, "%d OPEN id %d, FD %d, fs %p\n",
- (int) mypid,
- fs->id,
- fs->fd,
- fs);
+ DEBUG(2) {
+ fprintf(stderr, "%d OPEN id %d, FD %d, fs %p\n",
+ (int) mypid,
+ fs->id,
+ fs->fd,
+ fs);
+ }
return fd;
}
static int
-do_close(diomsg * r, int len)
+do_close(diomsg * r, int)
{
int fd;
file_state *fs;
fd = fs->fd;
hash_remove_link(hash, (hash_link *) fs);
- DEBUG(2)
- fprintf(stderr, "%d CLOSE id %d, FD %d, fs %p\n",
- (int) mypid,
- r->id,
- fs->fd,
- fs);
+ DEBUG(2) {
+ fprintf(stderr, "%d CLOSE id %d, FD %d, fs %p\n",
+ (int) mypid,
+ r->id,
+ fs->fd,
+ fs);
+ }
xfree(fs);
return close(fd);
}
static int
-do_read(diomsg * r, int len, char *buf)
+do_read(diomsg * r, int, char *buf)
{
int x;
int readlen = r->size;
}
if (r->offset > -1 && r->offset != fs->offset) {
- DEBUG(2)
- fprintf(stderr, "seeking to %"PRId64"\n", (int64_t)r->offset);
+ DEBUG(2) {
+ fprintf(stderr, "seeking to %" PRId64 "\n", (int64_t)r->offset);
+ }
if (lseek(fs->fd, r->offset, SEEK_SET) < 0) {
DEBUG(1) {
- fprintf(stderr, "%d FD %d, offset %"PRId64": ", (int) mypid, fs->fd, (int64_t)r->offset);
+ fprintf(stderr, "%d FD %d, offset %" PRId64 ": ", (int) mypid, fs->fd, (int64_t)r->offset);
perror("lseek");
}
}
}
x = read(fs->fd, buf, readlen);
- DEBUG(2)
- fprintf(stderr, "%d READ %d,%d,%"PRId64" ret %d\n", (int) mypid,
- fs->fd, readlen, (int64_t)r->offset, x);
+ DEBUG(2) {
+ fprintf(stderr, "%d READ %d,%d,%" PRId64 " ret %d\n", (int) mypid,
+ fs->fd, readlen, (int64_t)r->offset, x);
+ }
if (x < 0) {
DEBUG(1) {
}
static int
-do_write(diomsg * r, int len, const char *buf)
+do_write(diomsg * r, int, const char *buf)
{
int wrtlen = r->size;
int x;
if (r->offset > -1 && r->offset != fs->offset) {
if (lseek(fs->fd, r->offset, SEEK_SET) < 0) {
DEBUG(1) {
- fprintf(stderr, "%d FD %d, offset %"PRId64": ", (int) mypid, fs->fd, (int64_t)r->offset);
+ fprintf(stderr, "%d FD %d, offset %" PRId64 ": ", (int) mypid, fs->fd, (int64_t)r->offset);
perror("lseek");
}
}
}
- DEBUG(2)
- fprintf(stderr, "%d WRITE %d,%d,%"PRId64"\n", (int) mypid,
- fs->fd, wrtlen, (int64_t)r->offset);
+ DEBUG(2) {
+ fprintf(stderr, "%d WRITE %d,%d,%" PRId64 "\n", (int) mypid,
+ fs->fd, wrtlen, (int64_t)r->offset);
+ }
x = write(fs->fd, buf, wrtlen);
if (x < 0) {
}
static int
-do_unlink(diomsg * r, int len, const char *buf)
+do_unlink(diomsg * r, int, const char *buf)
{
if (unlink(buf) < 0) {
DEBUG(1) {
return -errno;
}
- DEBUG(2)
- fprintf(stderr, "%d UNLNK %s\n", (int) mypid, buf);
+ DEBUG(2) {
+ fprintf(stderr, "%d UNLNK %s\n", (int) mypid, buf);
+ }
return 0;
}
char *buf = NULL;
s->mtype = r->mtype;
s->id = r->id;
- s->seq_no = r->seq_no; /* optional, debugging */
+ s->seq_no = r->seq_no; /* optional, debugging */
s->callback_data = r->callback_data;
s->requestor = r->requestor;
- s->size = 0; /* optional, debugging */
- s->offset = 0; /* optional, debugging */
+ s->size = 0; /* optional, debugging */
+ s->offset = 0; /* optional, debugging */
s->shm_offset = r->shm_offset;
s->newstyle = r->newstyle;
if (s->shm_offset > -1)
buf = shmbuf + s->shm_offset;
+ else if (r->mtype != _MQD_CLOSE) {
+ fprintf(stderr, "%d UNLNK id(%u) Error: no filename in shm buffer\n", (int) mypid, s->id);
+ return;
+ }
switch (r->mtype) {
return (*k & (--n));
}
-SQUIDCEXTERN {
- static void
- alarm_handler(int sig) {
- (void) 0;
- }
+extern "C" {
+ static void alarm_handler(int) {}
};
int
if (rmsgid < 0) {
perror("msgget");
- return 1;
+ exit(EXIT_FAILURE);
}
key = atoi(argv[2]);
if (smsgid < 0) {
perror("msgget");
- return 1;
+ exit(EXIT_FAILURE);
}
key = atoi(argv[3]);
if (shmid < 0) {
perror("shmget");
- return 1;
+ exit(EXIT_FAILURE);
}
shmbuf = (char *)shmat(shmid, NULL, 0);
if (shmbuf == (void *) -1) {
perror("shmat");
- return 1;
+ exit(EXIT_FAILURE);
}
hash = hash_create(fsCmp, 1 << 4, fsHash);
assert(hash);
- fcntl(0, F_SETFL, SQUID_NONBLOCK);
+ if (fcntl(0, F_SETFL, SQUID_NONBLOCK) < 0) {
+ perror(xstrerr(errno));
+ exit(EXIT_FAILURE);
+ }
memset(&sa, '\0', sizeof(sa));
sa.sa_handler = alarm_handler;
sa.sa_flags = SA_RESTART;
for (;;) {
alarm(1);
memset(&rmsg, '\0', sizeof(rmsg));
- DEBUG(2)
- std::cerr << "msgrcv: " << rmsgid << ", "
- << &rmsg << ", " << diomsg::msg_snd_rcv_sz
- << ", " << 0 << ", " << 0 << std::endl;
+ DEBUG(2) {
+ std::cerr << "msgrcv: " << rmsgid << ", "
+ << &rmsg << ", " << diomsg::msg_snd_rcv_sz
+ << ", " << 0 << ", " << 0 << std::endl;
+ }
rlen = msgrcv(rmsgid, &rmsg, diomsg::msg_snd_rcv_sz, 0, 0);
if (rlen < 0) {
}
}
- DEBUG(2)
- fprintf(stderr, "%d diskd exiting\n", (int) mypid);
+ DEBUG(2) {
+ fprintf(stderr, "%d diskd exiting\n", (int) mypid);
+ }
if (msgctl(rmsgid, IPC_RMID, 0) < 0)
perror("msgctl IPC_RMID");
if (shmctl(shmid, IPC_RMID, 0) < 0)
perror("shmctl IPC_RMID");
- return 0;
+ return EXIT_SUCCESS;
}
+