mirror of
https://github.com/sheumann/hush.git
synced 2025-01-03 16:29:50 +00:00
Exit with failure status if we are unable to list any files or
directories. Patch thanks to Kent Robotti <robotti@metconnect.com>.
This commit is contained in:
parent
e7e1e2dcad
commit
33fdae54d1
@ -173,6 +173,8 @@ static unsigned short tabstops = 8;
|
|||||||
#define column_width COLUMN_WIDTH
|
#define column_width COLUMN_WIDTH
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
static int status = EXIT_SUCCESS;
|
||||||
|
|
||||||
static void newline(void)
|
static void newline(void)
|
||||||
{
|
{
|
||||||
if (column > 0) {
|
if (column > 0) {
|
||||||
@ -459,6 +461,7 @@ struct dnode **list_dir(char *path)
|
|||||||
dir = opendir(path);
|
dir = opendir(path);
|
||||||
if (dir == NULL) {
|
if (dir == NULL) {
|
||||||
errorMsg("%s: %s\n", path, strerror(errno));
|
errorMsg("%s: %s\n", path, strerror(errno));
|
||||||
|
status = EXIT_FAILURE;
|
||||||
return(NULL); /* could not open the dir */
|
return(NULL); /* could not open the dir */
|
||||||
}
|
}
|
||||||
while ((entry = readdir(dir)) != NULL) {
|
while ((entry = readdir(dir)) != NULL) {
|
||||||
@ -477,6 +480,7 @@ struct dnode **list_dir(char *path)
|
|||||||
if (follow_links == TRUE) {
|
if (follow_links == TRUE) {
|
||||||
if (stat(cur->fullname, &cur->dstat)) {
|
if (stat(cur->fullname, &cur->dstat)) {
|
||||||
errorMsg("%s: %s\n", cur->fullname, strerror(errno));
|
errorMsg("%s: %s\n", cur->fullname, strerror(errno));
|
||||||
|
status = EXIT_FAILURE;
|
||||||
free(cur->fullname);
|
free(cur->fullname);
|
||||||
free(cur);
|
free(cur);
|
||||||
continue;
|
continue;
|
||||||
@ -485,6 +489,7 @@ struct dnode **list_dir(char *path)
|
|||||||
#endif
|
#endif
|
||||||
if (lstat(cur->fullname, &cur->dstat)) { /* get file stat info into node */
|
if (lstat(cur->fullname, &cur->dstat)) { /* get file stat info into node */
|
||||||
errorMsg("%s: %s\n", cur->fullname, strerror(errno));
|
errorMsg("%s: %s\n", cur->fullname, strerror(errno));
|
||||||
|
status = EXIT_FAILURE;
|
||||||
free(cur->fullname);
|
free(cur->fullname);
|
||||||
free(cur);
|
free(cur);
|
||||||
continue;
|
continue;
|
||||||
@ -791,6 +796,7 @@ extern int ls_main(int argc, char **argv)
|
|||||||
if (follow_links == TRUE) {
|
if (follow_links == TRUE) {
|
||||||
if (stat(av[oi], &cur->dstat)) {
|
if (stat(av[oi], &cur->dstat)) {
|
||||||
errorMsg("%s: %s\n", av[oi], strerror(errno));
|
errorMsg("%s: %s\n", av[oi], strerror(errno));
|
||||||
|
status = EXIT_FAILURE;
|
||||||
free(cur->fullname);
|
free(cur->fullname);
|
||||||
free(cur);
|
free(cur);
|
||||||
continue;
|
continue;
|
||||||
@ -799,6 +805,7 @@ extern int ls_main(int argc, char **argv)
|
|||||||
#endif
|
#endif
|
||||||
if (lstat(av[oi], &cur->dstat)) { /* get file info into node */
|
if (lstat(av[oi], &cur->dstat)) { /* get file info into node */
|
||||||
errorMsg("%s: %s\n", av[oi], strerror(errno));
|
errorMsg("%s: %s\n", av[oi], strerror(errno));
|
||||||
|
status = EXIT_FAILURE;
|
||||||
free(cur->fullname);
|
free(cur->fullname);
|
||||||
free(cur);
|
free(cur);
|
||||||
continue;
|
continue;
|
||||||
@ -842,7 +849,7 @@ extern int ls_main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return(0);
|
return(status);
|
||||||
|
|
||||||
print_usage_message:
|
print_usage_message:
|
||||||
usage(ls_usage);
|
usage(ls_usage);
|
||||||
|
9
ls.c
9
ls.c
@ -173,6 +173,8 @@ static unsigned short tabstops = 8;
|
|||||||
#define column_width COLUMN_WIDTH
|
#define column_width COLUMN_WIDTH
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
static int status = EXIT_SUCCESS;
|
||||||
|
|
||||||
static void newline(void)
|
static void newline(void)
|
||||||
{
|
{
|
||||||
if (column > 0) {
|
if (column > 0) {
|
||||||
@ -459,6 +461,7 @@ struct dnode **list_dir(char *path)
|
|||||||
dir = opendir(path);
|
dir = opendir(path);
|
||||||
if (dir == NULL) {
|
if (dir == NULL) {
|
||||||
errorMsg("%s: %s\n", path, strerror(errno));
|
errorMsg("%s: %s\n", path, strerror(errno));
|
||||||
|
status = EXIT_FAILURE;
|
||||||
return(NULL); /* could not open the dir */
|
return(NULL); /* could not open the dir */
|
||||||
}
|
}
|
||||||
while ((entry = readdir(dir)) != NULL) {
|
while ((entry = readdir(dir)) != NULL) {
|
||||||
@ -477,6 +480,7 @@ struct dnode **list_dir(char *path)
|
|||||||
if (follow_links == TRUE) {
|
if (follow_links == TRUE) {
|
||||||
if (stat(cur->fullname, &cur->dstat)) {
|
if (stat(cur->fullname, &cur->dstat)) {
|
||||||
errorMsg("%s: %s\n", cur->fullname, strerror(errno));
|
errorMsg("%s: %s\n", cur->fullname, strerror(errno));
|
||||||
|
status = EXIT_FAILURE;
|
||||||
free(cur->fullname);
|
free(cur->fullname);
|
||||||
free(cur);
|
free(cur);
|
||||||
continue;
|
continue;
|
||||||
@ -485,6 +489,7 @@ struct dnode **list_dir(char *path)
|
|||||||
#endif
|
#endif
|
||||||
if (lstat(cur->fullname, &cur->dstat)) { /* get file stat info into node */
|
if (lstat(cur->fullname, &cur->dstat)) { /* get file stat info into node */
|
||||||
errorMsg("%s: %s\n", cur->fullname, strerror(errno));
|
errorMsg("%s: %s\n", cur->fullname, strerror(errno));
|
||||||
|
status = EXIT_FAILURE;
|
||||||
free(cur->fullname);
|
free(cur->fullname);
|
||||||
free(cur);
|
free(cur);
|
||||||
continue;
|
continue;
|
||||||
@ -791,6 +796,7 @@ extern int ls_main(int argc, char **argv)
|
|||||||
if (follow_links == TRUE) {
|
if (follow_links == TRUE) {
|
||||||
if (stat(av[oi], &cur->dstat)) {
|
if (stat(av[oi], &cur->dstat)) {
|
||||||
errorMsg("%s: %s\n", av[oi], strerror(errno));
|
errorMsg("%s: %s\n", av[oi], strerror(errno));
|
||||||
|
status = EXIT_FAILURE;
|
||||||
free(cur->fullname);
|
free(cur->fullname);
|
||||||
free(cur);
|
free(cur);
|
||||||
continue;
|
continue;
|
||||||
@ -799,6 +805,7 @@ extern int ls_main(int argc, char **argv)
|
|||||||
#endif
|
#endif
|
||||||
if (lstat(av[oi], &cur->dstat)) { /* get file info into node */
|
if (lstat(av[oi], &cur->dstat)) { /* get file info into node */
|
||||||
errorMsg("%s: %s\n", av[oi], strerror(errno));
|
errorMsg("%s: %s\n", av[oi], strerror(errno));
|
||||||
|
status = EXIT_FAILURE;
|
||||||
free(cur->fullname);
|
free(cur->fullname);
|
||||||
free(cur);
|
free(cur);
|
||||||
continue;
|
continue;
|
||||||
@ -842,7 +849,7 @@ extern int ls_main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return(0);
|
return(status);
|
||||||
|
|
||||||
print_usage_message:
|
print_usage_message:
|
||||||
usage(ls_usage);
|
usage(ls_usage);
|
||||||
|
Loading…
Reference in New Issue
Block a user