mirror of
https://git.proxmox.com/git/mirror_zfs.git
synced 2026-05-23 19:04:45 +03:00
Prune /*NOTREACHED*/
This includes a simplification of mkbusy and format correctness in zhack and ztest Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov> Signed-off-by: Ahelenia Ziemiańska <nabijaczleweli@nabijaczleweli.xyz> Issue #12201
This commit is contained in:
@@ -4,3 +4,5 @@ pkgexecdir = $(datadir)/@PACKAGE@/zfs-tests/bin
|
||||
|
||||
pkgexec_PROGRAMS = mkbusy
|
||||
mkbusy_SOURCES = mkbusy.c
|
||||
|
||||
mkbusy_LDADD = $(abs_top_builddir)/lib/libzfs_core/libzfs_core.la
|
||||
|
||||
@@ -29,19 +29,21 @@
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include <libzutil.h>
|
||||
|
||||
static void
|
||||
|
||||
static __attribute__((noreturn)) void
|
||||
usage(char *progname)
|
||||
{
|
||||
(void) fprintf(stderr, "Usage: %s <dirname|filename>\n", progname);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
static void
|
||||
fail(char *err, int rval)
|
||||
static __attribute__((noreturn)) void
|
||||
fail(char *err)
|
||||
{
|
||||
perror(err);
|
||||
exit(rval);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -50,7 +52,7 @@ daemonize(void)
|
||||
pid_t pid;
|
||||
|
||||
if ((pid = fork()) < 0) {
|
||||
fail("fork", 1);
|
||||
fail("fork");
|
||||
} else if (pid != 0) {
|
||||
(void) fprintf(stdout, "%ld\n", (long)pid);
|
||||
exit(0);
|
||||
@@ -65,24 +67,14 @@ daemonize(void)
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
int ret, c;
|
||||
int c;
|
||||
boolean_t isdir = B_FALSE;
|
||||
boolean_t fflag = B_FALSE;
|
||||
boolean_t rflag = B_FALSE;
|
||||
struct stat sbuf;
|
||||
char *fpath = NULL;
|
||||
char *prog = argv[0];
|
||||
|
||||
while ((c = getopt(argc, argv, "fr")) != -1) {
|
||||
while ((c = getopt(argc, argv, "")) != -1) {
|
||||
switch (c) {
|
||||
/* Open the file or directory read only */
|
||||
case 'r':
|
||||
rflag = B_TRUE;
|
||||
break;
|
||||
/* Run in the foreground */
|
||||
case 'f':
|
||||
fflag = B_TRUE;
|
||||
break;
|
||||
default:
|
||||
usage(prog);
|
||||
}
|
||||
@@ -94,84 +86,68 @@ main(int argc, char *argv[])
|
||||
if (argc != 1)
|
||||
usage(prog);
|
||||
|
||||
if ((ret = stat(argv[0], &sbuf)) != 0) {
|
||||
char *arg, *dname, *fname;
|
||||
int arglen;
|
||||
char *slash;
|
||||
int rc;
|
||||
if (stat(argv[0], &sbuf) != 0) {
|
||||
char *arg;
|
||||
const char *dname, *fname;
|
||||
size_t arglen;
|
||||
ssize_t dnamelen;
|
||||
|
||||
/*
|
||||
* The argument supplied doesn't exist. Copy the path, and
|
||||
* remove the trailing slash if present.
|
||||
*/
|
||||
if ((arg = strdup(argv[0])) == NULL)
|
||||
fail("strdup", 1);
|
||||
fail("strdup");
|
||||
arglen = strlen(arg);
|
||||
if (arg[arglen - 1] == '/')
|
||||
arg[arglen - 1] = '\0';
|
||||
|
||||
/*
|
||||
* Get the directory and file names, using the current directory
|
||||
* if the provided path doesn't specify a directory at all.
|
||||
*/
|
||||
if ((slash = strrchr(arg, '/')) == NULL) {
|
||||
dname = strdup(".");
|
||||
fname = strdup(arg);
|
||||
} else {
|
||||
*slash = '\0';
|
||||
dname = strdup(arg);
|
||||
fname = strdup(slash + 1);
|
||||
}
|
||||
free(arg);
|
||||
if (dname == NULL || fname == NULL)
|
||||
fail("strdup", 1);
|
||||
/* Get the directory and file names. */
|
||||
fname = zfs_basename(arg);
|
||||
dname = arg;
|
||||
if ((dnamelen = zfs_dirnamelen(arg)) != -1)
|
||||
arg[dnamelen] = '\0';
|
||||
else
|
||||
dname = ".";
|
||||
|
||||
/* The directory portion of the path must exist */
|
||||
if ((ret = stat(dname, &sbuf)) != 0 || !(sbuf.st_mode &
|
||||
S_IFDIR))
|
||||
if (stat(dname, &sbuf) != 0 || !(sbuf.st_mode & S_IFDIR))
|
||||
usage(prog);
|
||||
|
||||
rc = asprintf(&fpath, "%s/%s", dname, fname);
|
||||
free(dname);
|
||||
free(fname);
|
||||
if (rc == -1 || fpath == NULL)
|
||||
fail("asprintf", 1);
|
||||
if (asprintf(&fpath, "%s/%s", dname, fname) == -1)
|
||||
fail("asprintf");
|
||||
|
||||
} else if ((sbuf.st_mode & S_IFMT) == S_IFREG ||
|
||||
(sbuf.st_mode & S_IFMT) == S_IFLNK ||
|
||||
(sbuf.st_mode & S_IFMT) == S_IFCHR ||
|
||||
(sbuf.st_mode & S_IFMT) == S_IFBLK) {
|
||||
fpath = strdup(argv[0]);
|
||||
} else if ((sbuf.st_mode & S_IFMT) == S_IFDIR) {
|
||||
fpath = strdup(argv[0]);
|
||||
isdir = B_TRUE;
|
||||
} else {
|
||||
usage(prog);
|
||||
}
|
||||
free(arg);
|
||||
} else
|
||||
switch (sbuf.st_mode & S_IFMT) {
|
||||
case S_IFDIR:
|
||||
isdir = B_TRUE;
|
||||
/* FALLTHROUGH */
|
||||
case S_IFLNK:
|
||||
case S_IFCHR:
|
||||
case S_IFBLK:
|
||||
if ((fpath = strdup(argv[0])) == NULL)
|
||||
fail("strdup");
|
||||
break;
|
||||
default:
|
||||
usage(prog);
|
||||
}
|
||||
|
||||
if (fpath == NULL)
|
||||
fail("strdup", 1);
|
||||
if (!isdir) {
|
||||
int fd;
|
||||
|
||||
if (isdir == B_FALSE) {
|
||||
int fd, flags;
|
||||
mode_t mode = S_IRUSR | S_IWUSR;
|
||||
|
||||
flags = rflag == B_FALSE ? O_CREAT | O_RDWR : O_RDONLY;
|
||||
|
||||
if ((fd = open(fpath, flags, mode)) < 0)
|
||||
fail("open", 1);
|
||||
if ((fd = open(fpath, O_CREAT | O_RDWR, 0600)) < 0)
|
||||
fail("open");
|
||||
} else {
|
||||
DIR *dp;
|
||||
|
||||
if ((dp = opendir(fpath)) == NULL)
|
||||
fail("opendir", 1);
|
||||
fail("opendir");
|
||||
}
|
||||
free(fpath);
|
||||
|
||||
if (fflag == B_FALSE)
|
||||
daemonize();
|
||||
daemonize();
|
||||
(void) pause();
|
||||
|
||||
/* NOTREACHED */
|
||||
return (0);
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@
|
||||
|
||||
#define FILE_MODE (S_ISVTX + S_IRUSR + S_IWUSR)
|
||||
|
||||
static void usage(void);
|
||||
static void usage(void) __attribute__((noreturn));
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
@@ -278,5 +278,4 @@ static void usage()
|
||||
(void) fprintf(stderr, gettext(
|
||||
"Usage: mkfile [-nv] <size>[g|k|b|m] <name1> [<name2>] ...\n"));
|
||||
exit(1);
|
||||
/* NOTREACHED */
|
||||
}
|
||||
|
||||
@@ -66,19 +66,15 @@ normal_writer(void *filename)
|
||||
err(1, "failed to open %s", file_path);
|
||||
}
|
||||
|
||||
char *buf = malloc(1);
|
||||
char buf;
|
||||
while (1) {
|
||||
write_num = write(fd, buf, 1);
|
||||
write_num = write(fd, &buf, 1);
|
||||
if (write_num == 0) {
|
||||
err(1, "write failed!");
|
||||
break;
|
||||
}
|
||||
lseek(fd, page_size, SEEK_CUR);
|
||||
}
|
||||
|
||||
if (buf) {
|
||||
free(buf);
|
||||
}
|
||||
}
|
||||
|
||||
static void *
|
||||
@@ -140,7 +136,7 @@ main(int argc, char **argv)
|
||||
int i = 0;
|
||||
|
||||
if (argc != 3) {
|
||||
(void) printf("usage: %s <normal write file name>"
|
||||
(void) printf("usage: %s <normal write file name> "
|
||||
"<map write file name>\n", argv[0]);
|
||||
exit(1);
|
||||
}
|
||||
@@ -156,7 +152,6 @@ main(int argc, char **argv)
|
||||
err(1, "pthread_create map_writer failed.");
|
||||
}
|
||||
|
||||
/* NOTREACHED */
|
||||
pthread_join(map_write_tid, NULL);
|
||||
return (0);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user