28xassert(
const char *msg,
const char *file,
int line)
30 fprintf(stderr,
"assertion failed: %s:%d: \"%s\"\n", file, line, msg);
36#define DEBUG(LEVEL) if ((LEVEL) <= DebugLevel)
61 fd = open(buf, r->
offset, 0600);
65 fprintf(stderr,
"%d %s: ", (
int)
mypid, buf);
78 fprintf(stderr,
"%d OPEN id %d, FD %d, fs %p\n",
97 fprintf(stderr,
"%d CLOSE id %d: ", (
int)
mypid, r->
id);
107 fprintf(stderr,
"%d CLOSE id %d, FD %d, fs %p\n",
121 int readlen = r->
size;
128 fprintf(stderr,
"%d READ id %d: ", (
int)
mypid, r->
id);
137 fprintf(stderr,
"seeking to %" PRId64 "\n", (int64_t)r->
offset);
140 if (lseek(fs->
fd, r->
offset, SEEK_SET) < 0) {
142 fprintf(stderr,
"%d FD %d, offset %" PRId64 ": ", (
int)
mypid, fs->
fd, (int64_t)r->
offset);
148 x = read(fs->
fd, buf, readlen);
150 fprintf(stderr,
"%d READ %d,%d,%" PRId64 " ret %d\n", (
int)
mypid,
151 fs->
fd, readlen, (int64_t)r->
offset, x);
156 fprintf(stderr,
"%d FD %d: ", (
int)
mypid, fs->
fd);
170 int wrtlen = r->
size;
178 fprintf(stderr,
"%d WRITE id %d: ", (
int)
mypid, r->
id);
186 if (lseek(fs->
fd, r->
offset, SEEK_SET) < 0) {
188 fprintf(stderr,
"%d FD %d, offset %" PRId64 ": ", (
int)
mypid, fs->
fd, (int64_t)r->
offset);
195 fprintf(stderr,
"%d WRITE %d,%d,%" PRId64 "\n", (
int)
mypid,
196 fs->
fd, wrtlen, (int64_t)r->
offset);
198 x = write(fs->
fd, buf, wrtlen);
202 fprintf(stderr,
"%d FD %d: ", (
int)
mypid, fs->
fd);
216 if (unlink(buf) < 0) {
218 fprintf(stderr,
"%d UNLNK id %d %s: ", (
int)
mypid, r->
id, buf);
226 fprintf(stderr,
"%d UNLNK %s\n", (
int)
mypid, buf);
248 fprintf(stderr,
"%d UNLNK id(%u) Error: no filename in shm buffer\n", (
int)
mypid, s->
id);
285 const int *
A = (
const int *)a;
286 const int *
B = (
const int *)b;
294 const int *k = (
const int *)key;
315 setbuf(stdout,
nullptr);
316 setbuf(stderr,
nullptr);
320 rmsgid = msgget(key, 0600);
328 smsgid = msgget(key, 0600);
336 shmid = shmget(key, 0, 0600);
343 shmbuf = (
char *)shmat(shmid,
nullptr, 0);
345 if (
shmbuf == (
void *) -1) {
356 memset(&sa,
'\0',
sizeof(sa));
359 sigaction(SIGALRM, &sa,
nullptr);
363 memset(&rmsg,
'\0',
sizeof(rmsg));
365 std::cerr <<
"msgrcv: " << rmsgid <<
", "
367 <<
", " << 0 <<
", " << 0 << std::endl;
372 if (EINTR == errno) {
373 if (read(0, rbuf, 512) <= 0) {
374 if (EWOULDBLOCK == errno)
376 else if (EAGAIN == errno)
383 if (EAGAIN == errno) {
401 fprintf(stderr,
"%d diskd exiting\n", (
int)
mypid);
404 if (msgctl(rmsgid, IPC_RMID,
nullptr) < 0)
405 perror(
"msgctl IPC_RMID");
407 if (msgctl(smsgid, IPC_RMID,
nullptr) < 0)
408 perror(
"msgctl IPC_RMID");
413 if (shmctl(shmid, IPC_RMID,
nullptr) < 0)
414 perror(
"shmctl IPC_RMID");
int main(int argc, char *argv[])
static int do_open(diomsg *r, int, const char *buf)
static int do_read(diomsg *r, int, char *buf)
static void alarm_handler(int)
static int do_close(diomsg *r, int)
static int fsCmp(const void *a, const void *b)
static int do_write(diomsg *r, int, const char *buf)
static int do_unlink(diomsg *r, int, const char *buf)
static unsigned int fsHash(const void *key, unsigned int n)
void xassert(const char *msg, const char *file, int line)
static void msg_handle(diomsg *r, int rl, diomsg *s)
SQUIDCEXTERN hash_table * hash_create(HASHCMP *, int, HASHHASH *)
SQUIDCEXTERN void hash_join(hash_table *, hash_link *)
SQUIDCEXTERN void hash_remove_link(hash_table *, hash_link *)
SQUIDCEXTERN hash_link * hash_lookup(hash_table *, const void *)
static const int msg_snd_rcv_sz
void * xcalloc(size_t n, size_t sz)
const char * xstrerr(int error)