2 Copyright (c) 2010 Frank Lahm <franklahm@gmail.com>
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
17 #endif /* HAVE_CONFIG_H */
20 #include <sys/types.h>
34 #include <atalk/adouble.h>
35 #include <atalk/cnid.h>
36 #include <atalk/cnid_dbd_private.h>
37 #include <atalk/volinfo.h>
40 static volatile sig_atomic_t alarmed;
44 catch SIGINT and SIGTERM which cause clean exit. Ignore anything else.
47 static void sig_handler(int signo)
53 static void set_signal(void)
57 sv.sa_handler = sig_handler;
58 sv.sa_flags = SA_RESTART;
59 sigemptyset(&sv.sa_mask);
60 if (sigaction(SIGTERM, &sv, NULL) < 0)
61 ERROR("error in sigaction(SIGTERM): %s", strerror(errno));
63 if (sigaction(SIGINT, &sv, NULL) < 0)
64 ERROR("error in sigaction(SIGINT): %s", strerror(errno));
66 memset(&sv, 0, sizeof(struct sigaction));
67 sv.sa_handler = SIG_IGN;
68 sigemptyset(&sv.sa_mask);
70 if (sigaction(SIGABRT, &sv, NULL) < 0)
71 ERROR("error in sigaction(SIGABRT): %s", strerror(errno));
73 if (sigaction(SIGHUP, &sv, NULL) < 0)
74 ERROR("error in sigaction(SIGHUP): %s", strerror(errno));
76 if (sigaction(SIGQUIT, &sv, NULL) < 0)
77 ERROR("error in sigaction(SIGQUIT): %s", strerror(errno));
80 static void usage_find(void)
83 "Usage: ad find VOLUME_PATH NAME\n"
87 int ad_find(int argc, char **argv)
92 printf("argc: %d, argv0: %s\n", argc, argv[0]);
102 SLOG("opening volume: %s", argv[2]);
103 if (openvol(argv[2], &vol) != 0)
104 ERROR("Cant open volume \"%s\"", argv[2]);
106 SLOG("searching: %s", argv[3]);
109 char resbuf[DBD_MAX_SRCH_RSLTS * sizeof(cnid_t)];
110 if ((count = cnid_find(vol.volume.v_cdb, argv[3], strlen(argv[3]), resbuf, sizeof(resbuf))) < 1) {
113 SLOG("%d matches", count);
117 memcpy(&cnid, bufp, sizeof(cnid_t));
118 bufp += sizeof(cnid_t);
119 SLOG("Got CNID: %u", ntohl(cnid));