mirror of
https://github.com/sheumann/hush.git
synced 2024-12-24 12:29:47 +00:00
Patch from Denis Vlasenko to add xstat() and use it.
This commit is contained in:
parent
965030e35a
commit
c5b1d4d6b1
@ -103,9 +103,7 @@ int gunzip_main(int argc, char **argv)
|
|||||||
src_fd = bb_xopen(old_path, O_RDONLY);
|
src_fd = bb_xopen(old_path, O_RDONLY);
|
||||||
|
|
||||||
/* Get the time stamp on the input file. */
|
/* Get the time stamp on the input file. */
|
||||||
if (stat(old_path, &stat_buf) < 0) {
|
xstat(old_path, &stat_buf);
|
||||||
bb_error_msg_and_die("Couldn't stat file %s", old_path);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check that the input is sane. */
|
/* Check that the input is sane. */
|
||||||
|
@ -165,8 +165,7 @@ int date_main(int argc, char **argv)
|
|||||||
|
|
||||||
if(filename) {
|
if(filename) {
|
||||||
struct stat statbuf;
|
struct stat statbuf;
|
||||||
if(stat(filename,&statbuf))
|
xstat(filename,&statbuf);
|
||||||
bb_perror_msg_and_die("File '%s' not found.", filename);
|
|
||||||
tm=statbuf.st_mtime;
|
tm=statbuf.st_mtime;
|
||||||
} else time(&tm);
|
} else time(&tm);
|
||||||
memcpy(&tm_time, localtime(&tm), sizeof(tm_time));
|
memcpy(&tm_time, localtime(&tm), sizeof(tm_time));
|
||||||
|
@ -230,7 +230,7 @@ static struct dnode *my_stat(char *fullname, char *name)
|
|||||||
rc = getfilecon(fullname,&sid);
|
rc = getfilecon(fullname,&sid);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
rc = stat(fullname, &dstat);
|
rc = stat(fullname, &dstat);
|
||||||
if(rc) {
|
if(rc) {
|
||||||
bb_perror_msg("%s", fullname);
|
bb_perror_msg("%s", fullname);
|
||||||
status = EXIT_FAILURE;
|
status = EXIT_FAILURE;
|
||||||
|
@ -105,9 +105,7 @@ int uuencode_main(int argc, char **argv)
|
|||||||
switch (argc - optind) {
|
switch (argc - optind) {
|
||||||
case 2:
|
case 2:
|
||||||
src_stream = bb_xfopen(argv[optind], "r");
|
src_stream = bb_xfopen(argv[optind], "r");
|
||||||
if (stat(argv[optind], &stat_buf) < 0) {
|
xstat(argv[optind], &stat_buf);
|
||||||
bb_perror_msg_and_die("stat");
|
|
||||||
}
|
|
||||||
mode = stat_buf.st_mode & (S_IRWXU | S_IRWXG | S_IRWXO);
|
mode = stat_buf.st_mode & (S_IRWXU | S_IRWXG | S_IRWXO);
|
||||||
if (src_stream == stdout) {
|
if (src_stream == stdout) {
|
||||||
puts("NULL");
|
puts("NULL");
|
||||||
|
@ -53,8 +53,8 @@ pid_is_exec(pid_t pid, const char *name)
|
|||||||
char buf[32];
|
char buf[32];
|
||||||
struct stat sb, exec_stat;
|
struct stat sb, exec_stat;
|
||||||
|
|
||||||
if (name && stat(name, &exec_stat))
|
if (name)
|
||||||
bb_perror_msg_and_die("stat %s", name);
|
xstat(name, &exec_stat);
|
||||||
|
|
||||||
sprintf(buf, "/proc/%d/exe", pid);
|
sprintf(buf, "/proc/%d/exe", pid);
|
||||||
if (stat(buf, &sb) != 0)
|
if (stat(buf, &sb) != 0)
|
||||||
|
@ -274,15 +274,13 @@ int find_main(int argc, char **argv)
|
|||||||
xdev_dev = xmalloc ( xdev_count * sizeof( dev_t ));
|
xdev_dev = xmalloc ( xdev_count * sizeof( dev_t ));
|
||||||
|
|
||||||
if ( firstopt == 1 ) {
|
if ( firstopt == 1 ) {
|
||||||
if ( stat ( ".", &stbuf ) < 0 )
|
xstat ( ".", &stbuf );
|
||||||
bb_error_msg_and_die("could not stat '.'" );
|
|
||||||
xdev_dev [0] = stbuf. st_dev;
|
xdev_dev [0] = stbuf. st_dev;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
||||||
for (i = 1; i < firstopt; i++) {
|
for (i = 1; i < firstopt; i++) {
|
||||||
if ( stat ( argv [i], &stbuf ) < 0 )
|
xstat ( argv [i], &stbuf );
|
||||||
bb_error_msg_and_die("could not stat '%s'", argv [i] );
|
|
||||||
xdev_dev [i-1] = stbuf. st_dev;
|
xdev_dev [i-1] = stbuf. st_dev;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -292,8 +290,7 @@ int find_main(int argc, char **argv)
|
|||||||
struct stat stat_newer;
|
struct stat stat_newer;
|
||||||
if (++i == argc)
|
if (++i == argc)
|
||||||
bb_error_msg_and_die(msg_req_arg, "-newer");
|
bb_error_msg_and_die(msg_req_arg, "-newer");
|
||||||
if (stat (argv[i], &stat_newer) != 0)
|
xstat (argv[i], &stat_newer);
|
||||||
bb_error_msg_and_die("file %s not found", argv[i]);
|
|
||||||
newer_mtime = stat_newer.st_mtime;
|
newer_mtime = stat_newer.st_mtime;
|
||||||
#endif
|
#endif
|
||||||
#ifdef CONFIG_FEATURE_FIND_INUM
|
#ifdef CONFIG_FEATURE_FIND_INUM
|
||||||
|
@ -122,6 +122,8 @@ extern FILE *bb_xfopen(const char *path, const char *mode);
|
|||||||
extern int bb_fclose_nonstdin(FILE *f);
|
extern int bb_fclose_nonstdin(FILE *f);
|
||||||
extern void bb_fflush_stdout_and_exit(int retval) ATTRIBUTE_NORETURN;
|
extern void bb_fflush_stdout_and_exit(int retval) ATTRIBUTE_NORETURN;
|
||||||
|
|
||||||
|
extern void xstat(const char *filename, struct stat *buf);
|
||||||
|
|
||||||
#define BB_GETOPT_ERROR 0x80000000UL
|
#define BB_GETOPT_ERROR 0x80000000UL
|
||||||
extern const char *bb_opt_complementally;
|
extern const char *bb_opt_complementally;
|
||||||
extern const struct option *bb_applet_long_options;
|
extern const struct option *bb_applet_long_options;
|
||||||
|
@ -26,7 +26,7 @@ LIBBB-y:= \
|
|||||||
restricted_shell.c run_parts.c run_shell.c safe_read.c safe_write.c \
|
restricted_shell.c run_parts.c run_shell.c safe_read.c safe_write.c \
|
||||||
safe_strncpy.c setup_environment.c sha1.c simplify_path.c \
|
safe_strncpy.c setup_environment.c sha1.c simplify_path.c \
|
||||||
trim.c u_signal_names.c vdprintf.c verror_msg.c \
|
trim.c u_signal_names.c vdprintf.c verror_msg.c \
|
||||||
vherror_msg.c vperror_msg.c wfopen.c xconnect.c xgetcwd.c \
|
vherror_msg.c vperror_msg.c wfopen.c xconnect.c xgetcwd.c xstat.c \
|
||||||
xgethostbyname.c xgethostbyname2.c xreadlink.c xregcomp.c xgetlarg.c \
|
xgethostbyname.c xgethostbyname2.c xreadlink.c xregcomp.c xgetlarg.c \
|
||||||
get_terminal_width_height.c fclose_nonstdin.c fflush_stdout_and_exit.c \
|
get_terminal_width_height.c fclose_nonstdin.c fflush_stdout_and_exit.c \
|
||||||
getopt_ulflags.c default_error_retval.c wfopen_input.c speed_table.c \
|
getopt_ulflags.c default_error_retval.c wfopen_input.c speed_table.c \
|
||||||
|
@ -76,9 +76,7 @@ int run_parts(char **args, const unsigned char test_mode, char **env)
|
|||||||
|
|
||||||
filename = concat_path_file(arg0, namelist[i]->d_name);
|
filename = concat_path_file(arg0, namelist[i]->d_name);
|
||||||
|
|
||||||
if (stat(filename, &st) < 0) {
|
xstat(filename, &st);
|
||||||
bb_perror_msg_and_die("failed to stat component %s", filename);
|
|
||||||
}
|
|
||||||
if (S_ISREG(st.st_mode) && !access(filename, X_OK)) {
|
if (S_ISREG(st.st_mode) && !access(filename, X_OK)) {
|
||||||
if (test_mode) {
|
if (test_mode) {
|
||||||
puts(filename);
|
puts(filename);
|
||||||
|
11
libbb/xstat.c
Normal file
11
libbb/xstat.c
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
/*
|
||||||
|
* xstat.c - a stat() which dies on failure with meaningful error message
|
||||||
|
*/
|
||||||
|
#include <unistd.h>
|
||||||
|
#include "libbb.h"
|
||||||
|
|
||||||
|
void xstat(const char *name, struct stat *stat_buf)
|
||||||
|
{
|
||||||
|
if (stat(name, stat_buf))
|
||||||
|
bb_perror_msg_and_die("Can't stat '%s'", name);
|
||||||
|
}
|
@ -1871,8 +1871,7 @@ static void process_dev (char *devname)
|
|||||||
#ifndef HDIO_DRIVE_CMD
|
#ifndef HDIO_DRIVE_CMD
|
||||||
int force_operation = 0;
|
int force_operation = 0;
|
||||||
#endif
|
#endif
|
||||||
if (stat(devname,&stat_buf))
|
xstat(devname,&stat_buf);
|
||||||
bb_perror_msg_and_die(devname);
|
|
||||||
|
|
||||||
switch(major(stat_buf.st_rdev))
|
switch(major(stat_buf.st_rdev))
|
||||||
{
|
{
|
||||||
|
@ -23,8 +23,7 @@ static int swap_enable_disable(const char *device)
|
|||||||
int status;
|
int status;
|
||||||
struct stat st;
|
struct stat st;
|
||||||
|
|
||||||
if (stat(device, &st) < 0)
|
xstat(device, &st);
|
||||||
bb_perror_msg_and_die("cannot stat %s", device);
|
|
||||||
|
|
||||||
/* test for holes */
|
/* test for holes */
|
||||||
if (S_ISREG(st.st_mode))
|
if (S_ISREG(st.st_mode))
|
||||||
|
Loading…
Reference in New Issue
Block a user