YAZ  5.34.0
unix.c
Go to the documentation of this file.
1 /* This file is part of the YAZ toolkit.
2  * Copyright (C) Index Data
3  * See the file LICENSE for details.
4  */
9 #if HAVE_CONFIG_H
10 #include <config.h>
11 #endif
12 
13 #include <yaz/yconfig.h>
14 
15 #ifndef WIN32
16 
17 #include <stdio.h>
18 #include <string.h>
19 #include <stdlib.h>
20 #include <errno.h>
21 #include <time.h>
22 #if HAVE_SYS_TYPES_H
23 #include <sys/types.h>
24 #endif
25 #if HAVE_UNISTD_H
26 #include <unistd.h>
27 #endif
28 #if HAVE_SYS_SOCKET_H
29 #include <sys/socket.h>
30 #endif
31 #include <fcntl.h>
32 #include <signal.h>
33 
34 #include <grp.h>
35 #if HAVE_PWD_H
36 #include <pwd.h>
37 #endif
38 
39 #if HAVE_SYS_STAT_H
40 #include <sys/stat.h>
41 #endif
42 #if HAVE_SYS_UN_H
43 #include <sys/un.h>
44 #endif
45 
46 #include <yaz/unix.h>
47 #include <yaz/errno.h>
48 #include <yaz/log.h>
49 
50 #ifndef YAZ_SOCKLEN_T
51 #define YAZ_SOCKLEN_T int
52 #endif
53 
54 static void unix_close(COMSTACK h);
55 static int unix_put(COMSTACK h, char *buf, int size);
56 static int unix_get(COMSTACK h, char **buf, int *bufsize);
57 static int unix_connect(COMSTACK h, void *address);
58 static int unix_more(COMSTACK h);
59 static int unix_rcvconnect(COMSTACK h);
60 static int unix_bind(COMSTACK h, void *address, int mode);
61 static int unix_listen(COMSTACK h, char *raddr, int *addrlen,
62  int (*check_ip)(void *cd, const char *a, int len, int type),
63  void *cd);
64 static int unix_set_blocking(COMSTACK p, int blocking);
65 
66 static COMSTACK unix_accept(COMSTACK h);
67 static const char *unix_addrstr(COMSTACK h);
68 static void *unix_straddr(COMSTACK h, const char *str);
69 
70 #ifndef SUN_LEN
71 #define SUN_LEN(ptr) ((size_t) (((struct sockaddr_un *) 0)->sun_path) \
72  + strlen ((ptr)->sun_path))
73 #endif
74 
75 /* this state is used for both SSL and straight TCP/IP */
76 typedef struct unix_state
77 {
78  char *altbuf; /* alternate buffer for surplus data */
79  int altsize; /* size as xmalloced */
80  int altlen; /* length of data or 0 if none */
81 
82  int written; /* -1 if we aren't writing */
83  int towrite; /* to verify against user input */
84  int (*complete)(const char *buf, int len); /* length/complete. */
85  struct sockaddr_un addr; /* returned by cs_straddr */
86  int uid;
87  int gid;
88  int umask;
89  char buf[128]; /* returned by cs_addrstr */
91 
92 static int log_level = 0;
93 
94 static void unix_init (void)
95 {
96  static int log_level_set = 0;
97  if (!log_level_set)
98  {
99  log_level = yaz_log_module_level("comstack");
100  log_level_set = 1;
101  }
102 }
103 
104 /*
105  * This function is always called through the cs_create() macro.
106  * s >= 0: socket has already been established for us.
107  */
108 COMSTACK unix_type(int s, int flags, int protocol, void *vp)
109 {
110  COMSTACK p;
111  unix_state *state;
112  int new_socket;
113 
114  unix_init();
115  if (s < 0)
116  {
117  if ((s = socket(AF_UNIX, SOCK_STREAM, 0)) < 0)
118  return 0;
119  new_socket = 1;
120  }
121  else
122  new_socket = 0;
123  if (!(p = (struct comstack *)xmalloc(sizeof(struct comstack))))
124  return 0;
125  if (!(state = (struct unix_state *)(p->cprivate =
126  xmalloc(sizeof(unix_state)))))
127  return 0;
128 
129  p->flags = flags;
130  if (!(p->flags&CS_FLAGS_BLOCKING))
131  {
132  if (fcntl(s, F_SETFL, O_NONBLOCK) < 0)
133  return 0;
134 #ifndef MSG_NOSIGNAL
135  signal (SIGPIPE, SIG_IGN);
136 #endif
137  }
138 
139  p->io_pending = 0;
140  p->iofile = s;
141  p->type = unix_type;
142  p->protocol = (enum oid_proto) protocol;
143 
144  p->f_connect = unix_connect;
146  p->f_get = unix_get;
147  p->f_put = unix_put;
148  p->f_close = unix_close;
149  p->f_more = unix_more;
150  p->f_bind = unix_bind;
151  p->f_listen = unix_listen;
152  p->f_accept = unix_accept;
153  p->f_addrstr = unix_addrstr;
154  p->f_straddr = unix_straddr;
156 
157  p->state = new_socket ? CS_ST_UNBND : CS_ST_IDLE; /* state of line */
158  p->event = CS_NONE;
159  p->cerrno = 0;
160  p->user = 0;
161 
162  state->altbuf = 0;
163  state->altsize = state->altlen = 0;
164  state->towrite = state->written = -1;
165  state->complete = cs_complete_auto;
166 
167  yaz_log(log_level, "Created UNIX comstack h=%p", p);
168 
169  return p;
170 }
171 
172 
173 static int unix_strtoaddr_ex(const char *str, struct sockaddr_un *add)
174 {
175  char *cp;
176 
177  unix_init();
178  yaz_log(log_level, "unix_strtoaddr_ex %s", str ? str : "NULL");
179  add->sun_family = AF_UNIX;
180  strncpy(add->sun_path, str, sizeof(add->sun_path)-1);
181  add->sun_path[sizeof(add->sun_path)-1] = 0;
182  cp = strchr (add->sun_path, ':');
183  if (cp)
184  *cp = '\0';
185  return 1;
186 }
187 
188 static void *unix_straddr1(COMSTACK h, const char *str, char *f)
189 {
190  unix_state *sp = (unix_state *)h->cprivate;
191  char * s = f;
192  const char * file = NULL;
193 
194  sp->uid = sp->gid = sp->umask = -1;
195 
196  if (strchr(s, '='))
197  {
198  char *eol;
199  do
200  {
201  if ((eol = strchr(s, ',')))
202  *eol++ = '\0';
203  if (sp->uid == -1 && strncmp(s, "user=", 5) == 0)
204  {
205  char * arg = s + 5;
206  if (strspn(arg, "0123456789") == strlen(arg))
207  {
208  sp->uid = atoi(arg);
209  }
210  else
211  {
212  struct passwd * pw = getpwnam(arg);
213  if (pw == NULL)
214  {
215  yaz_log(log_level, "unix_strtoaddr1 No such user %s",
216  arg);
217  return 0;
218  }
219  sp->uid = pw->pw_uid;
220  }
221  }
222  else if (sp->gid == -1 && strncmp(s, "group=", 6) == 0)
223  {
224  char * arg = s + 6;
225  if (strspn(arg, "0123456789") == strlen(arg))
226  {
227  sp->gid = atoi(arg);
228  }
229  else
230  {
231  struct group * gr = getgrnam(arg);
232  if (gr == NULL)
233  {
234  yaz_log(log_level, "unix_strtoaddr1 No such group %s",
235  arg);
236  return 0;
237  }
238  sp->gid = gr->gr_gid;
239  }
240  }
241  else if (sp->umask == -1 && strncmp(s, "umask=", 6) == 0)
242  {
243  char * end;
244  char * arg = s + 6;
245 
246  sp->umask = strtol(arg, &end, 8);
247  if (errno == EINVAL ||
248  *end)
249  {
250  yaz_log(log_level, "unix_strtoaddr1 Invalid umask %s",
251  arg);
252  return 0;
253  }
254  }
255  else if (file == NULL && strncmp(s, "file=", 5) == 0)
256  {
257  char * arg = s + 5;
258  file = arg;
259  }
260  else
261  {
262  yaz_log(log_level, "unix_strtoaddr1 "
263  "invalid or double argument %s", s);
264  return 0;
265  }
266  } while ((s = eol));
267  }
268  else
269  {
270  file = str;
271  }
272  if (!file)
273  {
274  errno = EINVAL;
275  return 0;
276  }
277 
278  yaz_log(log_level, "unix_straddr1: %s", str ? str : "NULL");
279 
280  if (!unix_strtoaddr_ex (file, &sp->addr))
281  return 0;
282  return &sp->addr;
283 }
284 
285 static void *unix_straddr(COMSTACK h, const char *str)
286 {
287  char *f = xstrdup(str);
288  void *vp = unix_straddr1(h, str, f);
289  xfree(f);
290  return vp;
291 }
292 
293 struct sockaddr_un *unix_strtoaddr(const char *str)
294 {
295  static struct sockaddr_un add;
296 
297  yaz_log(log_level, "unix_strtoaddr %s", str ? str : "NULL");
298 
299  if (!unix_strtoaddr_ex (str, &add))
300  return 0;
301  return &add;
302 }
303 
304 static int unix_more(COMSTACK h)
305 {
306  unix_state *sp = (unix_state *)h->cprivate;
307 
308  return sp->altlen && (*sp->complete)(sp->altbuf, sp->altlen);
309 }
310 
311 /*
312  * connect(2) will block (sometimes) - nothing we can do short of doing
313  * weird things like spawning subprocesses or threading or some weird junk
314  * like that.
315  */
316 static int unix_connect(COMSTACK h, void *address)
317 {
318  struct sockaddr_un *add = (struct sockaddr_un *)address;
319  int r;
320  int i;
321 
322  yaz_log(log_level, "unix_connect h=%p", h);
323  h->io_pending = 0;
324  if (h->state != CS_ST_UNBND)
325  {
326  h->cerrno = CSOUTSTATE;
327  return -1;
328  }
329  for (i = 0; i<3; i++)
330  {
331  r = connect(h->iofile, (struct sockaddr *) add, SUN_LEN(add));
332  if (r < 0 && yaz_errno() == EAGAIN)
333  {
334 #if HAVE_NANOSLEEP
335  struct timespec v;
336  v.tv_sec = 0L;
337  v.tv_nsec = i*10000000L + 1000000L; /* 1ms, 11ms, 21ms */
338  nanosleep(&v, 0);
339 #else
340  sleep(1);
341 #endif
342  continue;
343  }
344  else
345  break;
346  }
347  if (r < 0)
348  {
349  if (yaz_errno() == EINPROGRESS)
350  {
351  h->event = CS_CONNECT;
352  h->state = CS_ST_CONNECTING;
354  return 1;
355  }
356  h->cerrno = CSYSERR;
357  return -1;
358  }
359  h->event = CS_CONNECT;
360  h->state = CS_ST_CONNECTING;
361 
362  return unix_rcvconnect (h);
363 }
364 
365 /*
366  * nop
367  */
369 {
370  yaz_log(log_level, "unix_rcvconnect h=%p", h);
371 
372  if (h->state == CS_ST_DATAXFER)
373  return 0;
374  if (h->state != CS_ST_CONNECTING)
375  {
376  h->cerrno = CSOUTSTATE;
377  return -1;
378  }
379  h->event = CS_DATA;
380  h->state = CS_ST_DATAXFER;
381  return 0;
382 }
383 
384 static int unix_bind(COMSTACK h, void *address, int mode)
385 {
386  unix_state *sp = (unix_state *)h->cprivate;
387  struct sockaddr *addr = (struct sockaddr *)address;
388  const char * path = ((struct sockaddr_un *)addr)->sun_path;
389  struct stat stat_buf;
390 
391  yaz_log(log_level, "unix_bind h=%p", h);
392 
393  if (stat(path, &stat_buf) != -1) {
394  struct sockaddr_un socket_unix;
395  int socket_out = -1;
396 
397  if (!S_ISSOCK(stat_buf.st_mode)) {
398  h->cerrno = CSYSERR;
399  yaz_set_errno(EEXIST); /* Not a socket (File exists) */
400  return -1;
401  }
402  if ((socket_out = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) {
403  h->cerrno = CSYSERR;
404  return -1;
405  }
406  socket_unix.sun_family = AF_UNIX;
407  strncpy(socket_unix.sun_path, path, sizeof(socket_unix.sun_path)-1);
408  socket_unix.sun_path[sizeof(socket_unix.sun_path)-1] = 0;
409  if (connect(socket_out, (struct sockaddr *) &socket_unix, SUN_LEN(&socket_unix)) < 0) {
410  if (yaz_errno() == ECONNREFUSED) {
411  yaz_log(log_level, "unix_bind socket exists but nobody is listening");
412  } else {
413  h->cerrno = CSYSERR;
414  return -1;
415  }
416  } else {
417  close(socket_out);
418  h->cerrno = CSYSERR;
419  yaz_set_errno(EADDRINUSE);
420  return -1;
421  }
422  unlink(path);
423  }
424 
425  if (bind(h->iofile, (struct sockaddr *) addr, SUN_LEN((struct sockaddr_un *)addr)))
426  {
427  h->cerrno = CSYSERR;
428  return -1;
429  }
430  if (chown(path, sp->uid, sp->gid))
431  {
432  h->cerrno = CSYSERR;
433  return -1;
434  }
435  if (chmod(path, sp->umask != -1 ? sp->umask : 0666))
436  {
437  h->cerrno = CSYSERR;
438  return -1;
439  }
440  if (mode == CS_SERVER && listen(h->iofile, 100) < 0)
441  {
442  h->cerrno = CSYSERR;
443  return -1;
444  }
445  h->state = CS_ST_IDLE;
446  h->event = CS_LISTEN;
447  return 0;
448 }
449 
450 static int unix_listen(COMSTACK h, char *raddr, int *addrlen,
451  int (*check_ip)(void *cd, const char *a, int len, int t),
452  void *cd)
453 {
454  struct sockaddr_un addr;
455  YAZ_SOCKLEN_T len = sizeof(addr);
456 
457  yaz_log(log_level, "unix_listen h=%p", h);
458  if (h->state != CS_ST_IDLE)
459  {
460  h->cerrno = CSOUTSTATE;
461  return -1;
462  }
463  h->newfd = accept(h->iofile, (struct sockaddr*)&addr, &len);
464  if (h->newfd < 0)
465  {
466  if (
467  yaz_errno() == EWOULDBLOCK
468 #ifdef EAGAIN
469 #if EAGAIN != EWOULDBLOCK
470  || yaz_errno() == EAGAIN
471 #endif
472 #endif
473  )
474  h->cerrno = CSNODATA;
475  else
476  h->cerrno = CSYSERR;
477  return -1;
478  }
479  if (addrlen && (size_t) (*addrlen) >= sizeof(struct sockaddr_un))
480  memcpy(raddr, &addr, *addrlen = sizeof(struct sockaddr_un));
481  else if (addrlen)
482  *addrlen = 0;
483  h->state = CS_ST_INCON;
484  return 0;
485 }
486 
488 {
489  COMSTACK cnew;
490  unix_state *state, *st = (unix_state *)h->cprivate;
491 
492  yaz_log(log_level, "unix_accept h=%p", h);
493  if (h->state == CS_ST_INCON)
494  {
495  if (!(cnew = (COMSTACK)xmalloc(sizeof(*cnew))))
496  {
497  h->cerrno = CSYSERR;
498  close(h->newfd);
499  h->newfd = -1;
500  return 0;
501  }
502  memcpy(cnew, h, sizeof(*h));
503  cnew->iofile = h->newfd;
504  cnew->io_pending = 0;
505  if (!(state = (unix_state *)
506  (cnew->cprivate = xmalloc(sizeof(unix_state)))))
507  {
508  h->cerrno = CSYSERR;
509  if (h->newfd != -1)
510  {
511  close(h->newfd);
512  h->newfd = -1;
513  }
514  return 0;
515  }
516  if (!(cnew->flags&CS_FLAGS_BLOCKING) &&
517  (fcntl(cnew->iofile, F_SETFL, O_NONBLOCK) < 0)
518  )
519  {
520  h->cerrno = CSYSERR;
521  if (h->newfd != -1)
522  {
523  close(h->newfd);
524  h->newfd = -1;
525  }
526  xfree (cnew);
527  xfree (state);
528  return 0;
529  }
530  h->newfd = -1;
531  state->altbuf = 0;
532  state->altsize = state->altlen = 0;
533  state->towrite = state->written = -1;
534  state->complete = st->complete;
535  memcpy(&state->addr, &st->addr, sizeof(state->addr));
536  cnew->state = CS_ST_ACCEPT;
537  cnew->event = CS_NONE;
538  h->state = CS_ST_IDLE;
539 
540  h = cnew;
541  }
542  if (h->state == CS_ST_ACCEPT)
543  {
544  }
545  else
546  {
547  h->cerrno = CSOUTSTATE;
548  return 0;
549  }
550  h->io_pending = 0;
551  h->state = CS_ST_DATAXFER;
552  h->event = CS_DATA;
553  return h;
554 }
555 
556 #define CS_UNIX_BUFCHUNK 4096
557 
558 /*
559  * Return: -1 error, >1 good, len of buffer, ==1 incomplete buffer,
560  * 0=connection closed.
561  */
562 static int unix_get(COMSTACK h, char **buf, int *bufsize)
563 {
564  unix_state *sp = (unix_state *)h->cprivate;
565  char *tmpc;
566  int tmpi, berlen, rest, req, tomove;
567  int hasread = 0, res;
568 
569  yaz_log(log_level, "unix_get h=%p bufsize=%d", h, *bufsize);
570  if (sp->altlen) /* switch buffers */
571  {
572  yaz_log(log_level, " %d bytes in altbuf (%p )", sp->altlen,
573  sp->altbuf);
574  tmpc = *buf;
575  tmpi = *bufsize;
576  *buf = sp->altbuf;
577  *bufsize = sp->altsize;
578  hasread = sp->altlen;
579  sp->altlen = 0;
580  sp->altbuf = tmpc;
581  sp->altsize = tmpi;
582  }
583  h->io_pending = 0;
584  while (!(berlen = (*sp->complete)(*buf, hasread)))
585  {
586  if (!*bufsize)
587  {
588  if (!(*buf = (char *)xmalloc(*bufsize = CS_UNIX_BUFCHUNK)))
589  return -1;
590  }
591  else if (*bufsize - hasread < CS_UNIX_BUFCHUNK)
592  if (!(*buf =(char *)xrealloc(*buf, *bufsize *= 2)))
593  return -1;
594  res = recv(h->iofile, *buf + hasread, CS_UNIX_BUFCHUNK, 0);
595  yaz_log(log_level, " recv res=%d, hasread=%d", res, hasread);
596  if (res < 0)
597  {
598  if (yaz_errno() == EWOULDBLOCK
599 #ifdef EAGAIN
600 #if EAGAIN != EWOULDBLOCK
601  || yaz_errno() == EAGAIN
602 #endif
603 #endif
604  || yaz_errno() == EINPROGRESS
605  )
606  {
608  break;
609  }
610  else if (yaz_errno() == 0)
611  continue;
612  else
613  return -1;
614  }
615  else if (!res)
616  return hasread;
617  hasread += res;
618  }
619  yaz_log(log_level, " Out of read loop with hasread=%d, berlen=%d",
620  hasread, berlen);
621  /* move surplus buffer (or everything if we didn't get a BER rec.) */
622  if (hasread > berlen)
623  {
624  tomove = req = hasread - berlen;
625  rest = tomove % CS_UNIX_BUFCHUNK;
626  if (rest)
627  req += CS_UNIX_BUFCHUNK - rest;
628  if (!sp->altbuf)
629  {
630  if (!(sp->altbuf = (char *)xmalloc(sp->altsize = req)))
631  return -1;
632  } else if (sp->altsize < req)
633  if (!(sp->altbuf =(char *)xrealloc(sp->altbuf, sp->altsize = req)))
634  return -1;
635  yaz_log(log_level, " Moving %d bytes to altbuf(%p)", tomove,
636  sp->altbuf);
637  memcpy(sp->altbuf, *buf + berlen, sp->altlen = tomove);
638  }
639  if (berlen < CS_UNIX_BUFCHUNK - 1)
640  *(*buf + berlen) = '\0';
641  return berlen ? berlen : 1;
642 }
643 
644 
645 
646 /*
647  * Returns 1, 0 or -1
648  * In nonblocking mode, you must call again with same buffer while
649  * return value is 1.
650  */
651 static int unix_put(COMSTACK h, char *buf, int size)
652 {
653  int res;
654  struct unix_state *state = (struct unix_state *)h->cprivate;
655 
656  yaz_log(log_level, "unix_put h=%p size=%d", h, size);
657  h->io_pending = 0;
658  h->event = CS_DATA;
659  if (state->towrite < 0)
660  {
661  state->towrite = size;
662  state->written = 0;
663  }
664  else if (state->towrite != size)
665  {
666  h->cerrno = CSWRONGBUF;
667  return -1;
668  }
669  while (state->towrite > state->written)
670  {
671  if ((res =
672  send(h->iofile, buf + state->written, size -
673  state->written,
674 #ifdef MSG_NOSIGNAL
675  MSG_NOSIGNAL
676 #else
677  0
678 #endif
679  )) < 0)
680  {
681  if (
682  yaz_errno() == EWOULDBLOCK
683 #ifdef EAGAIN
684 #if EAGAIN != EWOULDBLOCK
685  || yaz_errno() == EAGAIN
686 #endif
687 #endif
688  )
689  {
690  yaz_log(log_level, " Flow control stop");
692  return 1;
693  }
694  h->cerrno = CSYSERR;
695  return -1;
696  }
697  state->written += res;
698  yaz_log(log_level, " Wrote %d, written=%d, nbytes=%d",
699  res, state->written, size);
700  }
701  state->towrite = state->written = -1;
702  yaz_log(log_level, " Ok");
703  return 0;
704 }
705 
706 static void unix_close(COMSTACK h)
707 {
708  unix_state *sp = (struct unix_state *)h->cprivate;
709 
710  yaz_log(log_level, "unix_close h=%p", h);
711  if (h->iofile != -1)
712  {
713  close(h->iofile);
714  }
715  if (sp->altbuf)
716  xfree(sp->altbuf);
717  xfree(sp);
718  xfree(h);
719 }
720 
721 static const char *unix_addrstr(COMSTACK h)
722 {
723  unix_state *sp = (struct unix_state *)h->cprivate;
724  char *buf = sp->buf;
725  sprintf(buf, "unix:%s", sp->addr.sun_path);
726  return buf;
727 }
728 
729 static int unix_set_blocking(COMSTACK p, int flags)
730 {
731  unsigned long flag;
732 
733  if (p->flags == flags)
734  return 1;
735  flag = fcntl(p->iofile, F_GETFL, 0);
736  if (flags & CS_FLAGS_BLOCKING)
737  flag = flag & ~O_NONBLOCK;
738  else
739  flag = flag | O_NONBLOCK;
740  if (fcntl(p->iofile, F_SETFL, flag) < 0)
741  return 0;
742  p->flags = flags;
743  return 1;
744 }
745 #endif /* WIN32 */
746 /*
747  * Local variables:
748  * c-basic-offset: 4
749  * c-file-style: "Stroustrup"
750  * indent-tabs-mode: nil
751  * End:
752  * vim: shiftwidth=4 tabstop=8 expandtab
753  */
754 
int cs_complete_auto(const char *buf, int len)
Definition: comstack.c:466
#define CS_ST_ACCEPT
Definition: comstack.h:59
#define CS_ST_CONNECTING
Definition: comstack.h:60
#define CS_LISTEN
Definition: comstack.h:68
#define CSWRONGBUF
Definition: comstack.h:159
#define CS_DATA
Definition: comstack.h:69
#define CSOUTSTATE
Definition: comstack.h:157
#define CS_WANT_READ
Definition: comstack.h:114
#define CS_NONE
Definition: comstack.h:65
#define CSNODATA
Definition: comstack.h:158
#define CS_CONNECT
Definition: comstack.h:66
#define CS_ST_UNBND
Definition: comstack.h:54
#define CS_WANT_WRITE
Definition: comstack.h:115
#define CS_SERVER
Definition: comstack.h:78
#define CS_FLAGS_BLOCKING
Definition: comstack.h:165
#define CS_ST_DATAXFER
Definition: comstack.h:58
#define CS_ST_INCON
Definition: comstack.h:56
#define CS_ST_IDLE
Definition: comstack.h:55
#define CSYSERR
Definition: comstack.h:156
int yaz_errno(void)
returns errno
Definition: errno.c:31
void yaz_set_errno(int v)
sets errno to value
Definition: errno.c:36
Header for errno utilities.
enum l_file_type type
Definition: log.c:47
void yaz_log(int level, const char *fmt,...)
Writes log message.
Definition: log.c:487
int yaz_log_module_level(const char *name)
returns level for module
Definition: log.c:586
Logging utility.
oid_proto
Definition: oid_util.h:45
int(* f_bind)(COMSTACK handle, void *address, int mode)
Definition: comstack.h:76
int flags
Definition: comstack.h:62
COMSTACK(* f_accept)(COMSTACK handle)
Definition: comstack.h:82
void(* f_close)(COMSTACK handle)
Definition: comstack.h:83
unsigned io_pending
Definition: comstack.h:63
void * user
Definition: comstack.h:87
int(* f_listen)(COMSTACK h, char *raddr, int *addrlen, int(*check_ip)(void *cd, const char *a, int len, int type), void *cd)
Definition: comstack.h:79
int(* f_put)(COMSTACK handle, char *buf, int size)
Definition: comstack.h:71
void *(* f_straddr)(COMSTACK handle, const char *str)
Definition: comstack.h:85
CS_TYPE type
Definition: comstack.h:48
int(* f_more)(COMSTACK handle)
Definition: comstack.h:73
const char *(* f_addrstr)(COMSTACK handle)
Definition: comstack.h:84
int state
Definition: comstack.h:53
int event
Definition: comstack.h:64
int newfd
Definition: comstack.h:61
int(* f_set_blocking)(COMSTACK handle, int blocking)
Definition: comstack.h:86
int iofile
Definition: comstack.h:50
int(* f_rcvconnect)(COMSTACK handle)
Definition: comstack.h:75
int cerrno
Definition: comstack.h:49
int(* f_connect)(COMSTACK handle, void *address)
Definition: comstack.h:74
int(* f_get)(COMSTACK handle, char **buf, int *bufsize)
Definition: comstack.h:72
enum oid_proto protocol
Definition: comstack.h:70
void * cprivate
Definition: comstack.h:51
int uid
Definition: unix.c:86
int towrite
Definition: unix.c:83
int written
Definition: unix.c:82
char * altbuf
Definition: unix.c:78
int umask
Definition: unix.c:88
int altlen
Definition: unix.c:80
int altsize
Definition: unix.c:79
int gid
Definition: unix.c:87
char buf[128]
Definition: unix.c:89
int(* complete)(const char *buf, int len)
Definition: unix.c:84
struct sockaddr_un addr
Definition: unix.c:85
static int unix_strtoaddr_ex(const char *str, struct sockaddr_un *add)
Definition: unix.c:173
static int unix_rcvconnect(COMSTACK h)
Definition: unix.c:368
static int unix_bind(COMSTACK h, void *address, int mode)
Definition: unix.c:384
static int unix_put(COMSTACK h, char *buf, int size)
Definition: unix.c:651
static void unix_close(COMSTACK h)
Definition: unix.c:706
static int unix_get(COMSTACK h, char **buf, int *bufsize)
Definition: unix.c:562
struct unix_state unix_state
static COMSTACK unix_accept(COMSTACK h)
Definition: unix.c:487
static void * unix_straddr(COMSTACK h, const char *str)
Definition: unix.c:285
static int unix_listen(COMSTACK h, char *raddr, int *addrlen, int(*check_ip)(void *cd, const char *a, int len, int type), void *cd)
static int unix_connect(COMSTACK h, void *address)
Definition: unix.c:316
static int unix_more(COMSTACK h)
Definition: unix.c:304
#define CS_UNIX_BUFCHUNK
Definition: unix.c:556
struct sockaddr_un * unix_strtoaddr(const char *str)
Definition: unix.c:293
static int log_level
Definition: unix.c:92
static void * unix_straddr1(COMSTACK h, const char *str, char *f)
Definition: unix.c:188
#define SUN_LEN(ptr)
Definition: unix.c:71
static const char * unix_addrstr(COMSTACK h)
Definition: unix.c:721
static int unix_set_blocking(COMSTACK p, int blocking)
Definition: unix.c:729
#define YAZ_SOCKLEN_T
Definition: unix.c:51
static void unix_init(void)
Definition: unix.c:94
COMSTACK unix_type(int s, int flags, int protocol, void *vp)
Definition: unix.c:108
Header for UNIX domain socket COMSTACK.
#define xstrdup(s)
utility macro which calls xstrdup_f
Definition: xmalloc.h:55
#define xfree(x)
utility macro which calls xfree_f
Definition: xmalloc.h:53
#define xrealloc(o, x)
utility macro which calls xrealloc_f
Definition: xmalloc.h:47
#define xmalloc(x)
utility macro which calls malloc_f
Definition: xmalloc.h:49
Header with fundamental macros.
static int log_level_set
Definition: ztest.c:41