From: Frank Lahm Date: Tue, 12 Oct 2010 12:22:19 +0000 (+0200) Subject: ad ls wasnt calling cnid_init() X-Git-Url: https://arthur.barton.de/cgi-bin/gitweb.cgi?p=netatalk.git;a=commitdiff_plain;h=b4fe2a4772f8b2d1e0d91debe3ffd28e259877d2 ad ls wasnt calling cnid_init() --- diff --git a/bin/ad/ad_ls.c b/bin/ad/ad_ls.c index 02c4fc66..63226a37 100644 --- a/bin/ad/ad_ls.c +++ b/bin/ad/ad_ls.c @@ -41,6 +41,8 @@ #define DIR_DOT_OR_DOTDOT(a) \ ((strcmp(a, ".") == 0) || (strcmp(a, "..") == 0)) +static volatile sig_atomic_t alarmed; + /* ls options */ static int ls_a; static int ls_l; @@ -70,6 +72,44 @@ static char *labels[] = { "ora" }; +/* + SIGNAL handling: + catch SIGINT and SIGTERM which cause clean exit. Ignore anything else. +*/ + +static void sig_handler(int signo) +{ + alarmed = 1; + return; +} + +static void set_signal(void) +{ + struct sigaction sv; + + sv.sa_handler = sig_handler; + sv.sa_flags = SA_RESTART; + sigemptyset(&sv.sa_mask); + if (sigaction(SIGTERM, &sv, NULL) < 0) + ERROR("error in sigaction(SIGTERM): %s", strerror(errno)); + + if (sigaction(SIGINT, &sv, NULL) < 0) + ERROR("error in sigaction(SIGINT): %s", strerror(errno)); + + memset(&sv, 0, sizeof(struct sigaction)); + sv.sa_handler = SIG_IGN; + sigemptyset(&sv.sa_mask); + + if (sigaction(SIGABRT, &sv, NULL) < 0) + ERROR("error in sigaction(SIGABRT): %s", strerror(errno)); + + if (sigaction(SIGHUP, &sv, NULL) < 0) + ERROR("error in sigaction(SIGHUP): %s", strerror(errno)); + + if (sigaction(SIGQUIT, &sv, NULL) < 0) + ERROR("error in sigaction(SIGQUIT): %s", strerror(errno)); +} + /* Check for netatalk special folders e.g. ".AppleDB" or ".AppleDesktop" Returns pointer to name or NULL. @@ -475,6 +515,11 @@ static int ad_ls_r(char *path, afpvol_t *vol) /* First run: print everything */ dirempty = 1; while ((ep = readdir (dp))) { + if (alarmed) { + ret = -1; + goto exit; + } + /* Check if its "." or ".." */ if (DIR_DOT_OR_DOTDOT(ep->d_name)) continue; @@ -510,6 +555,11 @@ static int ad_ls_r(char *path, afpvol_t *vol) if (ls_R) { rewinddir(dp); while ((ep = readdir (dp))) { + if (alarmed) { + ret = -1; + goto exit; + } + /* Check if its "." or ".." */ if (DIR_DOT_OR_DOTDOT(ep->d_name)) continue; @@ -577,6 +627,9 @@ int ad_ls(int argc, char **argv) } + set_signal(); + cnid_init(); + if ((argc - optind) == 0) { openvol(".", &vol); ad_ls_r(".", &vol);