1 /* This file is part of the Zebra server.
2 Copyright (C) 1994-2011 Index Data
4 Zebra is free software; you can redistribute it and/or modify it under
5 the terms of the GNU General Public License as published by the Free
6 Software Foundation; either version 2, or (at your option) any later
9 Zebra is distributed in the hope that it will be useful, but WITHOUT ANY
10 WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
30 #include <sys/locking.h>
39 #include <yaz/yaz-util.h>
40 #include <yaz/yaz-version.h>
41 #include <yaz/diagbib1.h>
42 #include <yaz/querytowrbuf.h>
43 #include <yaz/pquery.h>
44 #include <sys/types.h>
46 #include <yaz/backend.h>
47 #include <yaz/charneg.h>
48 #include <idzebra/api.h>
50 static int bend_sort(void *handle, bend_sort_rr *rr);
51 static int bend_delete(void *handle, bend_delete_rr *rr);
52 static int bend_esrequest(void *handle, bend_esrequest_rr *rr);
53 static int bend_segment(void *handle, bend_segment_rr *rr);
54 static int bend_search(void *handle, bend_search_rr *r);
55 static int bend_fetch(void *handle, bend_fetch_rr *r);
56 static int bend_scan(void *handle, bend_scan_rr *r);
58 bend_initresult *bend_init(bend_initrequest *q)
60 bend_initresult *r = (bend_initresult *)
61 odr_malloc(q->stream, sizeof(*r));
63 struct statserv_options_block *sob;
70 q->bend_sort = bend_sort;
71 q->bend_delete = bend_delete;
72 q->bend_esrequest = bend_esrequest;
73 q->bend_segment = bend_segment;
74 q->bend_search = bend_search;
75 q->bend_fetch = bend_fetch;
76 q->bend_scan = bend_scan;
78 zebra_get_version(version_str, 0);
80 q->implementation_name = "Zebra Information Server";
81 q->implementation_version = odr_strdup(q->stream, version_str);
83 yaz_log(YLOG_DEBUG, "bend_init");
85 sob = statserv_getcontrol();
86 if (!(zh = zebra_open(sob->handle, 0)))
88 yaz_log(YLOG_WARN, "Failed to read config `%s'", sob->configname);
89 r->errcode = YAZ_BIB1_PERMANENT_SYSTEM_ERROR;
94 q->query_charset = odr_strdup(q->stream, zebra_get_encoding(zh));
97 if (q->auth->which == Z_IdAuthentication_open)
99 char *openpass = xstrdup(q->auth->u.open);
100 char *cp = strchr(openpass, '/');
104 user = nmem_strdup(odr_getmem(q->stream), openpass);
105 passwd = nmem_strdup(odr_getmem(q->stream), cp+1);
109 else if (q->auth->which == Z_IdAuthentication_idPass)
111 Z_IdPass *idPass = q->auth->u.idPass;
113 user = idPass->userId;
114 passwd = idPass->password;
117 if (zebra_auth(zh, user, passwd) != ZEBRA_OK)
119 r->errcode = YAZ_BIB1_INIT_AC_BAD_USERID_AND_OR_PASSWORD;
123 if (q->charneg_request) /* characater set and language negotiation? */
131 NMEM nmem = nmem_create();
133 yaz_get_proposal_charneg(nmem, q->charneg_request,
134 &charsets, &num_charsets,
135 &langs, &num_langs, &selected);
137 for (i = 0; i < num_charsets; i++)
139 const char *right_name = "";
141 * FIXME! It is like rudiment :-))
142 * We have to support this short names of character sets,
143 * because a lot servers in Russia to use own in during
144 * character set and language negotiation still.
147 if (!yaz_matchstr(charsets[i], "win")) {
148 right_name = "WINDOWS-1251";
149 } else if (!yaz_matchstr(charsets[i], "koi")) {
150 right_name = "KOI8-R";
151 } else if (!yaz_matchstr(charsets[i], "iso")) {
152 right_name = "ISO-8859-5";
153 } else if (!yaz_matchstr(charsets[i], "dos")) {
154 right_name = "CP866";
155 } else if (!yaz_matchstr(charsets[i], "uni")) {
156 right_name = "UTF-8";
158 right_name = charsets[i];
160 if (odr_set_charset(q->decode, "UTF-8", right_name) == 0)
162 yaz_log(YLOG_LOG, "charset %d %s (proper name %s): OK", i,
163 charsets[i], right_name);
164 odr_set_charset(q->stream, right_name, "UTF-8");
166 zebra_record_encoding(zh, right_name);
167 zebra_octet_term_encoding(zh, right_name);
168 q->charneg_response =
169 yaz_set_response_charneg(q->stream, charsets[i],
173 yaz_log(YLOG_LOG, "charset %d %s (proper name %s): unsupported", i,
174 charsets[i], right_name);
182 static void search_terms(ZebraHandle zh, bend_search_rr *r)
186 int type = Z_Term_general;
187 struct Z_External *ext;
188 Z_SearchInfoReport *sr;
190 zebra_result_set_term_no(zh, r->setname, &no_terms);
194 r->search_info = odr_malloc(r->stream, sizeof(*r->search_info));
196 r->search_info->num_elements = 1;
197 r->search_info->list =
198 odr_malloc(r->stream, sizeof(*r->search_info->list));
199 r->search_info->list[0] =
200 odr_malloc(r->stream, sizeof(**r->search_info->list));
201 r->search_info->list[0]->category = 0;
202 r->search_info->list[0]->which = Z_OtherInfo_externallyDefinedInfo;
203 ext = odr_malloc(r->stream, sizeof(*ext));
204 r->search_info->list[0]->information.externallyDefinedInfo = ext;
205 ext->direct_reference = odr_oiddup(r->stream,
206 yaz_oid_userinfo_searchresult_1);
207 ext->indirect_reference = 0;
209 ext->which = Z_External_searchResult1;
210 sr = odr_malloc(r->stream, sizeof(Z_SearchInfoReport));
211 ext->u.searchResult1 = sr;
213 sr->elements = odr_malloc(r->stream, sr->num *
214 sizeof(*sr->elements));
215 for (i = 0; i<no_terms; i++)
217 Z_SearchInfoReport_s *se;
222 size_t len = sizeof(outbuf);
223 const char *term_ref_id = 0;
225 zebra_result_set_term_info(zh, r->setname, i,
226 &count, &approx, outbuf, &len,
228 se = sr->elements[i] = odr_malloc(r->stream, sizeof(**sr->elements));
229 se->subqueryId = term_ref_id ?
230 odr_strdup(r->stream, term_ref_id) : 0;
232 se->fullQuery = odr_booldup(r->stream, 0);
233 se->subqueryExpression =
234 odr_malloc(r->stream, sizeof(Z_QueryExpression));
235 se->subqueryExpression->which =
236 Z_QueryExpression_term;
237 se->subqueryExpression->u.term =
238 odr_malloc(r->stream, sizeof(Z_QueryExpressionTerm));
239 term = odr_malloc(r->stream, sizeof(Z_Term));
240 se->subqueryExpression->u.term->queryTerm = term;
243 case Z_Term_characterString:
244 term->which = Z_Term_characterString;
245 term->u.characterString = odr_strdup(r->stream, outbuf);
248 term->which = Z_Term_general;
249 term->u.general = odr_malloc(r->stream, sizeof(*term->u.general));
250 term->u.general->size = term->u.general->len = len;
251 term->u.general->buf = odr_malloc(r->stream, len);
252 memcpy(term->u.general->buf, outbuf, len);
255 term->which = Z_Term_general;
256 term->u.null = odr_nullval();
258 se->subqueryExpression->u.term->termComment = 0;
259 se->subqueryInterpretation = 0;
260 se->subqueryRecommendation = 0;
261 se->subqueryCount = odr_intdup(r->stream, count);
262 se->subqueryWeight = 0;
267 static int break_handler(void *client_data)
269 bend_association assoc =(bend_association) client_data;
270 if (!bend_assoc_is_alive(assoc))
275 static Z_RPNQuery *query_add_sortkeys(ODR o, Z_RPNQuery *query,
276 const char *sortKeys)
278 #if YAZ_VERSIONL >= 0x40200
279 /* sortkey layour: path,schema,ascending,caseSensitive,missingValue */
280 /* see cql_sortby_to_sortkeys of YAZ. */
282 int num_sortspec = 0;
286 nmem_strsplit_blank(odr_getmem(o), sortKeys, &sortspec, &num_sortspec);
287 if (num_sortspec > 0)
290 WRBUF w = wrbuf_alloc();
292 /* left operand 'd' will be replaced by original query */
293 wrbuf_puts(w, "@or d");
294 for (i = 0; i < num_sortspec; i++)
299 nmem_strsplitx(odr_getmem(o), ",", sortspec[i], &arg, &num_arg, 0);
303 yaz_log(YLOG_WARN, "Invalid sort spec '%s' num_arg=%d",
304 sortspec[i], num_arg);
308 ascending = atoi(arg[2]);
310 if (i < num_sortspec-1)
311 wrbuf_puts(w, " @or");
312 wrbuf_puts(w, " @attr 1=");
313 yaz_encode_pqf_term(w, arg[0], strlen(arg[0]));
314 wrbuf_printf(w, "@attr 7=%d %d", ascending ? 1 : 2, i);
316 nquery = p_query_rpn(o, wrbuf_cstr(w));
319 yaz_log(YLOG_WARN, "query_add_sortkeys: bad RPN: '%s'",
324 Z_RPNStructure *s = nquery->RPNStructure;
326 if (s->which != Z_RPNStructure_complex)
328 yaz_log(YLOG_WARN, "query_add_sortkeys: not complex operand");
332 /* left operand 'd' is replaced by origial query */
333 s->u.complex->s1 = query->RPNStructure;
334 /* and original query points to our new or+sort things */
335 query->RPNStructure = s;
343 yaz_log(YLOG_WARN, "sortkeys ignored because YAZ version < 4.2.0");
349 int bend_search(void *handle, bend_search_rr *r)
351 ZebraHandle zh = (ZebraHandle) handle;
356 res = zebra_select_databases(zh, r->num_bases,
357 (const char **) r->basenames);
360 zebra_result(zh, &r->errcode, &r->errstring);
363 zebra_set_break_handler(zh, break_handler, r->association);
364 yaz_log(YLOG_DEBUG, "ResultSet '%s'", r->setname);
365 switch (r->query->which)
367 case Z_Query_type_1: case Z_Query_type_101:
368 q2 = query_add_sortkeys(r->stream, r->query->u.type_1, r->srw_sortKeys);
369 res = zebra_search_RPN_x(zh, r->stream, q2,
371 &r->estimated_hit_count,
372 &r->partial_resultset);
374 zebra_result(zh, &r->errcode, &r->errstring);
382 r->errcode = YAZ_BIB1_QUERY_TYPE_UNSUPP;
383 r->errstring = "type-2";
386 r->errcode = YAZ_BIB1_QUERY_TYPE_UNSUPP;
388 zebra_set_break_handler(zh, 0, 0);
393 int bend_fetch(void *handle, bend_fetch_rr *r)
395 ZebraHandle zh = (ZebraHandle) handle;
396 ZebraRetrievalRecord retrievalRecord;
399 retrievalRecord.position = r->number;
402 res = zebra_records_retrieve(zh, r->stream, r->setname, r->comp,
403 r->request_format, 1, &retrievalRecord);
406 /* non-surrogate diagnostic */
407 zebra_result(zh, &r->errcode, &r->errstring);
409 else if (retrievalRecord.errCode)
411 /* surrogate diagnostic (diagnostic per record) */
412 r->surrogate_flag = 1;
413 r->errcode = retrievalRecord.errCode;
414 r->errstring = retrievalRecord.errString;
415 r->basename = retrievalRecord.base;
419 r->basename = retrievalRecord.base;
420 r->record = retrievalRecord.buf;
421 r->len = retrievalRecord.len;
422 r->output_format = odr_oiddup(r->stream, retrievalRecord.format);
427 static int bend_scan(void *handle, bend_scan_rr *r)
429 ZebraScanEntry *entries;
430 ZebraHandle zh = (ZebraHandle) handle;
434 res = zebra_select_databases(zh, r->num_bases,
435 (const char **) r->basenames);
438 zebra_result(zh, &r->errcode, &r->errstring);
441 if (r->step_size != 0 && *r->step_size != 0) {
442 r->errcode = YAZ_BIB1_ONLY_ZERO_STEP_SIZE_SUPPORTED_FOR_SCAN;
446 res = zebra_scan(zh, r->stream, r->term,
449 &r->num_entries, &entries, &is_partial,
454 r->status = BEND_SCAN_PARTIAL;
456 r->status = BEND_SCAN_SUCCESS;
457 for (i = 0; i < r->num_entries; i++)
459 r->entries[i].term = entries[i].term;
460 r->entries[i].display_term = entries[i].display_term;
461 r->entries[i].occurrences = entries[i].occurrences;
466 r->status = BEND_SCAN_PARTIAL;
467 zebra_result(zh, &r->errcode, &r->errstring);
472 void bend_close(void *handle)
474 zebra_close((ZebraHandle) handle);
475 xmalloc_trav("bend_close");
478 int bend_sort(void *handle, bend_sort_rr *rr)
480 ZebraHandle zh = (ZebraHandle) handle;
482 if (zebra_sort(zh, rr->stream,
483 rr->num_input_setnames, (const char **) rr->input_setnames,
484 rr->output_setname, rr->sort_sequence, &rr->sort_status)
486 zebra_result(zh, &rr->errcode, &rr->errstring);
490 int bend_delete(void *handle, bend_delete_rr *rr)
492 ZebraHandle zh = (ZebraHandle) handle;
494 rr->delete_status = zebra_deleteResultSet(zh, rr->function,
495 rr->num_setnames, rr->setnames,
500 static void es_admin_request(bend_esrequest_rr *rr, ZebraHandle zh, Z_AdminEsRequest *r)
502 ZEBRA_RES res = ZEBRA_OK;
503 if (r->toKeep->databaseName)
505 yaz_log(YLOG_LOG, "adm request database %s", r->toKeep->databaseName);
507 switch (r->toKeep->which)
509 case Z_ESAdminOriginPartToKeep_reIndex:
510 yaz_log(YLOG_LOG, "adm-reindex");
511 rr->errcode = YAZ_BIB1_ES_IMMEDIATE_EXECUTION_FAILED;
512 rr->errstring = "adm-reindex not implemented yet";
514 case Z_ESAdminOriginPartToKeep_truncate:
515 rr->errcode = YAZ_BIB1_ES_IMMEDIATE_EXECUTION_FAILED;
516 rr->errstring = "adm-reindex not implemented yet";
517 yaz_log(YLOG_LOG, "adm-truncate");
519 case Z_ESAdminOriginPartToKeep_drop:
520 yaz_log(YLOG_LOG, "adm-drop");
521 res = zebra_drop_database(zh, r->toKeep->databaseName);
523 case Z_ESAdminOriginPartToKeep_create:
524 yaz_log(YLOG_LOG, "adm-create %s", r->toKeep->databaseName);
525 res = zebra_create_database(zh, r->toKeep->databaseName);
527 case Z_ESAdminOriginPartToKeep_import:
528 yaz_log(YLOG_LOG, "adm-import");
529 res = zebra_admin_import_begin(zh, r->toKeep->databaseName,
530 r->toKeep->u.import->recordType);
532 case Z_ESAdminOriginPartToKeep_refresh:
533 yaz_log(YLOG_LOG, "adm-refresh");
535 case Z_ESAdminOriginPartToKeep_commit:
536 yaz_log(YLOG_LOG, "adm-commit");
537 if (r->toKeep->databaseName)
539 if (zebra_select_database(zh, r->toKeep->databaseName) !=
541 yaz_log(YLOG_WARN, "zebra_select_database failed in "
546 case Z_ESAdminOriginPartToKeep_shutdown:
547 yaz_log(YLOG_LOG, "shutdown");
548 res = zebra_admin_shutdown(zh);
550 case Z_ESAdminOriginPartToKeep_start:
551 yaz_log(YLOG_LOG, "start");
552 zebra_admin_start(zh);
555 yaz_log(YLOG_LOG, "unknown admin");
556 rr->errcode = YAZ_BIB1_ES_IMMEDIATE_EXECUTION_FAILED;
557 rr->errstring = "adm-reindex not implemented yet";
560 zebra_result(zh, &rr->errcode, &rr->errstring);
563 static void es_admin(bend_esrequest_rr *rr, ZebraHandle zh, Z_Admin *r)
567 case Z_Admin_esRequest:
568 es_admin_request(rr, zh, r->u.esRequest);
573 yaz_log(YLOG_WARN, "adm taskpackage (unhandled)");
574 rr->errcode = YAZ_BIB1_ES_IMMEDIATE_EXECUTION_FAILED;
575 rr->errstring = "adm-task package (unhandled)";
578 int bend_segment(void *handle, bend_segment_rr *rr)
580 ZebraHandle zh = (ZebraHandle) handle;
581 Z_Segment *segment = rr->segment;
583 if (segment->num_segmentRecords)
584 zebra_admin_import_segment(zh, rr->segment);
586 zebra_admin_import_end(zh);
590 int bend_esrequest(void *handle, bend_esrequest_rr *rr)
592 ZebraHandle zh = (ZebraHandle) handle;
594 yaz_log(YLOG_LOG, "function: " ODR_INT_PRINTF, *rr->esr->function);
595 if (rr->esr->packageName)
596 yaz_log(YLOG_LOG, "packagename: %s", rr->esr->packageName);
597 yaz_log(YLOG_LOG, "Waitaction: " ODR_INT_PRINTF, *rr->esr->waitAction);
599 if (!rr->esr->taskSpecificParameters)
601 yaz_log(YLOG_WARN, "No task specific parameters");
603 else if (rr->esr->taskSpecificParameters->which == Z_External_ESAdmin)
605 es_admin(rr, zh, rr->esr->taskSpecificParameters->u.adminService);
607 else if (rr->esr->taskSpecificParameters->which == Z_External_update)
609 Z_IUUpdate *up = rr->esr->taskSpecificParameters->u.update;
610 yaz_log(YLOG_LOG, "Received DB Update");
611 if (up->which == Z_IUUpdate_esRequest)
613 Z_IUUpdateEsRequest *esRequest = up->u.esRequest;
614 Z_IUOriginPartToKeep *toKeep = esRequest->toKeep;
615 Z_IUSuppliedRecords *notToKeep = esRequest->notToKeep;
617 yaz_log(YLOG_LOG, "action");
620 switch (*toKeep->action)
622 case Z_IUOriginPartToKeep_recordInsert:
623 yaz_log(YLOG_LOG, "recordInsert");
625 case Z_IUOriginPartToKeep_recordReplace:
626 yaz_log(YLOG_LOG, "recordUpdate");
628 case Z_IUOriginPartToKeep_recordDelete:
629 yaz_log(YLOG_LOG, "recordDelete");
631 case Z_IUOriginPartToKeep_elementUpdate:
632 yaz_log(YLOG_LOG, "elementUpdate");
634 case Z_IUOriginPartToKeep_specialUpdate:
635 yaz_log(YLOG_LOG, "specialUpdate");
637 case Z_ESAdminOriginPartToKeep_shutdown:
638 yaz_log(YLOG_LOG, "shutDown");
640 case Z_ESAdminOriginPartToKeep_start:
641 yaz_log(YLOG_LOG, "start");
644 yaz_log(YLOG_LOG, " unknown (" ODR_INT_PRINTF ")",
648 if (toKeep->databaseName)
650 yaz_log(YLOG_LOG, "database: %s", toKeep->databaseName);
652 if (zebra_select_database(zh, toKeep->databaseName))
657 yaz_log(YLOG_WARN, "no database supplied for ES Update");
659 YAZ_BIB1_ES_MISSING_MANDATORY_PARAMETER_FOR_SPECIFIED_FUNCTION_;
660 rr->errstring = "database";
663 if (zebra_begin_trans(zh, 1) != ZEBRA_OK)
665 zebra_result(zh, &rr->errcode, &rr->errstring);
670 for (i = 0; notToKeep && i < notToKeep->num; i++)
672 Z_External *rec = notToKeep->elements[i]->record;
673 Odr_oct *opaque_recid = 0;
677 if (notToKeep->elements[i]->u.opaque)
679 switch(notToKeep->elements[i]->which)
681 case Z_IUSuppliedRecords_elem_opaque:
682 opaque_recid = notToKeep->elements[i]->u.opaque;
683 break; /* OK, recid already set */
684 case Z_IUSuppliedRecords_elem_number:
685 sysno_tmp = *notToKeep->elements[i]->u.number;
690 if (rec->direct_reference)
692 char oid_name_str[OID_STR_MAX];
693 const char *oid_name =
694 yaz_oid_to_string_buf(
695 rec->direct_reference,
698 yaz_log(YLOG_LOG, "record %d type %s", i,
703 case Z_External_sutrs:
704 if (rec->u.octet_aligned->len > 170)
705 yaz_log(YLOG_LOG, "%d bytes:\n%.168s ...",
709 yaz_log(YLOG_LOG, "%d bytes:\n%s",
713 case Z_External_octet:
714 if (rec->u.octet_aligned->len > 170)
715 yaz_log(YLOG_LOG, "%d bytes:\n%.168s ...",
716 rec->u.octet_aligned->len,
717 rec->u.octet_aligned->buf);
719 yaz_log(YLOG_LOG, "%d bytes\n%s",
720 rec->u.octet_aligned->len,
721 rec->u.octet_aligned->buf);
723 if (rec->which == Z_External_octet)
725 enum zebra_recctrl_action_t action = action_update;
727 const char *match_criteria = 0;
730 if (*toKeep->action ==
731 Z_IUOriginPartToKeep_recordInsert)
732 action = action_insert;
733 else if (*toKeep->action ==
734 Z_IUOriginPartToKeep_recordReplace)
735 action = action_replace;
736 else if (*toKeep->action ==
737 Z_IUOriginPartToKeep_recordDelete)
738 action = action_delete;
739 else if (*toKeep->action ==
740 Z_IUOriginPartToKeep_specialUpdate)
741 action = action_update;
745 YAZ_BIB1_ES_IMMEDIATE_EXECUTION_FAILED;
746 rr->errstring = "unsupported ES Update action";
752 size_t l = opaque_recid->len;
753 if (l >= sizeof(recid_str))
755 rr->errcode = YAZ_BIB1_ES_IMMEDIATE_EXECUTION_FAILED;
756 rr->errstring = "opaque record ID too large";
759 memcpy(recid_str, opaque_recid->buf, l);
761 match_criteria = recid_str;
763 res = zebra_update_record(
766 sysno, match_criteria, 0, /* fname */
767 (const char *) rec->u.octet_aligned->buf,
768 rec->u.octet_aligned->len);
769 if (res == ZEBRA_FAIL)
772 YAZ_BIB1_ES_IMMEDIATE_EXECUTION_FAILED;
773 rr->errstring = "update_record failed";
777 if (zebra_end_trans(zh) != ZEBRA_OK)
779 yaz_log(YLOG_WARN, "zebra_end_trans failed for"
780 " extended service operation");
787 yaz_log(YLOG_WARN, "Unknown Extended Service(%d)",
788 rr->esr->taskSpecificParameters->which);
789 rr->errcode = YAZ_BIB1_ES_EXTENDED_SERVICE_TYPE_UNSUPP;
795 static void bend_start(struct statserv_options_block *sob)
797 Res default_res = res_open(0, 0);
800 zebra_stop((ZebraService) sob->handle);
801 res_set(default_res, "profilePath", DEFAULT_PROFILE_PATH);
802 res_set(default_res, "modulePath", DEFAULT_MODULE_PATH);
803 sob->handle = zebra_start_res(sob->configname, default_res, 0);
804 res_close(default_res);
807 yaz_log(YLOG_FATAL, "Failed to read config `%s'", sob->configname);
813 if (!sob->inetd && !sob->background)
819 zebra_pidfname(sob->handle, pidfname);
821 fd = open(pidfname, O_EXCL|O_WRONLY|O_CREAT, 0666);
826 yaz_log(YLOG_FATAL|YLOG_ERRNO, "lock file %s", pidfname);
829 fd = open(pidfname, O_RDWR, 0666);
832 yaz_log(YLOG_FATAL|YLOG_ERRNO, "lock file %s", pidfname);
836 area.l_type = F_WRLCK;
837 area.l_whence = SEEK_SET;
838 area.l_len = area.l_start = 0L;
839 if (fcntl(fd, F_SETLK, &area) == -1)
841 yaz_log(YLOG_ERRNO|YLOG_FATAL, "Zebra server already running");
848 sprintf(pidstr, "%ld", (long) getpid());
849 if (write(fd, pidstr, strlen(pidstr)) != strlen(pidstr))
851 yaz_log(YLOG_ERRNO|YLOG_FATAL, "write fail %s", pidfname);
859 static void bend_stop(struct statserv_options_block *sob)
864 if (!sob->inetd && !sob->background && sob->handle)
867 zebra_pidfname(sob->handle, pidfname);
873 ZebraService service = sob->handle;
878 int main(int argc, char **argv)
880 struct statserv_options_block *sob;
882 sob = statserv_getcontrol();
883 strcpy(sob->configname, "zebra.cfg");
884 sob->bend_start = bend_start;
885 sob->bend_stop = bend_stop;
887 strcpy(sob->service_name, "zebrasrv");
888 strcpy(sob->service_display_name, "Zebra Server");
890 statserv_setcontrol(sob);
892 return statserv_main(argc, argv, bend_init, bend_close);
897 * c-file-style: "Stroustrup"
898 * indent-tabs-mode: nil
900 * vim: shiftwidth=4 tabstop=8 expandtab